akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cassert>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
 
#ifdef LOCAL_CODE
	#define DEBUG(x) cerr << "[" << #x << '=' << x << "]" << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int i = (N)-1; i >= 0; i--)
#define REP(i, N) for(int i = 0; i < (int)(N); i++)
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.first >> p.second; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.first << ' ' << p.second; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

unsigned long long n,m,k;//A,B,C,D;
ll dp[3333][3333];
const int MOD = 998244353;
void solve(istream& cin, ostream& cout) {
	int S;
	cin >> n>>S;
	vector<int> A(n);
	cin>>A;
	dp[0][0] = 1;
	REP(i, n) {
		REP(j, S+1) {
			dp[i+1][j] = (2*dp[i][j])%MOD; 
			if(j-A[i] >= 0) {
				dp[i+1][j] = (dp[i+1][j]+dp[i][j-A[i]])%MOD;
			}
			DEBUG(i+1);
			DEBUG(j);
			DEBUG(dp[i+1][j]);
		}
	}
	cout << dp[n][S] <<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 81724
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        long N = sc.nextLong();
        double sqrt = Math.Sqrt((double)N);
        int min = int.MaxValue;
        for (int i = 1; i <= sqrt; i++) {
            if (N % i == 0) {
                min = Math.Min(min, Math.Max(i.ToString().Length, (N / i).ToString().Length));
            }
        }
        WriteLine(min);
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {


        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 13268
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P) :
 P = sorted(P)
 phU = []
 phU.append(P[0])
 phU.append(P[1])
 for p in P[2:] :
  phU.append(p)
  if isCLKWISE(phU) : continue
  while(True):
   del phU[-2]
   try:
    if isCLKWISE(phU) : break
   except IndexError : break
 phL = []
 phL.append(P[-1])
 phL.append(P[-2])
 for p in P[-3::-1] :
  phL.append(p)
  if isCLKWISE(phL) : continue
  while(True) :
   del phL[-2]
   try:
    if isCLKWISE(phL) : break
   except IndexError : break
 ph = phU + phL[1:-1]
 return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
P = P[idx:] + P[:idx]
for p in P : print(p[0],p[1])

Measured memory_bytes: 33140
using System;

namespace abc052
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = Convert.ToInt32(str[0]);
            int b = Convert.ToInt32(str[1]);
            int c = Convert.ToInt32(str[2]);
            int d = Convert.ToInt32(str[3]);

            int rectangle1 = a * b;
            int rectangle2 = c * d;

            if (rectangle1 == rectangle2)
            {
                Console.WriteLine(rectangle1.ToString());
            }
            else if(rectangle1 > rectangle2)
            {
                Console.WriteLine(rectangle1.ToString());
            }
            else
            {
                Console.WriteLine(rectangle2.ToString());
            }
        }
    }
}


Measured memory_bytes: 2904
// AOJ 2473 Poor Computer
// 2018.2.1 bal4u

#include <stdio.h>

#define MAX 42

int lim;
long long goal;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int bitcount64(long long x)
{
	x = ((x & 0xAAAAAAAAAAAAAALL) >>  1) + (x & 0x55555555555555LL);
	x = ((x & 0xCCCCCCCCCCCCCCLL) >>  2) + (x & 0x33333333333333LL);
	x = ((x & 0xF0F0F0F0F0F0F0LL) >>  4) + (x & 0x0F0F0F0F0F0F0FLL);
	x = ((x & 0x00FF00FF00FF00LL) >>  8) + (x & 0xFF00FF00FF00FFLL);
	x = ((x & 0xFF0000FFFF0000LL) >> 16) + (x & 0x00FFFF0000FFFFLL);
	x = ((x & 0xFFFFFF00000000LL) >> 32) + (x & 0x000000FFFFFFFFLL);
	return (int)x;
}

int trailingZero(long long x)
{
#if 0
	int k = 0;
	while (!(x & 1)) k++, x >>= 1;
	return k;
#endif
	return bitcount64(~x & (x-1));
}

int check(long long s, int k)
{
	int i, j, t;
	long long s1, s2;

	if (k + bitcount64(goal & ~s) > lim) return 0;
	if ((s & goal) == goal) return 1;

	for (s1 = s; s1; s1 &= s1-1) {
		i = trailingZero(s1);
		for (s2 = s; s2; s2 &= s2-1) {
			j = trailingZero(s2);
			t = i+j;
			if (t <= MAX && !((s >> t)&1)) {
				if (check(s | (1LL << t), k+1)) return 1;
			}
			t = i-j; if (t < 0) t = -t;
			if (t > 0 && !((s >> t)&1)) {
				if (check(s | (1LL << t), k+1)) return 1;
			}
		}
		for (; i < MAX; i <<= 1) {
			if (!((s >> i) & 1)) {
				if (check(s | (1LL << i), k+1)) return 1;
			}
		}
	}
	return 0;
}

int main()
{
	int n, i;
 
	n = in();
	for (i = 0; i < n; i++) goal |= 1LL << in();
	for (lim = n; !check(2LL, 0); lim++);
	printf("%d\n", lim);
	return 0;
}


Measured memory_bytes: 2080
import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			if(n == 1 || n == 2 || n == 3){
				System.out.println("deficient number");
				continue;
			}

			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(1);
			for(int i=2;i*i<=n;i++){
				if(n%i == 0){
					list.add(i);
					if(i != n/i){
						list.add(n/i);
					}
				}
			}

			int count=0;
			for(int i=0;i<list.size();i++){
				count += list.get(i);
			}

			if(count == n){
				System.out.println("perfect number");
			}else if(count < n){
				System.out.println("deficient number");
			}else{
				System.out.println("abundant number");
			}
		}
	}
}

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

rsp={"r":0, "s":1 , "p":2}
n,k=map(int,input().split())
rsp_points=list(map(int,input().split()))
T=input()
for i in range(k):
    dp=[[0]*3 for i in range(2)]
    odev=0
    for ti in range(i,n,k):
        now = (rsp[T[ti]]+2)%3
        rspp=rsp_points[now]
        dp[(odev+1)%2][now] = max(rspp+dp[odev][(now+1)%3],rspp+dp[odev][(now+2)%3])
        dp[(odev+1)%2][(now+1)%3] = max(dp[odev][now],dp[odev][(now+2)%3])
        dp[(odev+1)%2][(now+2)%3] = max(dp[odev][(now+1)%3],dp[odev][now])
        # print(dp[(odev+1)%2])
        odev=(odev+1)%2
    ans+=max(dp[odev])
    # print(*dp,sep="\n")
    # print()
print(ans)




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

using namespace std;

const int C = 26;

int n, m;
int cnt[C];

bool fuck(int a1, int a2, int a4) {
	for (int i = 0; a1 && i < C; i++) {
		if (cnt[i] % 2 == 1) {
			a1--;
			cnt[i]--;
		}
	}
	if (a1) return false;
	for (int i = 0; i < C; i++) {
		if (cnt[i] % 2 != 0) {
			return false;
		}
	}

	for (int i = 0; a2 && i < C; i++) {
		while (cnt[i] % 4 == 2) {
			a2--;
			cnt[i] -= 2;
		}
	}

	if (a2) return true;

	for (int i = 0; i < C; i++) {
		if (cnt[i] % 4 != 0) return false;
	}

	return true;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++) {
			cnt[s[j] - 'a']++;
		}
	}
	int a4 = 0, a2 = 0, a1 = 0;
	if (n % 2 == 1 && m % 2 == 1) {
		a1 += 1;
		a2 += (n - 1 + m - 1) / 2;
		n--, m--;
	}
	if (m % 2 == 1) swap(n, m);
	if (n % 2 == 1) {
		a2 += m / 2;
		n--;
	}
	assert(n % 2 == 0 && m % 2 == 0);
	a4 = n * m / 4;
	if (fuck(a1, a2, a4)) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}


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

int main() {
    int a,b,ans=0;cin>>a>>b;
    
    if(a==1)a=14;
    if(b==1)b=14;
    
    if(a>b)cout<<"Alice"<<endl;
    if(a<b)cout<<"Bob"<<endl;
    if(a==b)cout<<"Draw"<<endl;

	return 0;
}

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

int main()
{
  int N;
  cin>>N;
  int mod = N%10;
  switch(mod)
  {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout<<"hon\n";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout<<"pon\n";
      break;
    default:
      cout<<"bon\n";
  }
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

	int a[100010];
	for (int i = 0; i < n; ++i){
		cin>>a[i];
	}

	sort(a,a+n);
	cout<<abs(a[n/2]-a[n/2-1])<<endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
    long long a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
        cout<<a-k<<" "<<b<<endl;
    else if(a+b>=k)
        cout<<"0 "<<a+b-k<<endl;
    else
        cout<<"0 0\n";
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll pow_mod(ll a, ll b) {
    if (b == 0) {
        return 1;
    }
    ll c = pow_mod(a, b/2);
    c = (c*c) % mod;
    if (b % 2 == 0) return c;
    return (c*a) % mod;
}
ll x[2000001] = {1};
ll nCk(ll n, ll k) {
    ll X = x[n], Y = (x[k]*x[n-k]) % mod;
    return (X*pow_mod(Y, mod-2)) % mod;
}
int main() {
    for (int i = 1; i <= 2000000; i++) {
        x[i] = x[i-1] * i;
        x[i] %= mod;
    }
    ll K;
    string S;
    cin >> K >> S;
    int a = S.size();
    int z = 26;
    ll ans = pow_mod(z, a+K);
    ll e = 1;
    for (int i = 1; i <= K+1; i++)  {
        e *= z-1;
        e %= mod;
    }
    for (int i = a-1; i >= 0; i--) {
        ans -= (nCk(a+K, i)*e);
        ans %= mod;
        e = (e*(z-1)) % mod;
    }
    ans += mod+mod;
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 20892
import numpy as  np
import math

def get_sieve_of_eratosthenes(n):
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


x = int(input())
data = get_sieve_of_eratosthenes(x+100)
data = np.array(data)
indices = np.where(data >= x)[0]
# print(indices)
print(data[indices[0]])



Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
typedef pair<int,int> ii;

int n;
vector<ii> a[maxn];
int color[maxn];
int d[maxn]={0};
int avl[maxn]={0};

void DFS(int u){
    avl[u]=1;
    for(int i=0;i<a[u].size();i++){
        int v=a[u][i].first;int w=a[u][i].second;
        if (avl[v]==0){
            d[v]=d[u]^w;
            DFS(v);
        }
    }
}

int main(){
    cin>>n;
    for(int i=1;i<=n-1;i++){
        int u,v,w;
        cin>>u>>v>>w;w=w%2;
        a[u].push_back(ii(v,w));
        a[v].push_back(ii(u,w));
    }
    DFS(1);
    for(int i=1;i<=n;i++) cout<<d[i]<<endl;
}


Measured memory_bytes: 8704
#include <iostream>
using namespace std;
#define REP(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define rep(i,n) REP((i),0,(n))
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    

    while(true)
    {
        int cnt=0;
        int n,x;
        cin >> n >> x;
        if (n==0 && x==0) break;
        for (int i=1;i<=n;i++)
        {
            for (int j=i+1;j<=n;j++)
            {
                for (int k=j+1;k<=n;k++)
                {
                    if (i+j+k==x) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    

}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;


int main() {

	int N;
	cin >> N;
	vector<int> H(N,0);
	
	for(int i = 0; i < N; i++){		
		cin >> H[i];
	}	
	
	
	int count = 0, max_count = 0;
	for(int i = 0; i < (N-1); i++){

		if(H[i] >= H[i + 1]){
			count++;
			if(max_count < count){
				max_count = count;
			}
		}else{
			if(max_count < count){
				max_count = count;
			}
			count = 0;
		}

	}
	
	cout << max_count << endl;


    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int n;
    cin>>n;
    vector <pair <LL,LL> > p;
    pair <LL,LL> q;
    for(int i=0;i<n;i++){
        cin>>q.first>>q.second;
        p.push_back(q);
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    int ans=1;
    q=p.back();
    p.pop_back();
    LL min=q.first-q.second;
    LL max=q.first+q.second;
    LL nmin=0;
    LL nmax=0;
    while(!p.empty()){
        q=p.back();
        p.pop_back();
        nmin=q.first-q.second;
        nmax=q.first+q.second;
        if(nmax<=max){
            max=nmax;
            min=nmin;
        }
        else{
            if(nmin>=max){
                ans++;
                max=nmax;
                min=nmin;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
int main(void)
{
	int n, c, k, t[100000] = {};
	int ans = 0, first = 0;
	std::cin >> n >> c >> k;
	for(int i = 0; i != n; i++) std::cin >> t[i];
	std::sort(t, t + n);
	for(int i = 0; i != n; i++){
		if(t[i] - t[first] > k || i - first >= c){
			first = i;
			ans++;
		}
	}
	std::cout << ans + 1 << std::endl;
	return 0;
}

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

#define int long long

const int mod = 1e9 + 7 ;
const int N = 1e6 ;
int fact[N]  ;

int modexp(int a , int n){
	if(n == 0) return 1 ;
	if(n == 1) return a ;
	int x = modexp(a , n / 2) ;
	x = (x*x) % mod ;
	if(n&1) x = (x*a) % mod ;
	return x ;
}

int32_t main(){
	fact[0] = 1 ;
	for(int i = 1 ; i < N ; i++){
		fact[i] = (fact[i-1]*i) % mod ;
	}
	int n , m ;
	cin >> n >> m ;
	auto ncr = [&](int n , int r) -> int {
		return (((fact[n]*modexp(fact[r] , mod - 2)) % mod) * modexp(fact[n-r],mod -2) ) % mod ;
	} ;
	int x = ( fact[n]*ncr(m,n) ) % mod ;
	int y = x ;
	for(int i = 1 ; i <= n ; i++){
		int val = ncr(n,i)*ncr(m-i,n-i) ;
      	val %= mod ;
		val = (val*fact[n-i]) % mod ;
		if(i&1) y = ( y - val + mod ) % mod ;
		else y = (y + val) % mod ;
	}
	cout << ( x * y ) % mod ;
	return 0 ;
}

Measured memory_bytes: 11412
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
INF = 10**9+1

def solve():
    ans = -INF

    for i in range(N):
        memo = [0] * (N+1)
        j = 0
        p = i
        while j < N:
            memo[j+1] = memo[j] + C[p]
            p = P[p] - 1
            j += 1
            if p == i:
                break
        tans =-INF
        if memo[j] > 0:
            for k in range(j):
                q = (K-k-1) // j
                tans = max(tans, memo[k+1] + memo[j] * q)
        else:
            for k in range(min(K, j)):
                tans = max(tans, memo[k+1])

        ans = max(ans, tans)
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 75124
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
/*
  3
1 0 4
  2
  5
*/
int dice[6][6] ={ // [top][front] -> right
  {-1, 2, 4, 1, 3,-1},
  { 3,-1, 0, 5,-1, 2},
  { 1, 5,-1,-1, 0, 4},
  { 4, 0,-1,-1, 5, 1},
  { 2,-1, 5, 0,-1, 3},
  {-1, 3, 1, 4, 2,-1}
};

/* ??\????????§?¨??????§???????????¨??????dx,dy,df
 ????????? y
 ???
 ???
 x

[k]  1
    ???
3 ???  ??? 2
    ???
    0
*/
const int dx[] = {1,-1,0,0}, dy[]={0,0,1,-1};
function<pair<int,int>(int,int)> df[] = { // return <top,front>
  [&](int t, int f){return mp(5-f, t);},
  [&](int t, int f){return mp(f, 5-t);},
  [&](int t, int f){return mp(5-dice[t][f], f);},
  [&](int t, int f){return mp(dice[t][f], f);},
  [&](int t, int f){return mp(t, dice[t][f]);},
  [&](int t, int f){return mp(t, 5-dice[t][f]);}
};

map<char,int> m = {
  {'N', 1},
  {'E', 2},
  {'W', 3},
  {'S', 0},
  {'R', 4},
  {'L', 5}
};

int main(){
  int n;
  while(cin>>n, n){
    int t = 0, f=1;
    int ans = 1;
    rep(i,n){
      string s;
      cin>>s;
      auto p = df[m[s[0]]](t,f);
      t = p.fi, f = p.se;
      ans += t+1;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3136
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr); ios::sync_with_stdio(false);
  using ll = long long;
  int X;
  cin >> X;
  auto pow5 = [](ll n) -> ll { return n * n * n * n * n; };
  auto get_root5 = [=](ll n)-> optional<int> {
    int i = -1000;
    for (; i < 1000; ++i) {
      if (pow5(i) != n)continue;
      return make_optional(i);
    }
    return nullopt;
  };
  for (int A = 0; A <= X; ++A) {
    ll Bp5 = pow5(A) - X;
    auto opt = get_root5(Bp5);
    if (!opt.has_value())continue;
    cout << A << ' ' << opt.value() << endl;
    break;
  }
}


Measured memory_bytes: 3648
import java.util.*;
class Main
{
		public static void main(String[] args)
		{
			
			Scanner sc = new Scanner(System.in);
			
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			
			int res = 0;
			
			for(int i=0 ; i<=a ; i++){
				for(int j=0 ; j<=b ; j++){
					for(int k=0 ; k<=c ; k++){
						int total = 500*i + 100*j + 50*k;
						
						if( total==x ){
							res++;
						}
					}
				}
				}
				System.out.println(res);
			}
}

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

#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp                       __builtin_popcountll

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}


int32_t main()
{
    speed upp
	int n;
    cin>>n;
    string s;
    cin>>s;
    int a[n+1],b[n+1][4];
    b[0][0]=b[0][1]=b[0][2]=0;
    f(i,1,n)
        if(s[i-1]=='R')
            a[i]=1;
        else if(s[i-1]=='G')
            a[i]=2;
        else    
            a[i]=0;
    f(i,1,n)
    {
        f(j,0,2)
            b[i][j]=b[i-1][j] ;
        b[i][a[i]]++;
    }
    int ans=0;
    f(i,1,n)
    {
        f(j,i+2,n)
        {
            if(a[i]!=a[j])
            {
                int z=3-a[i]-a[j];
                ans+=b[j-1][z]-b[i][z];
                if((j-i)%2==0)
                {
                    //cout<<j <<endl<<i<<endl;
                    if(a[i + (j-i)/2] == z)
                        ans--;
                }
                
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;
const int cnt=1e7+7; 

map<int,int> mp;

int main()
{
//	freopen("input.txt","r",stdin);
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    int num=0,ans=0;//W的数量 
    for(int i=0;i<n;i++) if(s[i]=='W') num++;
    for(int i=n-num;i<n;i++) if(s[i]=='R') ans++;
    cout<<ans;
     
	return 0;
}





















Measured memory_bytes: 3444
#include <iostream>
#include <list>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;


int main(){

    long n;
    cin >> n;

    int h = 0;

    h += int(n/500) * 1000;

    n -= 500 * int(n/500);


    h += int(n/5) * 5;

    cout << h << endl;

    return 0;
}


Measured memory_bytes: 256
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
#define ll long long
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> pii;
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false);

int main(){fast;
	
	string s; cin>>s;
	int q; cin>>q;
	bool st = 0;
	vector<char> a[2];
	while(q--){
		int type; cin>>type;
		if(type == 1){
			st = !st;
		}
		else{
			int f; char c; cin>>f>>c; f--;
			a[f ^ st].push_back(c);
		}
	}
	string ans;
	for(int i = sz(a[0]) - 1; i >= 0; i--){
		ans += a[0][i];
	}
	ans += s;
	for(char x: a[1]){
		ans += x;
	}
	if(st) reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
}


Measured memory_bytes: 1448
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

ll gcd(ll a, ll b){
  if(a < b)  swap(a,b);
  if(a%b==0) return b;
  else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(int i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++) {
    res = lcm(res, numbers[i]);
  }
  return res;
}

signed main(){
  ll n,k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MOD = 1e9 + 7;
const int MAXN = 22;

int n;
int a[MAXN][MAXN];
int dp[MAXN][(int)1<<MAXN];
vector <int> v[MAXN];

int main(){

    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];

    for (int mask = 0; mask < (int)1<<n; mask++){
        int br = 0;
        for (int i = 0; i < n; i++)
            if (mask & 1<<i) br++;
        v[br].pb(mask);
    }

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j < v[i-1].size(); j++){
            for (int k = 0; k < n; k++){
                if (a[i-1][k] && (v[i-1][j] & 1<<(n-1-k)) == 0){
                    dp[i][v[i-1][j] ^ 1<<(n-1-k)] = (dp[i][v[i-1][j] ^ 1<<(n-1-k)]%MOD + dp[i-1][v[i-1][j]]%MOD)%MOD;
                    //cout << i << " " << k << " " << dp[i][v[i-1][j] ^ 1<<(n-1-k)] << '\n';
                }
            }
        }
    }

    cout << dp[n][(int)(1<<n)-1];

    return 0;

}

Measured memory_bytes: 189884
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int tl[2001][2001][2];
bool s[2001],t[2001];
int main()
{
	int n,m;
	int i,j;
	int ma;
	char a;
	cin >> n >> m;
	for(i=0;i<n;i++)
	{
		cin >> a;
		if(a=='I') s[i]=true;
		else s[i]=false;
	}
	for(i=0;i<m;i++)
	{
		cin >>  a;
		if(a=='I') t[i]=true;
		else t[i]=false;
	}
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			ma=0;
			if(i>0 && s[i-1]==true)
			{
				ma=max(ma,tl[i-1][j][0]+1);
			}
			if(j>0 && t[j-1]==true)
			{
				ma=max(ma,tl[i][j-1][0]+1);
			}
			tl[i][j][1]=ma;
			ma=0;
			if(i>0 && s[i-1]==false && tl[i-1][j][1]>0)
			{
				ma=max(ma,tl[i-1][j][1]+1);
			}
			if(j>0 && t[j-1]==false && tl[i][j-1][1]>0)
			{
				ma=max(ma,tl[i][j-1][1]+1);
			}
			tl[i][j][0]=ma;
		}
	}
	int cnt=0;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			cnt=max(cnt,tl[i][j][1]);
		}
	}
	cout << cnt << endl;
	return 0; 
}

Measured memory_bytes: 34396
import bisect
n = int(input())
A = [int(input()) for j in range(n)]
dp = A[:1]
for a_i in A[1:]:
    if dp[-1] < a_i:
        dp.append(a_i)
    else:
        dp[bisect.bisect_left(dp, a_i)] = a_i
print(len(dp))

Measured memory_bytes: 13316
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll D;
    cin >> D;
    vll c(26 + 1);
    for (size_t i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }
    auto s = make_v<ll>(D + 1, 26 + 1);
    for (size_t i = 1; i <= D; i++)
    {
        for (size_t j = 1; j <= 26; j++)
        {
            cin >> s[i][j]; //s[i][j] := i日目にコンテストjを開催したときの満足度の増加量
        }
    }
    vll solution(D + 1);
    auto solve = [&](vll solution) {
        auto last = make_v<ll>(D + 1, 26 + 1);
        for (size_t i = 1; i <= D; i++)
        {
            last[i][solution[i]] = i; //i日目以前にタイプsolution[i]のコンテストを開催した最後の日
            for (size_t j = 0; j <= 26; j++)
            {
                if (j == solution[i])
                    continue;

                chmax(last[i][j], last[i - 1][j]);
            }
        }

        ll score = 0;

        for (int i = 1; i <= D; i++)
        {
            score += s[i][solution[i]];
            ll decrease = 0;
            for (int j = 1; j <= 26; j++)
            {
                decrease += c[j] * (i - last[i][j]);
            }
            score -= decrease;
        }
        return score;
    };
    for (size_t i = 1; i <= D; i++)
    {
        solution[i] = 1 + rand()%26;
    }
    for (size_t i = 0; i < 100; i++)
    {
        ll score = solve(solution);
        vll newSolution(D+1);
        for (size_t j = 1; j <= D;j++)
        {
            if(solution[j] == 26)
            newSolution[j] = solution[j] - (rand()%2);
            else if(solution[j] == 1)
            newSolution[j]=solution[j]+(rand()%2);
            else
            newSolution[j] = solution[j] + rand()%3 - 1; 
        }
        ll newScore = solve(newSolution);
        if(newScore>score)
        {
            solution = newSolution;
        }
    }
    for(int i = 1;i<=D;i++)
    {
        cout<<solution[i]<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    long long int a;
    cin>>n>>k;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    std::deque<long long int> S(n+1,0);
    for (int i=1;i<=n;i++) {
        if (i<k) {
            S[i]=0;
        } else if (i==k) {
            S[i]=deq[i-k];
        } else {
            S[i]=deq[i-1];
        }
    }/*
    for (auto x:S) {
        cout<<x<<" ";
    }cout<<endl;*/
    for (int i=k+1;i<=n;i++) {
        if (S[i]>S[i-1]) {
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
        S[i]=deq[i-k];
    }
}

Measured memory_bytes: 6896
N = int(input())
W = list(map(int, input().split()))

abs_diffs = []
for T in range(N-1):
    S1 = sum(W[:T+1])
    S2 = sum(W[T+1:])

    abs_diffs.append(abs(S1-S2))

print(min(abs_diffs))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
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; }

vvint to(101010);
vint dist;
int n;

void dfs(int u,int d = 0,int p = -1){
  dist[u] = d;
  for(auto v2:to[u]){
    if(v2 == p) continue;
    dfs(v2,d+1,u);
  }
}
vint distcalc(int a){
  dist = vector<int>(n);
  dfs(a);
  return dist;
}
signed main(){
  int u,v;
  cin >> n >> u >> v;
  u--;v--;
  rep(i,0,n-1){
    int a,b;
    cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vint distu = distcalc(u);
  vint distv = distcalc(v);
  int ans = 0;
  rep(i,0,n){
    if(distu[i] < distv[i]) ans = max(ans,distv[i]);
  }
  cout << ans - 1 << endl;
}

Measured memory_bytes: 12144
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int i, j;
	long ans = 0;

	cin >> n;
	long pre, nex;
	cin >> pre;
	for (i = 1; i < n; i++) {
		cin >> nex;
		if (pre > nex) {
			ans += pre - nex;
		}
		pre = max(pre, nex);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
struct line
{
	int num,v;
}a[MAXN*2];
int cmp(line i,line j){
	return i.v>j.v;
}
int main()
{
	int m,n,i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		cin>>a[i].v;
		a[i].num=1;
	}
	for(i;i<=n+m;i++){
		cin>>a[i].num;
		cin>>a[i].v;
	}
	sort(a+1,a+n+m+1,cmp);
	ll s=0;
	int k=0;
	for(i=1;i<=n+m+1;i++){
		if(k+a[i].num<=n){
		k+=a[i].num;
		s+=(ll)a[i].num*a[i].v;
		}
		else{
			s+=(ll)(n-k)*a[i].v;
			break;
		}
	}
	cout<<s<<endl;
	return 0;
 } 

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

int main() {
  int H, N;
  cin >> H >> N;
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    sum += x;
  }
  
  if (sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;

using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	#ifdef LOCAL
	((std::cout << args << " "), ...);
	cout << endl;
	#endif
}
 */
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e5 + 6;

string ss[] = {"dream", "dreamer", "erase", "eraser"};

bool d[MAXN];

int main() {
	#ifdef LOCAL

	setIn("in.txt");
	setOut("out.txt");
	#endif

	string s;
	cin >> s;

	for(int i = 0; i < s.size(); i++){
		if(i == 0 || d[i]) {
			for (auto x : ss) {
				bool ok = 1;
				for (int j = 0; j < x.size(); j++) {
					if (s[i + j] != x[j]) {
						ok = 0;
						break;
					}
				}

				if (ok) {
					d[i + x.size()] = 1;
				}
			}
		}
	}

	cout << (d[s.size()] ? "YES" : "NO");
}


Measured memory_bytes: 512
s = input()
n = len(s)
ans = [0]*n
s += "e"
start = 0
end = 0
r = 0
l = 0
for i in range(n):
    if s[i] == "L" and s[i+1] == "R" or s[i+1] == "e":
        end = i
        tmps = s[start:end+1]
        tmpn = len(tmps)
        #print(tmps,r-1,l)
        numr = r - 1
        numl = l
        #print(start,end)
        for j in range(tmpn):
            if tmps[j] == "R" and tmps[j+1] == "L":
                indexr = start + j
                indexl = start + j + 1
                break
        #print(indexr,indexl)
        if numl % 2 == 1:
            ans[indexr] += 1
        if numr % 2 == 1:
            ans[indexl] += 1
        ans[indexr] += 1 + numr // 2 + numl // 2 
        ans[indexl] += 1 + numr // 2 + numl // 2 
        start = i + 1
        r = 0
        l = 0
    else:
        if s[i] == "R":
            r += 1
        else:
            l += 1
print(*ans)


Measured memory_bytes: 51516
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
long long dp[100100];
int n;
int W;
int w;
long long v;
void add(){
	for(int i=W;i>=w;i--)
		dp[i]=max(dp[i],dp[i-w]+v);
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>W;
	for(int i=1;i<=n;i++){
		cin>>w>>v;
		add();
	}
	cout<<*max_element(dp+1,dp+W+1);
	return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
template <class... T> void printArr(T&&...){ }
#endif

int main(){
    ll n, k;
    cin >> n >> k;
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    for(auto p : v){
        k -= p.second;
        if(k <= 0){
            cout << p.first << '\n';
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1400
from math import sqrt
def Divisor_Set(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
            s.add(n//i)
    return s

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a_sum = sum(a)
    s = Divisor_Set(a_sum)
    ans = 1
    for v in s:
        a_mod = [x%v for x in a]
        a_mod.sort()
        for i in range(1, n):
            a_mod[i] += a_mod[i-1]
        for i in range(n):
            l, r = a_mod[i], v*(n-i-1) - (a_mod[-1] - a_mod[i])
            if l == r and r <= k:
                if ans < v:
                    ans = v
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n, x);
	VEC(int, a, n);
	sort(ALL(a));

	int sm = 0, ans = 0;
	REP(i, n) {
		sm += a[i];
		if (sm > x) break;
		if (i == n - 1 && sm != x) break;
		ans++;
	}
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static int count(long a[], int b, int e, long k){
        int count = 0;
        for(int i = b ; i < e ; i++){
            if(a[i] == k)
                count++;
        }
        return count;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        for(int i = 0 ; i < n ; i++)
            a[i] = sc.nextLong();
        int q = sc.nextInt();
        for(int i = 0 ; i < q ; i++){
            int b = sc.nextInt();
            int e = sc.nextInt();
            long k = sc.nextLong();
            System.out.println(count(a,b,e,k));
        }
    }
}


Measured memory_bytes: 37208
import java.io.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		double r = Double.parseDouble(str);
		double s, l;

		s = (double)r*r*Math.PI;
		l = 2.0*r*Math.PI;

		System.out.printf("%.6f %.6f\n", s, l);
	}
}

Measured memory_bytes: 17076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    long long int n;
    cin >> n;
    long long int num[n];
    long long int check = 0;
    long long int sum=0;
    long long int ans = 1;
    for(int i = 0; i < n; i++){
        cin >> num[i];
        check+=i;
        sum+=num[i];
    }
    for(int i = 0; i < n/2; i++){
        ans*=2;
        ans%=inf;
    }
    if(n%2==0){
        if(sum%inf==((n/2)*(n/2)*2)%inf)
            cout << ans << endl;
        else 
            cout << '0' << endl;
    }
    else if(n%2!=0){
        if(sum%inf==((check-(n/2)*(n/2))*2)%inf)
            cout << ans << endl;
        else
            cout << '0' << endl;
    }   
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll smod=998244353;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll,ll> T;





ll i,j,k;


int main(){
  //オーバーフローに注意！
  ll A,B,H,M;
  cin>>A>>B>>H>>M;
  long double a,b;
  a=(1.0*H/12)*2*M_PI+(1.0*M/60)*M_PI/6.0;
  b=(1.0*M/60)*2*M_PI;
  long double ans=max(a,b)-min(a,b);
  
  if(ans>M_PI)ans=2*M_PI-ans;
  cout<<setprecision(15)<<fixed<<sqrt(A*A+B*B-2*A*B*cos(ans))<<endl;


  

 
  
  
}


Measured memory_bytes: 4160
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 23:11:33 2020

@author: liang
"""

N, K = map(int, input().split())
ans = 0
for i in range(1,N+1):
    tmp = i
    count = 0
    while tmp< K:
        count += 1
        tmp *= 2
    ans += 1/2**count
ans /= N
print(ans)

Measured memory_bytes: 9072
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {
  int a[4] = {1868, 1912, 1926, 1989};
  int b[4] = {1911, 1925, 1988, 2016};
  int e;
  int y;
  cin >> e >> y;
  if( e == 0 ){
    if( y <= 1911 ){
      cout << 'M';
      cout << 44 - (1911-y) << endl;
    }else if( y <= 1925 ){
      cout << 'T';
      cout << 14 - (1925-y) << endl;
    }else if( y <= 1988 ){
      cout << 'S';
      cout << 63 - (1988-y) << endl;
    }else if( y <= 2016 ){
      cout << 'H';
      cout << 28 - (2016-y) << endl;
    }
  }else{
    cout << a[e-1] + y - 1 << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3128
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int f[100] = {0};
int p[100][11];

int countSameBitNum(int n, int m){
  int res = 0;
  while(n && m){
    if((n & 1) && (m & 1)) res++;
    n /= 2;
    m /= 2;
  }
  return res;
}

int main(){
  int N;
  cin >> N;
  rep(i, N){
    rep(j, 10){
      int ff;
      cin >> ff;
      f[i] += ff;
      f[i] *= 2;
    }
    f[i] /= 2;
  }
  rep(i, N){
    rep(j, 11){
      cin >> p[i][j];
    }
  }

  int ans = 0;
  rep(i, 1, 1024){
    int sum = 0;
    rep(j, N){
      sum += p[j][countSameBitNum(i, f[j])];
    }
    if(i == 1) {
      ans = sum;
    }else{
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    string s;
    cin >> s;

    string T[] = {"dream","dreamer","erase","eraser"};


    reverse(s.begin(),s.end());
    for(int i = 0; i < 4;i++){
        reverse(T[i].begin(),T[i].end());
    }

    for(int i = 0; i < s.length();){
        bool corr = true;
        for(int l = 0; l < 4;l++){
            int tlen = T[l].length();
            if(T[l] == s.substr(i,tlen)){
                i += tlen;
                break;
            }else if(l == 3){
                corr = false;
            }
        }
        if(!corr){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl; 

    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int a = stdIn.nextInt();
		
		int nn = n % 500;
		if(a>=nn) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}

}


Measured memory_bytes: 23636