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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int k = 50;
  vector<string> grid(2 * k);
  rep(i, 0, k) {
    grid[i] = string(2 * k, '.');
    grid[i + 50] = string(2 * k, '#');
  }

  int a, b;
  cin >> a >> b;
  a--;
  b--;

  {
    int r = 0;
    for(int i = 0, c = 0; i < b; ++i, c += 2) {
      if(c == 100) {
        r += 2;
        c = 0;
      }
      grid[r][c] = '#';
    }
  }

  {
    int r = 99;
    for(int i = 0, c = 0; i < a; ++i, c += 2) {
      if(c == 100) {
        r -= 2;
        c = 0;
      }
      grid[r][c] = '.';
    }
  }

  cout << 2 * k << " " << 2 * k << endl;
  rep(i, 0, 2 * k) cout << grid[i] << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 110;
char S[maxn], T[maxn];

int min_rep(const char * const s, int len)
{
    int i = 0, j = 1, k = 0;
    while (i < len && j < len && k < len) {
        int t = s[(i+k)%len] - s[(j+k)%len];
        if (!t)                 /* S[I] == S[J] */
            k++;
        else {
            if (t > 0)          /* flip this if for max_rep() */
                i = i + k + 1;
            else
                j = j + k + 1;
            if (i == j)
                ++ j;
            k = 0;
        }
    }
    return (i < j ? i : j);
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> S >> T) {
        const int n = strlen(S);
        const int m = strlen(T);
        bool good = false;
        if (n == m) {
            good = true;
            int i = min_rep(S,n);
            int j = min_rep(T,n);
            FOR(_,0,n) {
                if (S[i] != T[j]) 
                    good = false;
                i++; i %= n;
                j++; j %= n;
            }
        }
        if (good)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 100005;

int n,k,h[N],dp[N];

int main() {

	n=read(),k=read();; rep(i,1,n) h[i]=read();
	dp[1]=0; rep(i,2,n) {
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		rep(j,max(1,i-k),i-2) dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
	}
	printf("%d\n",dp[n]);	

	return 0;
	
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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);}
/*
 <url:https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0583?year=2006>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int n; cin >> n;
    vector<ll> a(n); for(auto& in:a) cin >> in;
    for(int i = 1; i <= 1e8;i++){
        if([&](){
            for(int j = 0; j < n;j++){
                if(a[j]%i != 0) return false;
            }
            return true;
        }()){
            cout << i << endl;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



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

using namespace std;

double pi = acos(-1);

int main(){
	int a, b, h, m;

	cin >> a >> b >> h >> m;

	int x = m * 6;
	double y = (h * 60 + m) / 2.0;


	double angle = fabs(x - y);

	angle = min(angle, 360.0 - angle);

	double sz = a * a + b * b - 2.0 * a * b * cos((angle * pi) / 180.0);

	cout << fixed << setprecision(18) << sqrt(sz) << endl;

	return 0;
}

Measured memory_bytes: 4192
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
#define MAX_N 500
#define MAX_K 500
#define MAX_V 1002
#define INF 1000000000
 
 
struct edge { int to, cap, rev; };
vector<edge> G[MAX_V];
bool used[MAX_V]; 
int V;
void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}
void resetG(int ver){
    V = ver;
    REP(i,V)
        G[i].clear();
}
 
int N, K;
bool can[MAX_N][MAX_K];
void solve() {
    int s = N + K, t = s + 1;
    for (int i = 0; i < N; i++) {
        add_edge(s, i, 1);
    }
    for (int i = 0; i < K; i++) {
        add_edge(N + i, t, 1);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) {
            if (can[i][j]) {
                add_edge(i, N + j, 1);
            }
        }
    }
    printf("%d\n",max_flow(s,t));
}
 
int gcd(int a,int b){
    if(a < b){
        int c = a;
        a = b;
        b = c;
    }
    if(a % b == 0)
        return b;
    return gcd(b,a % b);
}
 
int inb[500],inr[500];
 
bool input(){
    scanf("%d%d",&N,&K);
    if(N == 0 && K == 0)
        return false;
    REP(i,N)
        scanf("%d",&inb[i]);
    REP(i,K)
        scanf("%d",&inr[i]);
 
    memset(can,false,sizeof(can));
    REP(i,N){
        REP(j,K){
            if(gcd(inb[i],inr[j]) > 1)
                can[i][j] = true;
        }
    }
    resetG(N + K + 2);
    return true;
}
 
int main(){
    while(input()){
        solve();
    }
    return 0;
}

Measured memory_bytes: 9680
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		m=max(m,a[2]);
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])puts("YES");
		else{
			if(m<20)puts("NO");
			else puts("YES");
		}
	}
}

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

int main(){
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    sort(A.begin(), A.end());
    int gapmax = -1;

    rep(i, N-1){
        gapmax = max(gapmax, A[i + 1] - A[i]);
    }
    gapmax = max(gapmax, K - A[N-1] + A[0]);

    cout << K - gapmax << endl;
    return 0;
}

Measured memory_bytes: 1024
// Problem : D - .. (Double Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int dist[100000], pred[100000];
vector<int> adj[100000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int n, m;
    cin >> n >> m;
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }
    
    memset(dist, -1, sizeof(dist));
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        
        for (int v : adj[u])
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                pred[v] = u;
                q.push(v);
            }
    }
    
    for (int i=0; i<n; i++)
        if (dist[i] == -1) {
            cout << "No\n";
            return 0;
        }
    
    cout << "Yes\n";
    for (int i=1; i<n; i++)
        cout << pred[i] + 1 << "\n";

    return 0;
}


Measured memory_bytes: 10780
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
count=0


for y in T:
    left=0
    right=len(S)
    while left<right:
        mid=(left+right)//2
        if S[mid]==y:
            count+=1
            break
        elif y<S[mid]:
            right=mid
        elif y>S[mid]:
            left=mid+1


print(count)



Measured memory_bytes: 16708
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> res(4, 0);
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s == "AC")
        {
            res[0]++;
        }
        else if (s == "WA")
        {
            res[1]++;
        }
        else if (s == "TLE")
        {
            res[2]++;
        }
        else if (s == "RE")
        {
            res[3]++;
        }
    }
    cout << "AC x " << res[0] << endl;
    cout << "WA x " << res[1] << endl;
    cout << "TLE x " << res[2] << endl;
    cout << "RE x " << res[3] << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
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;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;

// Graph problem
using Graph = vector<vector<int>>;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

// coding start

int main()
{
    int N;
    cin >> N;
    Graph G(N);
    rep(i, N)
    {
        int hoge, k;
        cin >> hoge >> k;
        rep(j, k)
        {
            int tmp;
            cin >> tmp;
            tmp--;
            G[i].push_back(tmp);
        }
    }
    vector<int> dist(N, -1);
    dist[0] = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] != -1)
                continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    rep(i, N) printf("%d %d\n", i + 1, dist[i]);
}



Measured memory_bytes: 3212
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    to = [0]*(n+1)
    ans = 0
    for _ in range(m):
        a, b = map(int, input().split())
        to[a] = max(to[a], h[b-1])
        to[b] = max(to[b], h[a-1])
    for i, hi in enumerate(h, 1):
        t = to[i]
        if t == 0 or hi > t:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 84828
n = int(input())
s = {}
for i in range(n):
    c = input()
    if s.get(c):
        s[c] += 1
    else:
        s[c] = 1

m = 0
for k in s:
    m = max(m, s[k])

ans = []
for k in s:
    if s[k] == m:
        ans.append(k)
ans.sort()
for a in ans:
    print(a)


Measured memory_bytes: 32096
#include"bits/stdc++.h"
using namespace std;

int main() {

    int koota[3];
    for(int i=0;i<3;i++){
        cin >> koota[i];
    }
    sort(koota,koota+3);
    
    int answer = 3;
    for(int i=1;i<3;i++){
        if(koota[i-1] == koota[i]){
           answer--; 
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
//phoenix




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=0; i--)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a) sort(a,a+n);


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;



/*
ll solveDp(ll i,ll w[],ll v[],ll n,ll wt,map <ll,map <ll,ll> > &dp) {
    if(i>=n || wt<0)
        return 0;
    if(dp[wt][i])
        return dp[wt][i];
    else if(wt<w[i])
        return dp.insert(mp([wt][i]=solveDp(i+1,w,v,n,wt,dp);
    else
        return dp[wt][i]=max(solveDp(i+1,w,v,n,wt,dp),v[i]+solveDp(i+1,w,v,n,wt-w[i],dp));
}
*/



void bfs(ll k,bool vis[],ll n,vector <ll> v[]) {
    queue <ll> q;
    q.push(k);
    while(!q.empty()) {
        ll node=q.front();
        q.pop();
        cout<<node<<" ";
        vis[node-1]=true;
        fr(j,0,v[node-1].size()) {
            if(vis[v[node-1][j]-1]!=true)
                q.push(v[node-1][j]),vis[v[node-1][j]-1]=true;
        }
    }
}




void dfs(ll k,bool vis[],ll n,vector <ll> v[]) {
    cout<<k<<" ";
    vis[k-1]=true;
    fr(i,0,v[k-1].size()) {
        if(!vis[v[k-1][i]-1])
            dfs(v[k-1][i],vis,n,v);
    }
}




void cazz() {
    ll n,i,j,k,ans=0,f=0,b,wt,m;
    cin>>n;
    while(n) {
        if((n%10)==7) {
            f=1;
            break;
        }
        n=n/10;
    }
    if(f)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    /*cin>>n>>m;
    vector <ll> v[n];
    fr(i,0,m) {
        cin>>j>>k;
        v[j-1].pb(k);
        v[k-1].pb(j);
    }
    cout<<"\n";
    fr(i,0,n) {
        cout<<i+1<<"\t";
        fr(j,0,v[i].size()) {
            cout<<v[i][j]<<" ";
        }cout<<"\n";
    }
    cout<<"\n";
    cin>>k;
    bool vis[n]={};
    bfs(k,vis,n,v);
    cout<<"\n";
    bool vi[n]={};
    dfs(k,vi,n,v);*/
}




int main() {
    spdio;
	cazz();
	return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <stdlib.h>
#include <ctime>
#include <cmath>
#include <complex>
#include <iostream>
#include <cctype>
#include <cstring>
#include <bitset>
#include <stack>
#include <functional>
#include <cassert>
#include <tuple>
#include <iomanip>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ldb long double
#define mt make_tuple
template<typename T> bool ckmn(T &a, T b){ T c=a;a=min(a,b);return a!=c;}
template<typename T> bool ckmx(T &a, T b){ T c=a;a=max(a,b);return a!=c;}
int mod;
int add(int a, int b){ a+=b;return a>=mod?a-mod:a;}
void ckadd(int &a, int b){ a=add(a,b);}
int sub(int a, int b){ a-=b;return a<0?a+mod:a;}
void cksub(int &a, int b){ a=sub(a,b);}
int mul(int a, int b){ return (ll)a*b%mod;}
void ckmul(int &a, int b){ a=mul(a,b);}
int powmod(int x, int k){ int ans=1;for(;k;k>>=1,ckmul(x,x)) if(k&1) ckmul(ans,x);return ans;}
int inv(int x){ return powmod(x,mod-2);}
int dv(int x,int y){return mul(x,inv(y));}
const int N=6050;
int dp3[N],dp2[N],F[N];
int main(){
	int n;
	scanf("%i %i",&n,&mod);
	dp3[0]=1;
	for(int i=1;i<=n;i++)dp3[i*3]=mul(dp3[i*3-3],((ll)i*(i*3-1)*(i*3-2))%mod);
	F[0]=1;for(int i=1;i<=n;i++)F[i]=mul(F[i-1],i);
	//printf(":D\n");
	dp2[0]=dp2[1]=1;
	for(int i=2;i<=n*3;i++)dp2[i]=mul(dp2[i-2],((ll)i*(i-1)/2)%mod);
	int ans=0;
	for(int g1=0;g1<=n;g1++)
		for(int g2=0;g2<=n;g2++)if(g1+g2<=n){
			int now=1;
			ckmul(now,dv(dp3[3*n],dp3[3*n-3*g1]));
			ckmul(now,inv(F[g1]));
			ckmul(now,dv(dp2[3*n-3*g1],dp2[3*n-3*g1-2*g2]));
			ckmul(now,inv(F[g2]));
			//printf("%i %i %i\n",g1,g2,now);
			ckadd(ans,now);
		}
	printf("%i\n",ans);

	/*vector<int> p;
	for(int i=1;i<=n*3;i++)p.pb(i);
	map<pair<int,int>,int> cnt;
	int uk=0;
	do{
		int g1=0,g2=0,g3=0;
		for(int i=0,j=0;i<p.size();i=j){
			for(j=i+1;j<p.size() && p[j]<p[i];j++);
			if(j-i>3)g3++;
			if(j-i==2)g2++;
			if(j-i==3)g1++;
		}
		if(g3==0 && g1+g2<=n){
			cnt[{g1,g2}]++;
			uk++;
		}
	}while(next_permutation(p.begin(),p.end()));
	for(auto it:cnt)printf("%i %i %i\n",it.first.first,it.first.second,it.second);
	printf("%i\n",uk);
	/*dp[n*3][1][0]=1;
	for(int i=n*3;i>1;i--){
		for(int g1=0;g1<=n;g1++)
			for(int g2=0;g2<=n;g2++){
				printf("%i %i\n",g1,g2);
				ckadd(dp[i-1][g1+1][g2],dp[i][g1][g2]);

				if(g1>0)ckadd(dp[i-1][g1-1][g2+1],mul(2*g1,dp[i][g1][g2]));
				printf("%i:D\n",g2-1);
				if(g2>0)ckadd(dp[i-1][g1][g2-1],mul(3*g2,dp[i][g1][g2]));

			}
	}
	printf("%i\n",dp[1][0][0]);*/
	return 0;
}

Measured memory_bytes: 256
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans;
char c[400010];
int main(){
	scanf("%s",c+1);int n=strlen(c+1);
	for(rt i=1;i<=n;i++)if(c[i]=='0')ans++;else cnt++;
	cout<<2*min(ans,cnt);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int K;cin>>K;
    K--;
    int res[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<res[K]<<endl;

}


Measured memory_bytes: 256
#include"iostream"

using namespace std;

int main()
{
	int n,m,x,i,j,a[15][15],s[15]={0},min,k;
	cin>>n>>m>>x;
	min=-1;
	for(i=0;i<n;i++)
		for(j=0;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<(1<<n);i++)
	{
		for(k=0;k<=m;k++)
			s[k]=0;
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{	
				for(k=0;k<=m;k++)
					s[k]+=a[j][k];
			}
		}
		for(k=1;k<=m;k++)
			if(s[k]<x) break;
		if(k>m&&((min==-1)||s[0]<min)) min=s[0];
	}
	cout<<min<<endl;
	return 0;
}


Measured memory_bytes: 3604
#!/usr/bin/env python3
import sys
import re

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if len(S)%2!=0:
        print("No")
        exit()
    l=S[::2];count=0;p=S[1::2]
    #if len(l)
    for i in range(len(l)):
        if l[i]=="h":
            count+=1
        if p[i]=="i":
            count+=1
    if count==len(S):
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,m,r = myinput()
R = list(myinput())
ABC = mylistinput(m)

ans = INF

d = [ [INF]*n for _ in range(n) ]

# ワーシャルフロイド（warshall_floyd）法
# d[u][v]: 辺uvのコスト(存在しないときはinf)
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

for i in range(m):
    a = ABC[i][0] - 1
    b = ABC[i][1] - 1
    c = ABC[i][2]
    d[a][b] = c
    d[b][a] = c

d = warshall_floyd(n,d)

ls = list(permutations(R))
# print(ls)

for i in range(len(ls)):
    l = ls[i]
    cost = 0
    for j in range(r-1):
        s = l[j] - 1
        t = l[j+1] - 1
        cost += d[s][t]
    ans = min( ans, cost )
print(ans)

Measured memory_bytes: 65880
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    S = readline().strip()
    x = int(S[:2])
    y = int(S[2:])

    if 1 <= x <= 12:
        if 1 <= y <= 12:
            print('AMBIGUOUS')
        else:
            print('MMYY')
    else:
        if 1 <= y <= 12:
            print('YYMM')
        else:
            print('NA')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.*;
import java.io.*;

class Main
{
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main (String[] args)
	{
		FastReader reader = new FastReader();
		int n = reader.nextInt();
		long[] array = new long[n+1];
		ArrayList<Long> value = new ArrayList<Long>();
		ArrayList<Long> index =  new ArrayList<Long>();
		ArrayList<Long> adder = new ArrayList<Long>();

		/*long one = 1;
		array[0] = (one<<20) - 1;
		value.add (array[0]);
		index.add (0);*/


		for (int i=0; i<n; i++)
		{
			array[i] = reader.nextLong();
			if (array[i] > 0)
			{
				value.add (array[i]);
				index.add ((long)i);
			}
		}

		long one = 1;
		array[n] = (one<<20) - 1;
		value.add (array[n]);
		index.add ((long)n);

		long ans = 0;

		long count = 0;
		for (int i=0; i<=n; i++)
		{
			if (array[i] == 0)
				count++;
			else
			{
				ans += ((count+1)*count)/2;

				adder.add (count);
				count = 0;
			}
		}

		for (int i=0; i<index.size(); i++)
		{
			long sum = 0;
			long xor = 0;

			int j = i;
			while (j < index.size())
			{
				if (sum+value.get(j) == (xor^value.get(j)))
				{
					sum += value.get(j);
					xor ^= value.get(j);
					j++;
				}
				else
				{
					ans += (index.get(j) - index.get(i)) * (adder.get(i) + 1);
					break;
				}
			}
		}



		System.out.println (ans);
	}
}


Measured memory_bytes: 57200
import Control.Monad
import Data.List

toInt :: String -> Int
toInt = read :: String -> Int

solve :: [Int] -> Int
solve s
  | mod t 10 == 0 = t-m
  | otherwise = t
    where
      t = sum s
      m = head $ filter (\x -> mod x 10 /= 0) $ sort s

check :: [Int] -> Bool
check s = (length $ filter (\x -> mod x 10 /= 0) s) > 0

main = do
  n <- toInt <$> getLine
  s <- map toInt <$> replicateM n getLine
  print $ if check s then (solve s) else 0


Measured memory_bytes: 4364
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	int n, k, x, y, sum=0;
	cin >> n >> k >> x >> y;
	rep(i, n)
	{
		if (i < k)
			sum += x;
		else
			sum += y;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

char toMark(int x){
  switch(x){
    case 0:
    return 'S';
    case 1:
    return 'H';
    case 2:
    return 'C';
    case 3:
    default:
    return 'D';
  }
}

int toNum(char x){
  if(x == 'S') return 0;
  if(x == 'H') return 1;
  if(x == 'C') return 2;
  if(x == 'D') return 3;
}

int main() {
  int n;
  int number;
  char mark;
  bool cards[4][13] = {false};
  cin >> n;
  for(int i=0; i < n; ++i){
    cin >> mark >> number;
    cards[toNum(mark)][number-1] = true;
  }
  for(int i=0; i < 4; ++i){
    for(int j=0; j < 13; ++j){
      if(cards[i][j] == false) cout << toMark(i) << " " << j+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3132
N, M = map(int, input().split())

C = []
dp = [10 ** 9 for i in range (1 << N)]
dp [0] = 0
for i in range(M):
  a, b = map(int, input().split())
  c = list(map(lambda x: int(x) - 1, input().split()))
  b = 0
  for i in c:
    b |= 1 << i
  C.append((b,a))
for s in range(1 << N):
  for c in range(M):
    t = s | C[c][0]
    dp[t] = min(dp[t], dp[s] + C[c][1])
print (dp[-1] if dp[-1] != 10 ** 9 else -1)

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

int main(){
    int h,w,k;
    cin>>h>>w>>k;
    vector<string>s(h);
    rep(i,h)cin>>s[i];
    int ans=0;
    rep(is,1<<h)rep(js,1<<w){
        int cnt=0;
        rep(i,h)rep(j,w){
            if(is>>i&1)continue;
            if(js>>j&1)continue;
            if(s[i][j]=='#')cnt++;

        }
        if(cnt==k)ans++;

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



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

int main() {
    char N;
    cin >> N;

    string ans = "consonant";

    if (N == 'a' || N == 'e' || N == 'i' || N == 'o' || N == 'u') {
        ans = "vowel";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//abc112_b.cpp
//Fri Nov  2 22:25:45 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int c[n],t[n];
	int count = 0;
	for (int i=0;i<n;i++){
		cin >> c[i] >> t[i];
		if (t[i] > T){
			c[i] = INTINF;
		}else{
			count++;
		}
	}

	if (count == 0){
		cout << "TLE" << endl;
	}else {
		sort(c,c+n);
		cout << c[0] << endl;
	}

}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//


int solve(int N,int M,vi& _a,vi& _b) {
    vector<ii> ab(M);
    rep(i,M) ab[i] = ii(_a[i]-1, _b[i]-1);
    sort(ALL(ab));
    int cut = 0;
    priority_queue<int> pq;
    for (ii p: ab){
        int a = p.first, b = p.second;
        if (!pq.empty() && -pq.top() <= a) {
            ++cut;
            while (!pq.empty()) pq.pop();
        }
        pq.push(-b);
    }
    if (!pq.empty()) ++cut;

    return cut;
}

int main() {
    int N,M; cin >>N>>M;
    vi a(M), b(M);
    rep(i,M) cin >> a[i] >> b[i];
    cout << solve(N,M,a,b) << endl;
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int a[100007],b[100007];
int fa[100007],siz[100007];
typedef long long ll;
int find(int x){
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
vector<ll>res;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        fa[i]=i;
        siz[i]=1;
    }
    for(int i=0;i<m;i++)
        scanf("%d%d",&a[i],&b[i]);
    ll ans=0;
    int fx=0,fy=0;
    for(int i=m-1;i>=0;i--){
        res.push_back(1ll*n*(n-1)/2-ans);
        fx=find(a[i]);
        fy=find(b[i]);
        if(fx!=fy){
            ans+=1ll*siz[fx]*siz[fy];
            fa[fx]=fy;
            siz[fy]+=siz[fx];
        }
    }
    reverse(res.begin(),res.end());
    for(auto&it:res)
        printf("%lld\n",it);
    return 0;
}



Measured memory_bytes: 3828
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = in.readLine();
		String t = in.readLine();
		int min = t.length();
		for (int i = 0; i <= s.length()-t.length(); i++) {
			int change = t.length();
			for (int j = 0; j < t.length(); j++) {
				if (t.charAt(j) == s.charAt(i+j))
					change--;
			}
			min = Math.min(change, min);
		}
		System.out.println(min);
	}
}


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

int main(){
  ios::sync_with_stdio(0); cin.tie(0);
  long long n, result=0, minimum=10; cin >> n;
  for(long long i=1;i<n;i++){
    if(to_string(i).size() > to_string(n/i).size()) break;
    if(i*(n/i) == n) result = max(to_string(i).size(), to_string(n/i).size());
    minimum = min(minimum, result);
  }
  if(n < 10) cout << 1 << endl;
  else cout << minimum << endl;
  return 0;
}


Measured memory_bytes: 3716
A=[int(input()) for _ in range(5)]
ans=0
B=[a%10 for a in A]
m=1001001001
s=0
for i in range(5):
  if B[i]!=0 and m>B[i]:
    s=i
    m=B[i]
U=A[s]
del A[s]
for i in range(4):
  if A[i]%10==0:
    ans+=A[i]
  else:
    ans+=((A[i]//10)+1)*10
print(ans+U)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
#define LL long long
#define PB push_back
#define INF 9223372036854775800
#define Pl pair<LL, LL>


struct E {//edge from one vartex
	LL t, d;//to/dist
};

struct graph {
	LL cs[100001];//cost of vartex from [0]
	vector<E>cn[100001];//connection of vartex i
} G;

LL N, M, K, S, P, Q, dst[100001];//distance from zombie town
queue<LL> q;//vartex id
priority_queue<Pl, vector<Pl>, greater<Pl>> pq;//cost/vartex id
bool dng[100001];//is in danger?

int main() {
	//input
	cin >> N >> M >> K >> S >> P >> Q;
	for (int i = 0; i < N; i++) { dng[i] = false; dst[i] = INF; }
	for (int i = 0; i < K; i++) {
		int c; cin >> c; c--;
		dng[c] = true;
		dst[c] = 0;
		q.push(c);
	}
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b; a--; b--;
		G.cn[a].PB({ b, 0 });
		G.cn[b].PB({ a, 0 });
	}
	//BFS foreach zombie town
	while (!q.empty()) {
		LL tp = q.front(); q.pop();
		for (int i = 0; i < G.cn[tp].size(); i++) {
			LL dstn = G.cn[tp][i].t;//destination
			if (dst[dstn] > dst[tp] + 1) {
				dst[dstn] = dst[tp] + 1;
				q.push(dstn);
				if (dst[dstn] <= S) dng[dstn] = true;
			}
		}
	}
	dng[0] = dng[N - 1] = false;
	//decide edge cost
	for (int i = 0; i < N; i++) {
		G.cs[i] = INF;
		for (int j = 0; j < G.cn[i].size(); j++) {
			G.cn[i][j].d = (dng[G.cn[i][j].t] ? Q : P);
		}
	}
	//dijkstra 0-->N-1
	pq.push({ 0, 0 });//cost/valtex id
	while (!pq.empty()) {
		Pl tp = pq.top();
		pq.pop();
		if (G.cs[tp.second] == INF) {
			G.cs[tp.second] = tp.first;
			for (int i = 0; i < G.cn[tp.second].size(); i++) {
				if (dst[G.cn[tp.second][i].t] == 0) continue;
				pq.push({ G.cs[tp.second] + G.cn[tp.second][i].d, G.cn[tp.second][i].t });
				//コストが未確定頂点のうち最小のもの+辺のコスト, 辺の先の頂点
			}
		}
	}
	cout << G.cs[N - 1] - P << endl;
	return 0;
}


Measured memory_bytes: 17856
package main

import (
	"fmt"
)

func main()  {
	var l, pos int
	var str string

	fmt.Scan(&l, &pos)
	fmt.Scan(&str)

	nstr := make([]rune, len(str))
	for i, v := range str {
		if i == pos-1 {
			switch v {
			case 'A':
				nstr[i] = 'a'
			case 'B':
				nstr[i] = 'b'
			case 'C':
				nstr[i] = 'c'
			}
		} else {
			nstr[i] = v
		}
	}
	fmt.Println(string(nstr))
}


Measured memory_bytes: 512
while 1:
    n, s = map(int, raw_input().split())
    if n==0:
        exit(0)
    dp = [[0]*(s+1) for _ in xrange(n+1)]
    dp[0][0] = 1
    for i in xrange(min(s+1, 101)):
        si1 = s-i+1
        for k in xrange(n, 0, -1):
            dp_k = dp[k]; dp_k1 = dp[k-1]
            for j in xrange(si1):
                dp_k[i+j] += dp_k1[j]
    print dp[n][s]

Measured memory_bytes: 6576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		for(int i=0; i<n; i++){
			System.out.println(br.readLine().replaceAll("Hoshino", "Hoshina"));
		}

	}
}

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

using namespace std;
using ll = long long;


const int MOD = 1e9+7;

class Edge{
public:
    ll from,to, value;
    Edge(int f,int t, int c){
        from = f;
        to = t;
        value = c;
    }
};

int main(){
    int N,T;cin >> N >> T;
    vector<pair<int, int>> vec;
    for(int i = 0;i < N;i++){
        int a,b;cin >> a >> b;
        vec.push_back({a, b});
    }
    sort(vec.begin(), vec.end());
    vector<vector<int>> dp(N+1, vector<int>(6001, -1));
    dp[0][0] = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 6001;j++){
            if(dp[i][j] == -1)continue;
            dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
            if(j >= T)continue;
            dp[i+1][j + vec.at(i).first] = max(dp[i][j] + vec.at(i).second, dp[i+1][j + vec.at(i).first]);
        }
    }
    /*
    for(int i = 0;i < N+1;i++){
        for(int j = 0;j <= 10;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    cout<<*max_element(dp.back().begin(), dp.back().end())<<endl;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> arr(n);

    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);
    
    auto sorted = arr;

    sort(sorted.begin(), sorted.end());

    int lh = arr.size() / 2 - 1;
    int rh = lh + 1;

    for (int i = 0; i < n; i++)
    {
        if (arr[i] <= sorted[lh])
            printf("%d\n", sorted[rh]);
        else
            printf("%d\n", sorted[lh]);
    }

    return 0;
}

Measured memory_bytes: 3712
from math import atan2, pi, sqrt
from operator import itemgetter
# import sys
# input = sys.stdin.readline

n = int(input())
p = []
xa = ya = 0
for i in range(n):
    x, y = map(int, input().split())
    angle = atan2(y, x)
    p.append((x, y, angle))
    p.append((x, y, angle + 2 * pi))
    xa += x
    ya += y

p.sort(key=itemgetter(2))

r = 0
ans = 0
xs = ys = 0
for l in range(n):
    while p[r][2] < p[l][2] + pi:
        xs += p[r][0]
        ys += p[r][1]
        r += 1

    ans = max(ans, sqrt(xs**2 + ys**2), sqrt((xa - xs)**2 + (ya - ys)**2))

    xs -= p[l][0]
    ys -= p[l][1]

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long ll;
typedef unsigned uint;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
	string s,t;
	cin>>s>>t;
	int ans=0;
	rep(i,3){
		ans+=(s[i]==t[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a,b,h,w = map(int,input().split())
dp = [[0 for _ in range(w+1)] for _ in range(h+1)]
mod = 998244353
#dp[a][b] = 1
for i in range(1,h+1):
  if i < a:
    continue
  for j in range(1,w+1):
    if j < b:
      continue
    if i == a and j == b:
      dp[i][j] = 1
      continue
    dp[i][j] = dp[i][j-1]*i + dp[i-1][j]*j - dp[i-1][j-1]*(i-1)*(j-1)
    dp[i][j] %= mod
#for x in dp:
  #print(x)
print(dp[-1][-1])

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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)

const ll inf = 1e15;
const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

struct edge { 
    ll cost, from, to; 
    edge(ll c, ll f, ll t): cost(c), from(f), to(t){}
    bool operator >(const edge &e) const{
        return cost > e.cost;
    }
};

int V;
vector<edge> G[102];
ll d[102];
bool used[102];
ll E[102][102];

void dijkstra(ll s) {
    priority_queue<edge, vector<edge>, greater<edge> > que;
    fill(d, d + V, inf);
    fill(used, used + V, false);
    
    d[s] = 0;
    rep(i, G[s].size()) que.push(G[s][i]);
    while (!que.empty()) {
        edge e1 = que.top(); que.pop();
        
        if (!used[e1.to]) {
            used[e1.to] = true;
            d[e1.to] = e1.cost;
            E[e1.from][e1.to] = E[e1.to][e1.from] = 0;
            rep(i, G[e1.to].size()) {
                edge e2 = G[e1.to][i];
                que.push(edge(e1.cost + e2.cost, e2.from, e2.to));
            }
        }
    }
}

int main() {
    ll N, M; cin >> N >> M;
    
    memset(E, 0, sizeof(E));
    rep(i, M) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(edge(c, a, b));
        G[b].push_back(edge(c, b, a));
        E[a][b] = E[b][a] = 1;
    }
    
    V = N;
    rep(i, N) dijkstra(i);
    
    ll cnt = 0;
    rep(i, N) for(j, i+1, N) cnt += E[i][j];
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {

	long double N, K;

	cin >> N >> K;

	long double p = 0.0;

	for (double i = 1; i <= N; i+=1.0) {
		double score = i;
		double count = 0;
		
		while (score < K) {
			score *= 2.0;
			count += 1.0;
		}

		p += (1/N)*pow(0.5, count);
	}

	cout << setprecision(16) << p << endl;

	return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
bool vis[maxn];
int ans[maxn];
int cnt[2];
int num[3];
bool could[2][3];
vector<int> g[maxn];
int bas[3];
void dfs(int x,bool f)
{
    vis[x] = 1;
    cnt[f]++;
    for(int y:g[x])
    {
        if(!vis[y])
        {
            dfs(y,!f);
        }
    }
}
void work(int x,int f)
{
    vis[x] = 1;
    for(int i=2;i>=0;--i)
    {
        if(could[f][i] && num[i] > 0)
        {
            num[i]--;
            ans[x] = bas[i];
            bas[i] += 3;
            break;
        }
    }
    for(int y:g[x])
    {
        if(!vis[y])
        {
            work(y,!f);
        }
    }
}
void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    for(int i=0;i<N-1;++i)
    {
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }    
    dfs(1,0);
    num[0] = N/3;
    num[1] = N/3 + (N%3>=1);
    num[2] = N/3 + (N%3>=2);
    memset(vis,0,sizeof vis);

    if(max(cnt[0],cnt[1]) <= num[0] + num[1])
    {
        if(max(cnt[0],cnt[1])==cnt[0])
        {
            could[0][0]=1;
            could[0][1]=1;
            could[1][0]=1;
            could[1][2]=1;
        }else
        {
            could[1][0]=1;
            could[1][1]=1;
            could[0][0]=1;
            could[0][2]=1;
        }
    }else
    {
        if(cnt[0] <= cnt[1])
        {
            could[0][0]=1;
            could[1][0]=could[1][1]=could[1][2]=1;
        }else
        {
            could[1][0]=1;
            could[0][0]=could[0][1]=could[0][2]=1;
        }
    }
    bas[0] = 3;
    bas[1] = 1;
    bas[2] = 2;
    work(1,0);
    for(int i=1;i<=N;++i)
    {
        cout<<ans[i]<<(i==N?"\n":" ");
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 18560