akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (int, int, int, []int, [][]int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	n, m, x := scanInt(sc), scanInt(sc), scanInt(sc)
	cs := make([]int, n)
	as := make([][]int, n)
	for i := 0; i < n; i++ {
		cs[i] = scanInt(sc)
		as[i] = make([]int, m)
		for j := 0; j < m; j++ {
			as[i][j] = scanInt(sc)
		}
	}
	return n, m, x, cs, as
}

func resolve(n, m, x int, cs []int, as [][]int) int {
	ok := false
	min := math.MaxInt64
	for bits := range bitCombinations(n) {
		cost := 0
		skils := make([]int, m)
		for i := 0; i < n; i++ {
			if bits>>uint(i)&1 == 1 {
				cost += cs[i]
				for j := 0; j < m; j++ {
					skils[j] += as[i][j]
				}
			}
		}
		cl := true
		for j := 0; j < m; j++ {
			if skils[j] < x {
				cl = false
			}
		}
		ok = ok || cl
		if cl && min > cost {
			min = cost
		}
	}
	if ok {
		return min
	}
	return -1
}

func bitCombinations(num int) chan uint {
	ch := make(chan uint)
	go func() {
		defer close(ch)
		for i := 0; i < 1<<uint(num); i++ {
			ch <- uint(i)
		}
	}()
	return ch
}

func bitCombinationsOverSubsets(nums ...int) chan uint {
	ch := make(chan uint)
	s := uint(0)
	for _, v := range nums {
		s |= 1 << uint(v)
	}
	go func() {
		defer close(ch)
		for bit := s; ; bit = (bit - 1) & s {
			ch <- uint(bit)
			if bit == 0 {
				break
			}
		}
	}()
	return ch
}

func bitCombinationsWithSize(num, size int) chan uint {
	ch := make(chan uint)
	bit := uint(1<<uint(size) - 1)
	go func() {
		defer close(ch)
		for ; bit < 1<<uint(num); bit = nextBitCombination(uint(bit)) {
			ch <- bit
		}
	}()
	return ch
}

func nextBitCombination(cur uint) uint {
	x := cur & -cur // rightest bit only         '10100' -> '00100'
	y := cur + x    // carry at rightest 1-block '10111' -> '11000'
	return (((cur & ^y) / x) >> 1) | y
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

int n;
long double p[3000], ans, dp[3000][3000];
int main() {
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>p[i];
        
    dp[0][0]=1;

    for(int i=1;i<=n;++i)
        dp[i][0]=dp[i-1][0]*(1-p[i]);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=i;++j)
            dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
        
   
    for(int i=(n/2)+1;i<=n;++i)
        ans+=dp[n][i];
        cout<<setprecision(10)<<ans;
    return 0;
}

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

int main()
{
    long long int n,m,i,j,k=0;
     map<long long int,long long int>mp;
     cin>>n;
     int a[n+10];
     for(i=1;i<=n;i++)mp[i]=0;
     for(i=2;i<=n;i++)
     {
         cin>>a[i];
         k=a[i];
         mp[k]++;
     }
     for(i=1;i<=n;i++)
     {
         cout<<mp[i]<<endl;
     }
     return 0;
}


Measured memory_bytes: 16908
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a,v=nm()
b,w=nm()
t=ni()

d=abs(a-b)
d2=(v-w)*t

if(d<=d2):
  print('YES')
else:
  print('NO')


Measured memory_bytes: 61936
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
#undef LOCAL
#ifdef LOCAL
template <class T, class S>
ostream &operator<<(ostream &str, const pair<T, S> &p) {
  return (str << "{" << p.fi << ", " << p.se << "}");
}
template <template <class...> class Container, class... T>
ostream &operator<<(ostream &str, const Container<T...> &vec) {
  str << '[';
  for (auto it = vec.begin(); it != vec.end(); it++) {
    if (it != vec.begin())
      str << ", ";
    str << *it;
  }
  str << ']';
  return str;
}
#define var(x) "[" << #x << ": " << x << "] "
struct dbg {
  dbg() { cout << "  "; }
  ~dbg() { cout << endl; }
  template <class T> dbg &operator<<(T oth) {
    cout << oth;
    return *this;
  }
};
#else
#define var(x) 0
struct dbg {
  template <class T> dbg &operator<<(T oth) { return *this; }
};
#endif
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  auto solve = [&]() {
    int n, k;
    cin >> n >> k;
    vector<ll> pos, neg;
    for (int i = 0; i < n; i++) {
      ll d;
      cin >> d;
      if (d >= 0)
        pos.pb(d);
      else
        neg.pb(-d);
    }
    sort(neg.rbegin(), neg.rend());
    sort(pos.rbegin(), pos.rend());
    const ll mod = (ll)(1e9 + 7);
    
    if (n == k) {
      ll m1 = ll(1e9 + 6);
      ll ans = 1;
      for (auto g : pos)
        ans = (ans * g) % mod;
      for (auto g : neg)
        ans = (((ans * g) % mod) * m1) % mod;
      cout << ans << '\n';
      return;
    }

    if (pos.empty()) {
      ll ans = 1;
      if (k & 1) {
        for (int i = 0; i < k; i++)
          ans = (ans * neg[int(neg.size()) - 1 - i]) % mod;
        if (ans)
          ans = mod - ans;
      } else {
        for (int i = 0; i < k; i++)
          ans = (ans * neg[i]) % mod;
      }
      cout << ans << '\n';
    } else {
      int pos_taken = min(k, (int)pos.size());
      int neg_taken = k - pos_taken;
      if ((neg_taken & 1) && pos_taken != pos.size())
        --neg_taken, ++pos_taken;
      if ((neg_taken & 1) && neg_taken < (int)neg.size() && pos_taken == pos.size())
        ++neg_taken, --pos_taken;
      dbg() << var(pos_taken) << var(neg_taken);
      while (pos_taken >= 2 && neg_taken + 1 < (int)neg.size()) {
        ll pos_give = pos[pos_taken - 1] * pos[pos_taken - 2];
        dbg() << var(neg) << var(neg_taken);
        ll neg_give = neg[neg_taken] * neg[neg_taken + 1];
        if (neg_give < pos_give)
          break;
        pos_taken -= 2, neg_taken += 2;
      }
      ll ans = 1;

      for (int i = 0; i < pos_taken; i++)
        ans = (ans * pos[i]) % mod;
      for (int i = 0; i < neg_taken; i++)
        ans = (ans * neg[i]) % mod;
      cout << ans << '\n';
    }
  };
  int t;
  t = 1;
  while (t--)
    solve();
  return 0;
}


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

bool issame(char a,char b){
     if(a=='(')return b==')';
     if(a=='[')return b==']';
}

int main(){
     while(1){
	  string str;
	  getline(cin,str);
	  if(str[0]=='.')return 0;
	  char in;
	  stack<char> sta;
	  bool iscorrect=true;
	  int count=0;
	  while(in=str[count],in!='.'){
	       //cout<<in;
	       if(in=='('||in=='['){
		    sta.push(in);
		    //cout<<in<<endl;
	       }else if(in==')'||in==']'){
		    if(sta.empty()){
			 iscorrect=false;
			 break;
		    }
		    if(!issame(sta.top(),in)){
			 iscorrect=false;
			 break;
		    }
		    sta.pop();
	       }
	       count++;
	  }
	  cout<<((iscorrect&&sta.empty())? "yes":"no")<<endl;
     }
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


vector<vector<ll>> multmat(vector<vector<ll>> a, vector<vector<ll>> b,ll n){
  vector<vector<ll>> temp(n,vector<ll> (n,0));
  rep(i,n)rep(j,n)rep(k,n){
    ll now=a[i][j]*b[j][k];
    now%=mod;
    temp[i][k]+=now;
    temp[i][k]%=mod;
  }
  return temp;
}


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

  vector<vector<ll>> v(n,vector<ll>(n,ll(0)));
  v[n-1][n-1]=1;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      //mint temp;
      //cin>>temp;
      cin>>v[i][j];
    }
  }

  vector<vector<ll>> p(n,vector<ll>(n,0));
  rep(i,n)p[i][i]=1;
  while(k){
    if(k%2==1)p=multmat(p,v,n);
    k/=2;
    v=multmat(v,v,n);
  }

  ll ans=0;
  rep(i,n)rep(j,n){
    ans+=p[i][j];
    ans%=mod;
  }
  cout<<ans;

}


Measured memory_bytes: 3732
/* 
Name: Mohit Khare
CSE - MNNIT Allahabad
never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
#define speed ios_base::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<"#a "<<a<<endl;
#define pr2(a,b) cout<<"#a "<< a << " #b "<<b<<endl;

#define PI 3.1415926535897932384626
#define mod 1000000007
 
const ll linf=99999999999999999ll;
const int maxn=1e6+10;
 
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

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

vector<ll> divisors;
ll n,m,ans;


int main() {
    // freopen("input.in","r",stdin);
    // freopen("output.txt","w",stdout);
    cin >> n >> m;

    for (int i = 1;i*i <= m;i++) 
    { 
        if (m%i == 0) 
        {   
            if (m/i == i) 
                divisors.push_back(i);
  
            else {
                divisors.push_back(i);
                divisors.push_back(m/i); 
            }
        } 
    }
    
    for(int i = 0;i < divisors.size();i++) {
        if( m >= (n * divisors[i]))
            ans = max(ans,divisors[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MODSIZE 1000000007

long long a[300007];

int main(){
  int n,i,j;
  long long ans = 0;
  long long x = 0;
  long long now;

  scanf("%d", &n);

  for(i = 0;i < n;i++) scanf("%lld", &a[i]);

  for(i = 0;i < 60;i++){
    x = 0;
    for(j = 0;j < n;j++) if(a[j] >> i & 1) x++;
    now = x*(n - x) % MODSIZE;
    for(j = 0;j < i;j++) now = now*2 % MODSIZE;
    ans += now;
    ans %= MODSIZE;
  }

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

  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N;
int main(){
  cin>>N;
  vector<P>A(N);
  for(int i=0;i<N;i++){
  ll x,l;cin>>x>>l;
    P p(x+l,x-l);
    A[i]=p;
  }sort(A.begin(),A.end());
  ll ans=0;ll r=-1000000000000;
  for(int i=0;i<N;i++)
  if(r<=A[i].second){ans++;
    r=A[i].first;
                    }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4828
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define FOR(__I,__N) for (int __I = 0; __I < __N; ++__I)

typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64, int64> pll;
typedef double db;
typedef long double ldb;

const int INF = 0x3f3f3f3f;
const int64 INF64 = 0x3f3f3f3f3f3f3f3fLL;

const int MOD = 1000000007;


int solve(){

	int ret = 0;

	return ret;
}


int a[5];
int main(){
	FOR(i,5)	cin >> a[i];

	int ans = min_element(a,a+5)-a+1;	
	printf("%d\n",ans);

    //int ans = solve();
    //printf("%d\n",ans);

}





Measured memory_bytes: 3764
n = int(input())
s = input()

shiro_num = s.count(".")
kuro_num = n - shiro_num

right_kuro_num = kuro_num
right_siro_num = shiro_num

result = shiro_num

for e in s:
    if e == '.':
        right_siro_num -= 1
    else:
        right_kuro_num -= 1
    num = right_siro_num + kuro_num - right_kuro_num
    result = min(num,result)

print(result)

Measured memory_bytes: 3500
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int a,b;
  cin >> a >> b;
  int ans = max(2*a-1,max(a+b,2*b-1));
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
Broken = [0] * (N + 2)
for i in range(M):
    ai = int(input())
    Broken[ai] = 1


dp = [0] * (N + 1)
dp[0] = 1

for i in range(N):
    if (Broken[i + 1] == 0) and (i + 1) <= N:
        dp[i + 1] += dp[i]
        dp[i + 1] %= MOD

    if (Broken[i + 2] == 0) and (i + 2) <= N:
        dp[i + 2] += dp[i]
        dp[i + 2] %= MOD

print(dp[N] % MOD)


Measured memory_bytes: 7668
N = int(input())
d = [0] * N
for i in range(N):
    d[i] = int(input())

d.sort(reverse = True)

count = 0

for i in range(N):
    if i == 0:
        count += 1
    elif d[i] < d[i-1]:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  double x1, y1, x2, y2, xq, yq, a, b, c, d, e, x, y;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) == 6) {
    a = y2 - y1;
    b = x1 - x2;
    c = x2*y1 - x1*y2;
    d = a*xq + b*yq + c;
    e = d / (a*a + b*b);
    x = xq - 2*a*e;
    y = yq - 2*b*e;
    printf("%.6lf %.6lf\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 1084
#include<iostream>
using namespace std;
#define ll long long
int n;
ll a[3007],dp[3007][3007],pre[3007];
ll dfs(int l,int r){
	if(l==r){
		return a[l];
	}
	if(dp[l][r]!=0)return dp[l][r];
	return dp[l][r]=(pre[r]-pre[l-1])-min(dfs(l+1,r),dfs(l,r-1));
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pre[i]=pre[i-1]+a[i];
	}
	ll ans1=dfs(1,n);
	ll ans2=pre[n]-ans1;
	printf("%lld\n",ans1-ans2);
}


Measured memory_bytes: 49712
s=input()
n=len(s)
ans=[1]*n
for i in range(1,n-1):
	if s[i-1]==s[i]=="R":
		ans[i+1]+=ans[i-1]
		ans[i-1]=0
for i in range(n-2,0,-1):
	if s[i]==s[i+1]=="L":
		ans[i-1]+=ans[i+1]
		ans[i+1]=0
print(*ans)

Measured memory_bytes: 6400
function Main(input){
  var n = parseInt(input,10);
  if(n < 1200){
    console.log('ABC');
  }else if(n < 2800){
    console.log('ARC');
  }else{
    console.log('AGC');
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int a, b;
  cin >> a >> b;

  if ( a > 0 && b > 0) {
    if ( (a * b) % 2 == 0 ) {
      cout << "Even" << endl;
    }
    if ( (a * b) % 2 == 1 ) {
      cout << "Odd" << endl;
    }
  }
}

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

// macros
#define overload_rep(_1, _2, _3, name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations

// solve
int main(){

    int N;
    cin >> N;
    cout << (N - 1) / 2 << '\n';
    return 0;

}


Measured memory_bytes: 256
def main():
    # import sys
    # readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    M = 0
    grid = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            m = abs(A[i][j] - B[i][j])
            grid[i][j] = m
            M = max(M, m)

    dp = [[0] * W for _ in range(H)]
    dp[0][0] = (1 << grid[0][0])

    for i in range(H):
        for j in range(W):
            here = dp[i][j]
            if i < H - 1:
                nk = grid[i + 1][j]
                dp[i + 1][j] |= (here << nk) | (here >> nk)
                for k in range(1, nk + 1):
                    if (here >> k) & 1:
                        dp[i + 1][j] |= (1 << (nk - k))
            if j < W - 1:
                nk = grid[i][j + 1]
                dp[i][j + 1] |= (here << nk) | (here >> nk)
                for k in range(1, nk + 1):
                    if (here >> k) & 1:
                        dp[i][j + 1] |= (1 << (nk - k))

    k = dp[-1][-1]
    ans = 0
    while k > 0:
        if k & 1:
            print(ans)
            break
        k >>= 1
        ans += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 55516
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e], dp[e];

//beginner 1999 129

int n, m;

int main()
{
     cin >> n >> m;
     for(int i=1; i<=m; i++){
         int x;
         cin >> x;
         a[x] = 1;
     }
     dp[0] = 1;
     for(int i=1; i<=n; i++){
         if(a[i-1] == 0) dp[i] += dp[i-1];
         if(a[i-2] == 0) dp[i] += dp[i-2];
         dp[i] %= mod;
     }
     cout << dp[n];
}


Measured memory_bytes: 5132
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
//const ll mod=1e9+7 ;

ll dp[101010],ans[101010];
vector<int> v[101010];
ll mod;
struct LazySegmentTree{
private:
   int n;
   vector<ll> node,lazy;
public:
   LazySegmentTree(int sz,ll init=1){
      n=1;
      while(n<sz)n*=2;
      node.resize(2*n-1,init);
      lazy.resize(2*n-1,1);
   }

   void eval(int k,int l,int r){
      if(lazy[k]!=1)node[k]=node[k]*lazy[k]%mod;
      if(r-l>1){
          (lazy[2*k+1]*=lazy[k])%=mod;
          (lazy[2*k+2]*=lazy[k])%=mod;
      }
      lazy[k]=1;
   }
      //[a,b)にxを加算
   void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
       if(r<0)r=n;
       eval(k,l,r);
       if(r<=a||b<=l)return;
       if(a<=l&&r<=b){
          (lazy[k]*=x)%=mod;
          eval(k,l,r);
       }
       else {
          add(a,b,x,2*k+1,l,(l+r)/2);
          add(a,b,x,2*k+2,(l+r)/2,r);
          node[k]=node[2*k+1]*node[2*k+2]%mod;
        }
   }
   //[a,b)での和を返す
   ll get(int a,int b,int k=0,int l=0,int r=-1){
      if(r<0)r=n;
      eval(k,l,r);
      if(r<=a||b<=l)return 1;
      if(a<=l&&r<=b)return node[k];
      ll xl=get(a,b,2*k+1,l,(l+r)/2);
      ll xr=get(a,b,2*k+2,(l+r)/2,r);
      return xl*xr%mod;
   }
};


ll dfs1(int x,int p){
    ll ret=1;
    int n=v[x].size();
    rep(i,n){
        int to=v[x][i];
        if(to==p)continue;
        ll res=dfs1(to,x);
        (ret*=(res+1))%=mod;
    }
    dp[x]=ret;
    return ret;
}


void dfs2(int x,int p){
    ll ret=ans[x]+1;
    int n=v[x].size();
    LazySegmentTree sg(n);
    rep(i,n){
        int to=v[x][i];
        if(to==p)continue;
        (ret*=(dp[to]+1))%=mod;
        sg.add(0,i,dp[to]+1);
        sg.add(i+1,n,dp[to]+1);
    }
    sg.add(0,n,ans[x]+1);
    rep(i,n){
        int to=v[x][i];
        if(to==p)continue;
        else ans[to]=sg.get(i,i+1);
    }
    for(auto to:v[x]){
        if(to==p)continue;
        dfs2(to,x);
    }
    ans[x]=ret%mod;
}
int main(){
    int n;
    cin>>n>>mod;
    rep(i,n-1){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs1(0,-1);
    dfs2(0,-1);
    rep(i,n)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 30208
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n, a, b; cin >> n >> a >> b;
  vector<int> p(n + 2); REP (i, n) cin >> p[i + 1];
  p[n + 1] = n + 1;
  vector<int> dp(n + 2, 1e18);
  dp[0] = 0;
  REP (i, n + 2) {
    int acc = 0;
    for (int j = i - 1; j >= 0; j--) {
      if (p[j] > p[i]) {
        acc += a;
      } else {
        chmin(dp[p[i]], dp[p[j]] + acc);
        acc += b;
      }
    }
  }
  cout << dp.back() << endl;
}


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

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

const ll mod = 1000000007;

int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    // 圧縮
    vector<int> cnt(n,0);
    int idx = 0;
    int c = 1;
    if (s[0] == '0') {
        cnt[0] = 0;
        idx++;
    }
    rep(i,n-1) {
        if (s[i] != s[i+1]) {
            cnt[idx] = c;
            c = 1;
            idx++;
        } else {
            c++;
        }
    }
    cnt[idx] = c;
    idx++;
    if (s[n-1] == '0') {
        cnt[idx] = 0;
        idx++;
    }

    // 尺取り
    int ans = 0;
    int nsum = 0;
    if (2*k+1 >= idx) {
        for (int c:cnt) nsum += c;
        cout << nsum << endl;
        return 0;
    }
    rep(i,2*k+1) nsum += cnt[i];
    ans = nsum;
    for (int i = 2*k+1; i < idx; i += 2) {
        nsum = nsum - cnt[i-2*k-1] - cnt[i-2*k] + cnt[i] + cnt[i+1];
        ans = max(ans, nsum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3800
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
const ll MOD=1e9+7;
int main()
{
	int n, m;
	cin>>n>>m;
	int a[200], b[200];
	vector<int> g[20];
	for(int i=0; i<m; i++){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	ll p2[200];
	p2[0]=1;
	for(int i=1; i<=m; i++) p2[i]=p2[i-1]*2%MOD;
	bool myon[1<<15]={};
	int c[1<<15]={};
	for(int i=0; i<(1<<n); i++){
		unionfind uf(n);
		for(int j=0; j<m; j++){
			if(i&(1<<a[j]) && i&(1<<b[j])){
				uf.unite(a[j], b[j]);
				c[i]++;
			}
		}
		if(!(i&1) || !(i&2)) continue;
		if(uf.same(0, 1)) continue;
		bool dame=0;
		for(int j=0; j<n; j++){
			if(i&(1<<j)){
				if(!uf.same(0, j) && !uf.same(1, j)){
					dame=1;
					break;
				}
			}
		}
		if(dame) continue;
		myon[i]=1;
	}
	ll dp[1<<15]={};
	dp[3]=1;
	for(int i=4; i<(1<<n); i++){
		if(!myon[i]) continue;
		dp[i]=p2[c[i]];
		for(int j=i; j>0; j=(j-1)&i){
			if(j==i || !myon[j]) continue;
			dp[i]+=MOD-dp[j]*p2[c[i-j]]%MOD;
			if(dp[i]>=MOD) dp[i]-=MOD;
		}
	}
	ll ans=p2[m];
	for(int i=0; i<(1<<n); i++){
		if(!myon[i]) continue;
		ans+=MOD-dp[i]*p2[c[(1<<n)-1-i]]%MOD;
		if(ans>=MOD) ans-=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

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

  int ans = 0;
  for(int i = 1; i < n-1; i++) {
    if(p[i] <= p[i+1] && p[i-1] <= p[i]) ans++;
    if(p[i] >= p[i+1] && p[i-1] >= p[i]) ans++;
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 60;
typedef tuple< int64, int, int > Pi;

struct edge
{
  int to, cost;
};

int main()
{
  int N, M, S1, S2, T;

  int64 dp[1000][101];

  while(cin >> N >> M >> S1 >> S2 >> T, N) {
    vector< edge > G[1000];
    --S1, --S2, --T;

    int edged = 0;
    for(int i = 0; i < M; i++) {
      int a, b;
      string c;
      cin >> a >> b >> c;
      --a, --b;
      if(c == "x") {
        G[a].emplace_back((edge) {b, -1});
        G[b].emplace_back((edge) {a, -1});
        ++edged;
      } else {
        G[a].emplace_back((edge) {b, stoi(c)});
        G[b].emplace_back((edge) {a, stoi(c)});
      }
    }

    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    fill_n(*dp, 101 * 1000, INF);
    dp[T][0] = 0;
    que.emplace(0, T, 0);
    while(!que.empty()) {
      int64 cost, now, slow;
      tie(cost, now, slow) = que.top();
      que.pop();
      if(cost > dp[now][slow]) continue;
      for(auto &e : G[now]) {
        int64 ncost = cost, nslow = slow;
        if(e.cost == -1) ++nslow;
        else ncost += e.cost;
        if(nslow > edged || ncost >= dp[e.to][nslow]) continue;
        dp[e.to][nslow] = ncost;
        que.emplace(ncost, e.to, nslow);
      }
    }

    vector< int64 > latte;
    latte.push_back(0);
    latte.push_back(10000000000000LL);
    for(int i = 0; i <= edged; i++) {
      for(int j = i + 1; j <= edged; j++) {
        latte.emplace_back((dp[S1][i] - dp[S1][j]) / (j - i));
        latte.emplace_back((dp[S2][i] - dp[S2][j]) / (j - i));
        latte.emplace_back((dp[S1][i] - dp[S2][j]) / (j - i));
        latte.emplace_back((dp[S2][i] - dp[S1][j]) / (j - i));
      }
    }

    int64 ret = INF;
    auto get = [&](int64 v)
    {
      v = max(v, 0LL);
      int64 aa = INF, bb = INF;
      for(int i = 0; i <= edged; i++) aa = min(aa, dp[S1][i] + i * v);
      for(int i = 0; i <= edged; i++) bb = min(bb, dp[S2][i] + i * v);
      return (llabs(aa - bb));
    };

    for(auto &cost : latte) ret = min(ret, get(cost));
    for(auto &cost : latte) ret = min(ret, get(cost + 1));

    cout << ret << endl;
  }
}

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

int main() {
    // your code goes here
    ll n,i,p[200005],mx=1e8,ans=0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> p[i];
        if(mx>p[i]) ans++;
        mx=min(mx,p[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <vector>
#include <functional>
#include <cassert>
#include <cmath>
#include <map>
#include <set>

using namespace std;

int Cases;
const int N = 2019;
int L, R;

int main() {
	cin >> L >> R;

	int x = L / N, y = R / N;
	if (x != y) {
		cout << 0 << endl;
		return 0;
	}
	int a = L % 2019, b = R % 2019;
	int ret = 2019;
	for (int i = a; i <= b; i++) {
		for (int j = i + 1; j <= b; j++) {
			ret = min(ret, i * j % 2019);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
L = len(S)
dp = [[False] * (L + 1) for _ in range(L + 1)]

# [left, right)
for i in range(L + 1):
    dp[i][i] = True

for w in range(3, L + 1, 3):
    for left in range(L - w + 1):
        right = left + w
        if S[left] != 'm' or S[right - 1] != 'w':
            continue
        for mid in range(left + 1, right):
            if S[mid] == 'e' and dp[left + 1][mid] and dp[mid + 1][right - 1]:
                dp[left][right] = True
                break
print("Cat" if dp[0][L] else "Rabbit")

Measured memory_bytes: 9428
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

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

int main() {

    int m, n;
    cin >> m >> n;
    vector<vector<char>> s(m, vector<char>(n));
    rep(i, m) rep(j, n) cin >> s[i][j];

    int ans = 0;
    Rep(y, 1, m) {
        rep(x, n) {
            if (s[y][x] != '-') continue;
            bool can = true;
            rep(i, 8) {
                int ty = y + dy[i];
                int tx = x + dx[i];

                if (ty < 0 || ty >= m) continue;
                if (tx < 0 || tx >= n) continue;

                if (s[ty][tx] == 'x') {
                    can = false;
                    break;
                }
            }
            // 左右
            int tx = x - 1;
            if (tx >= 0) can &= (s[y][tx] != 'o');
            tx = x + 1;
            if (tx < n) can &= (s[y][tx] != 'o');

            if (can) ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {
  vint a(3),b(3),c(3);
  for (ll i=0;i<3;i++) {
    cin >> a.at(i);
  }
  for (ll i=0;i<3;i++) {
    cin >> b.at(i);
  }
  for (ll i=0;i<3;i++) {
    cin >> c.at(i);
  }
  
  ll p=a.at(1)-a.at(0), q=a.at(2)-a.at(1), judge=0;
  if (b.at(1)-b.at(0)!=p) {
    judge=1;
  }
  if (b.at(2)-b.at(1)!=q) {
    judge=1;
  }
  if (c.at(1)-c.at(0)!=p) {
    judge=1;
  }
  if (c.at(2)-c.at(1)!=q) {
    judge=1;
  }
  
  if (judge==1) cout << "No";
  if (judge==0) cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i,cost,coin;
    cin>>cost;
    while(cost!=0){
        coin=0;
        cost=1000-cost;
        coin+=cost/500;
        cost%=500;
        coin+=cost/100;
        cost%=100;
        coin+=cost/50;
        cost%=50;
        coin+=cost/10;
        cost%=10;
        coin+=cost/5;
        cost%=5;
        coin+=cost;
        cout<<coin<<endl;
        cin>>cost;
    }
}

Measured memory_bytes: 3088
n, t = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
min = 1001
ans = 0
flag = 0
for i in a:
    if i[1] <= t and i[0] < min:
        min = i[0]
        flag = 1
if flag:
    print(min)
else:
    print("TLE")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

instr = input()
target = int(input())

# 部分文字列の一覧リストを作成
str_list = []
for i in range(len(instr)):

	# 開始位置はi+1以降(i > jはやる意味ない)
	for j in range(i+1, len(instr)+1):
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		str_list.append(instr[i:j])

		j += 1
	i += 1

# 重複削除
str_list = list(set(str_list))
# 昇順ソート
str_list.sort()

print(str_list[target-1])

Measured memory_bytes: 5068
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[][] card = new string[3][];
      card[0]=Console.ReadLine().Split(' ');
      card[1]=Console.ReadLine().Split(' ');
      card[2]=Console.ReadLine().Split(' ');
      int N=int.Parse(Console.ReadLine());
      bool flg=false;
      for(int i=1;i<=N;i++){
        string num=Console.ReadLine();
        for(int j=0;j<3;j++){
          for(int k=0;k<3;k++){
            if(card[j][k]==num){
              card[j][k]="○";
            }
           if((card[0][k]=="○")&&(card[1][k]=="○")&&(card[2][k]=="○")){
             flg=true;
           }
          }
          if(card[j][0]=="○"&&(card[j][1]=="○")&&(card[j][2]=="○")){
            flg=true;
          }
        }
        
      }
     if((card[0][0]=="○")&&(card[1][1]=="○")&&(card[2][2]=="○")){
       flg=true;
     }else if((card[0][2]=="○")&&(card[1][1]=="○")&&(card[2][0]=="○")){
       flg=true;
     }
      if(flg){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }
     
    }
    
  }

}


Measured memory_bytes: 27496
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n,m;
vector<ii>g[55];
bool tk[55];
void dfs(int v,int forb)
{
	if(tk[v])
		return;
	tk[v]=true;
	for(int i=0;i<g[v].size();i++)
	{
		ii u=g[v][i];
		if(u.second==forb)
			continue;
		dfs(u.first,forb);
	}
}
bool con(int forb)
{
	fill(tk,tk+55,false);
	dfs(1,forb);
	for(int i=1;i<=n;i++)
	{
		if(!tk[i])
			return false;
	}
	return true;
}
int main()
{
	int a,b;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].push_back(ii(b,i));
		g[b].push_back(ii(a,i));
	}
	int res=0;
	for(int i=0;i<m;i++)
	{
		if(!con(i))
			res++;
	}
	cout<<res;

	return 0;
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) (v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        vi x(n), y(n);
        for(int i = 0; i<n; i++){
            cin >> x[i] >> y[i];
        }
        sort(all(x)), sort(all(y));
        int ans;
        if(n%2==1){
            ans = y[n/2]-x[n/2]+1;
        }
        else{
            ans = y[n/2-1]+y[n/2]-(x[n/2-1]+x[n/2])+1;
        }
        cout<<ans<<endl;

return 0;
}



Measured memory_bytes: 4748
a,b=[int(i) for i in input().split()]

one=[1,3,5,7,8,10,12]
two=[4,6,9,1]
three=[2]

if a in one and b in one:
    print("Yes")
elif a in two and b in two:
    print("Yes")
elif a in three and b in three:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;


int main(){
	fast;
	ll a;
	cin >> a;
	if(a >= 30) cout << "Yes";
	else cout << "No";
	return 0;
}


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



using namespace std;



int main(){

  int n, k;

  cin >> n >> k;

  cin.ignore();



  // 1人のときは、分けるもくそもない

  if(k == 1){

    cout << 0 << endl;

    return 0;

  }



  // 均等に配った余りがそれ



  int ans = n - k;

  cout << ans << endl;

  return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int dp[100010];
vector<bool>safe(100010);
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<int>a(m); rep(i, m)cin >> a[i];
	rep(i, m)safe[a[i]] = true;
	dp[0] = 1;
	if (!safe[1])dp[1] = 1;
	FOR(i,2,n+1) {
		if (!safe[i - 1])dp[i] += dp[i - 1];
		if (!safe[i - 2])dp[i] += dp[i - 2];
		dp[i] %= MOD;
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{

    int h,w;
    int[][] map;
    int[][] wall_h;
    int[][] wall_s;

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    w = sc.nextInt();
	    h = sc.nextInt();
	    if(w==0 && h==0) break;

	    map = new int[h][w];
	    wall_h = new int[h][w-1];
	    wall_s = new int[h-1][w];
	    for(int i=0; i<h*2-1; i++){
		if(i%2==0){
		    for(int j=0; j<w-1; j++) wall_h[i/2][j] = sc.nextInt();
		}else{
		    for(int j=0; j<w; j++) wall_s[i/2][j] = sc.nextInt();
		}
	    }

	    bfs();

	    System.out.println(map[h-1][w-1]);
	}
    }

    void bfs(){
	LinkedList<Integer> xlist = new LinkedList<Integer>();
	LinkedList<Integer> ylist = new LinkedList<Integer>();
	xlist.add(0); ylist.add(0);
	map[0][0] = 1;
	while(xlist.size()>0){
	    int x = xlist.poll(), y = ylist.poll();
	    if(y+1<h && map[y+1][x]==0 && wall_s[y][x]==0){
		map[y+1][x] = map[y][x]+1;
		xlist.add(x); ylist.add(y+1);
	    }
	    if(y-1>=0 && map[y-1][x]==0 && wall_s[y-1][x]==0){
		map[y-1][x] = map[y][x]+1;
		xlist.add(x); ylist.add(y-1);
	    }
	    if(x+1<w && map[y][x+1]==0 && wall_h[y][x]==0){
		map[y][x+1] = map[y][x]+1;
		xlist.add(x+1); ylist.add(y);
	    }
	    if(x-1>=0 && map[y][x-1]==0 && wall_h[y][x-1]==0){
		map[y][x-1] = map[y][x]+1;
		xlist.add(x-1); ylist.add(y);
	    }
	}
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    while (a % 2 == 0) {
      ans++;
      a /= 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;

long long int d[301][301] = {};

int main() {

    long long int n, m, l;
    cin >> n >> m >> l;

    for ( long long int i = 0; i < n; i++ ) {
        for ( long long int j = 0; j < n; j++ ) {
            if ( j == i ) continue;
            d[i][j] = 1145141919LL;
        }
    }

    for ( long long int i = 0; i < m; i++ ) {
        long long int a ,b, c;
        cin >> a >> b >> c;
        if ( c > l ) continue;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }

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

    for ( long long int i = 0; i < n; i++ ) {
        for ( long long int j = 0; j < n; j++ ) {
            if ( d[i][j] <= l ) {
                d[i][j] = 1;
            } else {
                d[i][j] = 1145141919LL;
            }
        }
    }

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

    long long int q;
    cin >> q;
    vector< long long int > vs, vt;
    for ( long long int i = 0; i < q; i++ ) {
        long long int s, t;
        cin >> s >> t;
        s--;
        t--;
        vs.push_back( s );
        vt.push_back( t );
    }
    for ( long long int i = 0; i < q; i++ ) {
        if ( d[vs[i]][vt[i]] >= 1145141919LL ) {
            cout << -1 << endl;
        } else {
            cout << d[vs[i]][vt[i]] - 1 << endl;
        }
    }

    return 0;

}


Measured memory_bytes: 2924
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll s[40], n, m, ans = 0;
int main() {
	cin >> n >> m;
	REP(i, n) {
		int a; cin >> a;
		REP(i, a) {
			int b;
			cin >> b;
			s[b]++;
		}
	}
	REP(i, 40)if (s[i] == n)ans++;
	cout << ans << endl;
}



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

int main() {
    bool sieve[10001] = {};
    sieve[0] = sieve[1] = true;
    for (int i=2; i*i<10001; ++i) {
        if ( ! sieve[i]) {
            for (int j=i*i; j<10001; j+=i) {
                sieve[j] = true;
            }
        }
    }
    int n;
    while (cin >> n, n) {
        for (int i=n; i>=5; --i) {
            if ( ! sieve[i-2] && ! sieve[i]) {
                cout << i-2 << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1180
s=input()
mae=s[0]+s[1]
ato=s[2]+s[3]
if 1<=int(mae)<=12 and 1<=int(ato)<=12:
  print("AMBIGUOUS")
elif 1<=int(mae)<=12:
  print("MMYY")
elif 1<=int(ato)<=12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060