akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define INF 0x7fffffff
using namespace std;

int main(){
    ll n,w;
    cin>>n>>w;
    ll A[n+1][2];
    for(ll i = 1; i <= n; i++){
        cin>>A[i][0]>>A[i][1];
    }
    ll dp[100001];
    for(ll i =1 ; i <= 100000; i++)
        dp[i] = INF;
    dp[0] = 0;
    for(ll i = 1; i <= n; i++){
        for(ll j = 100000; j >= 0; j--){
            if(j >= A[i][1]){
                dp[j] = min(A[i][0] + dp[j - A[i][1]],dp[j]);
                //cout<<j<<" "<<dp[j]<<"\n";
            }else break;
        }
    }
    for(ll i = 100000; i >= 0; i--){
        //cout<<dp[i]<<"   d\n";
        if(dp[i] <= w){
            cout<<i;
            return 0;
        }
    }
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 1152
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long total = 0;
        long n = sc.nextLong();
        long m = sc.nextLong();
        total = n <= m / 2 ? n : m / 2;
        m -= 2 * n;
        if (m > 0)
        total += m / 4;
        System.out.println(total);
    }

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N=1e7+10,mod=998244353;
int n,fac[N],inv[N],pw[N],ans;

int C(int n,int m){
	return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;
}

void upd(int &x,int y){x+=y; x-=x>=mod?mod:0;}

int ksm(int x,int y){
	int s=1;
	for (;y;y>>=1,x=(ll)x*x%mod) if (y&1) s=(ll)s*x%mod;
	return s;
}

void init(int n){
	fac[0]=1;
	rep (i,1,n) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	for (int i=n;i;i--) inv[i-1]=(ll)inv[i]*i%mod;
	pw[0]=1;
	rep (i,1,n) pw[i]=(ll)pw[i-1]*2%mod;
}

int main(){
	scanf("%d",&n); init(n);
	rep (i,n/2+1,n) upd(ans,(ll)C(n,i)*pw[n-i]%mod);
	printf("%lld\n",(ksm(3,n)+mod-ans*2ll%mod)%mod);
	return 0;
}

Measured memory_bytes: 117376
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    if(s[0][s[0].length()-1] == s[1][0] && s[1][s[1].length()-1] == s[2][0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int i,n,m,a,k[100000][2001];
main(){
for(i=1;i<=2000;i++){k[0][i]=i;}cin>>n>>m;
for(int i=1;i<=m;i++){cin>>a;
if(a>=1){for(int j=a+1;j<=n*2;j++){k[i][j-a]=k[i-1][j];}
for(int j=1;j<=a;j++){k[i][j+(2*n-a)]=k[i-1][j];}}
else{for(int j=1;j<=n;j++){k[i][j*2-1]=k[i-1][j];}
for(int j=1;j<=n;j++){k[i][j*2]=k[i-1][j+n];}}}
for(int i=1;i<=2*n;i++){cout<<k[m][i]<<endl;}}

Measured memory_bytes: 8556
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void push(int);
int pop();

int top,B[1000];

int main ()
{
  int a1,a2,top;
  char A[100];

  while(scanf("%s",A) != EOF)
    {
      if(A[0] == '+')
	{
	  a1 = pop();
	  a2 = pop();
	  push(a1 + a2);
	} else if(A[0] == '-')
	{
	  a1 = pop();
	  a2 = pop();
	  push(a2 - a1);
	} else if(A[0] == '*')
	{
	  a1 = pop();
	  a2 = pop();
	  push(a1 * a2);
	} else
	{
	  push(atoi(A));
	}
    }
  printf("%d\n",pop());
  return 0;
}
void push(int a)
{
  B[++top] = a;
}

int pop()
{
  top--;
  return B[top+1];
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


const int mod = 1e9+7;

void add_self(int& a, int b) {
	a+=b;
	if (a>mod) {
		a-=mod;
	}
}

void solve() {
	string K;
	cin >> K;
	int D;
	cin >> D;

	// 544 -> 499
	vector<vector<int>> dp(D, vector<int>(2));
	dp[0][false] = 1;
	for (int idx=0; idx<(int) K.size(); idx++) {
		vector<vector<int>> new_dp(D, vector<int>(2));
		for (int sum=0; sum<D; sum++) {
			for (bool smaller_already: {false, true}) {
				for(int digit=0; digit<10; digit++) {
					if (digit>K[idx]-'0' && !smaller_already) {
						break;
					}
					add_self(new_dp[(sum+digit)%D][smaller_already||(digit<K[idx]-'0')], dp[sum][smaller_already]);
				}
			}
		}
		dp = new_dp;
	}

	int res=(dp[0][true]+dp[0][false])%mod;
	res--;
	if (res==-1){
		res=mod-1;
	}

	cout << res << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 3640
n = int(input())
x = list(map(int, input().split()))

ans = 0

for i in range(max(x)):
    a = 0
    for j in range(n):
        a += (x[j]-i-1)**2
    if i == 0:
        ans += a
    else:
        ans = min(a, ans)

print(ans)

Measured memory_bytes: 38640
# ABC136D - Gathering Children
def main():
    """
    RR..LLの部分列に分解
    それぞれの部分列のRL境界に子どもが集まる
    奇数マスの子は奇数マスに、偶数マスの子は偶数マスの境界に (10^100 % 2 == 0)
    境界以外は全て0
    """
    S = input().rstrip()
    n = len(S)
    cur, P = S[0], []  # p: partial strings
    for i in S[1:]:
        if cur[-1] == "L" and i == "R":
            P += [cur]
            cur = ""
        cur += i
    P += [cur]

    ans = []
    for p in P:
        e = len(p) // 2
        o = len(p) - e
        r_cnt = p.count("R")
        l_cnt = len(p) - r_cnt
        l_pos = p.index("L")
        l, r = (e, o) if l_pos % 2 == 0 else (o, e)
        ans += [0] * (r_cnt - 1) + [l] + [r] + [0] * (l_cnt - 1)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

typedef long long ll;
const int N = 100005;
const int M = 1000000007;

int n, m;
int a[N];

int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) { scanf("%d", &a[i]); }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ans += a[i] / 2;
      a[i] -= a[i] / 2 * 2;
      if (i == n - 1) { continue; }
      ll t = min(a[i], a[i + 1]);
      ans += t;
      a[i + 1] -= t;
    }
    printf("%lld\n", ans);
  }
}


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

int main() {
	int n,k;
	cin>>n>>k;
	if(n%2!=0)
	n++;
	n=n/2;
	if(n>=k)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(ALL(a));
    ll ans = 0;
    for(int i=0;i<m;i++) ans += a[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
def trace(a,n) :
    li=[]
    for i in xrange(n):
        li.append(str(a[i]))
    print(" ".join(li))
    
def selectionsort(a,n):
    ct=0
    for i in xrange(n):
        if i==n-1:
            break
        else :
            mini=i
            for j in xrange(i,n,1):
                if a[j]<a[mini]:
                    mini=j
            if i!=mini:
                keep=a[i]
                a[i]=a[mini]
                a[mini]=keep
                ct+=1
    return ct
            
            
n=input()
a=map(int,raw_input().split())
ct=selectionsort(a,n)
trace(a,n)
print(ct)
                

Measured memory_bytes: 6472
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int N;
vector<int> g[maxn];
LL qpow(LL a, LL b)
{
    LL res = 1;
    a %= MOD;
    while(b)
    {
        if(b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
LL fact[maxn], fact_inv[maxn];
void preprocess()
{
    fact[0] = 1;
    for(int i = 1; i < maxn; i++)
        fact[i] = fact[i-1] * i % MOD;
    fact_inv[maxn-1] = qpow(fact[maxn-1], MOD - 2);
    for(int i = maxn - 2; i >= 0; i--)
        fact_inv[i] = fact_inv[i+1] * (i + 1) % MOD;
}
LL dp[maxn];
int sz[maxn];
void DFS1(int u, int fa)
{
    dp[u] = 1;
    sz[u] = 1;
    for(auto v : g[u])
    {
        if(v == fa)
            continue;
        DFS1(v, u);
        dp[u] = dp[u] * dp[v] % MOD * fact_inv[sz[v]] % MOD;
        sz[u] += sz[v];
    }
    dp[u] = dp[u] * fact[sz[u]-1] % MOD;
}
void DFS2(int u, int fa)
{
    for(auto v : g[u])
    {
        if(v == fa)
            continue;
        LL t = dp[u];
        dp[u] = dp[u] * fact_inv[N-1] % MOD * fact[N-sz[v]-1] % MOD * fact[sz[v]] % MOD;
        dp[u] = dp[u] * qpow(dp[v], MOD - 2) % MOD;
        dp[v] = dp[v] * fact_inv[sz[v]-1] % MOD * fact[N-1] % MOD * fact_inv[N-sz[v]] % MOD;
        dp[v] = dp[v] * dp[u] % MOD;
        dp[u] = t;
        DFS2(v, u);
    }
}
int main()
{
    preprocess();
    scanf("%d", &N);
    for(int i = 1; i <= N - 1; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    DFS1(1, -1);
    DFS2(1, -1);
    for(int i = 1; i <= N; i++)
        printf("%lld\n", dp[i]);
    return 0;
}


Measured memory_bytes: 19444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // 荳蟷ｴ縺ｮ遘呈焚
  string S;
  cin >> S;
  
  if(S == "Sunny")
  {
    cout << "Cloudy"<< endl;
  }
  else if(S == "Cloudy")
  {
    cout << "Rainy"<<endl;
  }
  else
  {
    cout <<"Sunny"<<endl;
  }
  // 莉･荳九�ｮ繧ｳ繝｡繝ｳ繝�/* */繧呈ｶ医＠縺ｦ霑ｽ險倥☆繧�
  //cout << /* 1蟷ｴ縺ｯ菴慕ｧ偵° */ << endl;
  //cout << /* 2蟷ｴ縺ｯ菴慕ｧ偵° */ << endl;
  //cout << /* 5蟷ｴ縺ｯ菴慕ｧ偵° */ << endl;
  //cout << /* 10蟷ｴ縺ｯ菴慕ｧ偵° */ << endl;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main() {
	char s[17];
	bool is9 = true;
	scanf("%s", s);
	int len = strlen(s);
	for (int i = 1; i < len; i++) {
		if (s[i] != '9') {
			is9 = false;
			break;
		}
	}
	if (is9) {
		printf("%d\n", s[0] - '0' + 9 * len - 9);
	} else {
		printf("%d\n", s[0] - '0' - 1 + 9 * len - 9);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 6007;

int dp[N][2*N+1];

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, mod;
	cin >> n >> mod;

	dp[0][N] = 1;
	dp[1][N+1] = 1;
	dp[2][N+2] = 1;
	dp[2][N-1] = 1;

	for (int i = 3; i <= 3*n; ++i) {
		for (int take = 0; take <= 2; ++take) {
			int cost = 0;
			if (take == 0) cost = 1;
			if (take == 1) cost = -1;

			for (int was = 0; was < 2*N+1; ++was) {
				if (!dp[i-take-1][was]) continue;
				int ways = 1;
				if (take == 1) {
					ways = i-1;
				}
				if (take == 2) {
					ways = ((ll) (i-1) * (i-2)) % mod;
				}
				dp[i][was + cost] += (((ll) dp[i-take-1][was] * ways) % mod);
				if (dp[i][was + cost] >= mod) dp[i][was + cost] -= mod;
			}
		}
	}

	int ans = 0;
	for (int i = N; i < 2*N+1; ++i) {
		ans += dp[3*n][i];
		ans %= mod;
	}

	cout << ans;


}


Measured memory_bytes: 279808
n = int(input())
Ss = []
cs = set("abcdefghijklmnopqrstuvwxyz")
ds = []
for i in range(n):
  S = input()
  d = {}
  for c in cs:
    d[c] = 0
  for c in S:
    d[c] += 1
  ds.append(d)
#print(ds)
md = {}
for c in cs:
  md[c] = min(map(lambda d: d[c], ds))
#print(md)
r = ""
for c in sorted(cs):
  r += c*md[c]
print(r)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

bool check(vi t, int m)
{
	while (t.size() > 1)
	{
		vi tmp = t;
		t.clear();
		FOR(i, 1, tmp.size() - 1)
		{
			vi a;
			for (int j = -1; j <= 1; j++) a.push_back(tmp[i + j]);
			sort(ALL(a));
			t.push_back(a[1]);
		}
	}
	return t[0] == m;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, x;
	cin >> n >> x;
	x--;
	if (n == 2)
	{
		if (x == 1)
		{
			cout << "Yes" << endl;
			REP(i, 3) cout << i + 1 << endl;
		}
		else cout << "No" << endl;
 	}
	else
	{
		if (x == 0 || x == 2 * n - 2) cout << "No" << endl;
		else
		{
			cout << "Yes" << endl;
			vi v(2 * n - 1, -1);
			vector<bool> used(2 * n - 1);
			v[n - 1] = x;
			v[n - 2] = x - 1;
			v[n] = x + 1;
			for (int i = x - 1; i <= x + 1; i++)
			{
				used[i] = true;
			}
			int p = 0;
			REP(i, 2 * n - 1)
			{
				while (used[p]) p++;
				if (v[i] == -1)
				{
					v[i] = p;
					used[p] = true;
				}
			}
			REP(i, 2 * n - 1) cout << v[i] + 1 << endl;
		}
	}
	return 0;
}

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

l = []
for _ in range(M):
    l += [0]
aa=[]
for i in range(N):
    aa.append([int(i) for i in input().split()])
    aa[i].pop(0)

for line in aa:
    for i in line:
        l[i - 1] += 1

ans = 0
for index, s in enumerate(l):
    if s == N:
        ans += 1

print(ans)




Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.next();
        String str2 = sc.next();
        
        StringBuffer str = new StringBuffer(str1);
        String result = "NO";
        if (str.reverse().toString().equals(str2)) result = "YES";
        System.out.println(result);
    }
}


Measured memory_bytes: 35772
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static PrintWriter out;

    public static void main(String[] args) {
        Main.run();
    }

    private static void run() {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        // aとbを結合
        StringBuilder sb = new StringBuilder();
        sb.append(a).append(b);
        double n = Double.parseDouble(sb.toString());
        out.println(Main.checksqrt(n));
        out.close();
        sc.close();
    }

    /**
     * 引数が平方数かどうか判定
     * @param pnum
     * @return 平方数の場合は"Yes"、それ以外は"No"
     */
    private static String checksqrt(double pnum) {
        // 引数の平方根を求める
        double n = Math.sqrt(pnum);
        // 引数を平方根で割った余りが0ならば平方数
        if (pnum % n == 0) {
            return "Yes";
        } else {
            return "No";
        }
    }

}


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

int main()
{
	int a , b , c ;
	cin >> a >> b >> c;
	if ( a > b )
		swap( a , b );
		if ( b > c )
			swap( b , c );
			if ( a > b )
				swap( a , b );
		cout << a << " " << b << " " << c << endl;


}

Measured memory_bytes: 1168
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
		//BufferedReader br=new BufferedReader(new FileReader("sample.txt"));
		String str=br.readLine();
		String[] st=str.split(" ");
		int n=Integer.parseInt(br.readLine());
		Dice dice1 =new Dice(st);
		for(int i=0;i<n;i++){
			st=br.readLine().split(" ");
			for(int j=0;j<6;j++){
				if(j==3)dice1.roll('E');
				if(st[1].equals(dice1.front))break;
				dice1.roll('N');
			}
			while(true){
				if(st[0].equals(dice1.top))break;
				dice1.roll('W');
			}
			System.out.println(dice1.right);
			}
		
		
	}
	}
class Dice{

String top,front,right,left,back,bot;

	Dice(String[] s){
		top=s[0];
		front=s[1];
		right=s[2];
		left=s[3];
		back=s[4];
		bot=s[5];
	}
		
	void roll(char c){
		String top,bot,back,front,left,right;
		
		top=this.top;bot=this.bot;
		front=this.front;
		back=this.back;
		left=this.left;
		right=this.right;
		
		switch(c){
		case 'N':
			top=this.front;
			bot=this.back;
			front=this.bot;
			back=this.top;
			break;
		
		case 'S':
			top=this.back;
			bot=this.front;
			front=this.top;
			back=this.bot;
			break;
		case 'W':
			top=this.right;
			bot=this.left;
			right=this.bot;
			left=this.top;break;
		
		case 'E':
			top=this.left;
			bot=this.right;
			right=this.top;
			left=this.bot;
			break;
		}
		this.top=top;
		this.front=front;
		this.right=right;
		this.left=left;
		this.back=back;
		this.bot=bot;
		
	}
	String getd1(){return this.top;}
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    string s;
    cin >> s;

    ll total = 0;
    ll total_b = 0;

    rep(i,s.size())
    {
        if( s[i] == 'a' && total < A+B )
        {
            cout << "Yes" << endl;
            total++;
        }
        else if( s[i] == 'b' && total < A+B && total_b < B )
        {
            cout << "Yes" << endl;
            total++;
            total_b++;
        }
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 896
import Control.Monad
import Data.List
main=do
    _<-getLine
    as<-reverse.sort.map read.words<$>getLine::IO[Int]
    print $ liftM2 (-) fst snd $ g (0,0) as

g (a,b) [] = (a,b)
g (a,b) [x] = (a+x,b)
g (a,b) (x:y:ar) = g (a+x,b+y) ar


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

int main() {
  int r, D, x;
  cin >> r >> D >> x;
  
  vector<int> X(11);
  X.at(0) = x;
  for (int i = 1; i < 11; i++) {
  	X.at(i) = r * X.at(i - 1) - D;
  	cout << X.at(i) << endl;
  }
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
vector<int> tree[100050];
int n;
ll fv = 0;
ll sv = 0;
int used[100050];
vector<int> f[100050];
vector<int> s[100050];
vector<int> shortRoot;
queue<pii> fq;
queue<pii> sq;
void recur(int player,int fd,int sd)
{
	if (f[fd].size() == 0 && s[sd].size() == 0) return;
	if(player == 1 && f[fd].size() > 0){
		for (int i = 0; i < f[fd].size(); i++)
		{
			int from = f[fd][i];
			for (int j = 0; j < tree[from].size(); j++)
			{
				int to = tree[from][j];
				if (used[to] == -1) {
					used[to] = 1;
					f[fd + 1].push_back(to);
				} 
			}
		}
		fd++;
	}
	else if(player == -1 && s[sd].size() > 0){
		for (int i = 0; i < s[sd].size(); i++)
		{
			int from = s[sd][i];
			for (int j = 0; j < tree[from].size(); j++)
			{
				int to = tree[from][j];
				if (used[to] == -1) {
					used[to] = 2;
					s[sd + 1].push_back(to);
				}
			}
		}
		sd++;
	}
	recur(-player, fd, sd);
}
void FennecVSSnuke(){

	cin >> n;
	for (size_t i = 1; i <= n; i++)
	{
		used[i] = -1;
	}
	for (size_t i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	used[1] = 1;
	used[n] = 2;
	f[0].push_back(1);
	s[0].push_back(n);
	recur(1, 0, 0);
	int count = 0;
	for (size_t i = 1; i <= n; i++)
	{
		count += (used[i] == 1);
	}
	int fne = count;
	int snu = n - fne;
	if (fne > snu) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}
}

int main() {
	FennecVSSnuke();
	return 0;
}


Measured memory_bytes: 24832
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	int n;
	cin>>n;
	int y=ceil(n/1000.0);
	// error(y);
	if(n%1000==0){
		cout<<0<<endl;
	}	
	else{
		int rem=y*1000 - n;
		cout<<rem<<endl;
	}
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3700
import itertools

S = int(input())

ans = 0
cnt = 0

for i in itertools.product([0,1], repeat = len(str(S)) - 1):
    A = str(S)
    cnt = 0
    for x, sign in enumerate(i):
        if sign == 0:
            cnt += 1
            if x == len(str(S)) - 2:
                ans += int(A[0:cnt+1])
        else :
            ans += int(A[0:cnt+1])
            cnt = 0
            A = str(S)[x+1:]
            if x == len(str(S)) - 2:
                ans += int(A[-1])

if len(str(S)) == 1:
    print(S)
else:
    print(ans)

Measured memory_bytes: 3064
// ABC 055 D
#include<bits/stdc++.h>
 
using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

str s; 

char make(str a,int i){
  if(a[i]=='S'){
    if(s[i]=='o'){
      if(a[i-1]=='S')  return 'S';
      else return'W';
    }
    else if(s[i]=='x'){
      if(a[i-1]=='S') return 'W';
      else return 'S';
    }
  }
  else if(a[i]=='W'){
    if(s[i]=='o'){
      if(a[i-1]=='S')  return 'W';
      else return 'S';
    }
    else if(s[i]=='x'){
      if(a[i-1]=='S') return 'S';
      else return 'W';
    }
  }
}
bool check(str a,int i,int n){
  if(a[(i+n)%n]=='S'){
    if(s[(i+n)%n]=='o'){
      if (a[(i+n-1)%n]==a[(i+n+1)%n]) return true;
      else return false;
    }
    else if(s[(i+n)%n]=='x'){
      if (a[(i+n-1)%n]!=a[(i+n+1)%n]) return true;
      else return false;
    }
  }
  else if(a[(i+n)%n]=='W'){
    if(s[(i+n)%n]=='o'){
      if (a[(i+n-1)%n]!=a[(i+n+1)%n]) return true;
      else return false;
    }
    else if(s[(i+n)%n]=='x'){
      if (a[(i+n-1)%n]==a[(i+n+1)%n]) return true;
      else return false;
    }
  }
}

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int n,k;
  str ans;
  cin >> n;
  cin >> s;
  str s1 = "SS";
  str s2 = "SW";
  str s3 = "WS";
  str s4 = "WW";
  vector <string> ss{s1,s2,s3,s4};
  EACH(i,ss){
    FOR(j,1,n-1){
      *i+=make(*i,j);
    }
    if(check(*i,n-1,n)&&check(*i,0,n)) {
      ans = *i;
      break;
    }
  }
  if(ans=="")ans="-1";
  cout << ans << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  double bunbo=1;
  for(int i=0; i<N; i++){
    bunbo=bunbo*A.at(i);
  }
  double bunsi=0;
  for(int i=0; i<N; i++){
    bunsi=bunsi + bunbo/A.at(i);
  }
  double ans = bunbo / bunsi;
  std::cout << std::setprecision(8) << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())

results = defaultdict(list)
for _ in range(M):
    p, s = input().split()
    results[p].append(s)

acCnt = 0
waCnt = 0
for result in results.values():
    cnt = 0
    for s in result:
        if s == 'AC':
            acCnt += 1
            break
        cnt += 1
    else:
        continue
    waCnt += cnt

print(acCnt, waCnt)

Measured memory_bytes: 31884
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int a, b;

void init()
{
}

void solve()
{
    int ans = 0;
    REP(i, 2){
        if(a > b){
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
require 'pp'

H,W = readline.chomp.split.map(&:to_i)
A = []
H.times do |h|
  A << readline.chomp.split.map(&:to_i).map {|i| i % 2 }
end

on = false
ans = []
A.size.times do |i|
  js = (i%2==0) ? (0..(W-1)) : (0..(W-1)).to_a.reverse
  js.each do |j|
    if on
      ans[-1] += [i+1,j+1]
    end
    if A[i][j]==1
      on = !on
    end
    if on
      ans << [i+1,j+1]
    end
  end
end

if ans.size > 0 and ans[-1].size < 4
  ans.pop
end
puts ans.size
ans.each {|a| puts a.join(' ') }


Measured memory_bytes: 30844
#include <stdio.h>

int main(void) {
	int a, b;
	int yukachi;
	if (scanf("%d%d", &a, &b) != 2) return 1;
	yukachi = b - a;
	/* 全体 - 出ている部分 = 雪の部分 */
	printf("%d\n", ((1 + yukachi) * yukachi / 2) - b);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#define pa pair<int,int>
 
using namespace std;

const int MAXN=1000010;
int dis[MAXN];
vector <pa> g[MAXN];
vector <int> new_g[MAXN],all[MAXN];
int visit[MAXN],ptr[MAXN];
queue <int> q;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		u--,v--;
		g[u].push_back(make_pair(c,v));
		g[v].push_back(make_pair(c,u));
		all[c].push_back(u);
		all[c].push_back(v);
	}
	for (int i=0;i<n;i++)
	{
		sort(g[i].begin(),g[i].end());
		visit[i]=-1;
	}
	int newn=n;
	for (int i=0;i<MAXN;i++)
	{
		if (all[i].empty())
		{
			continue;
		}
		for (int it=0;it<all[i].size();it++)
		{
			int v=all[i][it];
			if (visit[v]==i)
			{
				continue;
			}
			q.push(v);
			visit[v]=i;
			while (!q.empty())
			{
				int x=q.front();
				q.pop();
				while (ptr[x]<(int)g[x].size())
				{
					int c=g[x][ptr[x]].first;
					if (c!=i)
					{
						break;
					}
					int u=g[x][ptr[x]].second;
					if (visit[u]!=i)
					{
						visit[u]=i;
						q.push(u);
					}
					ptr[x]++;
				}
				new_g[x].push_back(newn);
				new_g[newn].push_back(x);	
			}
			newn++;
		}
	}
	for (int i=0;i<newn;i++)
	{
		dis[i]=-2;
	}
	q.push(0);
	dis[0]=0;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		for (int i=0;i<new_g[x].size();i++)
		{
			int u=new_g[x][i];
			if (dis[u]==-2)
			{
				dis[u]=dis[x]+1;
				q.push(u);	
			}
		}
	}
	cout<<dis[n-1]/2;
    return 0;
}


Measured memory_bytes: 98816
n = int(input())
record = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for i in  range(n):
  b, f, r, v = [int(x) for x in input().split()]
  record[b-1][f-1][r-1] += v
for b in range(4):
  for f in record[b]:
    print(' '+' '.join([str(x) for x in f]))
  if b != 3:
    print(''.join(['#' for x in range(20)]))

Measured memory_bytes: 7656
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int z;
    int sums=0;
    int& sum=sums;
    cin>>z;
    
    if(z>=15)
    {
        sum=z/15;
        cout<<z*800-sum*200<<endl;
    }else{
        cout<<z*800<<endl;        
    }
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#include <atcoder/convolution>
#include <atcoder/modint>

using namespace std;
using ll = long long int;
using mint = atcoder::modint998244353;
constexpr int MAX_H = 100000;
// constexpr int MAX_H = 3;
constexpr int MAX_N = 50000;
// constexpr int MAX_N = 2;
mint f[2 * MAX_N + 1];

int cnt[MAX_H + 1] = {0};
mint p[MAX_N + 1];

int h[2 * MAX_N];

mint C(int n, int m) {
    return f[n] * (f[n - m] * f[m]).inv();
}

int main(int, char **) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < 2 * n; i++) {
        cin >> h[i];
    }

    for (int i = 0; i < 2 * n; i++) {
        cnt[h[i]]++;
    }
    f[0] = 1;
    for (int i = 1; i <= MAX_N * 2; i++) {
        f[i] = f[i - 1] * i;
    }
    p[0] = 1;
    for (int i = 1; i <= MAX_N; i++) {
        p[i] = p[i - 1] * mint(2 * i - 1);
    }

    queue<vector<mint>> q;
    q.push(vector<mint>(1, 1));
    for (int i = 0; i <= MAX_H; i++) {
        if (cnt[i] < 2) continue;
        vector<mint> v(cnt[i] / 2 + 1);
        for (int j = 0; 2 * j <= cnt[i]; j++) {
            v[j] = C(cnt[i], 2 * j) * p[j];
        }

        // for (int j = 0; j < v.size(); j++) {
        //     cout << v[j].val() << " ";
        // }
        // cout << endl;

        q.push(v);
    }

    while (q.size() > 1) {
        auto v1 = q.front();
        q.pop();
        auto v2 = q.front();
        q.pop();
        auto v3 = atcoder::convolution(v1, v2);
        q.push(v3);
    }

    auto v = q.front();

    mint ans = 0;
    for (int i = 0; i <= n && i < v.size(); i++) {
        ans += v[i] * p[n - i] * (i % 2 == 0 ? 1 : -1);
    }
    cout << ans.val() << endl;

    // for (int i = 0; i < 2; i++) {
    //     cout << v[i].val() << " ";
    // }
    // cout << endl;

    return 0;
}


Measured memory_bytes: 6624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <bitset>
using namespace std;
#define ll long long
 
int main(void){
    ll a, b;
    cin >> a >> b;
    ll check = (b-a)/2;
    ll ans = 0;
    if(a%2!=0 && b%2!=0){
        ans = a;
        if(check%2!=0) ans--;
    }
    else if(a%2!=0 && b%2==0){
        string sa, sb;
        while(a>0){
            if(a%2==0) sa.insert(sa.begin(),'0');
            else if(a%2!=0) sa.insert(sa.begin(),'1');
            a /= 2;
        }
        while(b>0){
            if(b%2==0) sb.insert(sb.begin(),'0');
            else if(b%2!=0) sb.insert(sb.begin(),'1');
            b /= 2;
        }
        for(ll i = sa.length(); i < sb.length(); i++)
            sa.insert(sa.begin(), '0');

        for(ll i = 0; i < sa.length(); i++){
            ll len = sa.length();
            if(sa[len-i-1]=='1' && sb[len-i-1]=='0')
                ans += pow(2, i);
            else if(sa[len-i-1]=='0' && sb[len-i-1]=='1')
                ans += pow(2, i);
        }
        if(ans%2!=0 && check%2!=0)
            ans--;
        else if(ans%2==0 && check%2!=0)
            ans++;
    }
    else if(a%2==0 && b%2==0){
        ans = b;
        if(check%2!=0) ans++;
    }
    else if(a%2==0 && b%2!=0)
        ans = ((b-a+1)/2)%2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i, 0, n)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#ifdef LOCAL
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 10000
#define N 512
int m;
int memo[N][2][3][10][3][N];
char a[3][N];
int k;
// bool debug=false;

int DP(int, int, int, int, int, int);
int dp(int p, int q, int r, int s, int t, int u){
	if(~memo[p][q][r][s][t][u]) return memo[p][q][r][s][t][u];
	else return memo[p][q][r][s][t][u]=DP(p, q, r, s, t, u);
	// return DP(p, q, r, s, t, u);
}
// digit count, leading zero, constrain,     before, next none/up/down, mod
int DP(int p, int q, int r,    int s, int t, int u){
	int ret=0;
	if(p==0){
		if(u==0){
		 	ret=1;
		}else ret=0;
	}else{
		if(q){
			REP(i, 10){
				if(i>a[r][k-p]) continue;
					// printf(" (%d, %d)->(%d, %d)\n", p, u, p-1, u*10+i);
				ret+=dp(p-1, i==0, i<a[r][k-p]?2:r, i, 0, i%m);
			}
		}else{
			if(t==0){
				REP(i, 10){
					if(i==s) continue;
					if(i>a[r][k-p]) continue;
					ret+=dp(p-1, q, i<a[r][k-p]?2:r, i, s>i?1:2, (u*10+i)%m);
				}
			}else if(t==1){
				FOR(i, s+1, 10){
					if(i>a[r][k-p]) continue;
					ret+=dp(p-1, q, i<a[r][k-p]?2:r, i, 2, (u*10+i)%m);
				}
			}else{
				REP(i, s){
					if(i>a[r][k-p]) continue;
					ret+=dp(p-1, q, i<a[r][k-p]?2:r, i, 1, (u*10+i)%m);
				}
			}
		}
	}
	ret%=MOD;
	return ret;
}

int main(){
	scanf("%s%s%d", a[0], a[1], &m);
	int x[2];
	REP(i, 2){
		x[i]=strlen(a[i]);
		REP(j, x[i]) a[i][j]-='0';
	}
	REP(i, N) a[2][i]=9;
	REP(h, N) REP(i, 2) REP(j, 3) REP(f, 10) REP(l, 3) REP(g, N)
	 	memo[h][i][j][f][l][g]=-1;
	k=x[0];
	int p=dp(k, 1, 0, 0, 0, 0);
	// debug=true;
	REP(h, N) REP(i, 2) REP(j, 3) REP(f, 10) REP(l, 3) REP(g, N)
	 	memo[h][i][j][f][l][g]=-1;
	k=x[1];
	int q=dp(k, 1, 1, 0, 0, 0);
	int r=0;
	REP(j, 2){
		bool ok=true;
		REP(i, x[0]-1){
			if((i+j)%2==0 && a[0][i]>=a[0][i+1]) ok=false;
			if((i+j)%2==1 && a[0][i]<=a[0][i+1]) ok=false;
		}
		if(ok) r=1;
	}
	int buf=0;
	REP(i, x[0]){
		buf*=10;
		buf+=a[0][i];
		buf%=m;
	}
	if(buf) r=0;
	int ans=(q-p+r+MOD*100)%MOD;
	printf("%d\n", ans);
}

Measured memory_bytes: 187548
/*  ex5_3
    ruuu0048 */
#include <stdio.h>

int main(void){

    int height,wide; //高さと横幅の変数を宣言

    scanf("%d %d",&height,&wide); //高さと変数を宣言

    char table[height][wide]; //マス目の配列を宣言


    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j <wide; j++)
        {
            scanf(" %c",&table[i][j]); //白黒を入力
        }   
    }

  
  	//空行があったら,その行は.を！に変える
    
    for (int i = 0; i < height; i++)
    {
        int count = 0; //数える変数を宣言
        for (int j = 0; j <wide; j++)
        {
            if(table[i][j] == '#'){ //黒があったら
                count ++; //カウントする
            }
        }
        if (count == 0){ //i行目に一つも黒がなかったら
            for(int j = 0; j <wide; j++)
            {
                table[i][j] ='!'; //i行目をすべて'!'にする
            }
        }
    }
  
  
  	//空列があったら,その列は.を！に変える

    for (int j= 0; j < wide; j++) //iとjを入れ替えて同じことをする
    {
        int count = 0;
        for (int i = 0; i <height; i++)
        {
            if(table[i][j] == '#'){
                count ++;
            }
        }
        if (count == 0){ //j列目に一つも黒がなかったら
            for(int i = 0; i <height; i++)
            {
                table[i][j] ='!'; //i行目をすべて'!'にする
            }
        }
    }
  
	
  	//最後に出力

    for (int i = 0; i < height; i++)
    {
        int count = 0; //数える変数を宣言
        for (int j = 0; j <wide; j++)
        {
            if(table[i][j] != '!'){ //!じゃなかったら
                printf("%c",table[i][j]); //出力
                count ++; //数える
            }
        }
        if(count > 0){ //空行じゃなかったら
            printf("\n"); //改行を出力
        }
    }
    

    return 0; 
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

Int f[1001][1001];
Int H[1001];
Int W[1001];

int main() {
    Int h, w, a, b;
    cin >> h >> w >> a >> b;
    //Int x = gcd(h, w);
    if (a == 0 && b == 0) {
        for (Int i = 0; i < h; i++) {
            for (Int j = 0; j < w; j++) {
                cout << 0;
            }
            cout << endl;
        }
    }
    else if (a == 0) {
        for (Int i = 0; i < h; i++) {
            for (Int j = 0; j < w; j++) {
                if (i < b) {
                    cout << 1;
                }
                else {
                    cout << 0;
                }
            }
            cout << endl;
        }
    }
    else if (b == 0) {
        for (Int i = 0; i < h; i++) {
            for (Int j = 0; j < w; j++) {
                if (j < a) {
                    cout << 1;
                }
                else {
                    cout << 0;
                }
            }
            cout << endl;
        }
    }
    else {
        for (Int i = 0; i < h; i++) {
            for (Int j = 0; j < w; j++) {
                if ((i < b && j < a) || (b <= i && a <= j)) {
                    cout << 1;
                }
                else {
                    cout << 0;
                }
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
from collections import Counter
from itertools import product

n = int(input())
d = Counter(list(map(int, input().split())) + [0])

ans, cnt = [], []
for num in d:
    if d[num] > (2 - (num in {0, 12})):
        print(0)
        exit()
    elif (num in {0, 12}) and d[num] == 1:
        ans.append(num)
    elif d[num] == 2:
        ans.append(num), ans.append(24 - num)
    elif d[num] == 1:
        cnt.append(num)

s = 0
if len(cnt) == 0:
    s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
for bit in product([1, -1], repeat=len(cnt)):
    tmp = ans[:]
    tmp += [(ci - 12) * bi + 12 for bi, ci in zip(bit, cnt)]
    tmp = sorted(tmp + [i + 24 for i in tmp])
    stmp = min(tmp[i] - tmp[i - 1] for i in range(1, len(tmp)))
    s = max(s, stmp)
print(s)


Measured memory_bytes: 73476
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
        lint n,q;
        string s;
        cin>>n>>q;
        if(n<=q)cout<<"unsafe";
       else cout<<"safe";

          }
  
     


Measured memory_bytes: 3720
from collections import deque
from heapq import heappop, heappush


def main():
    N = int(input())
    win = [0] * N
    A = [int(input()) for _ in range(N-1)]
    for a in A:
        win[a-1] += 1
    ans = [-1] * N
    q = deque()
    pq = [[] for _ in range(N)]
    for i in range(N):
        if win[i] == 0:
            q.append(i)
    while len(q):
        x = q.popleft()
        tmp = 1
        for i in range(1, len(pq[x])+1)[::-1]:
            nxt = heappop(pq[x])
            tmp = max(tmp, nxt + i)
        ans[x] = tmp
        if x >= 1:
            w = A[x-1]-1
            heappush(pq[w], ans[x])
            win[w] -= 1
            if win[w] == 0:
                q.append(w)
    print(ans[0] - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 79576
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int N, M;
  std::cin >> N >> M;

  std::vector<std::vector<long long>> A(8, std::vector<long long>(N));
  for(int i=0; i<N; i++) {
    long long x, y, z;
    std::cin >> x >> y >> z;
    A[0][i] = + x + y + z;
    A[1][i] = - x + y + z;
    A[2][i] = + x + y - z;
    A[3][i] = - x + y - z;
    A[4][i] = + x - y + z;
    A[5][i] = - x - y + z;
    A[6][i] = + x - y - z;
    A[7][i] = - x - y - z;
  }

  for(int i=0; i<8; i++) std::sort(A[i].begin(), A[i].end(), [] ( long long &x, long long &y ) { return x > y; });

  std::vector<long long> ans(8,0);
  for(int i=0; i<M; i++) for(int j=0; j<8; j++) ans[j] += A[j][i];
  std::cout << *std::max_element(ans.begin(), ans.end()) << std::endl;

  return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    ll n, k, ans = 0; cin >> n;
    for(ll i = 1; i * i <= n; i++) if(n % i == 0) k = n / i;
    for(; k; k /= 10, ans++);
    cout << ans;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v(5);
    for(int i = 0; i < 5; ++i){	
    	cin >> v[i];
    }
    for(int i = 0; i < 5; ++i){	
    	if(v[i] == 0){	
    		cout << i + 1 << endl;
    	}
    }
    return 0;
}


Measured memory_bytes: 3616