akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <functional>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<double,double> dd;
typedef pair<ll,ll> pll;
typedef pair<string,int> psi;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<ii> > vvip;
typedef vector<ii> vii;
typedef map<int,int> mpi;
#define pb push_back
#define F first
#define S second
//#define MOD 1000000007
#define NA -1
#define ALL(v) v.begin(),v.end()
#define mp make_pair
#define rep(i, n) for (int (i) = 0; (i) < (n); (i) ++)
#define rep1(i, n) for (int (i) = 1; (i) <= (n); (i) ++)
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout<<#a<<" :";FOR(i123,x,y)cout<<setw(4)<<(a)[i123];cout<<endl;}
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); e++) 
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) int((x).size())
#define endl '\n'
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
#define sc(t) scanf("%d",&t)
// vector<string> split(const string &s, char delim) {
//     stringstream ss(s);
//     string item;
//     vector<string> tokens;
//     while (getline(ss, item, delim)) {
//         tokens.push_back(item);
//     }
//     return tokens;
// }

typedef pair<pll,ll> ppll;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define re return
#define MAX 100

 // struct compare  
 // {  
 //   bool operator()(const ii& a, const ii& b)  
 //   {  
 //       re (a.S-a.F+1 < b.S-b.F+1) || (a.S-a.F+1 == b.S-b.F+1 && a.F>b.F);
 //   }
 // };

	ll xx(vll &v)
	{
		ll s=0;
	ll ans=0;
	int n=sz(v);
	for(int i=0;i<n;i++)
	{
		if(!i)
		s=v[0];
		else
		{
			if(s>0)
			{
				if( s+v[i]<0)
				{
					s+=v[i];
					continue;
				}
				ll x ,y;
				x= max(s+v[i]+1,(ll)0);
				ans+=x;
				if(x!=0)
				s=-1;
			}
			else
			{
				if( s+v[i]>0)
				{
					s+=v[i];
					continue;
				}
				ll x ,y;
				x= max(1-(s+v[i]),(ll)0);
				ans+=x;
				if(x!=0)
				s=1;

			}
		}

	}
	re ans;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	//     freopen("output.txt","w",stdout);;
	// #endif
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	//ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
	int n;
	cin>>n;
	vll v(n);
	rep(i,n)
	cin>>v[i];
	ll z=0;
	if(n==1)
	{
		if(v[0]!=0)
		cout<<0<<endl;
		else
			cout<<1<<endl;
		re 0;
	}
	ll ans=INFL;
	if(v[0]==0)
	{
		v[0]+=1;

		ans=min(ans,xx(v)+1);
		v[0]=-1;
		ans=min(ans,xx(v)+1);
	}
	else if(v[0]>0)
	{
		ans=min(ans,xx(v));
		ll z= v[0]+1;
		v[0]=-1;
		ans=min(ans,xx(v)+z);
		
	}
	else 
	{
			ll z= 1-v[0];
		ans=min(ans,xx(v));
		v[0]=1;
		ans=min(ans,xx(v)+z);
		

	}
cout<<ans<<endl;



}

Measured memory_bytes: 1024
#!/usr/bin/env python3

def judge(k):
    n = str(k)
    return n[0] == n[4] and n[1] == n[3]

def solve(a,b):
    c = 0
    for i in range(a,b+1):
        if judge(i):
            c += 1
    return c 

def main():
    A,B = map(int,input().split())
    print(solve(A,B))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} 		
}




Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
int main() {
    int N,K;
    cin >> N >> K;
    if(2*N < K){
        cout << 0 << endl;
        exit(0);
    }
    ll a[210000] = {};
    ll b[210000] = {};
    a[0] = 1;
    a[1] = 2;
    a[2] = 9;
    a[3] = 16;
    a[4] = 35;
    a[5] = 54;

    reps(i,6,200001) {
        a[i] = 2*a[i-1] + a[i-2] -4*a[i-3] + a[i-4] + 2*a[i-5]-a[i-6];
    }
    rep(i,200001){
        b[i] = (i+1)*(i+1)*(i+1);
    }

    if(K%2 == 0) {
        ll t = K/2;
        if(N < t){
            cout << 0 << endl;
        }
        else{
            ll s = N - t + 1;
            if(s%t == 0){
                cout << a[s/t - 1] << endl;
            }
            else{
                cout << a[s/t] << endl;
            }
        }
    }
    else {
        if(N <= K-1){
            cout << 0 << endl;
        }
        else{
           ll s =  N-K;
            cout << b[s/K] << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 3584
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 文字列の入力
        List<String> sList = Arrays.asList(sc.next().split(""));
        Collections.sort(sList);
        int count = 0;
        String lastChar = "";
        String ans = "Yes";
        for(String chara : sList) {
          if (!chara.equals(lastChar)) {
            if (count % 2 == 0) {
              count = 0;
            } else {
              ans = "No";
              break;
            }
          }
          lastChar = chara;
          count++;
        }
        if (count % 2 == 1) {
          ans = "No";
        }
      
		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 20948
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d, n;
  cin >> d >> n;
  int s = pow(100,d);
  if(n == 100) cout << s * (n+1) << endl;
  else cout << s * n << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int n; cin >> n;
	cout << 180 * (n - 2) << endl;
}

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

typedef long long int ll;

int main()
{
    ll n;
    cin >> n;
    if(n % 2 == 0){
        cout << n / 2 - 1;
    }
    else{
        cout << n / 2;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cnt;
int main(){

  int n;

  while(1){



    cin >> n;
    if(n != 0 && cnt == 3) cout << endl;
    if(n == 0) break;
    
    int coin[4] = {};
    int mjarr[4] = {10,50,100,500};
    int num = 0, ddd = 0;
    int ncpy = 0;
    int mini = INT_MAX;
    int savey[4] = {};
    int aaaa;

    for(int i = 0; i < 4; i++){
      cin >> coin[i];
      num += coin[i];
    }
    ncpy = n;
    ddd = num;

  
    for(int j = 0; j <= coin[0]; j++){
      for(int t = 0; t <= coin[1]; t++){
	for(int s = 0; s <= coin[2]; s++){
	  for(int l = 0; l <= coin[3]; l++){
	    aaaa = j * mjarr[0] +  t * mjarr[1] + s * mjarr[2] + l * mjarr[3];
	    n -= aaaa;
	    //   cout << -n << " ";

	    if(n == 0 && mini > num-j-s-t-l){
	      mini = num-j-t-s-l;
	      n = ncpy;
	      savey[0] = j;
	      savey[1] = t;
	      savey[2] = s;
	      savey[3] = l;
	    }else if(n > 0){
	      n = ncpy;
	      
	    }else if(n < 0){
	      int ll[4];
	      n *=  -1;
	      ll[3] = (n/500);
	      ll[2] = (n-(500 * ll[3]))/100;
	      ll[1] = (n-(100 * ll[2])-(500 * ll[3]))/50;
	      ll[0] = (n-(50 * ll[1]) - (100 * ll[2]) - (500 * ll[3]))/10;
	      
	      //  cout << mini << " " ;
	      if(mini > num-j-t-s-l+ll[0]+ll[1]+ll[2]+ll[3]){
		mini = num-j-t-s-l+ll[0]+ll[1]+ll[2]+ll[3];
		
		savey[0] = j-ll[0];
		savey[1] = t-ll[1];
		savey[2] = s-ll[2];
		savey[3] = l-ll[3];
		n = ncpy;
		//		  cout << n << endl;
	      }
	      //		cout << -n << " " <<endl;
	      n = ncpy;
	    }
	    //   cout << mini << endl;
	  }
	}
      }
    }
  
    for(int i = 0; i < 4; i++){
      if(savey[i] > 0) cout << mjarr[i] << " " << savey[i] << endl;
       cnt = 3;
    }
   
    // cout << -n;
  }

}

Measured memory_bytes: 1160
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define endl "\n"
#define MOD 998244353
#define nl cout<<"\n"
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i];nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
long findTrailingZeros(long n) 
{ 
    long count = 0;
    for (long i = 5; n / i >= 1; i *= 5) 
        count += n / i;
    return count; 
} 
int main()
{
    fastio();
    ll N;
    cin>>N;
    if(N%2==1)
        cout<<0;
    else
    {
        ll ans=N/10+findTrailingZeros(N/10);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    S=list(input())
    T=list(reversed(S))
    N=len(S)
    for a,b in zip(S,T):
        if a!=b:
            print('No')
            exit()
    U=S[:(N-1)//2]
    V=list(reversed(U))
    for a,b in zip(U,V):
        if a!=b:
            print('No')
            exit()
    print('Yes')
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38324
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 998244353
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
 
int power(int x,int y,int mod) 
{ 
 	int ret = 1;
 	x = x % mod;
 	while (y){
 		if(y&1) ret = (ret*x)%mod;
 		y = y>>1;
 		x = (x*x)%mod;
    } 
    return ret%mod; 
}

int isprime(int x)
{
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return 0;
	return 1;
}

void solve()
{	
	int n,k;
	cin>>n>>k;
	vector<int> inp(n),dp(n,1e9+5);
	dp[0] = 0;
	for (auto &x:inp) cin>>x;
	for (int i=0;i<n;i++){
		for (int j=i+1;j<i+k+1 && j<n;j++){
			dp[j] = min(dp[j],dp[i]+abs(inp[j]-inp[i])); 
		}
	}
	cout<<dp[n-1]<<endl;

}
 
 
signed main(){
	// int t;
	// cin>>t;
	// while (t--)	
	solve();	
 
}
	

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  int N; cin>>N;
  ll A[N];

  ll minusmin=-INF;
  ll plusmin=INF;
  ll ans=0;
  ll minusct=0;
  rep(i,N){
    cin>>A[i];
    if(A[i]<0){
      minusct++;
      ans-=A[i];
      maxi(minusmin,A[i]);
    }
    else{
      ans+=A[i];
      mini(plusmin,A[i]);
    }
  }
  if(minusct%2==1){
    if(minusmin+plusmin<0){
      ans-=plusmin*2;
    }
    else{
      ans+=minusmin*2;
    }
  }

  cout<< ans<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1024
n = int(input())
taro, hanako = 0, 0
for i in range(n):
    t, h = input().split()
    if t > h:
        taro += 3
    elif t < h:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print(f"{taro} {hanako}")


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    rep(i, s.length())
    {
        if (i % 2 == 0)
        {
            if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
                ;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
                ;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    string s; cin >> s;
    if(s.size()<4){
        cout << "No" << endl;
        return 0;
    }
    if(s.substr(0,4)=="YAKI"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    string s; cin >> s;
    for(int i=0; i<s.size(); ++i){
        if(s[i] == ',') s[i] = ' ';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,a,b,arr[N];
bool chk(ll cnt){
    ll rmv = cnt*b;
    ll req = 0;
    for(ll i=0;i<n;i++){
        ll val = arr[i] - rmv;
        ll extra = (val + a-b-1 )/(a-b);
        if(val>0)req+=extra;
    }
    return req<=cnt;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>a>>b;
    for(ll i=0;i<n;i++)cin>>arr[i];
    ll s=0,e=1e9;
    ll ans=1e10;
    while(s<=e){
        ll mid=(s+e)>>1;
        if(chk(mid))ans=min(ans,mid),e=mid-1;
        else s=mid+1;
    }
    cout<<ans;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	vector<vector<pair<int,int>>> P(N);
	REP(i,N){
		int A=in();
		REP(j,A){
			int x=in(),y=in();
			P[i].emplace_back(x,y);
		}
	}
	
	int maxN=0;
	REP(i,1<<N){
		vector<int> X(N,0);
		int V=i,index=0,K=0;
		REP(j,N){
			if(V&1){
				X[index]=1;
				K++;
			}
			index++;
			V/=2;
		}
		bool truth=true;
		REP(j,N){
			if(X[j]==1){
				for(auto& x:P[j]){
					if(X[x.first-1]!=x.second){
						truth=false;
					}
				}
			}
		}
		if(truth){
			maxN = max(maxN,K);
		}
	}
	out(maxN);
	return 0;
}


Measured memory_bytes: 256
S = list(input())
N = len(S)
child = [1] * N
memo = []

# RLのインデックスを取得する
for i in range(N-1):
    if S[i] == "R" and S[i+1] == "L":
        memo.append(i)
        memo.append(i+1)
memo.append("dummy")
count = 0
for i in range(N):
    if i != memo[count]:
        if S[i] == "R":
            if (memo[count] - i) % 2 == 0:
                child[memo[count]] += 1
                child[i] -= 1
            else:
                child[memo[count+1]] += 1
                child[i] -= 1
        elif S[i] == "L":
            if (i - memo[count-1]) % 2 == 0:
                child[memo[count-1]] += 1
                child[i] -= 1
            else:
                child[memo[count-2]] += 1
                child[i] -= 1
    else:
        count += 1

ans = [str(n) for n in child]
ans = " ".join(ans)
print(ans)

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

typedef long long ll;

string s1, s2;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s1 >> s2;
    int Cnt = 0;
    for (int i = 0; i < 3; ++i) {
        if (s1[i] == s2[i])
            ++Cnt;
    }
    cout << Cnt << endl;

    return 0;
}



Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
	priority_queue<pair<int, int> > PQ;
	int color[MAX], d[MAX];
	for(int i = 0; i < n; i++) {
		color[i] = WHITE;
		d[i] = INFTY;
	}
	
	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = GRAY;
	
	while(!PQ.empty()) {
        pair<int, int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		
		color[u] = BLACK;
		
		if(d[u] < f.first * (-1)) continue;
		
		for(int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if(color[v] == BLACK) continue;
			if(d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}		
	}
	
	for(int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	} 
}


int main() {
	int u, k, v, c;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) {
			cin >> v >> c;
			adj[u].push_back( make_pair(v, c));
		}
	}
	
	dijkstra();
	
	return 0;
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    vl A;
    set<ll> S1, S2;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            S1.insert(i);
            S1.insert(n / i);
        }
    }

    for (ll i = 1; i * i <= n - 1; i++) {
        if ((n - 1) % i == 0) {
            S2.insert(i);
            S2.insert((n - 1) / i);
        }
    }
  

    for (auto ite = S1.begin(); ite != S1.end();ite++){
        x = *ite;
        a = n;
        while (x!=1&&a % x == 0) a /= x;
        if (a % x == 1){
          ans++;
        }
    }

    ans += S2.size() - 1;

    cout << ans << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

template<uint32_t mod>
struct ModInt{
	uint32_t a;
	ModInt& s(uint32_t vv){
		a=vv<mod?vv:vv-mod;
		return *this;
	}

	ModInt(int64_t x=0){s(x%mod+mod);}

	ModInt& operator+=(const ModInt &x){return s(a+x.a);}
	ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
	ModInt& operator*=(const ModInt &x){
		a=uint64_t(a)*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
	ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
	bool operator==(const ModInt &x)const{return a==x.a;}
	bool operator!=(const ModInt &x)const{return a!=x.a;}
	bool operator<(const ModInt &x)const{return a<x.a;}

	ModInt operator-()const{return ModInt()-*this;}
	ModInt pow(int64_t n)const{
		ModInt res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}

	ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<1000000007>;
template<class Mint,int32_t lg>
struct ModIntTable{
	int N;
	vector<Mint>facts,finvs,invs;
	ModIntTable():N(1<<lg),facts(N),finvs(N),invs(N){
		const uint32_t mod=Mint(-1).a+1;
		invs[1]=1;
		for(int i=2;i<N;i++)invs[i]=invs[mod%i]*(mod-mod/i);

		facts[0]=1;
		finvs[0]=1;
		for(int i=1;i<N;i++){
			facts[i]=facts[i-1]*i;
			finvs[i]=finvs[i-1]*invs[i];
		}
	}
	inline Mint fact(int n)const{return facts[n];}
	inline Mint finv(int n)const{return finvs[n];}
	inline Mint inv(int n)const{return invs[n];}
	inline Mint binom(int n,int k)const{return facts[n]*finvs[k]*finvs[n-k];}
	inline Mint perm(int n,int k)const{return facts[n]*finvs[n-k];} 
};
ModIntTable<mint,19>mtable;

signed main(){
	int N,K;
	cin>>N>>K;
	for(int i=1;i<=K;i++){
		if(N-K<i-1){
			cout<<0<<endl;
			continue;
		}
		mint num=1;
		num*=mtable.binom(K-i+i-1,i-1);
		num*=mtable.binom(N-K-(i-1)+i,i);
		cout<<num<<endl;
	}
	return 0;
}

Measured memory_bytes: 6400
from itertools import permutations

N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
x=set([n for n in range(1,N+1)])
x=list(permutations(x,N))

a,b=0,0
for num in range(len(x)):
    if p==list(x[num]):
        a=num+1
        if p==q:
            b=num+1
            print(abs(a-b))
            exit()
    elif q==list(x[num]):
        b=num+1

print(abs(a-b))

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

	const int h = 100;
	const int w = 100;
	vector<string> v(h);
	for (int i = 0; i < h / 2; ++i) {
		v[i].assign(w, '#');
		v[i + h / 2].assign(w, '.');
	}

	for (int i = 0; i < h / 2; i += 2) {
		for (int j = 0; j < w; j += 2) {
			if (A > 1) {
				v[i][j] = '.';
				--A;
			}
		}
		int k = h - 1 - i;
		for (int j = 0; j < w; j += 2) {
			if (B > 1) {
				v[k][j] = '#';
				--B;
			}
		}
	}

	cout << h << " " << w << endl;
	for (auto& s : v) {
		cout << s << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b>>c>>d>>e>>k;

    if (e-a<=k) {
        puts("Yay!");
    } else {
        puts(":(");
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(
					((Math.abs(a - c) <= d) || ((Math.abs(a - b) <= d) && (Math.abs(b - c) <= d))) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35656
#include<stdio.h>
#pragma GCC optimize("O2")
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int IMIN=(1<<31);int A[200000],B[200000];long K=0,p=0,m=0,z=0;
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Sort(unsigned *from,unsigned *to,unsigned bit)
{
  if(!bit||to<from+1)return;
  unsigned *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix(int *array,const int len)
{
  unsigned *x=(unsigned*)array;
  rep(i,len)x[i]^=IMIN;
  Sort(x,x+len,IMIN);
  rep(i,len)x[i]^=IMIN;
}
static inline int check(long x)
{
  long count=0;
  if(x>=0)
  {
    int plus=p-1,minus=m-1;count+=z*(p+m)+z*(z-1)/2+p*m;
    rep(i,plus){while(1l*A[i]*A[plus]>x){plus--;}if(i>=plus){break;}count+=plus-i;}
    rep(i,minus){while(1l*B[i]*B[minus]>x){minus--;}if(i>=minus){break;}count+=minus-i;}
  }
  else{x=-x;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<x&&low<p){low++;}count+=p-low;}}
  return count>=K;
}
int main(void)
{
  int N=IN(),x;long l=-2e18,r=-l,mid;K=IN();
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  Radix(A,p),Radix(B,m);
  while(l<=r){mid=(l+r)/2;if(check(mid))r=mid-1;else l=mid+1;}
  return OUT(l),0;
}

Measured memory_bytes: 2168
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    println!("{}", s.iter().zip(t.iter()).filter(|(s, t)| s != t).count());
}


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


int main(){
    string str;
    int a,b;
    stack<int> S;
    while(cin >> str){
        if(str == "+"){
            b = S.top();
            S.pop();
            a = S.top();
            S.pop();
            S.push(a+b);
        }else if(str == "-"){
            b = S.top();
            S.pop();
            a = S.top();
            S.pop();
            S.push(a-b);
        }else if(str == "*"){
            b = S.top();
            S.pop();
            a = S.top();
            S.pop();
            S.push(a*b);   
        }else{
            S.push(stoi(str));
        }
    }
    cout << S.top() << endl;
    


}


Measured memory_bytes: 3228
n = int(input())
a = []
for i in range(2):
  a.append(list(map(int, input().split())))

for i in range(1, n):
  a[0][i] += a[0][i-1]
  a[1][n-i-1] += a[1][n-i]

M = 0
for i in range(n):
  if M < a[0][i] + a[1][i]:
    M = a[0][i]+a[1][i]
print(M)


Measured memory_bytes: 3064
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)


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

int main(int argc, char const *argv[])
{
	int n,k;
	string s;
	cin>>n>>k>>s;
	int cnt=0;
	for (int i = 0; i < n-1; ++i)
	{
		if (s.at(i)!=s.at(i+1))
		{
			++cnt;
		}
	}
	if (cnt<=k*2-1)
	{
		cout<<n-1<<endl;
	}
	else
	{
		cout<<n-cnt-1+2*k<<endl;
	}
	return 0;
}


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


ll cal(ll N, ll b)
{
	ll ans = 0;
	while(N >= b){
		ans += N%b;
		N/=b;
	}
	return ans + N;
}

void solve()
{
	long long ans =  1e16;
	for(ll b=2; b*b<=N;++b){
		if(S==cal(N,b)) ans=min(ans,b);
	}
	for(ll x=1;x*x<=N;++x){
	    ll b=(N-S+x)/x;
	    if(b<2) continue;
	    if(S==cal(N,b)) ans=min(ans,b);
	}
	if(N==S) ans=min(ans, N+1);
	
	if(ans == 1e16) ans=-1;
	cout << ans << endl;
}

int main()
{
	cin >> N >> S;
	solve();
	return 0;
}

Measured memory_bytes: 256
import math
n,m = [int(x) for x in input().split()]

mod = 10**9 + 7

if n == m:
    ans = (math.factorial(n) * math.factorial(m) * 2) % mod
elif abs(n-m) > 1:
    ans = 0
else:
    ans = (math.factorial(n) * math.factorial(m)) % mod

print(ans)

Measured memory_bytes: 5184
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    K, X = LI()
    if K * 500 >= X:
        print("Yes")
    else:
        print("No")
    return


# B
def B():
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return

# Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int OFS = 2000;

int N, K;
int imos[4010][4010];
int sum[2010][2010];

signed main()
{
	cin >> N >> K;

	rep(i, N) {
		int x, y;
		char c;
		scanf("%lld %lld %c", &x, &y, &c);

		if (c == 'W') y += K;

		x %= 2 * K;
		y %= 2 * K;

		imos[x+0][y+0] += 1;
		imos[x+0][y+K] -= 1;
		imos[x+K][y+0] -= 1;
		imos[x+K][y+K] += 1;

		imos[x+K][y+K] += 1;
		imos[x+K][y+K+K] -= 1;
		imos[x+K+K][y+K] -= 1;
		imos[x+K+K][y+K+K] += 1;
	}

	rep(i, 4005) rep(j, 4005) imos[i][j + 1] += imos[i][j];
	rep(i, 4005) rep(j, 4005) imos[i + 1][j] += imos[i][j];
	rep(i, 4005) rep(j, 4005) sum[i%(2*K)][j%(2*K)] += imos[i][j];

	int mx = 1;

	rep(y, 2005) {
		rep(x, 2005) {
			chmax(mx, sum[y][x]);
		}
	}

	cout << mx << endl;
}




Measured memory_bytes: 157312
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
  	string s,s_memo1 = "",s_memo2 = "",s_memo3 = "";
 	cin >> s;
  
  	while(s != ""){
      s_memo1 = "";
      s_memo2 = "";
      s_memo3 = "";
      rep(i,0,5){
        s_memo3 += s[s.size()-5+i];
      }
      rep(i,0,6){
        s_memo1 += s[s.size()-6+i];
      }
      rep(i,0,7){
        s_memo2 += s[s.size()-7+i];
      }
      
      if(s_memo2 == "dreamer"){
        s.erase(s.size()-7,7);
      }
      else if(s_memo1 == "eraser"){
        s.erase(s.size()-6,6);
      }
      else if(s_memo3 == "erase"){
        s.erase(s.size()-5,5);
      }
      else if(s_memo3 == "dream"){
        s.erase(s.size()-5,5);
      }
      else{
        cout << "NO" << endl;
        return 0;
      }
    }
  
  	cout << "YES" << endl;
  
  
	return 0; 
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n, pos = 0;
vector<int> pre, in, post;
void rec(int l, int r);
int main()
{
	cin >> n;
	pre.resize(n);
	in.resize(n);
	for(int i = 0; i < n; i++)
		cin >> pre[i];
	for(int i = 0; i < n; i++)
		cin >> in[i];
	rec(0, pre.size());
	for(int i = 0; i< n; i++)
	{
		if(i)
			cout << " ";
		cout << post[i];
	}
	cout << endl;
}
void rec(int l, int r)
{
	if(l >= r)
		return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}



Measured memory_bytes: 3144
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
string S;

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

  int ans = 0;
  char c = '0';
  for (int i = 0; i < N; i++) {
    if (c != S[i]) {
      ans++;
      c = S[i];
    }
  }

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

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

typedef pair<int,int>par;

#define f first
#define s second
#define maxn 200010
#define int long long

int dp[maxn],abi[maxn];
int n;

void update(int pos,int value){
    while(pos <= n){
        abi[pos] = max(abi[pos],value);
        pos += (pos & (-pos));
    }
}
int query(int pos){
    int ans = 0;
    while(pos >= 1){
        ans = max(ans,abi[pos]);
        pos -= (pos & (-pos));
    }
    return ans;
}
int h[maxn],a[maxn];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int ans = 0;
    cin >> n;

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

    for(int i=1;i<=n;i++){
        cin >> a[i];
        int p = query(h[i]-1) + a[i];
        update(h[i],p);
        ans = max(ans,p);
    }

    cout << ans << '\n';
}







Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define ll long int
using namespace std;
int main()
{
    ll w,n,ans=0; cin>>n>>w;
    ll a[n],b[n];
    for(ll i=0;i<n;i++) {cin>>a[i]>>b[i];}
    //sort(v.begin(),v.end(),cmp);
    ll dp[n+1][w+1];
    //memset(dp,-1,sizeof(dp));
    //dp[0]=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0 or j==0) {dp[i][j]=0;continue;}
            if(a[i-1]>j) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(b[i-1]+dp[i-1][j-a[i-1]],dp[i-1][j]);
           // cout<<dp[i][j]<<" ";
          //ans=max(ans,dp[i][j]);
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 79104
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    sort(all(a));

    ll ans=0;
    ll sum=0;
    rep(i,n){
        if(2*sum<a[i])ans=0;
        sum+=a[i];
        ++ans;
    }
    cout<<ans<<endl;
}

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

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef int Capacity;
struct Dinic {
    int n, s, t;
    vector<int> level, iter, que;
    vector<vector<Capacity>> cap, flow;
    vector<vector<int>> g;
    Capacity inf;
    Dinic(int n)
        : n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
          g(n, vector<int>()), inf(numeric_limits<Capacity>::max()/8){}
    Dinic(const Graph &graph){
        *this = Dinic(graph.size());
        for(int i = 0; i < n; i++) for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
    }
    void addEdge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    inline Capacity residue(int u, int v){ return cap[u][v] - flow[u][v]; }
    Capacity solve(int s, int t){
        this->t = t, this->s = s;
        Capacity res = 0;
        while(levelize()){
            iter.assign(n, 0);
            res += augment(s, inf);
        }
        return res;
    }
    bool levelize(){
        int l = 0, r = 0;
        level.assign(n, -1); level[s] = 0;
        que.assign(n+1, 0);
        que[r++] = s;
        while(l != r){
            int v = que[l++];
            for(const int &d : g[v]){
                if((level[d] != -1 && level[d] <= level[v] + 1) || residue(v,d) == 0) continue;
                level[d] = level[v] + 1; que[r++] = d;
            }
        }
        return level[t] != -1;
    }
    Capacity augment(int v, Capacity lim){
        Capacity res = 0;
        if(v == t) return lim;
        for(int &i = iter[v]; i < (int)g[v].size(); i++){
            const int &d = g[v][i];
            if(residue(v,d) == 0 || level[v] + 1 != level[d]) continue;
            const Capacity aug = augment(d, min(lim, residue(v,d)));
            if(aug > 0){
                flow[v][d] += aug; flow[d][v] -= aug;
                res += aug; lim -= aug;
                if(lim == 0) break;
            }
        }
        return res;
    }
};

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

int main(){
    int N,M;
    cin >> N >> M;
    Graph g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(a,b,c);
    }
    Dinic dinic(g);
    cout << dinic.solve(0,N-1) << endl;
}

Measured memory_bytes: 1348
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

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

    int w, h, x, y;
    cin >> w >> h >> x >> y;

    Ld ans = (Ld)w * h / 2;

    cout << fixed << setprecision(10) << ans << ' ' << ((w == 2 * x && h == 2 * y) ? 1 : 0) << endl;

    return 0;
}

Measured memory_bytes: 3776
string = input()
H1, M1, H2, M2, K = [int(digit) for digit in string.split(" ")]
hour2minutes = lambda H1, H2 : (H2 - H1) * 60
total_minutes = hour2minutes(H1, H2) + (M2 - M1)
ans = total_minutes - K
print(ans)

Measured memory_bytes: 9072
import numpy as np

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

colors = np.array([[0]*W]*H)

i = 0
j = 0
flag = True
count = 0
for k in range(N):
    for m in range(a[k]):
        colors[i, j] = str(k+1)
        count += 1
        if count % W == 0:
            i += 1
            if flag == True:
                flag = False
            else:
                flag = True
            continue
        if flag == True:
            j += 1
        else:
            j -= 1

for i in range(H):
    s = list(colors[i])
    for j in range(W):
        s[j] = str(s[j])
    p = ' '.join(s)
    print(p)


Measured memory_bytes: 27140
//██████╗ ██╗   ██╗██╗      ██████╗ ███████╗
//██╔══██╗██║   ██║██║      ██╔══██╗██╔════╝
//██████╔╝██║   ██║██║█████╗██║  ██║█████╗
//██╔══██╗██║   ██║██║╚════╝██║  ██║██╔══╝
//██║  ██║╚██████╔╝██║      ██████╔╝███████╗
//╚═╝  ╚═╝ ╚═════╝ ╚═╝      ╚═════╝ ╚══════╝

#include <iostream>
#include <random>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <chrono>
#include <cstdio>
#include <map>
#include <memory.h>


// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef  double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;

#define next ajksdslk
#define prev aklsfjk

mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

const int maxn = (int) 5e6 + 100;
const int maxlog = 21;
const int base = 998244353;
const ld eps = (ld) 1e-9;
const ld PI = acos(-1.);
//const int pp = 41;
const int inf = 2e9;
const ll llinf = 1e18;

int N, M;
string s;
int n;

int nxt[maxn];
int f[maxn];

vector<int> pos[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  freopen ("input.txt", "r", stdin);
#endif
  cin >> N >> M >> s;

  vector<int> poses;
  reverse(all(s));
  for (int i = 0; i <= N; i ++) {
    if (s[i] == '0') poses.pb(i);
  }
  n = sz(poses);
  int r = 0;
  for (int i = 0; i + 1 < n; i ++) {
    while (r + 1 < n && poses[r + 1] - poses[i] <= M) {
      r ++;
    }
    if (r == i) {
      cout << -1;
      return 0;
    }
    nxt[i] = r;
  }
  for (int i = 0; i <= N; i ++) {
    f[i] = inf;
  }

  int v = 0;
  f[0] = 0;
  while (v != n - 1) {
    int l = v + 1;
    int r = nxt[v];
    for (int i = poses[l]; i <= poses[r]; i ++) {
      if (s[i] == '1') continue;
      f[i] = f[poses[v]] + 1;
    }
    v = r;
  }
  reverse(f, f + N + 1);


  for (int i = 0; i <= N; i ++) {
    if (f[i] == inf) continue;
    pos[f[i]].pb(i);
  }
  v = 0;
  while (v != N) {
    int curD = f[v];
    int nxtD = curD - 1;
    int nxtPos = pos[nxtD].front();
    cout << nxtPos - v << " ";
    v = nxtPos;
  }


  return 0;
}

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

int main() {
  string s;cin>>s;ll a=0;
  for(int i=0;i<s.size();i++){
    a=a+s[i]-48;
  }if(a%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3680
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

int main() {
  std::ios::sync_with_stdio(false);
  int n;
  while(cin>>n) {
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    if (n == 1) cout << 0 << endl;
    else {
      sort(all(a));
      cout << a.back() - a.front() << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256