akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>

int main() {
    FAST

    #ifndef ONLINE_JUDGE
        // freopen("in", "r", stdin);
        // freopen("out", "w", stdout);
    #endif

    int n,la,lb;
    cin>>n;
    vector<VI> arr(n+3, VI(3)), dp(n+3, VI(VI(3, INT_MAX)));
    for(la=1;la<=n;la++){
        for(lb=0;lb<3;lb++)
            cin>>arr[la][lb];
    }

    for(la=0;la<3;la++)
        dp[1][la]=arr[1][la];

    for(la=2;la<=n;la++){
        dp[la][0]=arr[la][0]+max(dp[la-1][1], dp[la-1][2]);
        dp[la][1]=arr[la][1]+max(dp[la-1][0], dp[la-1][2]);
        dp[la][2]=arr[la][2]+max(dp[la-1][1], dp[la-1][0]);
    }

    cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<endl;

    return 0;
}

Measured memory_bytes: 14184
from copy import deepcopy
from itertools import product
import numpy as np

h,w,k = map(int,input().split())
F = []
for i in range(h):
  F.append(list(input()))
  
ans = 0
for hs in product([0,1],repeat=h):
  for ws in product([0,1],repeat=w):
    A = np.array(deepcopy(F))
    for i in range(h):
      if hs[i]:
        A[i,:] = '.'
    for j in range(w):
      if ws[j]:
        A[:,j] = '.'
    if np.sum(A=='#') == k:
      ans += 1
      
print(ans)      

Measured memory_bytes: 27272
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue

#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>


#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define FORl(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORN(i,n) for(int i=(0);i<(n);i++)
#define FORR(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................



int main()
{
    fast
    long  double a,b;
    cin>>a>>b;
    long  double prd=a*b;
    prd=floor(prd);
    cout<<(long long int)prd<<"\n";
    return 0;
}

Measured memory_bytes: 3748
from fractions import gcd
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]//=2
a=sorted(set(a))[::-1]
n=len(a)
b=a[0]
d=a[0]
e=a[0]
ans=m
for i in range(n-1):
  b=gcd(d,a[i+1])
  d=d*a[i+1]//b
  e=gcd(e,a[i+1])

c=m//d-m//(2*d)
for i in range(n):
  a[i]//=e
  if a[i]%2==0:
    c=0
    break

print(c)

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

typedef long long ll;


int main() {
	std::ios_base::sync_with_stdio(false);
	int s = 0, temp; 
  	for (int i =0; i<5; i++) {
    	cin >> temp;
      	s += temp;
    }
  	cout << 15 - s << '\n';
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int x, y, z, k; cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];

    vector<ll> ab;
    rep(i, x) rep(j, y) ab.push_back(a[i] + b[j]);
    sort(rALL(ab));
    ab.resize(k);

    vector<ll> abc;
    rep(i, k) rep(j, z) abc.push_back(ab[i] + c[j]);
    sort(rALL(abc));

    rep(i, k) cout << abc[i] << endl;
}

Measured memory_bytes: 43112
#include<iostream>
#include<cstdio>
using namespace std;
int A[100005];
int BinarySearch(int a[], int size, int key) {
	int l = 0;
	int r = size - 1;
	while (l <= r) {
		int mid = l + (r - l) / 2;
		if (key == a[mid])
			return true;
		else if (key > a[mid])
			l = mid + 1;
		else
			r = mid - 1;
	}
	return false;//没有找到
}
int main() {
	int n, q, key, sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &key);
		if (BinarySearch(A,n,key))
			sum++;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 3484
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
string s;
int k;
int INF=1000000000;
int dh[4]={0,1,0,-1};
int dw[4]={1,0,-1,0};

int main(){
    int n,m;cin>>n>>m;
    vector<pair<int,int> > p;
  p.resize(m);
    rep(i,0,m){
        int a,b;
      cin>>a>>b;
        a--;b--;
        p[i]=(make_pair(b,a));
    }
  sort(p.begin(),p.end());
    int ans=0;
    int bri=-1;
    for(auto it=p.begin();it!=p.end();it++){
        if(!(bri>it->second&&bri<=it->first)){
            ans++;
            bri=it->first;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
a0=list(map(int,input().split()))
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
n=int(input())
c0=[-1,-1,-1]
c1=[-1,-1,-1]
c2=[-1,-1,-1]

for i in range(n):
    b=int(input())
    for j in range(3):
        if a0[j]==b:
            c0[j]=0
    for j in range(3):
        if a1[j]==b:
            c1[j]=0
    for j in range(3):
        if a2[j]==b:
            c2[j]=0

ans=0
if c0[0]==0 and c0[1]==0 and c0[2]==0:
    ans=1
elif c1[0]==0 and c1[1]==0 and c1[2]==0:
    ans=1
elif c2[0]==0 and c2[1]==0 and c2[2]==0:
    ans=1
elif c0[0]==0 and c1[0]==0 and c2[0]==0:
    ans=1
elif c0[1]==0 and c1[1]==0 and c2[1]==0:
    ans=1
elif c0[2]==0 and c1[2]==0 and c2[2]==0:
    ans=1
elif c0[0]==0 and c1[1]==0 and c2[2]==0:
    ans=1
elif c0[2]==0 and c1[1]==0 and c2[0]==0:
    ans=1

if ans==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3188
#include<stdio.h>
int n, i;
int w[100];
int d, m;
int main(void){
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", w+i);
		d += w[i];
	}
	d -= w[0]<<1;
	m = d;
	for(i=1; i<n; i++){
		d -= w[i]<<1;
		if(d>=0 && d<m){m=d;}else if(d<0 && -d<m){m=-d;}
	}
	printf("%d\n", m);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;

  map<int, int> m;
  for (auto x : a) m[x]++;

  bool f = true;
  for (auto p : m) f &= (p.second <= 1);
  cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 14336
package main

import "fmt"

type Dice struct {
	side [6]int
	topnum int
	rightnum, leftnum, forwardnum, backnum, bottomnum int
}
func (dice *Dice) init() {
	for i:=0; i<6; i++ {
		fmt.Scan(&(dice.side[i]))
	}
	dice.topnum, dice.rightnum, dice.leftnum, dice.forwardnum, dice.backnum, dice.bottomnum = 0, 2, 3, 4, 1, 5
}
func (dice *Dice) rotate(dir string) {
	temp := dice.topnum

	switch dir {
	case "N" :	
		dice.topnum = dice.backnum
		dice.backnum = dice.bottomnum
		dice.bottomnum = dice.forwardnum
		dice.forwardnum = temp
	case "E" :
		dice.topnum = dice.leftnum
		dice.leftnum = dice.bottomnum
		dice.bottomnum = dice.rightnum
		dice.rightnum = temp
	case "W" :
		dice.topnum = dice.rightnum
		dice.rightnum = dice.bottomnum
		dice.bottomnum = dice.leftnum
		dice.leftnum = temp
	case "S" :
		dice.topnum = dice.forwardnum
		dice.forwardnum = dice.bottomnum
		dice.bottomnum = dice.backnum
		dice.backnum = temp
	}
}

func main() {

	var dice Dice
	dice.init()
	var operator string
	fmt.Scan(&operator)
	roperator := []rune(operator)
	for i:=0; i<len(roperator); i++ {
		dice.rotate(string(roperator[i]))
	}
	fmt.Println(dice.side[dice.topnum])
	  
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000],c;

	int ara[n_size],ara2[n_size];

	sc st;

	cin>>n;

	f(i,0,n-1)
	{
	    cin>>c;

	    st.insert(c);
	}

	if(st.size()==1) cout<<"One"<<endl;
	else if(st.size()==2) cout<<"Two"<<endl;
	else if(st.size()==3) cout<<"Three"<<endl;
	else{
        cout<<"Four"<<endl;
	}



}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

double t, x;
int main(){
	scanf("%lf %lf",&t,&x);
	printf("%.9lf\n", t/x);
	return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<pair<double,int> > data;
    REP(i,n){
      int num;
      double h,w;
      cin>>num>>h>>w;
      data.push_back(pair<double, int>(w*10000/(h*h), num));
    }
    sort(data.begin(), data.end());
    vector<pair<double,int> >::iterator itl, itu;
    itl = lower_bound(data.begin(), data.end(), pair<double,int>(22,0));
    itu = (itl!=data.begin())?itl-1:itl;
    if(abs(22-(*itl).first)>abs(22-(*itu).first)){
      cout<<(*itu).second<<endl;
    }else{
      cout<<(*itl).second<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
xy = []

for i in range(N):
	A = INT()
	xy.append([LIST() for _ in range(A)])

ans = 0
for X in product((0, 1), repeat=N):
	for j in range(N):
		if X[j] == 1:
			for x, y in xy[j]:
				if X[x-1] != y:
					break
			else:
				continue
			break
	else:
		ans = max(ans, sum(X))

print(ans)

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

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 1; i <= n; ++i) {
        int a; cin >> a;
        v[i - 1] = make_pair(a, i);
    }
    sort(v.begin(), v.end());
    for (auto& p : v) {
        cout << p.second << " ";
    }
    cout << "\n";
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3992
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n,i,a=0,w=0,t=0,r=0;
        cin>>n;
        string s;
       for(i=0;i<n;i++)
       {
               cin>>s;
               if(s=="AC")
                       a++;
               else if(s=="WA")
                       w++;
               else if(s=="TLE")
                       t++;
               else if(s=="RE")
                       r++;
       }
        cout<<"AC x "<<a<<endl;
        cout<<"WA x "<<w<<endl;
        cout<<"TLE x "<<t<<endl;
        cout<<"RE x "<<r<<endl;
        
   return 0;    
}

Measured memory_bytes: 3628
A,B,C = [int(i) for i in input().split()]
if A%2 == B%2 == C%2:
    m = max(A,B,C)
    print((3*m - A - B - C)//2)
elif A%2 == B%2:
    A += 1
    B += 1
    m = max(A,B,C)
    print(1 + (3*m - A - B - C)//2)
elif A%2 == C%2:
    A += 1
    C += 1
    m = max(A,B,C)
    print(1 + (3*m - A - B - C)//2)
elif B%2 == C%2:
    B += 1
    C += 1
    m = max(A,B,C)
    print(1 + (3*m - A - B - C)//2)

Measured memory_bytes: 9220
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)1e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(),v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
   return powM(a, m-2, m);
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].ff=a[i];
        v[i].ss=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].ff;
        b[i]=v[i].ss;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].ff=a[i];
        v[i].ss=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].ff;
        b[i]=v[i].ss;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b+1 != d){cout<<1;}
    else{cout<<0;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  cin >> N;
  
  int t = N;
  int c = 0;
  // 各桁の数字の和
  while (t > 0) {
    c += t % 10;
    t /= 10;
  }
 
  if (N % c == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#define debug 0
#define test 0
#define CPLUS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#if CPLUS
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#include <queue>
#include <map>
#include <unordered_map>
#include <functional>
#include <iomanip>
using namespace std;
#endif


int check(int i)
{
	int flag[11] = { 0 };
	while (i) {
		if (i % 10 == 3 || i % 10 == 5 || i % 10 == 7)
			flag[i % 10] = 1;
		else
			return 0;
		i /= 10;
}
	if (flag[3] && flag[5] && flag[7])
		return 1;
	else
		return 0;
}

int main(void)
{
#if debug
	freopen("in.txt", "r", stdin);
#endif
	int t;
	scanf("%d", &t);
	int num[10000000] = { 0 };
	num[0] = 3;
	num[1] = 5;
	num[2] = 7;
	int i = 3;
	for (int j = 0; num[i-1] <= t; j++) {
		num[i++] = num[j] * 10 + 3;
		num[i++] = num[j] * 10 + 5;
		num[i++] = num[j] * 10 + 7;
	}
	int ans = 0;
	for (int i = 0; num[i] ; i++) {
		if (check(num[i]) && num[i] <= t) {
			//printf("%d\n", num[i]);
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 39296
#include <iostream>
#include <sstream>  // istringstream
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{   
    string s;
    cin >> s;
    // 端の文字と偶奇のみで求まる

    bool game_cont = true;    
    int turn = 1;
    while(game_cont){
        game_cont = false;
        for(int i=0; i<s.length()-2; ++i){
            // if(s.length() == 3){
            //     break;
            // }
            if(s[i] != s[i+2]){
                s.erase(i+1, 1);
                // cout << s << " " << turn << endl;
                game_cont = true;
                turn++;
                break; // forループを抜ける
            }
        }
        if(!game_cont){
            // cout << "set " << turn << endl;
        }
    }

    if(turn%2 == 0){
        cout << "First" << endl;        
    }
    else{
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
def choose(n, a):
    global mod
    x, y = 1, 1
    for i in range(a):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return x * pow(y, mod - 2, mod) % mod

n,a,b = map(int,input().split())
mod = pow(10,9)+7
all = pow(2,n,mod)-1
print((all-choose(n,a)-choose(n,b))%mod)

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

int n;
int h[100010];
int main()
{
	scanf("%d",&n);
	if(n==1) {cout<<"Yes"; return 0;}
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(int i=1;i<n;i++)
	{
		int j=i+1;
		if(h[i]-h[j]>1) {cout<<"No"; return 0;}
		else if(h[i]-h[j]==1) h[j]++;
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdbool.h>
#define ll long long 
char s[22][22];
int v[22][22];
int h,w;

void dfs(int y, int x,int a){
    if(x<0||x>=w||y<0||y>=h||v[y][x]<=a||s[y][x]=='#') return;
    v[y][x]=a;
    dfs(y+1,x,a+1);
    dfs(y,x+1,a+1);
    dfs(y-1,x,a+1);
    dfs(y,x-1,a+1);
    return;
}

int main(){
    int i,j,si,sj,gi,gj,ans = 0;
    scanf("%d %d",&h,&w);
    for(i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(si=0;si<h;si++){
        for(sj=0;sj<w;sj++){
            if(s[si][sj]=='.'){
              for (i = 0; i < h; i++)
                for (j = 0; j < w; j++)
                  v[i][j] = 1000000009;
              dfs(si, sj, 0);
              for (gi = 0; gi < h; gi++)
                for (gj = 0; gj < w; gj++)
                  if(s[gi][gj]=='.')
                    ans = ans<v[gi][gj]?v[gi][gj]:ans;
            }
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int h,n,a,s=0;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        s+=a;
    }
    s>=h ? cout<<"Yes" : cout<<"No";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input(); t = input()
n = len(s); m = len(t)
dp=[[0] * (m+1) for i in range(n+1)]
repair = [[0] * (m+1) for i in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dp[i+1][j+1] = dp[i][j] + 1
      repair[i+1][j+1] = (i,j)
    else:
      dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
      repair[i+1][j+1] = (i,j+1) if dp[i][j+1] >= dp[i+1][j] else (i+1,j)


M = dp[n][m]
ans = []
i = n; j = m
while i != 0 and j != 0:
  # print(i,j,repair[i][j])
  ni,nj = repair[i][j]
  if dp[ni][nj] < dp[i][j]:
    ans.append(s[ni])
  i,j = ni,nj
ans.reverse()
print(*ans, sep = "")

      


Measured memory_bytes: 405000
/************************************************************
	> File Name: e.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 31 May 2020 08:38:21 PM CST
************************************************************/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <ext/rope>
#define lowbit(x) (x&-x)
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int INF = 0x3f3f3f3f;
const LL INF_ll = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int N = 2e5+10;
int a[N],b[N],n;
int gcd1(int a,int b){
	return b?gcd1(b,a%b):a;
}
int mul(int a,int b,int p){
	int res = 0;
	while(b){
		if(b&1) res = (res + a) % p;
		a = (a+a)%p;
		b >>= 1;
	}
	return b;
}
int ksm(int a,int b,int p){
	int res = 1;
	while(b){
		if(b&1) res = a * res % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}
int ksm1(int a,int b,int p){
	int res = 1;
	while(b){
		if(b&1) res = a * res % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}
int ksm2(int a,int b,int p){
	int res = 1;
	while(b){
		if(b&1) res = a * res % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}
int ksm3(int a,int b,int p){
	int res = 1;
	while(b){
		if(b&1) res = a * res % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}
signed main(void){
	IOS;
	cin >> n;
	for(int i = 0;i < n;++i) cin >> a[i] >> b[i];
	sort(a,a+n);
	sort(b,b+n);
	if(n&1) cout << b[n/2]-a[n/2]+1 << endl;
	else cout << b[(n-1)/2]+b[(n+1)/2]-a[(n-1)/2]-a[(n+1)/2]+1 << endl;
	return 0;
}


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

void select_sort(int *data, int num);

int main(void)
{
	int n;
	int customer[1000];
	unsigned int waiting_time[1000];
	int minimum;
	int i;
	
	while (scanf("%d", &n) != EOF){
		
		if (n == 0){
			break;
		}
		
		memset(customer, 0, sizeof(customer));
		
		for (i = 0; i < n; i++){
			scanf("%d", &customer[i]);
		}
		
		select_sort(customer, n);
		
		memset(waiting_time, 0, sizeof(waiting_time));
		
		minimum = 0;
		for(i = 1; i <= n; i++){
			waiting_time[i] = waiting_time[i - 1] + customer[i - 1];
			minimum += waiting_time[i];
		}
		
		printf("%u\n", minimum);
	}
	
	return (0);
}

void select_sort(int *data, int num)
{
    int i;
    int j;
    int min;
    int temp;
    
    for (i = 0; i < num - 1; i++){
        min = i;
        for (j = i + 1; j < num; j++){
            if (data[min] > data[j]){
                temp = data[min];
                data[min] = data[j];
                data[j] = temp;
            }
        }
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

const double PI = acos(-1);

int main(){

    int N;
    long long K;
    cin >> N >> K;

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

    vector<bool> check(N, false);

    int now = 0;
    check[0] = true;

    int point_num; // ループを見つけた番号(初めて被った数)
    int pre2_num; // point_num に2回目に到達するまでの試行回数(被るまでの試行)
    int loop_num; // ループ周期
    int pre_num; // point_num に1回目に到達するまでの試行回数(pre2_num - loop_num)

    for (int i = 0; i < K; i++){
        now = A[now];
        // cout << "now: " << now << endl;
        if (!check[now]){
            check[now] = true;
        } else {
            pre2_num = i+1;
            break;
        }
    }
    point_num = now;

    // もう一回被るまでを数える
    for (int i = 0; i < N; i++){
        now = A[now];
        // cout << "now: " << now << endl;
        if (point_num == now){
            loop_num = i+1;
            break;
        }
    }

    pre_num = pre2_num - loop_num;

    // cout << "point_num: " << point_num << endl;
    // cout << "pre2_num: " << pre2_num << endl;
    // cout << "loop_num: " << loop_num << endl;
    // cout << "pre_num: " << pre_num << endl;

    // ここまでが準備
    ///////////////////////////////////////////////////////////////

    int ans;

    // point_num から 最終地点までの残り試行回数
    int K_last = (K - pre_num) % loop_num;

    if (K < pre_num) {
        now = 0;
        for (int i = 0; i < K; i++){
            now = A[now];
        }
        ans = now;
    } else {
        now = point_num;
        for (int i = 0; i < K_last; i++){
            now = A[now];
        }
        ans = now;
    }

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


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<vector<pii>> r;

vector<ll> bellman(int s){
	int n = sz(r);
	const ll inf = 1LL<<60;
	vector<ll> ds(n, -inf);
	ds[s] =0;
	for(int i =0, nxt =1; i<n+30 && nxt>0 ; i++){
		nxt = 0;
		rep(j, n) for(auto z: r[j]){
			if(ds[j] != -inf && ds[z.first] < ds[j] + z.second){
				ds[z.first] = ds[j] + z.second;
				nxt = 1;
				//dbg(i,j,z.first);
				if(i>n && z.first==n-1) {ds[0]=-1; return ds;}
			}
		}
	}
	return ds;
}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int N, M ;
	cin >>N >>M;
	r.resize(N);
	rep(i, M){
		int a,b,c;
		cin >>a >>b >>c;
		r[a-1].emplace_back(b-1, c);
	}
	auto rv = bellman(0);
	if(rv[0]==-1) cout <<"inf\n";
	else cout << rv[N-1] <<"\n";
	return 0;
}

Measured memory_bytes: 384
# ABC138
# B One Clue
# K個連続黒、Xが黒、座標-1000000+1000000
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
L = list(sorted(I))
for s in L:
    print(s,end = " ")


Measured memory_bytes: 9184
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {
	
	int n, d;
	cin >> n >> d;
	int x[15][15];

	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = 0; j < d; j++)
		{
			cin >> x[i][j];
		}
	}

	int p = 0;
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = i + 1; j < n; j++)
		{
			ll s2 = 0;
			for (size_t k = 0; k < d; k++)
			{
				s2 += pow(x[i][k] - x[j][k],2);
			}
			for (ll v = 0; v <= 200; v++)
			{
				if (v * v == s2) {
					p++;
					break;
				}
			}

		}
	}
	cout << p << endl;
}

int main() {
	COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 5120
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

#define f(i,n) for(int i=0;i<(int)n;i++)

int main(void) {
	int n, m;
	char a[15][15];
	bool used[30];
	int e[15];
	vector<char>b;
	int g[20];
	int h[20];
	int ans;
	int s1, s2, x, y, z;
	int k;
	int k2;
	int c;
	bool v;
	vector<int>d;

	k = 1;
	f(i, 10)k = k*(i + 1);
	while (true) {
		n = 0;
		m = 0;
		b.clear();
		scanf("%d", &n);
		if (n == 0)return 0;
		d.clear();
		f(i, 10)d.push_back(i);
		f(i, 20)g[i] = 0;
		f(i, 20)h[i] = 0;
		f(i, 30)used[i] = false;
		f(i, 15) {
			f(j, 15) {
				a[i][j] = 0;
			}
			e[i] = 0;
		}

		f(i, n) {
			scanf("%s", a[i]);
			e[i] = strlen(a[i]);
			f(j, e[i]) {
				if (!used[a[i][j] - 65]) {
					used[a[i][j] - 65] = true;
					b.push_back(a[i][j]);
				}
			}
		}
		f(i, n - 1) {
			x = 1;
			f(j, e[i])x = x * 10;
			f(j, e[i]) {
				f(ii, b.size()) {
					if (a[i][j] == b[ii]) {
						x = x / 10;
						g[ii] += x;
						break;
					}
				}
			}
		}
		x = 1;
		f(j, e[n - 1])x = x * 10;
		f(j, e[n - 1]) {
			f(ii, b.size()) {
				if (a[n - 1][j] == b[ii]) {
					x = x / 10;
					h[ii] += x;
					break;
				}
			}
		}
		k2 = 1;
		f(i, 10 - b.size())k2 = k2*(i + 1);
		ans = 0;
		f(kk, k / k2) {

			s1 = 0;
			s2 = 0;
			f(i, b.size())s1 += (d[i] * g[i]);
			f(i, b.size())s2 += (d[i] * h[i]);
			if (s1 == s2) {
				v = true;
				f(i, n - 1) {
					y = 0;
					f(ii, b.size()) {
						if (a[i][0] == b[ii]) {
							if (e[i] > 1 && d[ii] == 0)v = false;
							break;
						}
					}
					if (!v)break;
				}
				if (v) {
					f(ii, b.size()) {
						if (a[n - 1][0] == b[ii]) {
							if (e[n - 1] > 1 && d[ii] == 0)v = false;
							break;
						}
					}
					if (v)ans++;
				}
			}

			f(kkk, k2)next_permutation(d.begin(), d.end());
		}
		printf("%d\n", ans);

	}
	return 0;
}



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

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

    int n = s.size();
    int a[n] = {};
    rep(i, n-1){
        a[i] = (int) pow(2, n-2-i);
    }
    a[n-1] = 1;

    ll ans = 0;
    for (int i = n-1; i >= 0; i--){
        for (int j = i; j >= 0; j--){
            ans += (s[n-1-i]-'0') * pow(10, j) * a[j];
        }
        if(i!=0) a[i-1] += a[i];
    }
    
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  string St;
  cin >> St;
  string Ans = "Yes";
  int N;
  N = St.size();
  for(int i=0;i<N;i++){
    if(i%2 == 0){
      if(St.at(i)=='L'){
        Ans = "No";
        break;
      }
    }
    else{
      if(St.at(i)=='R'){
        Ans = "No";
        break;
      }
    }
  }
  cout << Ans << endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX_N=1e5;
int divup(int x,int y){
    if(x%y==0)return x/y;
    else return x/y+1;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
typedef pair<int,int>P;

signed main(){
    string s;int k;cin>>s>>k;
    int n=s.size();
    int dpk[n+1][5];
    int dpm[n+1][5];
    REP(i,n+1)REP(j,5)dpk[i][j]=dpm[i][j]=0;
    REPS(i,n){
        int d=s[i-1]-'0';
        if(i==1){
            if(d!=0){
                dpk[1][1]=d-1;
                dpk[1][0]=1;
                dpm[1][1]=1;
            }
            else dpm[1][0]=1;
        }
        else{
            if(d!=0){
                REP(j,4){
                    dpk[i][j+1]=dpk[i-1][j]*9;
                    dpk[i][j]+=dpk[i-1][j]+dpm[i-1][j];
                    dpk[i][j]+=dpm[i-1][j-1]*(d-1);
                    dpm[i][j]=dpm[i-1][j-1];
                }
            }
            else{
                REP(j,4){
                    dpk[i][j+1]=dpk[i-1][j]*9;
                    dpk[i][j]+=dpk[i-1][j];
                    dpm[i][j]=dpm[i-1][j];
                }
            }
        }
    }
    cout<<dpk[n][k]+dpm[n][k];
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] ai = new int[a];
		int b = sc.nextInt();
		int[] bi = new int[b];
		int m = sc.nextInt();
		int min = 2000000000;
		int minA = 2000000000;
		int minB = 2000000000;

		for(int i = 0; i < a; i++) {
			ai[i] = sc.nextInt();
			minA = (minA > ai[i]) ? ai[i] : minA;
		}

		for(int i = 0; i < b; i++) {
			bi[i] = sc.nextInt();
			minB = (minB > bi[i]) ? bi[i] : minB;
		}

		min = minA + minB;

		int n;
		for(int i = 0; i < m; i++) {
			n = ai[sc.nextInt() - 1] + bi[sc.nextInt() - 1] - sc.nextInt();
			min = (min > n) ? n : min;
		}

		System.out.println(min);
		sc.close();
	}
}


Measured memory_bytes: 150276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
// mt19937 mrand(random_device{}());
const ll mod = 1000000007;
// int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
// head

const int mxN = 1e5 + 5;
int n;
VI edges[mxN];

int mult(int a, int b){
	return (ll)a * (ll)b % mod;
}

// returns a pair {u = black, u = white}
PII dfs(int u, int parent) {
	int all_white = 1;// means: my vertex can be painted black
	int sth_is_black = 0;
	for (int v : edges[u]) {
		if (v != parent) {
			PII p = dfs(v, u);
			// p.first is the number of ways to color the subtree
			// such that 'v' is black;
			sth_is_black = (mult(sth_is_black, p.first + p.second) +
				mult(all_white, p.first)) % mod;
			all_white = mult(all_white, p.second);
		}
	}
	return mp(all_white, (sth_is_black + all_white) % mod);
}


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

	cin >> n;
	rep(i, 0, n-1) {
		int u, v;
		cin >> u >> v, --u, --v;
		edges[u].pb(v);
		edges[v].pb(u);
	}
	PII ans = dfs(0, -1);
	cout << (ans.first + ans.second)%mod << endl;
	return 0;
}



Measured memory_bytes: 12672
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

//座標圧縮
int cocomp(ll*a,int n){
	ll*b=(ll*)malloc(sizeof(ll)*n);
	memcpy(b,a,sizeof(ll)*n);
	sortup(b,n);
	int cnt=1;
	rep(r,1,n)if(b[r]!=b[cnt-1])b[cnt++]=b[r];
	rep(i,0,n){
		int l=0,r=cnt;
		while(r-l>1){int m=(l+r)/2;if(b[m]>a[i])r=m;else l=m;}
		a[i]=l+1;
	}
	free(b);
	return cnt;
}


//seg木
int segNUM;	
ll seg[1<<20],*segN;
//まずsegNUM<=2^19(2べき)を指定
void seguse(int n){if(n==(n&-n)){segNUM=n;segN=seg+segNUM-1;}}
//segN[]で各ノードを初期化してから↓を呼んでその上をまとめて初期化
void seginit(){
	for(int node=segNUM-1;node--;)seg[node]=seg[node*2+1]+seg[node*2+2];//sum
}

//segN[node]をxに更新
void segupdate(int node,ll x){
	node+=segNUM-1;
	seg[node]=x;
	while(node>0){
		node=(node-1)/2;
		seg[node]=seg[node*2+1]+seg[node*2+2];//合計
//		seg[node]=min(seg[node*2+1],seg[node*2+2]);//min
	}
}

ll subq(int a,int b,int k,int l,int r){
	//seg[k]に[l,r)が対応する
	//disjointな時は単位元を返す
	if(r<=a||b<=l)return 0;//sum

	if(a<=l&&r<=b)return seg[k];//完全に含む
	int left=subq(a,b,k*2+1,l,(l+r)/2),right=subq(a,b,k*2+2,(l+r)/2,r);
	return left+right;//sum
}

//[a,b)に対して答える
ll query(int a,int b){return subq(a,b,0,0,segNUM);}


ll a[200010];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		a[i+1]=a[i]+t-k;
	}
	cocomp(a,n+1);
	
	seguse(1<<18);
	ll ans=0;
	rep(i,0,n+1){
		ans+=query(0,a[i]+1);
		segupdate(a[i],segN[a[i]]+1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5408
#include<stdio.h>

int main(void){
  int n,i,a,b[3];
  scanf("%d",&n);
  for(i=0;i<3;i++) b[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a%4==0) b[2]++;
    else if(a%2==0) b[1]++;
    else b[0]++;
  }
  if(n/2-b[1]/2<=b[2]) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <string>

using namespace std;

struct Point{
	short x;
	short y;
};

int change( const Point& point)
{
	return point.x + point.y * 200;
}
int main(int argc, char const* argv[])
{
	int H,W;
	Point place;
	set<int> data;
	string stage[101];

START:
	while( cin >> W >> H && W != 0 ){
		for( int i = 0;i < W;i++ ) cin >> stage[i];

		data.clear();
		place.x = 0;
		place.y = 0;
		while( 1 ){
			switch( stage[place.x][place.y] ){
				case '>':
					place.y++;
					if( data.count( change( place ) ) ){
						cout << "LOOP" << endl;
						goto START;
					}
					data.insert( change( place ) );
					break;
				case '<':
					place.y--;
					if( data.count( change( place ) ) ){
						cout << "LOOP" << endl;
						goto START;
					}
					data.insert( change( place ) );
					break;
				case '^':
					place.x--;
					if( data.count( change( place ) ) ){
						cout << "LOOP" << endl;
						goto START;
					}

					data.insert( change( place ) );
					break;
				case 'v':
					place.x++;
					if( data.count( change( place ) ) ){
						cout << "LOOP" << endl;
						goto START;
					}

					data.insert( change( place ) );
					break;
				case '.':
					cout << (int)place.y << ' ' << (int)place.x << endl;
					goto START;
					break;
			}
		}
	}
	return 0;
	
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

	int[] n = new int[5];
	int W,H,x,y,r;

	Scanner scan = new Scanner(System.in);

	for(int i=0; i<5; i++) n[i] = scan.nextInt();
	
	W = n[0];
	H = n[1];
	x = n[2];
	y = n[3];
	r = n[4];
	
	if( (r<=x && x<=W-r) && (r<=y && y<=H-r) ) System.out.println("Yes");
	else System.out.println("No");
	
	scan.close();
	}
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    for (int i = 0;i < x;++i) cin >> a[i];
    for (int i = 0;i < y;++i) cin >> b[i];
    for (int i = 0;i < z;++i) cin >> c[i];
    map<ll,int> mp;
    for (int i = 0;i < y;++i) for (int j = 0;j < z;++j) mp[b[i]+c[j]]++;
    auto it = mp.end();
    it--;
    for (;it != mp.begin();) {
        int s = it->second;
        (--it)->second += s;
    }
    sort(a.begin(),a.end());
    ll p = 1e11,q = 0,r = 0;
    for (int d = 0;d < k;++d) {
        ll mn = max(q,r),mx = p;
        q = 0;
        while (mx-mn > 1) {
            ll md = (mn+mx)/2;
            int cnt = 0;
            for (int i = x-1;i >= 0;--i) {
                auto j = mp.lower_bound(md-a[i]);
                if (j != mp.end()) cnt += j->second;
                else break;
            }
            if (cnt > d+1) q = mn;
            if (cnt > k) r = mn;
            (cnt < d+1 ? mx : mn) = md;
        }
        cout << mn << endl;
        p = mx;
    }
    return 0;
}

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

using namespace std;

typedef long long  ll;

const int offset = 20;
double r; // ??????????????????1 <= r <= 20???
int n; // ?????????????????¨??????????????°???0 <= n <= 20???

bool C(double t, const vector<double> &h)
{
    const int lx = offset - r, rx = offset + r;
    double x0 = offset, y0 = -r + t; // ????????????

    // ??????[x, x+1]??????????????????????????????????????????????????????
    for (int x = lx; x < rx; ++x) {
        double tmp_x1 = (x - x0) * (x - x0);
        double c_y1 = sqrt(r * r - tmp_x1) + y0;
        double tmp_x2 = (x + 1.0 - x0) * (x + 1.0 - x0);
        double c_y2 = sqrt(r * r - tmp_x2) + y0;

        if (h[x] < c_y1 || h[x] < c_y2)
            return false;
    }

    return true;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(8) << setiosflags(ios::fixed); // printf("%.4f", x);

    while (cin >> r >> n) {
        if (r == 0 && n == 0)
            break;

        vector<double> h(41, 0);
        int xl, xr;
        double tmp_h;
        for (int i = 0; i < n; ++i) {
            cin >> xl >> xr >> tmp_h;
            xl += offset;
            xr += offset;
            for (int x = xl; x < xr; ++x)
                h[x] = max(h[x], tmp_h);
        }

        double lb = 0.0, ub = 100.0;
        for (int i = 0; i < 100; ++i) {
            double mid = (lb + ub) * 0.5;
            if (C(mid, h))
                lb = mid;
            else
                ub = mid;
        }

        cout << ub << endl;
    }

    return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<algorithm>
#include<cmath>
int main()
{
	int a = 0, b = 0,c=0,d=0, rate[100] = {};
	std::cin >> a>>b>>c>>d;
	if (std::abs(b - a) <= d &&std::abs( c - b) <= d) {
		std::cout << "Yes" << std::endl;
	}
	else if (std::abs(c - a) <= d) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////


int main() {
	int n, m; cin >> n >> m;
	int k[11];
	int s[11][11];
	int p[11];
	for (int i = 0; i < m; ++i) {
		cin >> k[i];
		for (int j = 0; j < k[i]; ++j) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for (int i = 0; i < m; ++i)cin >> p[i];
	int ans = 0;
	for (int bit = 0; bit < (1 << n); ++bit) {
		bool ok = true;
		for (int i = 0; i < m; ++i) {
			int cnt = 0;
			for (int j = 0; j < k[i]; ++j) {
				if ((1<<s[i][j]) & bit) {
					cnt++;
				}
			}
			if (cnt % 2 != p[i]) {
				ok = false;
				break;
			}
		}
		if (ok)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256