akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,w;
long long int* dp;                  //2-d array of size [n x w]
long long int fun(int num, int wei, int v[] ,int weight[]){
   //     cout<<num<<" "<<wei<<" "<<endl;
    if(dp[(w+1)*num+wei]!=-1) return dp[(w+1)*num+wei];
    if(num<=0) return 0;
    long long int ans=-1;
    if(wei>=weight[num]){
        ans=fun(num-1,wei-weight[num],v,weight)+v[num];
    }
    ans=max(ans,fun(num-1,wei,v,weight));
    dp[(w+1)*num+wei]=ans;
    //cout<<num<<" "<<wei<<" "<<ans<<endl;
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>w;
    dp=new long long int[(n+1)*(w+1)];
    
    memset(dp,-1,sizeof(long long int)*(n+1)*(w+1));
    //cout<<dp[35]<<endl;
    int v[n+1],weight[n+1];
    for(int i=1;i<=n;i++){
        cin>>weight[i]>>v[i];
    }
    cout<<fun(n,w,v,weight)<<endl;
    
}

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

int gcd(int x, int y)
{
    int r;
    if(x == 0 || y == 0){
        fprintf(stderr, "error\n");
        return 0;
    }
    while((r = x % y) != 0){
        x = y;
        y = r;
    }
    return y;
}
int main(void){
    int n,X,sa=0,min_s=10000000;
    long long x;
    vector<int> V;
    cin >> n >> X;
    if(n == 1){
        cin >> x;
        cout << abs(X-x);
        return 0;
    }
    
    for(int i=0;i<n;i++){
        cin >> x;
        sa = abs(X-x);
        V.push_back(sa);
    }
    int g = gcd(V[0],V[1]);
    for(int i=2;i<V.size();i++){
        int gg = gcd(g,V[i]);
        g = gg;
    }
    cout << g;
    return 0;
}


Measured memory_bytes: 892
x,y=map(int,input().split())
ans=abs(abs(x)-abs(y))
 
if (x<0 and y<0) or (x>0 and y>0):
    if x>y :
        ans+=2
elif x!=0 and y!=0:
    ans+=1
else:
    if y<=0 and x>y:
        ans+=1
 
print(ans)

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

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

    vector<string> S(N);

    for(int i = 0; i < N; i++)
    {
        cin >> S.at(i);
    }

    sort(S.begin(),S.end());
    string s = S.at(0);

    for(int i = 1; i < N; i++)
    {
        s += S.at(i);
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    int K; cin >> K;
    int value[3]; F0R(i, 3) cin >> value[i];
    string S; cin >> S;
    vi data;
    F0R(i, N) {
        if (S[i] == 'r') {
            data.pb(2);
        } else if (S[i] == 's') {
            data.pb(0);
        } else {
            data.pb(1);
        }
    }

    ll dp[N][3];
    F0R(i, N) {
        F0R(j, 3) {
            ll prev = 0;
            if (i >= K) {
                F0R(k, 3) {
                    if (k != j) prev = max(prev, dp[i-K][k]);
                }
            }
            dp[i][j] = prev;
            if (j == data[i]) dp[i][j] += value[j];
        }
    }

    ll ans = 0;
    F0Rd(i, K) {
        ll cur = 0;
        F0R(j, 3) {
            cur = max(cur, dp[N-i-1][j]);
        }
        ans += cur;
    }
	cout << ans << endl;
/*    F0R(i, N) {
        F0R(j, 3) {
            cout << i << " " << j << " " << dp[i][j] << endl;
        }
    }*/
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3272
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    x = int(input())

    if x<600:
        print(8)
    elif x<800:
        print(7)
    elif x <1000:
        print(6)
    elif x <1200:
        print(5)
    elif x<1400:
        print(4)
    elif x <1600:
        print(3)
    elif x <1800:
        print(2)
    else:
        print(1)




if __name__ == "__main__":
    main()


Measured memory_bytes: 61940
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main(){
    double r1, r2, r3;
    cin >> r1 >> r2;
    r3 = r1 * r2 / (r1 + r2);
    printf("%.10f\n", r3);
}

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

using namespace std;

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

#define X first
#define Y second

const int N=5e2+10;
const int MOD=1e9+7;
const int inf=1e9+10;
const int maxv=40;

int n,a[N];
string s[N];
int solve(){
    int pos=0;
    while (pos<n&&count(s[pos].begin(),s[pos].end(),'.')==n) pos++;
    if (pos==n) return -1;

    ///
    int calr=0;
    for(int col=0;col<n;col++){
        int sum=0;
        for(int i=0;i<n;i++) sum+=s[i][col]=='#';
        calr+=sum==n;
    }
    int alr=0;
    for(int row=0;row<n;row++) if (count(s[pos].begin(),s[pos].end(),'#')==n) alr++;
    if (alr) return n-calr;


    int ans=3*n;
    for(int row=0;row<n;row++){
        int alr=count(s[row].begin(),s[row].end(),'#');
        for(int i=0;i<n;i++) if (s[i][row]=='#'){
            ans=min(ans,n-alr+n-calr);
            break;
        }
        if (alr) ans=min(ans,n-alr+n-calr+1);
    }
    if (ans==3*n) return -1;
    return ans;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>s[i];
    cout<<solve();
}


Measured memory_bytes: 512
#include <cstdio>

int main(void){
		int a, b ,c;
		scanf("%d %d %d", &a, &b, &c);
		int count = 0;
		for(int i = a; i <= b; i++){
				if(c % i == 0)count++;
		}
		printf("%d\n", count);

		return 0;
}



Measured memory_bytes: 2740
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int left = 0;
		int right = 0;
		int max = 0;
		while (right < n) {
			if (arr[right] - arr[left] < 3) {
				max = Math.max(max, right - left + 1);
				right++;
			} else {
				left++;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 50212
#include<iostream>
#include<algorithm>
using namespace std;
int nums[21];
int n,q;
int solve(int i,int m) {
	if (m == 0) {
		return 1;
	}
	if (m < 0) {
		return 0;
	}
	if (i >= n) {
		return 0;
	}
	return solve(i + 1, m) || solve(i + 1, m - nums[i]);
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	cin >> q;
	int m;
	for (int i = 0; i < q; i++) {
		cin >> m;
		int rst = solve(0, m);
		if (rst == 1) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;
  for (double i = 1; i < 1010; i += 1)
  {
    if ((int)(i * 0.08) == A && (int)(i * 0.10) == B)
    {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll x;
  cin >> x;
  ll crt = 100;
  ll rtn = 0;
  while (1) {
//    crt *= 1.01;
    crt += crt / 100;
    ++rtn;
    if (crt >= x) break;
  }
  cout << rtn << endl;
}


Measured memory_bytes: 3148
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]


def dfs(cur, a, b, c):
    if cur >= N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else float('inf')
    res0 = dfs(cur + 1, a, b, c)
    res1 = dfs(cur + 1, a + L[cur], b, c) + 10
    res2 = dfs(cur + 1, a, b + L[cur], c) + 10
    res3 = dfs(cur + 1, a, b, c + L[cur]) + 10
    return min(res0, res1, res2, res3)


print(dfs(0, 0, 0, 0))


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

int main(){
  while(true){
    string result[3];
    for(int i = 0; i < 3; ++i){
      cin >> result[i];
      if(result[i]=="0")return 0;
    }
    for(int i = 0; i < 3; ++i){
      int a=0,b=0;
      for(int j = 1; j < result[i].length(); ++j){
	if(result[i][j]=='A')++a;
	else ++b;
      }
      //if(a>=10&&b>=10&&abs(b-a)<=1){
	if(b>a)++b;else ++a;
	//}
      cout << a << ' ' << b << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
A, B, C, D = map(int, input().split())

import fractions

def lcm(x, y):
	return (x * y) // fractions.gcd(x, y)

E = lcm(C, D)

n_a = (A - 1) // C + (A - 1) // D - (A - 1) // E
n_b = B // C + B // D - B // E

print((B - A + 1) - (n_b - n_a))

Measured memory_bytes: 5560
N,M=map(int,input().split())
A=list(map(int,input().split()))
S=sum(A)
total=0
for i in range(1,N+1):
    if A[i-1]>=S/4/M:
        total=total+1
if total>=M:
    print("Yes")
else:
    print("No")

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

using namespace std;

string f(int n) {
    int a = n;
    int b = 0;
    while (a) {
        b += a % 10;
        a /= 10;
    }

    if (n % b == 0) {
        return "Yes";
    }

    return "No";
}

int main() {

    int n;
    cin >> n;

    string result = f(n);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
 
int main() {
    int x;
    cin>>x;
    int ans=0;
    if(x>2100)  ans=1;
    else {
        rep(a,21) {
            rep(b,21) {
                rep(c,21) {
                    rep(d,21) {
                        rep(e,21) {
                            rep(f,21) {
                                if(100*a+101*b+102*c+103*d+104*e+105*f==x)  ans=1;
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<endl;

 return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


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

int dir[4];

int main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i] == 'N') dir[0]++;
    if(s[i] == 'W') dir[1]++;
    if(s[i] == 'S') dir[2]++;
    if(s[i] == 'E') dir[3]++;
  }
  bool flag = true;

    if(dir[0] >= 1  && dir[2] == 0) flag = false;
    if(dir[2] >= 1  && dir[0] == 0) flag = false;
    if(dir[1] >= 1  && dir[3] == 0) flag = false;
    if(dir[3] >= 1  && dir[1] == 0) flag = false;

  cout << (flag?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

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

    if (n >= 10) cout << r << endl;
    else cout << r + 100 * (10 - n) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    int n,k; cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];
    int al = a[0];
    repi(i,1,n) al = gcd(al,a[i]);
    auto it = max_element(a.begin(), a.end());
    if(k<=*it && gcd(k,al)==al) cout << "POSSIBLE" << '\n';
    else cout << "IMPOSSIBLE" << '\n';
    
    
    
    
}

Measured memory_bytes: 3692
#include <stdio.h> 
#include <ctype.h> 

 
int main(){ 
     char ch; 
     while(1){ 
         scanf("%c", &ch); 
         if(ch=='\n'){ 
             printf("\n"); 
             break; 
         }else if(islower(ch)){ 
             printf("%c", toupper(ch)); 
         }else if(isupper(ch)){ 
             printf("%c", tolower(ch)); 
         }else{ 
             printf("%c", ch); 
         } 
     } 
 
 
    return 0; 
 } 



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

int main(){
    int h, w;
    cin >> h >> w;
    char s[100][100];
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            char c;
            cin >> c;
            s[i][j] = c;
        }
    }

    string ans = "Yes";

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(s[i][j] == '#'){
                if(!(s[i-1][j] == '#' || s[i+1][j] == '#' || s[i][j-1] == '#' || s[i][j+1] == '#')){
                    ans = "No";
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
for n in range(N):
    KA = list(map(int, input().split()))
    A.append(KA[1:])

if N == 1:
    print(len(A[0]))
    quit()
else:
    res = list(set(A[0]) & set(A[1]))
    for a, v in enumerate(A):
        res = list(set(res) & set(v))
    print(len(res))

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<vector>

int main(void){
    int n, k;
    std::cin >> n >> k;
    if(n <= k){
	std::cout << 0 << std::endl;
	return 0;
    }
    std::vector<int> h(n);
    for(int i = 0; i < n; i++){
	std::cin >> h[i];
    }
    std::sort(h.rbegin(), h.rend());

    long long ans = 0;
    for(int i = k; i < n; i++){
	ans += h[i];	
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 3960
#include<stdio.h>
long long n,k,L,R,M;
long long t[100000];

int check(long long x){
  long long i,id=0,cnt=0;
  for(i=0;i<n;i++){
    if(cnt+t[i]>x){
      cnt=t[i];
      id++;
    }else{
      cnt+=t[i];
    }
    if(id==k||t[i]>x)return 0;
  } 
  return 1;
}

int main(){
  int i;
  scanf("%d %d",&n,&k);
  L=1;
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
    L=(L<t[i]?t[i]:L);
  }

  R=1000000000LL;
  while(L<R){
    M=(L+R)/2;
    if(check(M)==1){
      R=M;
    }else{
      L=M+1;
    }
  }
  printf("%d\n",L);
  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i <= 999; i++) {
        int dgt = 1, t = i;
        while (t / 10) {
            t /= 10;
            dgt++;
        }
        string c;
        if (dgt < 3) {
            for (int i = dgt; i < 3; i++) c += "0";
        }
        c += to_string(i);
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == c[j]) j++;
            if (j == 3) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
// #define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

ll n,hell,x,y;
vi adj[N];
ll dp1[N],dp2[N],cor[N];
void dfs1(ll n,ll p)
{
    dp1[n]=1;
    vi child,pre,suf;

    for(auto u:adj[n])
    {
        if(u!=p)
        {
            dfs1(u,n);
            dp1[n]=(dp1[n]*(dp1[u]+1))%hell;
            child.pb(u);
        }
    }
    ll a=1,b=1;
    rep(i,0,child.size())
    {
        pre.pb(a);
        a*=(dp1[child[i]]+1);
        a%=hell;
        suf.pb(b);
        b*=(dp1[child[child.size()-1-i]]+1);
        b%=hell;
    }
    reverse(all(suf));
    rep(i,0,child.size())
    {
        cor[child[i]]=(pre[i]*suf[i])%hell;
    }
}
void dfs2(ll n,ll p)
{
    dp2[n]=(dp1[n]*cor[n])%hell;
    for(auto u:adj[n])
    {
        if(u!=p)
        {
            cor[u]=((cor[u]*cor[n])%hell+1)%hell;
            dfs2(u,n);
        }
    }
}
void solve()
{
    cin>>n>>hell;
    rep(i,0,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs1(1,0);
    cor[1]=1;
    dfs2(1,0);
    rep(i,1,n+1)
    cout<<dp2[i]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 24024
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64
    }
    let ans = if a >= 13 {
        b
    } else if a >= 6 {
        b / 2
    } else {
        0
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const double PI=acos(-1.0);
int main()
{
    double a,b,x,ans;
    cin>>a>>b>>x;
    double s=x/a;
    if(s*2.0<=a*b)
    {
        double aa=s*2.0/b;
        ans=90.0-atan(aa/b)*180.0/PI;
    }
    else
	{
        double x=(s*2.0-a*b)/a;
        ans=90.0-atan(a/(b-x))*180.0/PI;
    }
    cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
ll dp[100005];
int main()
{
    fio;
    ll n,k;
    cin>>n>>k;
    rep(i,100005)
    dp[i]=1e9;
    ll h[n];
    rep(i,n)
    cin>>h[i];
    dp[1]=abs(h[1]-h[0]);
    dp[0]=0;
    repA(i,2,n-1)
    {
        if(i<=k)
        {
            rep(j,i)
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
        else{
            repA(j,i-k,i-1)
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
# return x^{-1} % mod
# it take O(log{mod})
def mod_inverse(x, mod):
    return pow(x, mod-2, mod)

# return nCk % mod
# it take O(k)
def mod_comb(n, k, mod):
    numer, denom = 1, 1
    for i in range(k):
        # numer: 分子, denom: 分母
        numer = numer * ((n-i) % mod) % mod
        denom = denom * ((i+1) % mod) % mod

    return numer * mod_inverse(denom, mod) % mod


n, a, b = map(int, input().split())
mod = 1000000007
ans = pow(2, n, mod) - 1
ans = (ans - mod_comb(n, a, mod)) % mod
ans = (ans - mod_comb(n, b, mod)) % mod
print( (ans + mod) % mod )


Measured memory_bytes: 3064
//#pragma GCC optimize("03")
//#pragma GCC target("avx2")
 
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sqr(a) (a)*(a)
#define um unordered_map 
#define us unordered_set
using namespace std;
 
hash<string> hfn;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef double dbl;
typedef unsigned int ui;
const int inf = 2e9;
const ll mod = 998244353;
const ld eps = 1e-7;
const ll biginf = 1e18;
const ld pi = acosl(-1);

int n, m;
vector<vector<int> > g;
vi used, dp;

void dfs(int cur)
{
  used[cur] = true;
  for(auto to : g[cur])
  {
    if(!used[to])
      dfs(to);
    dp[cur] = max(dp[cur], dp[to] + 1);
  }
}

void solve()
{
  cin >> n >> m;
  used.resize(n, false);
  g.resize(n);
  dp.resize(n, 0);
  for(int i = 0; i < m; i++)
  {
    int f, t;
    cin >> f >> t;
    f--, t--;
    g[f].pb(t);
  }
  for(int i = 0; i < n; i++)
  {
    if(!used[i])
      dfs(i);
  }
  int maxx = 0;
  for(int i = 0; i < n; i++)
    maxx = max(maxx, dp[i]);
  cout << maxx;
}
 
void multisolve()
{
  int t;
  cin >> t;
  while(t--)
    solve();
}
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //freopen("hull.in", "r", stdin);
  //freopen("hull.out", "w", stdout);
  solve();
  //multisolve();
}

Measured memory_bytes: 8576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a,b,c; cin>>a>>b>>c;
    if(a + b >= c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
int main() {
  int a, b;
  read(a); read(b);
  if(a <= 2 * b) printf("0");
  else printf("%d\n", a - 2 * b);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >>a>>b;
    
    if(a==b){
    cout <<"a == b"<<endl;    
    }
    
    else if(a<b){
    cout <<"a < b"<<endl;
    }
    
    else if(a>b){
    cout <<"a > b"<<endl;    
    }
    
    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#pragma warning (disable : 4996)
using namespace std;
const int N = 100000;
const int MAX = 1234567890;
int main()
{
	int arr[N + 6] = { 0 };
	vector<int> six;
	vector<int> nine;
	six.push_back(0), nine.push_back(0);
	for (int y = 6; y <= N; y *= 6) six.push_back(y);
	for (int y = 9; y <= N; y *= 9) nine.push_back(y);
	for (int i = 1; i <= N; i++) arr[i] = MAX;
	arr[1] = 1;
	for (int i = 2; i <= N; i++)
	{
		int si = -1, ni = -1;
		for (int j = 0; j < six.size(); j++) if (i >= six[j]) si = j;
		for (int j = 0; j < nine.size(); j++) if (i >= nine[j]) ni = j;
		arr[i] = min(arr[i], min(arr[i - six[si]], min(arr[i - 1], arr[i - nine[ni]]))) + 1;
	}
	int n; scanf("%d", &n);
	return !printf("%d\n", arr[n]);
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] a = new int[N];
		long y = 0;
		for(int i=0; i<N; i++) {
			a[i] = sc.nextInt();
			y += a[i];
		}

		long ans = Long.MAX_VALUE;
		
		long x = 0;
		for(int i=0; i<N-1; i++) {
			x += a[i];
			y -= a[i];
			ans = Math.min(ans, Math.abs(x-y));
		}
		
		System.out.println(ans);
				
		sc.close();
	}
}


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


using namespace std;

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

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

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

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	string s; cin >> s;


	int cnt = 0;
	for (char c : s) {
		if (c == '2')cnt++;
	}

	cout << cnt << endl;

	return 0;
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int hund = n / 500;
  n -= hund * 500;
  int onefive = n / 5;
  cout << hund * 1000 + onefive * 5;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N = int(input())

def rec(n):
  if n==1:
    return 1
  return rec(n//2)*2 + 1
print(rec(N))  

Measured memory_bytes: 3060
#include <cctype>
#include <cstdint>
#include <iostream>

using namespace std;

int main()
{
    constexpr auto UNINITIALIZED = 200000000ll;
    int64_t register_ = UNINITIALIZED;
    char op;
    while (true) {
        auto c = cin.get();
        int64_t value;
        if (isdigit(c)) {
            cin.unget();
            cin >> value;
            if (register_ == UNINITIALIZED) {
                register_ = value;
            }
            else {
                switch (op) {
                case '+':
                    register_ += value;
                    break;
                case '-':
                    register_ -= value;
                    break;
                case '*':
                    register_ *= value;
                    break;
                case '/':
                    register_ /= value;
                    break;
                default:
                    break;
                }
            }
        }
        else if (c == '+' || c == '-' || c == '*' || c == '/') {
            op = static_cast<char>(c);
        }
        else if (c == '=') {
            break;
        }
    }
    cout << register_ << endl;
}


Measured memory_bytes: 3084
S = input()
Sum = 0
for i in range(2**(len(S)-1)):
  binary = str(format(i,'b'))
  binary_zero = binary.zfill(len(S)-1)
  t = 0
  for j in range(len(S)-1):
    if binary_zero[j]=='1':
      Sum += int(S[t:j+1])
      t = j+1
  Sum += int(S[t:])
print(Sum)  

  

Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;int a[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }

    }
    ll cost=0;ll dp[n][3];
    dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(j==1)
            {
                dp[i][j]=a[i][j]+max(dp[i-1][0],dp[i-1][2]);
            }
            if(j==0)
            {
                dp[i][j]=a[i][j]+max(dp[i-1][1],dp[i-1][2]);
            }
             if(j==2)
            {
                dp[i][j]=a[i][j]+max(dp[i-1][1],dp[i-1][0]);
            }
        }
    }
    ll max=-1;
    for(int j=0;j<3;j++)
    {
        if(max<dp[n-1][j])
        {
            max=dp[n-1][j];
        }
    }
    cout<<max;
}


Measured memory_bytes: 3840
//abc169_c.cpp
//Sun May 31 20:45:47 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll a;
	string b;
	cin >> a >> b;

	ll bb = 0;
	bb += ll(b[0]-'0')*100;
	bb += ll(b[2]-'0')*10;
	bb += ll(b[3]-'0');

	ll ans = a*bb;
	ans = ans/100;

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  ll N,ans=0;
  cin>>N;
  vector<ll> A;
  map<ll,ll> L;
  REP(i,N){
    ll a;
    cin>>a;
    A.PB(a);
    L[a]++;
  }
  
  SORT(A);
  REVERSE(A);
  
  REP(i,N){
    if(L[A[i]]==0) continue;
    ll T=1;
    while(T<=A[i]) T*=2;
    if(T==2*A[i]){
      if(L[T-A[i]]>1){
        L[T-A[i]]--;
        L[A[i]]--;
        ans++;
      }
    }
    else if(L[T-A[i]]>0){
      L[T-A[i]]--;
      L[A[i]]--;
      ans++;
    }
  }
  
  
  co(ans);
  return 0;
}

Measured memory_bytes: 26736
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define so(Dwarf) sort(Dwarf.begin(), Dwarf.end());
#define star(a,n) long   *a=new long  [n];
#define  m(a,b,s) memset(a,b,s);
#define NOLIMT ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
void right() {
	cout << "YES";
	exit(0);
}
void p(int num) {
	cout << num << "\n";
}
int n;
int a[100001];
int b[100001];
int c[100001];
int dp[4][100005];
int dfs(int ind,char curr) {
	
	if (ind == n+1)
	{
		return 0;
	}
	
	if (dp[curr - 'a' + 1][ind])return dp[curr - 'a' + 1][ind];
	long long  choice3; long long  choice1; long long  choice2;
	if(curr!='c')  choice1 = dfs(ind + 1,'c')+c[ind];
	if(curr!='b')  choice2 = dfs(ind + 1,'b')+b[ind];
	if(curr!='a')  choice3 = dfs(ind + 1,'a')+a[ind];
	if (curr == 'a') {
		dp[curr - 'a' + 1][ind] = max(choice1, choice2);
		return max(choice1, choice2);
	}
	else if (curr == 'b'){
		return dp[curr - 'a' + 1][ind] = max(choice1, choice3);
		return max(choice1, choice3);
	}
	else {
		return dp[curr - 'a' + 1][ind] = max(choice3, choice2);
		return max(choice3, choice2);
	}
	
}
int main(void) {
	NOLIMT;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	long long choice1 = dfs(1, 'c');
	long long choice2 = dfs(1, 'b');
	long long choice3 = dfs(1, 'a');
	p(max(choice1, max(choice2, choice3)));

	
}

Measured memory_bytes: 10368
/* basic header */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <climits>
#include <float.h>
/* STL */
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <array>
#include <iterator>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define init(a,b) fill(begin(a),end(a),b)
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define repa(i,a) for(auto &i:a)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

const int maxn = 1e5 + 10;
struct Edge
{
    int u, v, w;
} edge[maxn * 2];
vector<int>g[maxn];
int n, cnt = 0, ans[maxn], vis[maxn]; //odd is 0, even is 1

void addedge(int u, int v, int w)
{
    edge[++cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].w = w;
    g[u].pb(cnt);
}

void bfs()
{
    queue<int>q;
    q.push(1);
    while (!q.empty())
    {
        int curr = q.front();
        q.pop();
        if (vis[curr]) continue;
        vis[curr] = 1;
        for (int i = 0; i < g[curr].size(); i++)
        {
            int cur = g[curr][i];
            if (!vis[edge[cur].v])
            {
                if (edge[cur].w % 2 == 0)
                {
                    ans[edge[cur].v] = ans[curr];
                }
                else
                {
                    ans[edge[cur].v] = 1 - ans[curr];
                }
                q.push(edge[cur].v);
            }
        }
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; i++)
    {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        addedge(u, v, w); addedge(v, u, w);
    }
    bfs();
    for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 9088
#include<stdio.h>
int main(void){
  int A,B,C;
  int count5,count7;
  scanf("%d %d %d",&A,&B,&C);
  if(A==5) count5++;
  if(A==7) count7++;
  if(B==5) count5++;
  if(B==7) count7++;
  if(C==5) count5++;
  if(C==7) count7++;

  if(count5==2&&count7==1) printf("YES\n");
  else  printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

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

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll dis(ll n)
{
	ll s = 0;
	while (n > 0)
	{
		s += n % 10;
		n /= 10;
	}
	return s;
}

int main()
{
	int N;
	cin >> N;
	ll min = INF;
	FOR(i, N, 1)
	{
		ll a = i, b = N - i;
		min = std::min(min, dis(a) + dis(b));
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int area[33][33][33][33];
pair<int,int> dp[33][33][33][33];
int H,W,provided_power;

pair<int,int> dfs(int lx,int ly,int rx,int ry){
  if(dp[lx][ly][rx][ry].first != -1) return dp[lx][ly][rx][ry];

  if(area[0][0][W-1][H-1] - area[lx][ly][rx][ry] > provided_power){
    dp[lx][ly][rx][ry].first = 0;
    return dp[lx][ly][rx][ry];
  }

  int diff = abs((area[0][0][W-1][H-1] - area[lx][ly][rx][ry]) - provided_power);
  pair<int,int> res(1,diff);
  for(int x=lx;x+1<=rx;x++){
    pair<int,int> left = dfs(lx,ly,x,ry);
    pair<int,int> right = dfs(x+1,ly,rx,ry);

    if(left.first > 0 && right.first > 0){
      pair<int,int> tmp = make_pair(left.first + right.first,min(left.second,right.second));
      res = max(tmp,res);
    }
  }

  for(int y=ly;y+1<=ry;y++){
    pair<int,int> upper = dfs(lx,ly,rx,y);
    pair<int,int> lower = dfs(lx,y+1,rx,ry);
    if(upper.first > 0 && lower.first > 0){
      pair<int,int> tmp = make_pair(upper.first + lower.first,min(upper.second,lower.second));
      res = max(tmp,res);
    }
  }

  return (dp[lx][ly][rx][ry] = res);
}

int main(){
  while(~scanf("%d %d %d",&H,&W,&provided_power)){
    if(H==0 && W==0 && provided_power == 0) break;
    int stage[33][33];
    for(int y=0;y<H;y++){
      for(int x=0;x<W;x++){
	int needs;
	scanf("%d",&needs);
	stage[y][x] = needs;
      }
    }

    //compute area
    memset(area,0,sizeof(area));
    for(int ly=0;ly<H;ly++){
      for(int lx=0;lx<W;lx++){
	for(int ry=0;ry<H;ry++){
	  for(int rx=0;rx<W;rx++){
	    int sum = 0;
	    for(int y=ly;y<=ry;y++){
	      for(int x=lx;x<=rx;x++){
		sum += stage[y][x];
	      }
	    }
	    //init dp
	    dp[lx][ly][rx][ry].first = -1;
	    dp[lx][ly][rx][ry].second = INF;

	    area[lx][ly][rx][ry] = sum;
	  }
	}
      }
    }

    pair<int,int> res = dfs(0,0,W-1,H-1);
    printf("%d %d\n",res.first,res.second);
  }
}

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

int main() {
  
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if(A+B+C == K)
    cout << A-C << endl;
  
  else if(B+A <= K)
    cout << 2*A+B-K << endl;
  
  else if(A <= K)
    cout << A << endl;
  
  else 
    cout << K << endl;
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n = 0;
    cin >> n;

    set<string> st;

    while (n--) {
        string s;
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << '\n';

    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

Measured memory_bytes: 19148
import sys

input = sys.stdin.readline
sys.setrecursionlimit(1000000)


def getN():
    return int(input())


def getList():
    return list(map(int, input().split()))


import math
MOD = 10**9 + 7

def factorial(n):
    ans = 1
    for i in range(1, n+1):
        ans *= i
        ans %= MOD

    return ans % MOD

n = getN()
s = input().strip()

ans = 1

open = 0
for c in s:
    # print(c, ans, open, cur)
    if c == "B":
        if open%2 == 0:
            open += 1

        else:
            if open == 0:
                print(0)
                sys.exit()
            ans *= open
            ans %= MOD
            open -= 1


    else:
        if open%2 == 1:
            open += 1

        else:
            if open == 0:
                print(0)
                sys.exit()
            ans *= open
            ans %= MOD
            open -= 1


if open != 0:
    print(0)
    sys.exit()
print((ans * factorial(n)) % MOD)

Measured memory_bytes: 41580
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{

	int a,b,i,j,k=0;
	cin>>a>>b;
	if(a*4==b || a*2==b) 
		{
			k=1;
		}
	else
	{
		for(i=1; i<=a; i++)
		{
			j=a-i;
				if((i*4)+(j*2)==b) 
					{
						k=1;
						break;
					}
			
		}
	}
	if(k==1) cout<<"Yes";
	else cout<<"No";

	return 0;
}

Measured memory_bytes: 3596
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


a, b, c, k = list(map(int, sys.stdin.buffer.readline().split()))

ans = 0
cnt = min(a, k)
a -= cnt
k -= cnt
ans += cnt
cnt = min(b, k)
b -= cnt
k -= cnt
cnt = min(c, k)
c -= cnt
k -= cnt
ans -= cnt
print(ans)


Measured memory_bytes: 27132