akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
using namespace std;

int main() {
	int n;
	cin>>n;
	multimap<int, int> m;
	for (int i=0; i<n; i++) {
		int a;
		cin>>a;
		m.insert(make_pair(a, i));
		if (m.size() > 2)
			m.erase( m.begin() );
		// cout<<m.begin()->first<<" "<<m.rbegin()->first<<endl;
	}
	int maxval = m.rbegin()->first;
	int maxpos = m.rbegin()->second;
	int m2val = m.begin()->first;
	for (int i=0; i<n; i++) {
		if (i == maxpos)
			cout<<m2val<<" ";
		else
			cout<<maxval<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1664
using System;
    using System.IO;
    using System.Windows;
    using System.Collections.Generic;
    using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            //input
            string[] input = Console.ReadLine().Split(' ');
            string n = input[0];
            string m = input[1];
            string l = input[2];
            Console.WriteLine(l + ' ' + n + ' ' + m);
        }
    }

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int inf = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> a(5);
    FORO(i, 5) cin >> a[i];
    sort(ALL(a));
    int ans = inf;
    do {
        int t = 0;
        FORO(i, 5) {
            t += a[i];
            if(i + 1 < 5 && t % 10) t = (int(t/10) + 1) * 10; 
        }
        ans = min(ans, t);
    } while(next_permutation(ALL(a)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())
p = list(map(int, input().split()))
p = list(map(lambda x:(x+1)*0.5, p))
temp = []
p_sum=0
for i in range(N):
    p_sum+=p[i]
    temp.append(p_sum)
ans = []
for j in range(K,N):
    ans.append(temp[j]-temp[j-K])
if len(ans) != 0:
    print(max(ans))
else:
    print(p_sum)

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

int main() {
	int n;
	cin>>n;
	long long h[n+2]={0},dp[n]={0},i;
	for(i=0;i<n;i++)
	cin>>h[i];
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	dp[2]+=min(dp[1]+abs(h[1]-h[2]),abs(h[2]-h[0]));
	for(i=3;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
		//cout<<dp[i]<<' ';
	}
	//cout<<dp[0]<<dp[1]<<dp[2]<<endl;
	//sort(dp,dp+n);
	// your code goes here
	cout<<dp[n-1];
	return 0;
}

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

int main() {
    /* Input */
    int n;
    cin >> n;

    bool has_seven = false;
    int digit_1  = n % 10;
    n /= 10;
    int digit_2 = n % 10;
    n /= 10;
    int digit_3  = n % 10;

    if (digit_1 == 7) has_seven = true;
    if (digit_2 == 7) has_seven = true;
    if (digit_3 == 7) has_seven = true;

    if (has_seven) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3492
#include <iostream>
#include <string>
#define LONG_INF 10000000000000000
#define REP(i,N) for(int (i) = 0; (i) < (N); i++)

using namespace std;

int gcd(int a, int b){
    int r = a%b;
    if(r == 0) return b;

    return gcd(b,r);
}

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

	ans = n*2/gcd(n,2);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=2000+19;
const int p=1e9+7;

int Pow(int a,int b){
	int res=1;
	for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p;
	return res;
}

int f[N][N],g[N][N],C[N][N];
int n,K,res;

int main(){
	For(i,0,N){
		C[i][0]=1;
		For(j,1,i+1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
	}
	n=IN(),K=IN();
	if (n==1){
		printf("1\n");
		return 0;
	}
	if (K==1){
		printf("%d\n",Pow(2,n-2));
		return 0;
	}
	f[1][2]=1;
	For(i,1,K){
		For(j,1,N){
			g[i][j]=(g[i][j-1]+f[i][j])%p;
		}
		for (int j=1;j<=i+1;j++){
			f[i+1][j+1]=(f[i+1][j+1]+f[i][j])%p;
		}
		for (int k=2;k<=i+1;k++){
			f[i+1][k]=(0ll+f[i+1][k]+g[i][i+1]-g[i][k-1]+p)%p;
		}
	}
	if (n==K){
		res=1ll*C[n-2][K-1]*f[K-1][K]%p;
		res=(res+1ll*C[n-2][K-2]*f[K-1][K])%p;
		For(i,2,K){
			res=(res+1ll*C[n-2][K-2]*f[K-1][i])%p;
		}
	} else{
		res=1ll*C[n-2][K-1]*f[K-1][K]%p*Pow(2,n-K-1)%p;
		res=(res+1ll*C[n-2][K-2]*f[K-1][K]%p*Pow(2,n-K-1))%p;
		For(i,2,K){
			res=(res+1ll*C[i-1+n-K][i-1]*f[K-1][i]%p*Pow(2,n-K-1))%p;
		}
	}
	printf("%d\n",res);
}

Measured memory_bytes: 46976
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
/*string s;
int main(){
    cin>>s;
    if (s[0]==s[1] && s[1]==s[2]) return puts("Yes")*0;
    if (s[1]==s[2] && s[2]==s[3]) return puts("Yes")*0;
    puts("No");
    return 0;
}*/
/*ll a[87];
int main(){
    int n;
    a[0]=2,a[1]=1;
    for (int i=2;i<=86;i++) a[i]=a[i-1]+a[i-2];
    read(n);
    cout<<a[n]<<endl;
    return 0;
}*/
/*string s;
int main(){
    cin>>s;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    int tmp=a;
    for (int i=0;i<2;i++){
        for (int j=0;j<2;j++){
            for (int k=0;k<2;k++){
                int ans=tmp;
                if (i==0) ans+=b;
                else ans-=b;
                if (j==0) ans+=c;
                else ans-=c;
                if (k==0) ans+=d;
                else ans-=d;
                if (ans==7){
                    printf("%d%c%d%c%d%c%d=7\n",a,i==0?'+':'-',b,j==0?'+':'-',c,k==0?'+':'-',d);
                    return 0;
                }
            }
        }
    }
    return 0;
}*/
int h,w;
int val[15][15];
int main(){
    read(h),read(w);
    for (int i=0;i<=9;i++){
        for (int j=0;j<=9;j++){
            read(val[i][j]);
        }
    }
    for (int k=0;k<=9;k++){
        for (int i=0;i<=9;i++){
            for (int j=0;j<=9;j++){
                val[i][j]=min(val[i][j],val[i][k]+val[k][j]);
            }
        }
    }
    int ans=0;
    for (int i=1;i<=h;i++){
        for (int j=1;j<=w;j++){
            int x;read(x);
            if (x==-1 || x==1) continue;
            ans+=val[x][1];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n; cin >> n;
  int ans = 100000;
  while (n--) {
    ans = ans + ceil(ans * 0.05 / 1000) * 1000;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  for (int i = 0; i < N; i++) cin >> X.at(i);
  
  ll ans = 0;
  for (int i = 0; i < N-1; i++) {
    ans += min(A * (X.at(i+1) - X.at(i)), B);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
from math import sin, cos
from math import radians as rad
x, y, t = 0, 0, 0
while(1):
    a, b = map(int,input().split(','))
    if (a == b == 0): break;
    x += a * sin(rad(t))
    y += a * cos(rad(t))
    t += b
print(int(x))
print(int(y))

Measured memory_bytes: 7852
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int N;
int p[200005];


int main(void) {
    scanf("%d", &N);
    rep(i, 0, N) scanf("%d", &p[i]);

    int minp = p[0];

    rep(i, 0, N) {
        minp = min(minp, p[i]);
        if (p[i] <= minp) ans++;
    }
   

  
    printf("%d\n", ans);

	return 0;
}


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

int main(){
    int N,flag=0;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(A[i] % 2 == 0){
            if(A[i] % 3 != 0 && A[i] % 5 != 0 ){
                cout << "DENIED";
                flag = 1;
                break;
            }
            // cout << A[i];
        }
    }
    if(flag != 1){
        cout << "APPROVED";
    }
}

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

int func(int a) {
	int res = 0;
	res += a / 500; a %= 500;
	res += a / 100; a %= 100;
	res += a / 50; a %= 50;
	res += a / 10;
	return res;
}
int main() {
	int n; scanf("%d", &n);
	while (1) {
		int a, b, c, d, e = 0, f = 0, g = 0, h = 0;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int Min = INT_MAX;
		rep(i, a)rep(j, b)rep(k, c)rep(l, d) {
			int sum = 10 * i + 50 * j + 100 * k + 500 * l;
			int cnt = a - i + b - j + c - k + l - d + func(sum - n);
			if (sum >= n&&cnt < Min) {
				Min = cnt;
				e = i; f = j; g = k; h = l;
			}
		}
		if (e)printf("10 %d\n", e);
		if (f)printf("50 %d\n", f);
		if (g)printf("100 %d\n", g);
		if (h)printf("500 %d\n", h);
		scanf("%d", &n);
		if (n)printf("\n");
		else break;
	}
}

Measured memory_bytes: 3196
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  }
}


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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int a,b,h,m;

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

  double aAngle = h*30 + (double)m/60 * 30;
  double bAngle = m*6;
  double dif = abs(aAngle-bAngle);
  double angle = min(dif,360-dif)/180 * acos(-1);
  cout << fixed << setprecision(15) << sqrt(a*a + b*b - 2*a*b*cos(angle)) << endl;
  

  return 0;
}

Measured memory_bytes: 4236
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);

    map<int, set<int>> m;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
        m[A[i]].insert(i);
    }

    vector<int> next(N, N);
    for (int i = 0; i < N; i++) {
        auto it = m[A[i]].upper_bound(i);
        if (it == m[A[i]].end()) continue;
        next[i] = *it;
    }

    int D = 1;
    int idx = 0;
    vector<int> first_idxs;
    while (true) {
        int nxt = next[idx];
        if (nxt == N) {
            nxt = *m[A[idx]].begin();
            D++;

            first_idxs.push_back(idx);
        }

        idx = (nxt + 1) % N;
        if (idx == 0) break;
    }

    // 周期
    K = K % D;
    if (K == 0) return 0;

    int first_idx = first_idxs[K - 1];

    vector<int> ans;
    for (int i = first_idx; i < N;) {
        if (next[i] != N) {
            i = next[i] + 1;
        } else {
            ans.push_back(A[i]);
            i++;
        }
    }

    int M = ans.size();
    for (int i = 0; i < M; i++) {
        cout << ans[i];
        if (i != M - 1) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 36084
#include<iostream>
#include<cstring>
const int mod=1000000007;
using namespace std;
long long npow(long long x)
{
	long long ans=1,n=mod-2;
	while(n)
	{
		if(n&1) ans=ans*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return ans;
}
long long co(long long x,long long y)
{
	long long ans=1;
	for(int i=0;i<x;i++)
		ans=(ans*(y-i))%mod;
	for(int i=0;i<x-1;i++)
		ans=(ans*npow(x-i))%mod;
	return ans;
}
int main()
{
	long long h,w,a,b,c1=1,c2,ans=0;
	cin>>h>>w>>a>>b;
	c1=1;
	c2=co(h-1,h+w-b-2);
	ans=(ans+c1*c2%mod)%mod;
	for(int i=2;i<=h-a;i++)
	{
		c1=(c1*(i+b-2)%mod*npow(i-1))%mod;
		c2=(c2*(h-i+1)%mod*npow(h-i+w-b))%mod;
		ans=(ans+c1*c2%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
 } 

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

using namespace std;

int main ()
{
    int a,b,c;
    cin>>a>>b>>c;
    int n=0;
    while(a<=b)
    {
        if(c%a==0)
        {
            n++;
        }
        a++;
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> x(n, -1);

  vector<vector<P>> to(n);
  vector<bool> seen(n, false);
  vector<ll> deg(n, 0);
  REP(i, m) {
    ll l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    to[l].push_back({r, d});
    deg[r]++;
    seen[l] = seen[r] = true;
  }

  ll uni = 0;
  REP(i, n) {
    if (seen[i]) {
      uni++;
    }
  }

  stack<ll> st;
  REP(i, n) if (seen[i] && deg[i] == 0) st.push(i);
  // dp[i] = 頂点iを始点とするパス長の最大値
  vector<ll> topo, dp(n, 0);
  while (!st.empty()) {
    ll cv = st.top();
    st.pop();
    topo.push_back(cv);
    FOREACH(x, to[cv]) {
      ll nv = x.first;
      deg[nv]--;
      dp[nv] = max(dp[nv], dp[cv] + 1);
      if (deg[nv] == 0) st.push(nv);
    }
  }
  //トポロジカルソート列に全頂点が格納されていない場合，閉路がある
  if (SZ(topo) != uni) no();

  for (ll i : topo) {
    if (x[i] == -1 && SZ(to[i]) < 2) {
      continue;
    }
    if (x[i] == -1) {
      x[i] = 0;
    }
    for (P p : to[i]) {
      ll j = p.first, d = p.second;
      if (x[j] == -1) {
        x[j] = x[i] + d;
        continue;
      }
      if (x[i] + d != x[j]) {
        no();
      }
    }
  }
  yes();
}

Measured memory_bytes: 11256
#include <stdio.h>

int main(void){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  a += b;
  c += d;
  if(a > c) printf("Left\n");
  if(a < c) printf("Right\n");
  if(a == c) printf("Balanced\n");
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, s;
		int a[];
		short dp[][][];

		a = new int[10];
		dp = new short[350][1025][12];
		while (sc.hasNext()) {
			n = sc.nextInt();
			s = sc.nextInt();
			if (340 < s) {
				System.out.println("0");
				if (sc.hasNext()) {
					continue;
				} else {
					break;
				}
			}
			for (int i = 0; i < 350; i++) {
				for (int j = 0; j < 1025; j++) {
					for (int k = 0; k < 12; k++) {
						dp[i][j][k] = -1;
					}
				}
			}
			System.out.println(countFuctrialMemo(dp, n, s, a, 1) + 32768);
		}
	}

	public static short countFuctrialMemo(short dp[][][], int n, int s, int a[], int k) {
		int binSum = 0;
		int bin = 1;
		for (int i = 0; i < 10; i++) {
			binSum += a[i] * bin;
			bin *= 2;
		}

		if (dp[s][binSum][k] != -1) {
			return dp[s][binSum][k];
		} else if (k == n + 1) {
			if (s == 0) {
				dp[s][binSum][k] = -32767;
			} else {
				dp[s][binSum][k] = -32768;
			}
			return dp[s][binSum][k];
		} else {
			int count = 0;
			for (int i = 0; i < 10; i++) {
				if (0 <= s - k * i) {
					if (a[i] == 0) {
						a[i] = 1;
						count += countFuctrialMemo(dp, n, s - k * i, a, k + 1) + 32768;
						a[i] = 0;
					}
				} else {
					break;
				}
			}
			dp[s][binSum][k] = (short)(count - 32768);
			return dp[s][binSum][k];
		}
	}
}

Measured memory_bytes: 27000
N = int(input())
A = list(map(int, input().split()))

def gcd(n, m):
    if n == 0 or m == 0:
        return max(n, m)
    while n % m != 0:
        n, m = m, n % m
    return m

l = [0]
for i in range(N-1):
    l.append(gcd(l[i], A[i]))
r = [0]
for i in range(1, N):
    r.append(gcd(r[i-1], A[N-i]))
m = [gcd(l[i], r[N-1-i]) for i in range(N)]
print(max(m))


Measured memory_bytes: 14584
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> vec(100);
    double ans = 0;
    int n, m;cin >> n >> m;
    for(int i = 0;i < n;i++){
        cin >> vec.at(i);
        
    }
    ans = accumulate(vec.begin(),vec.end(),0);
    ans = ans / (4.0 * m);
    sort(vec.rbegin(), vec.rend());
    if(vec.at(m-1) >= ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int R = nextInt();
		int G = nextInt();


		System.out.println(2*G-R);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

int main() {
    ll l;
    cin >> l;
    
    struct ftl {
        ll f, t, l;
    };
    vector<ftl> outs;
    auto put = [&](ll f, ll t, ll l) {
        outs.push_back(ftl{f, t, l});
    };
    
    ll k = 1;
    ll i = 0;
    for (; l >> (i + 1) > 0; i++) {
        put(i + 1, i + 2, 0);
        put(i + 1, i + 2, k);
        k *= 2;
    }
    for (auto j = 0; j < i; j++) {
        if (l >> j & 1) {
            put(j + 1, i + 1, k);
            k += (1ULL << j);
        }
    }
    cout << i + 1 << ' ' << outs.size() << endl;
    for (auto &o : outs)
        cout << o.f << ' ' << o.t << ' ' << o.l << endl;
    
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){

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

    if(b == 1){
        cout << 0 << endl;
    }else if(a >= b){
        cout << 1 << endl;
    }else{
        b = b - a;

        int ans;

        ans = (b + a - 2) / (a - 1) + 1;

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    string s;
    cin >> s;
    ll l = 0, r = s.size() - 1, ans = 0;
    while(l < r){
        if(s[l] == s[r]){
            l++;
            r--;
        }
        else if(s[l] == 'x'){
            ans++;
            l++;
        }
        else if(s[r] == 'x'){
            ans++;
            r--;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    int main(){
    int a, b, c, d, f;
    cin >> a >> b >> c >> d;
    int e = min(min(min(a, b), c), d);
    if(e == a){
        f = min(min(b, c), d);
    }
    else if(e == b){
        f = min(min(a, c), d);
    }
    else if(e == c){
        f = min(min(a, b), d);
    }
    else if(e == d){
        f = min(min(a, b), c);
    }
    int g = max(max(max(a, b), c), d), h;
    if(g == a){
        h = max(max(b, c), d);
    }
    else if(g == b){
        h = max(max(a, c), d);
    }
    else if(g == c){
        h = max(max(a, b), d);
    }
    else if(g == d){
        h = max(max(a, b), c);
    }
    if(e == 1 && f == 4 && h == 7 && g == 9){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    return 0;
    }


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

using namespace std;

int n;
const ll mod=1000000007;
ll a[10010];
ll cnt[1000020];
ll nzs;
ll sum=0;

ll mul(ll a, ll b)
{
    return (a*b)%mod;
}

ll step(ll a, int st)
{
    ll ret=1;
    while(st>0)
    {
        if(st%2==1)
            ret=mul(ret,a);
        a=mul(a,a);
        st/=2;
    }
    return ret;
}

ll add(ll a, ll b)
{
    ll ret=a+b;
    if(ret>=mod) ret-=mod;
    return ret;
}

ll div2(ll a, ll b)
{
    return mul(a,step(b,mod-2));
}

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

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

    for(int i=0;i<n;i++)
    {
        int tek=a[i];
        for(int j=2;j*j<=tek;j++)
        {
            ll br=0;
            while(tek%j==0)
                tek/=j, br++;
            cnt[j]=max(cnt[j],br);
        }
        cnt[tek]=max(cnt[tek],(ll)1);
    }

    nzs=1;
    for(int i=2;i<1000010;i++)
    {
        int tek=cnt[i];
        while(tek>0)
            nzs=mul(nzs,i), tek--;
    }
    //cout<<nzs;
    for(int i=0;i<n;i++)
        sum=add(sum,div2(nzs,a[i]));
    cout<<sum;
	return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
using namespace std;
using int64 = int_fast64_t;
#define int int64
constexpr int MAX_N = 202020;
constexpr int MOD = 1e9 + 7;

signed main() {
  string a,b,c;
  cin >> a >> b >> c;
  cout << (a.back() == b[0] && b.back() == c[0] ? "YES" : "NO") << endl;
  return 0;
}



Measured memory_bytes: 760
#include <iostream>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::sort;

int main()
{
    int n,sum=0;
    cin>>n;
    int a[n];
    for(int i=0;i!=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);
    sum-=a[n-1];

    if(a[n-1]<sum)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    return 0;
}

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


public class Main {

	public static void main(String[] a){

		int NumberOfColumn = 0;
		int NumberOfBar = 0;
		int[][] arr;
		int[] ans;
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		String tmpString;
		try {
			if(null != (tmpString = bf.readLine())){
				NumberOfColumn = Integer.parseInt(tmpString);
			}
			if(null != (tmpString = bf.readLine())){
				NumberOfBar = Integer.parseInt(tmpString);
			}
			arr = new int[NumberOfBar][2];
			for(int i = 0; i < NumberOfBar; i++){
				if(null != (tmpString = bf.readLine())){
					String[]  tmp = tmpString.split(",");
					arr[i][0] = Integer.parseInt(tmp[0]);
					arr[i][1] = Integer.parseInt(tmp[1]);
				}
			}

			ans = new int[NumberOfColumn];
			for(int i = 0; i < NumberOfColumn; i++){
				ans[i] = i + 1;
				for(int j = 0; j < NumberOfBar; j++){
					if(arr[j][0] == ans[i]){
						ans[i] = arr[j][1];
					} else if(arr[j][1] == ans[i]){
						ans[i] = arr[j][0];
					}
				}
			}
			for(int i = 0; i < NumberOfColumn; i++){
				for(int j = 0; j < NumberOfColumn; j++ ){
					if(ans[j] == i + 1){
						System.out.println(j + 1);
						break;
					}
				}
			}

		} catch (Exception e) {
			System.err.println("error");
		} finally {
			try {
				bf.close();
			} catch (IOException e) {
			}
		}

	}

}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int bubblesort(int a[],int n){
  int cnt = 0;
  bool flag = true;
  while(flag){
    flag = false;
    FORD(i,n-1,1){
      if(a[i]<a[i-1]){
        swap(a[i],a[i-1]);
        ++cnt;
        flag = true;
      }
    }
  }
  return cnt;
}

int main(){
  int n; cin >> n;
  int a[n];
  FOR(i,0,n-1) cin >> a[i];
  int cnt = bubblesort(a,n);
  FOR(i,0,n-1){
    if(i!=n-1) cout << a[i] << " ";
    else cout << a[i];
  }
  cout << endl;
  cout << cnt << endl;
}



Measured memory_bytes: 3100
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key, null, null, null);

    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key, null, null, null);
      while (x != null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      newNode.parent = y;
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  ineorder(n = this.root) {
    if (n === null) return;
    this.ineorder(n.left);
    process.stdout.write(` ${n.key}`);
    this.ineorder(n.right);
  }

  preorder(n = this.root) {
    if (n === null) return;
    process.stdout.write(` ${n.key}`);
    this.preorder(n.left);
    this.preorder(n.right);
  }

  print() {
    this.ineorder();
    console.log();
    this.preorder();
    console.log();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  const commands = lines.map((line) => line.split(' '));
  commands.forEach(function(cmd) {
    switch(cmd[0].charAt(0)) {
    case 'i': tree.insert(Number(cmd[1])); break;
    default: tree.print(); break;
    }
  });

})();



Measured memory_bytes: 370892
#include<bits/stdc++.h>
using namespace std;
string s;
long long ans,k1;
int main(){
cin>>s;
cin>>k1;
int i=0;
while (s[i]==s[0]) i++;
int k=s.size()-1;
while (s[k]==s[0]) k--;
if (k==-1){
	cout<<k1*s.size()/2<<endl;
	return 0;
}
for (int j=i;j<=k;) {
	int x=j;
	while (s[x]==s[j]) x++;
	ans+=(x-j)/2;
	j=x;
}
cout<<ans*k1+((s.size()-(k-i+1))/2)*(k1-1)+(s.size()-1-(k+1)+1)/2+(i-1-0+1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>L(2*N);
  for(int i=0;i<2*N;i++)
    cin>>L.at(i);
  sort(L.begin(),L.end());
  int ans=0;
  for(int i=0;i<N;i++)
    ans+=L.at(2*i);
  cout<<ans<<endl;
     return 0;
}

Measured memory_bytes: 256
def main():
    n, a, b = map(int, input().split())
    ans = 0
    for i in range(1, n+1):
        s = sum([int(j) for j in str(i)])
        if s >= a and s <= b:
           ans += i
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9112
ans=0
n,t=map(int,input().split())
food=[]
for i in range(n):
    f=list(map(int,input().split()))
    food.append(f)
food=sorted(food)
dp=[0,0]+[-1]*(t-1)

for a,b in food:
    tmp=[dp[i] for i in range(t)]
    for i in range(t):
        if dp[i]==-1: continue
        j=i+a
        if j<t: tmp[j]=max(tmp[j],dp[i]+b)
        else: ans=max(ans,dp[i]+b)
    
    dp=[tmp[i] for i in range(t)]
print(max(ans,max(dp)))

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

long long H, W;
long long UP[2005][2005];
long long LEFT[2005][2005];
long long RIGHT[2005][2005];
long long DOWN[2005][2005];
string S[2005];

int main(){
	cin >> H >> W;
	for(long long i = 0; i < H; i++){
		cin >> S[i];
	}

	for(long long i = 0; i < H; i++){
		long long cur = 0;
		for(long long j = 0; j < W; j++){
			if(S[i][j] == '.'){
				LEFT[i][j] = cur;
				cur++;
			}else{
				cur = 0;
			}
		}

		cur = 0;
		for(long long j = W-1; j >= 0; j--){
			if(S[i][j] == '.'){
				RIGHT[i][j] = cur;
				cur++;
			}else{
				cur = 0;
			}
		}
	}

	for(long long j = 0; j < W; j++){
		long long cur = 0;
		for(long long i = 0; i < H; i++){
			if(S[i][j] == '.'){
				UP[i][j] = cur;
				cur++;
			}else{
				cur = 0;
			}
		}

		cur = 0;
		for(long long i = H-1; i >= 0; i--){
			if(S[i][j] == '.'){
				DOWN[i][j] = cur;
				cur++;
			}else{
				cur = 0;
			}
		}
	}

	
	long long ans = 0;
	for(long long i = 0; i < H; i++){
		for(long long j = 0; j < W; j++){
			if(S[i][j] == '.'){
				ans = max(ans, LEFT[i][j] + RIGHT[i][j] + UP[i][j] + DOWN[i][j] + 1);
			}
		}
	}
	cout << ans << endl;
}


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


struct mint {
  ll x;
  mint(ll x=0) : x((x%MOD+MOD)%MOD) {}
  mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
};
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }


const int M = 60;
mint dp[M+1][2][2][2];


int main() {
  ll L, R; cin >> L >> R;
  dp[0][0][0][0] = 1;

  rep(i, M) {
    int Li = L>>(M-1-i)&1; // L の上から i 桁目
    int Ri = R>>(M-1-i)&1; // R の上から i 桁目
    rep(j, 2) rep(l, 2) rep(r, 2) rep(xi, 2) rep(yi, 2) {
      int j2 = j, l2 = l, r2 = r; // 遷移前の状態で初期化

      if (xi > yi) continue; // (xi, yi) = (1, 0) なら無視

      if (!j && (xi < yi)) continue; // (1, 1) が現れる前に (0, 1) が現れたら無視
      if (xi&yi) j2 = 1;             // (1, 1) が現れたら j2 を更新

      // 条件 x ≧ R  の処理
      if (!l && (xi < Li)) continue;
      if (xi > Li) l2 = 1;

      // 条件 y ≦ R の処理
      if (!r && (yi > Ri)) continue;
      if (yi < Ri) r2 = 1;

      dp[i+1][j2][l2][r2] += dp[i][j][l][r]; // 遷移式
    }
  }

  mint ans = 0;
  rep(l, 2) rep(r, 2) ans += dp[M][1][l][r];
  cout << ans << '\n';
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

#define fs first
#define sc second
#define MAX 1000000001

int n,m;
int sum[5100][5100];
pair<int,int> p[5100];
vector<int> x,y;
int x1,y1,x2,y2;

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> p[i].fs >> p[i].sc;
    x.push_back(p[i].fs); y.push_back(p[i].sc);
  }

  x.push_back(MAX); x.push_back(-MAX); 
  y.push_back(MAX); y.push_back(-MAX);
  sort(x.begin(),x.end()); sort(y.begin(),y.end());
  x.erase(unique(x.begin(),x.end()),x.end());
  y.erase(unique(y.begin(),y.end()),y.end());

  for(int i=0;i<n;i++){
    p[i].fs = lower_bound(x.begin(),x.end(),p[i].fs) - x.begin();
    p[i].sc = lower_bound(y.begin(),y.end(),p[i].sc) - y.begin();
  }
  sort(p,p+n);

  int cnt = 0;
  for(int i=0;i<x.size();i++){
    for(int j=0;j<y.size();j++){
      if(!i || !j)sum[i][j] = 0;
      else sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1];
      while(cnt<n && p[cnt].fs == i && p[cnt].sc == j){
	sum[i][j]++;
	cnt++;
      }
    }
  }

  for(int i=0;i<m;i++){
    cin >> x1 >> y1 >> x2 >> y2;
    x1 = lower_bound(x.begin(),x.end(),x1)-x.begin()-1;
    y1 = lower_bound(y.begin(),y.end(),y1)-y.begin()-1;
    x2 = upper_bound(x.begin(),x.end(),x2)-x.begin()-1;
    y2 = upper_bound(y.begin(),y.end(),y2)-y.begin()-1;
    cout << sum[x2][y2] - sum[x2][y1] - sum[x1][y2] + sum[x1][y1] << endl;
  }
}

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

int main(){
	long int x;
  	cin>>x;
  
  	long int hpy=0;
  	hpy+=(x/500)*1000;
  	x=x%500;
  	
  	hpy+=(x/5)*5;
  
  	cout<<hpy<<endl;
  
  	return 0;
}

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

int main(){
  int tall[10],no1=0,no2=0,no3=0,i;
  for(i=0;i<=9;i++){
    cin>>tall[i];
  }
  for(i=0;i<=9;i++){
    if(tall[i]>=no1){
      no3=no2;
      no2=no1;
      no1=tall[i];
    }
    if(tall[i]>=no2&&tall[i]<no1){
      no3=no2;
      no2=tall[i];
    }
    if(tall[i]>=no3&&tall[i]<no2){
      no3=tall[i];
    }
  }
  cout<<no1<<endl<<no2<<endl<<no3<<endl;

  return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

vector<int> K;
int D,N;
vector<vector<long long>> DP[2];   //確定未確定・桁・あまり

int main() {
	string S;
	cin >> S >> D;
	N = S.size();
	K.resize(N);
	for (int n = 0; n < N; n++)K[n] = S[n] - '0';
	DP[0].resize(N, vector<long long>(D, 0));
	DP[1].resize(N, vector<long long>(D, 0));
	for (int k = 0; k < K[0]; k++)DP[0][0][k % D]++;
	DP[1][0][K[0] % D]++;
	for (int n = 1; n < N; n++) {
		for (int d = 0; d < D; d++) {
			for (int k = 0; k < 10; k++) {
				DP[0][n][(d + k)%D] += DP[0][n - 1][d];
				DP[0][n][(d + k)%D] %= MOD;
			}
			for (int k = 0; k < K[n]; k++) {
				DP[0][n][(d + k)%D] += DP[1][n - 1][d];
				DP[0][n][(d + k)%D] %= MOD;
			}
			DP[1][n][(d + K[n]) % D] += DP[1][n - 1][d];
			DP[1][n][(d + K[n]) % D] %= MOD;
		}
	}
	cout << (DP[0][N - 1][0] + DP[1][N - 1][0]+MOD-1) % MOD << endl;
	return 0;
}

Measured memory_bytes: 16768
import sys
from collections import deque, Counter, defaultdict
from itertools import accumulate  # 累積和
from bisect import bisect_left, bisect
from heapq import heappop, heappush  # 優先度付きキュー
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

h, w = map(int, input().split())
rows = []
not_skip = defaultdict(bool)
for i in range(h):
    row = input()
    if "#" in row:
        rows.append(row)
        for i in range(w):
            if row[i] == "#":
                not_skip[i] = True

for row in rows:
    for i in range(w):
        if not_skip[i]:
            print(row[i], end="")
    print()


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

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

    if (r >= l + 2019) {
        r = l + 2018;
    }

    l %= 2019;
    r %= 2019;

    if (l >= r) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 2018 * 2018;
    for (int i = l; i <= r - 1; i++) {
        for (int j = i + 1; j <= r; j++) {
            ans = min(ans, ((i * j) % 2019));
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int64_t N, ans, L1, L0;
  cin >> N;
  
  L1=1;
  L0=2;
  ans=1;
  
  for(int i=2; i<=N; i++){
    ans = L1 + L0;
    L0=L1; L1=ans;
  }
  
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  
  for(int i = 0;i<N+1;i++){
    int ketasuu = 0;
    int I = i;
    while(I > 0){
      I = I / 10;
      ketasuu++;
    }
    if(ketasuu  % 2 != 0) ans++;
    //cout << i << ":" << ans << endl;
  }
  
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXSIZE = 200002;
int a[MAXSIZE];
bool cmp(int x,int y)
{
	return x > y;
}
int main()
{
	long long int a = 1,sum = 1,h,t=0;
	scanf("%lld",&h);
	while(h > 1)
	{
		h /= 2;
		t++;
	}
	for(int i = 0;i < t;i++)
	{
		a *= 2;
		sum += a;
	}
	printf("%lld\n",sum);
	return 0; 
}

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

int main() {
	int w, a, b;
    cin >> w >> a >> b;

    if (a + w < b){
        cout << b - (a + w) << endl;
    }
    else if (b + w < a){
        cout << a - (b + w) << endl;
    }
    else{
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
N,M = map(int,input().split())
x = []
y = []
for i in range(M):
    x_i,y_i = map(int,input().split())
    x.append(x_i)
    y.append(y_i)

box_c = [1 for i in range(N+1)]
box_r = [0 for i in range(N+1)]
box_r[1] = 1


for i in range(M):
    box_c[x[i]] -= 1
    box_c[y[i]] += 1
    
    if box_r[x[i]]==1:
        box_r[y[i]] = 1
        if box_c[x[i]]==0:
            box_r[x[i]] = 0
   
print(box_r.count(1))

Measured memory_bytes: 12540
def main():
    N, L, T = map(int, input().split())
    collision = 0
    ants = []
    for i in range(N):
        x, w = map(int, input().split())
        if w == 1:
            collision += (x + T) // L
            a = (x + T) % L
        else:
            collision += (x - T) // L
            a = (x - T) % L
        ants.append(a)
 
    collision %= N
    ants.sort()
    ants = ants[collision:] + ants[:collision]
    for ant in ants:
        print(ant)
 
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 8604
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    S = list(_ for _ in input())
    x = 0
    max_x = 0
    for s in S:        
        if s == 'I':
            x += 1
        elif s == 'D':
            x += -1
        max_x = max(x,max_x)
    print(max_x)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int i, a, b, c, height[12];

    for(i=1; i<=10; i++)
        cin>>height[i];

    sort(height+1, height+11);

    for(i=10; i>=8; i--)
        cout<<height[i]<<endl;

    return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
 
 
int main(){
   ll N;
	cin >> N;
	vector<ll> b(N);
	for(auto& bi :b)
		cin >> bi;
	vector<ll> ans;
 
	for (int i = N; i >= 1; i--)
	{
		ll pc = 0;
 
		pair<ll, ll> m(0, -1);
		for (int j = 0; j < N; j++)
		{
			if (b[j] > 0 && pc + 1 == b[j] && m.first < b[j])
			{
				m.first = max(b[j], m.first);
				m.second = j;
			}
			if (j == N-1 && m.first > 0)
			{
				ans.push_back(m.first);
				b[m.second] = 0;
			}
			if (b[j] > 0) pc++;
		}
	}
 
	if (ans.size() != N)
	{
			cout << -1 << endl;
	}
	else
	{
    for (int i = N - 1; i >= 0; i--)
		{
			if(i == N - 1)
				cout << ans[i];
			else
				cout << " " << ans[i];
		}
		cout << endl;
	
	}
 
	return 0;
}

Measured memory_bytes: 256
L=int(input());S=bin(L);N=len(S)-2;print(N,2*N+S.count("1")-3)
for i in range(N-1):
 for j in[0,1]:print(i+1,i+2,j*2**i)
 if S[N+1-i]=="1":L^=2**i;print(i+1,N,L)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;


int main(){
    double r; cin >> r;
    double pi = 3.141592;
    double ans = 2* r * pi;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3788
//AtCoder ABC123 C - Five Transportations
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N; cin>>N;
    vector<ll> tbl(5);
    ll mint=INT64_MAX;
    for(auto&& t:tbl){
        cin>>t;
        mint=min(t,mint);
    }
    ll ans=4+((N+mint-1)/mint);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
class in_t{public:
	int a;in_t(){cin>>a;}
	operator int() {return a;}
};
class lin_t{public:
	llint a;lin_t(){cin>>a;}
	operator llint() {return a;}
};
class ld_t{public:
	long double a;ld_t(){cin>>a;}
	operator long double() {return a;}
};
int main(void){
	llint n,a,b,bef;cin>>n>>a>>b>>bef;
	llint i,j,now;
	llint ans=0;
	for(i=1;i<n;i++){cin>>now;ans+=min(a*(now-bef),b);bef=now;}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

float f(int t, int vs, int ve, int vmax)
{
	float ret = 0.0;
	int v = vs;
	For(i, 1, t + 1){
		int vv;
		vv = min(vs + i, ve + t - i);
		vv = min(vv, vmax);
		ret += float(vv + v) / 2.0;
		if(vv == v && v < vmax) ret += 0.25;
		v = vv;
	}
	return ret;
}

int main(void)
{
	int N;
	int t[101];
	int T[101];
	int v[101];
	int vs[101];
	int ve[101];

	cin >> N;
	Rep(i, N) cin >> t[i];
	Rep(i, N) cin >> v[i];
	t[N] = 0;
	v[N] = 0;

	T[0] = 0;
	Rep(i, N) T[i + 1] = T[i] + t[i];

#if 0
	Rep(i, N + 1){
		cout << T[i] << endl;
	}
	cout << "----" << endl;
#endif
	vs[0] = 0;
	Rep(i, N){
		ve[i] = vs[i] + t[i];
		ve[i] = min(ve[i], v[i]);
		For(j, i + 1, N + 1){
			int vv = v[j] + T[j] - T[i + 1];
			ve[i] = min(ve[i], vv);
		}
		//cout << ve[i] << endl;
		vs[i + 1] = ve[i];
	}

	float ans = 0;
	Rep(i, N){
		ans += f(t[i], vs[i], ve[i], v[i]);
	}

	printf("%.15lf\n", ans);
	return 0;
}


Measured memory_bytes: 256