akhauriyash/Code-Regression huggingface dataset:
Q = int(input())
que = []
for q in range(Q): que.append([int(i) for i in input().split()])

def Eratosthenes(n):
    li = [i for i in range(2,n+1)]
    judge = [True for i in range(n+1)]
    ans = []

    for i in range(2,n+1):
        if judge[i] == True:
            for j in range(i*2,n+1,i):
                judge[j] = False
            ans.append(i)
    judge[0],judge[1] = False,False
    return judge

judge = Eratosthenes(10**5)
tmp,ans = 0,[]
for i in range(10**5+1):
    if judge[i] == True and judge[int((i+1)/2)] == True: tmp+=1
    ans.append(tmp)

for q in que:
    l,r = q
    if l == r and judge[l]==True and judge[int((l+1)/2)] == True: print(1)
    else:
        tmp = ans[r]-ans[l]
        if (judge[l]==True and judge[int((l+1)/2)]==True) or (judge[r]==True and judge[int((r+1)/2)==True]):
            tmp += 1
        print(tmp)
    #print(ans[r],ans[l])


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

int main(){
  string S;
  cin >> S;
  int cou0 = 0, cou1 = 0;
  for(int i=0;i<S.size();i++){
    if(S[i] == '0') cou0++;
    else cou1++;
  }
  cout << 2 * min(cou0, cou1) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	int l1=s1.length();
	int l2=s2.length();
	sort(s1.begin(),s1.end());
	sort(s2.begin(),s2.end());
	reverse(s2.begin(),s2.end());
	if(s1<s2) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

#define ff first
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
inline void fastio(){ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);}

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



int main(){
	fastio();

	ll n,k; cin>>n>>k;
	ll ans=0;
	ll h[n]; f(i,0,n-1) {cin>>h[i];
	if(h[i]>=k) ans++;}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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


  int t=1;
//  cin>>t;
  int tt=1;
  while(t--){
     ll n,k,s;
     cin>>n>>k>>s;
     int i=0;
     for(;i<k;i++)
     cout<<s<<" ";
   int value=1e9;
     for(;i<n;i++)
     {
      if(s==1e9)
        cout<<1<<" ";
      else
        cout<<value<<" ";
     } 
   // cout<<"Case #"<<tt<<": ";
   // tt++;
    }
  return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;
 
#define FOR(i,a,b) for(LL i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
 
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 705;

int A[MAX];
int main()
{
	//freopen("In.txt", "r", stdin);
	int n;
	cin >> n;
	FOR(i, 0, n)cin >> A[i];
	A[n] = INF;
	int cnt = 0;
	int cur = INF;
	int ans = 0;
	FOR(i, 0, n+1) {
		if (A[i] != cur) {
			ans += cnt / 2;
			cur = A[i];
			cnt = 0;
		}
		cnt++;
	}
	cout << ans << endl;
	return 0;
}



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

const int MOD = (int)1e9+7;

int main(){
	int N,W;
	cin >> N >> W;
	vector<long long> w(N),v(N);
	for(int i=0;i<N;i++)	cin >> w.at(i) >> v.at(i);

	vector<vector<long long>> dp(N+1,vector<long long>(100001,1e14));
	dp.at(0).at(0)=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<100001;j++){
			dp.at(i+1).at(j)=dp.at(i).at(j);
			if(j-v.at(i)<0)	continue;
			dp.at(i+1).at(j)=min(dp.at(i+1).at(j),dp.at(i).at(j-v.at(i))+w.at(i));
		}
	}
	long long ans=0;
	for(int i=100000;i>=0;i--){
		if(dp.at(N).at(i)<=W){
			ans=i;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}


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

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

Measured memory_bytes: 256
n=int(input())
i=1
L=[]
while i<=n:
    x=i
    if x%3==0:
        L.append(x)
    else:
        while x>0:
            if x%10==3:
                L.append(i)
                break
            x=int(x/10)
    i+=1
l=len(L)

for i in range(l):
    if i!=l-1:
        print(' {}'.format(L[i]),end='')
    else:
        print(' {}'.format(L[i]))



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


int main()
{
	double X, Y, Z;
	cin >> X >> Y >> Z;
	int c = 0;
	int t = X;
	while (true)
	{
		if (c == 0)
		{
			if (t >= Y + Z * 2)
			{
				c++;
				t -= Y + Z * 2;
			}
			else break;
		}
		else
		{
			if (t >= Y + Z)
			{
				c++;
				t -= Y + Z;
			}
			else break;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
constexpr auto oorret = 0;
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

vector<int> u;
vector<int> v;
vector<int> w;
vector<vector<P>> p;
vector<int> res;

void dfs(int a,int color=0) {
	res[a] = color;
	REP(i, p[a].size()) {
		P t = p[a][i];
		if (res[t.first] == -1) {
			//res[p[a][i]] = 1 - color;
			if (t.second % 2 == 0) {
				dfs(t.first, color);
			}
			else {
				dfs(t.first, 1 - color);
			}
			
		}
	}
}

int main() {
	int n;
	cin >> n;
	u.resize(n-1);
	v.resize(n-1);
	w.resize(n-1);
	p.resize(n);
	REP(i, n-1) {
		cin >> u[i] >> v[i] >> w[i];
		u[i]--;
		v[i]--;
		p[u[i]].push_back(P(v[i],w[i]));
		p[v[i]].push_back(P(u[i],w[i]));

	}
	res.resize(n, -1);
	dfs(0);

	REP(i, n) {
		put(res[i]);
	}
	return 0;
}

Measured memory_bytes: 9344
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
maxK = (N-1)*(N-2)//2
dK = maxK - K
if dK < 0:
    print(-1)
    exit()
M = (N-1) + dK
print(M)
for i in range(2,N+1):
    print(1, i)
n = 0
for i in range(2,N+1):
    for j in range(i+1,N+1):
        if n >= dK:
            break
        else:
            n += 1
            print(i,j)

Measured memory_bytes: 44656
#include <stdio.h>

int main(void)
{
	int i;
	int c[3];
	int m;
	int ans;
	
	while (scanf("%d %d %d", &c[0], &c[1], &c[2]) != EOF){
		m = 20 - c[0] - c[1];
		ans = m;
		
		for (i = 0; i < 3; i++){
			if (c[i] <= m){
				ans--;
			}
		}
		
		if (ans > 3){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	return (0);
}

Measured memory_bytes: 1008
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var q = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < q; i++)
        {
            var k = int.Parse(Console.ReadLine().Trim());
            var Lb = LowerBound(a, k);
            var ub = UpperBound(a, k);
            Console.WriteLine("{0} {1}", Lb, ub);
        }
    }
    public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int UpperBound<T>(T[] arr, T value) => UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    static int LowerBound<T>(T[] arr, T value) where T : IComparable => LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}




Measured memory_bytes: 33216
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	ll ans= (n/500)*1000 + ((n%500)/5)*5;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  n= 1
  while RA[eatRA - n] == GA[eatGA -n] and n != min(eatRA,eatGA):
    n += 1
  if RA[eatRA - n] > GA[eatGA - n]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C or eatRA == 0 or eatGA == 0:
    break
if eatRA == 0 and eatGA != 0 and eatWA != C:
  while GA[eatGA -1] < WA[eatWA]:
    eatGA -= 1
    eatWA += 1
    if eatWA == C or eatGA == 0:
      break
elif eatRA != 0 and eatGA == 0 and eatWA != C:
  while RA[eatRA -1] < WA[eatWA]:
    eatRA -= 1
    eatWA += 1
    if eatWA == C or eatRA == 0:
      break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[i]
print(ans)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int const INF=1000000000;
ll DP[101][1001];//i回まで見て価値wを持つ最小の重さ
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin>>A>>B;
    if(A<=5){cout<<0<<endl;}
    else if(A<=12){cout<<B/2<<endl;}
    else{cout<<B<<endl;}
}

Measured memory_bytes: 892
import java.util.Scanner;

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

            int count = 0;
            for (int l = 0, r = S.length() - 1; l < r; l++, r--) {
                if (S.charAt(l) != S.charAt(r)) {
                    count++;
                }
            }

            System.out.println(count);
        }
    }
}


Measured memory_bytes: 26904
D, G = map(int,input().split())
pc = [list(map(int,input().split())) for _ in range(D)]

ans = 10**9+7
#for i in range(2**D):
for i in range(1 << D):
  point = 0
  count = 0
  tmp = []
  #for ind, b in enumerate(format(i, 'b').zfill(D)):
    ##print(ind,b,i)
    #if(b == '1'):
  for j in range(D):
    if(((i >> j) & 1) == 1):
      point += pc[j][0] * 100 * (j + 1) + pc[j][1]
      count += pc[j][0]
    else:
      tmp.append(j)
  if(point < G):
    R = G - point
    k = tmp[-1]
    if((pc[k][0] - 1) * (k + 1) * 100 < R):
      continue
    count += -(-R // (100 * (k + 1)))
  ans = min(ans, count)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main( void ) {
    string input;
    cin >> input;

    int d[4] = {0};
    for ( string ::iterator it = input.begin(); it != input.end(); it++ ) {
        if ( *it == 'K' ) d[0]++;
        else if ( *it == 'U' ) d[1]++;
        else if ( *it == 'P' ) d[2]++;
        else if ( *it == 'C' ) d[3]++;
    }

    int answer = *min_element( d, d+4 );
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

bool isPal(string s)
{
    ll i;
    ll n = s.length();
    for(i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        {
            return 0;
        }
    }
    return 1;
}


int main()
{
    string s;
    cin>>s;
    string str=".";
    str+=s;
    ll n =str.length(),i;

    if(n==2)
    {
        cout<<"No"<<endl;
        exit(0);
    }

    string a="", b="";
    ll x = (n-1)/2;
    ll y = (n+3)/2;

    for(i=1;i<=x;i++)
    {
        a+=str[i];
    }
    for(i=y;i<n;i++)
    {
        b+=str[i];
    }
    //cout<<a<<" "<<b<<endl;
    if(isPal(a) && isPal(b) && isPal(s))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<18;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	string f[] = {"dream", "dreamer", "erase", "eraser"}, s;
	cin >> s;
	vector<int> dp(s.size()+1);
	dp[0] = 1;
	for(int i = 0; i < s.size(); i++) {
		for(int j = 0; j < 4; j++) {
			if(i + f[j].size() <= s.size() && s.substr(i, f[j].size()) == f[j]) dp[i+f[j].size()]|=dp[i];
		}
	}
	cout << (dp.back()?"YES":"NO");
}


Measured memory_bytes: 848
S = input()

S1 = int(S[:2])
S2 = int(S[2:4])

if 1 <= S1 <= 12 and 1 <= S2 <= 12:
	print("AMBIGUOUS")
elif 1 <= S1 <=12 and ( S2 == 0 or S2 > 12):
	print("MMYY")
elif 1 <= S2 <=12 and ( S1 == 0 or S1 > 12):
	print("YYMM")
else:print("NA")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define pu(n) cout << n; 
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
//#define MAX_N 10e2
//#define INF 10e4
int a[100],i;
int main(void){
	int N;
		cin >> N;
	int ans=10000;
	rep(i,0,N){
		int b;
		cin >> b;
		a[i+1]=a[i]+b;
	}
	rep(i,1,N+1)
		ans=min(ans,abs(a[N]-a[i]*2)   );
	puts(ans);
	return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y = map(int, input().split(' '))

# print(A,B,C,X,Y)

# A, Bだけでいく
case1 = A * X + B * Y

# AをABでつくってBがたりなかったらうめる
case2 = 2*C * X + B * max(Y - X, 0)

# BをABでつくってBがたりなかったらうめる
case3 = 2*C * Y + A * max(X - Y, 0)

# 全部AB
case4 = 2*C * max(X, Y)

# print(case1, case2, case3, case4)
print(min(case1, case2, case3, case4))

Measured memory_bytes: 9092
<?php
  $n = trim(fgets(STDIN));
$ans=0;
  for($a = 1;$a<$n;$a++){
    for($b=1;$b*$a<$n;$b++){
      if($n-$a*$b>0){
      $ans++;
      }
      
    }
  
  }
echo $ans;

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

using namespace std;

int n, k;
vector <int> g[100001];
int cur;
int mx = 0;
int ans = 1e9;
int asd = 0;

void dfs (int v, int pr, int lvl) {
	if (lvl > k / 2) cur ++;
	for (auto to : g[v]) {
		if (to == pr) continue;
		dfs (to, v, lvl + 1);
	}
}

void calc (int v, int pr, int lvl) {
	if (lvl == k / 2 + 1 && k % 2) asd ++;
	for (auto to : g[v]) {
		if (to == pr) continue;
		calc (to, v, lvl + 1);
	}
}

int main () {
	cin >> n >> k;
	for (int i = 1;i < n;i ++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back (y);
		g[y].push_back (x);
	}
	for (int i = 1;i <= n;i ++) {
		cur = 0;
		mx = 0;           	
		dfs (i, 0, 0);
		for (auto to : g[i]) {
			asd = 0;
			calc (to, i, 1);
			mx = max (mx, asd);
		}
		ans = min (ans, cur - mx);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
const int maxn=2e5+5;
const int mod=1e9+7;
#define ll long long
using namespace std;
int s[maxn];
int main(){
    ll a,b;
    ios::sync_with_stdio(false);
    cin>>a>>b;
    if(abs(a-b)==1||a==b){
        cout<<"Brown"<<endl;
    }
    else cout<<"Alice"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

const int MOD = 1000000007;

using namespace std;

int main(){

    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a>=3200){
        cout << s << endl; 
    }else{
        cout << "red" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

vector<string> board(70);
string memo[70][70];
int W, H;

inline bool isDigit(int x, int y)
{
    if ('0' <= board[y][x] && board[y][x] <= '9')
        return true;
    else
        return false;
}

string Rec(int x, int y)
{
    if (memo[y][x].size() != 0)
        return memo[y][x];

    string s, tmp;
    for (int d = 0; d < 2; ++d) {
        int nx = x + dx[d];
        int ny = y + dy[d];

        if (nx < 0 || nx >= W || ny < 0 || ny >= H || !isDigit(nx, ny))
            continue;

        tmp = Rec(nx, ny);
        if (tmp.size() > s.size() || (tmp.size() == s.size() && tmp > s))
            s = tmp;
    }

    return memo[y][x] = board[y][x] + s;
}

int main()
{
    while (cin >> W >> H, W || H) {
        // Input
        for (int i = 0; i < H; ++i) {
            cin >> board[i];
            for (int j = 0; j < W; ++j)
                memo[i][j] = "";
        }

        // Solve
        string tmp, ans;
        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                if (isDigit(j, i) && memo[i][j].size() == 0 && board[i][j] != '0') {
                    tmp = Rec(j, i);

                    if (tmp.size() > ans.size() || (tmp.size() == ans.size() && tmp > ans))
                        ans = tmp;
                }

        // Output
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1384
'use strict'

const main = (input) => {
    input = input.split(' ').map(i => parseInt(i))
    const A = input[0]
    const B = input[1]
    const C = input[2]
    const D = input[3]
    if(A + B === C + D){
        console.log('Balanced')
    }else if(A + B > C + D){
        console.log('Left')
    }else{
        console.log('Right')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  cout << max(0, A - 2 * B) << '\n';
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include <functional>
#include<algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int W,H;
char a[30][30];
void se(int x,int y,int (*re)[30],int *u){
	
	if(x<0||W<=x||y<0||H<=y||a[y][x]=='#')
		return;
	if(re[y][x]==1)
		return;
	
	re[y][x]=1;
		*u+=1;
	
	se(x+1,y,re,u);
	se(x-1,y,re,u);
	se(x,y+1,re,u);
	se(x,y-1,re,u);
}

int main(){
	int x,y;
	int x1,y1;
	while(cin>>W>>H){
		if(W!=0&&H!=0){
			int re[30][30]={0};
			int u=0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
			cin>>a[i][j];
				if(a[i][j]=='@'){
				x1=j;
				y1=i;}
			}
		}
			se(x1,y1,re,&u);
				cout<<u<<endl;
		}
		else
			break;
	}

	
}

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

#define ll long long
int main() {
  int N;
  cin >> N;
  set<string> setM, setA, setR, setC, setH;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S[0] == 'M') {
      setM.insert(S);
    } else if (S[0] == 'A'){
      setA.insert(S);
    } else if (S[0] == 'R') {
      setR.insert(S);
    } else if (S[0] == 'C') {
      setC.insert(S);
    } else if (S[0] == 'H') {
      setH.insert(S);
    }
  }
  
  vector<ll> num(5,0);
  num[0] = setM.size();
  num[1] = setA.size();
  num[2] = setR.size();
  num[3] = setC.size();
  num[4] = setH.size();

  
  ll ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i+1; j < 5; j++) {
      for (int k = j+1; k < 5; k++) {
        ans += num[i] * num[j] * num[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    map<int, pair<int, int>> stone;
    {
        vector<int> a(N);
        cin >> a;
        for (int i = 0; i < N; i++) stone[a[i]] = {-1, 0};
        for (int i = 0; i < N; i++) {
            if (stone[a[i]].first == -1) stone[a[i]].first = i + 1;
            stone[a[i]].second++;
        }
    }
    stone[0] = {N + 1, 0};
    vector<int> ans(N + 1, 0);
    for (auto itr = stone.rbegin(); next(itr, 1) != stone.rend(); itr++) {
        auto to = next(itr, 1);
        int count = (itr->first - to->first) * itr->second.second;
        ans[itr->second.first] += count;
        to->second.first = min(itr->second.first, to->second.first);
        to->second.second += itr->second.second;
    }
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }
}

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

a = int(input())
print(a+a**2+a**3)

Measured memory_bytes: 65364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)
int main(){
    int n; cin>>n;
    vector<vector<pair<int,int>>> g(n,vector<pair<int,int>>());
    for(int i=0;i<n-1;i++){
        int u,v,w; cin>>u>>v>>w;
        g[u-1].push_back({v-1, w%2});
        g[v-1].push_back({u-1, w%2});
    }

    int nvisited = 0;
    bool visited[n]={};
    queue<int> q;
    q.push(0);
    vector<int> ans(n,0);
    while(nvisited != n){
        int u = q.front();
        bool isodd = ans[u];
        q.pop();
        nvisited++;
        visited[u] = true;
        for(auto p: g[u]){
            int i = p.first;
            if(visited[i]) continue;
            bool isodd2 = p.second;
            ans[i] = isodd^isodd2;
            q.push(i);
        }
    }
    
    for(auto a:ans){
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 6912
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int main() {
  char c;
  cin >> c;
  cout << static_cast<char>(c + 1) << endl; 
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> ar(n , 0);
    for(int i =0; i< n; i ++)
    {
        int temp = 0;
        cin>>temp;
        ar[temp-1] = i+1;
    }
    for(auto i: ar)
        cout<<i<<" ";

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t


int main(void){
    
    int N;
    cin >> N;
    vector<int> p;
    for(int i = 0 ;i < N ; i++ ){
        int temp;
        cin >> temp;
        temp--;
        p.push_back(temp);
    }
    
    int a[N];
    int b[N];
    for(int i = 0 ; i < N ; i++ ){
        a[i] = 0;
        b[i] = 0;
    }
    
    for(int i = 0 ; i < N ; i++ ){
        a[i] = 30000*(i+1);
        b[i] = 30000*(N-i);
    }
    for(int i = 0 ; i < N ; i++ ){
        b[p[i]] += i+1;
    }
    
    for(int i = 0 ; i < N - 1; i++ ){
        cout << a[i] << " ";
    }
    cout << a[N-1] << endl;
    for(int i = 0 ; i < N - 1; i++ ){
        cout << b[i] << " ";
    }
    cout << b[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1152
d=[1]+[0]*12
for c in input():
 p=[0]*13
 for j in range(13):
  for k in range(10):t=(j*10+k)%13;p[t]+=d[j]*(c>'9'or k==int(c));p[t]%=10**9+7
 d=p
print(d[5])

Measured memory_bytes: 42732
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    vector<int> L;
    cin >> N;
    int tmp;
    rep(i, N){
        cin >> tmp;
//        cout << L[i] << endl;
        L.push_back(tmp);
    }


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

    ll ans = 0;
    rep(i, N){
        REP(j,i+1, N-1){
            auto Iter1 = lower_bound(L.begin() + j+1, L.end(), L[i]+L[j]);
           // cout << *(Iter1-1) << " " << L[i] << " " << L[j] << endl;
            if ((int)(Iter1 - 1 - L.begin()) <= j) {
                continue;
            }
            if (*(Iter1-1) < L[i] || *(Iter1-1) < L[j]){
                continue;
            }
            int index1 = Iter1-1 - L.begin() - j;
            ans += index1;

        }


    }

    cout <<  ans << endl;

}

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

int main()
{
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    for (int i = 0; i < M; i++)
    {
        cin >> B.at(i);
    }
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            cin >> A.at(i).at(j);
        }
    }

    int res = 0;
    for (int i = 0; i < N; i++)
    {
        int sum = 0;
        for (int j = 0; j < M; j++)
        {
            sum += A.at(i).at(j) * B[j];
        }
        if (sum + C > 0)
        {
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

int main()
{
    int n, k;
    std::cin >> n >> k;

    std::vector<int> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    long long ans = 0;
    for (int num_pop = 0; num_pop <= k; num_pop++) {
        for (int pop_from_right = 0; pop_from_right <= num_pop; pop_from_right++) {
            std::priority_queue<int, std::vector<int>, std::greater<int>> q;
            std::vector<int> copied_v = v;
            for (int i = 0; i < pop_from_right && copied_v.size(); i++) {
                q.push(copied_v.back());
                copied_v.pop_back();
            }
            std::reverse(copied_v.begin(), copied_v.end());

            for (int i = 0; i < num_pop - pop_from_right && copied_v.size(); i++) {
                q.push(copied_v.back());
                copied_v.pop_back();
            }

            for (int i = 0; i < k - num_pop && q.size() && q.top() < 0; i++) {
                q.pop();
            }

            long long sum = 0;
            while (q.size()) {
                sum += q.top();
                q.pop();
            }

            ans = std::max(ans, sum);
        }
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def solve():
    INF = 10**10

    N, M = map(int, input().split())
    keys = []
    costs = []
    for _ in range(M):
        a, b = map(int, input().split())
        costs.append(a)
        cs = list(map(int, input().split()))
        key = 0
        for c in cs:
            key |= 1<<(c-1)
        keys.append(key)

    dp = [INF] * (1<<N)
    dp[0] = 0
    for key, cost in zip(keys, costs):
        for S in reversed(range(1<<N)):
            S2 = S | key
            c2 = dp[S] + cost
            if c2 < dp[S2]:
                dp[S2] = c2

    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


solve()


Measured memory_bytes: 3188
import java.util.*;
 
public class Main{
  	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = Integer.parseInt(sc.next());
      	int b = Integer.parseInt(sc.next());
      	int c = Integer.parseInt(sc.next());
      	int k = Integer.parseInt(sc.next());
      	for(int cnt = 0;cnt < k;cnt++){
         	if(a >= b){
            	b *= 2;
            }else if(b >= c){
            	c *= 2;
            }
        }
      	if(a < b && b < c){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 35548
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int N, K;
    scanf("%d %d", &N, &K);

    int *p;
    p = (int*)malloc((sizeof(int))*N);

    for(int i=0; i<N; i++){
        scanf("%d", &(*(p+i)));
    }

    int min, tmp, sum;
    sum = 0;
    for(int i=0; i<K; i++){
        min = *(p+i);
        for(int j=i+1; j<N; j++){
            if(*(p+j) < min){
                tmp = min;
                min = *(p+j);
                *(p+j) = tmp;
            }
        }
        sum += min;
    }

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

    free(p);
    return 0;
}

Measured memory_bytes: 1736
import java.util.*;
import java.io.*;
class Main
{
  public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] s = br.readLine().split("\\s");
    	int n = Integer.parseInt(s[0]);
    	int k = Integer.parseInt(s[1]);
		String[] ss = br.readLine().split("\\s");
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	}
      	int t1=0;
      	if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	}
      	int[] dp = new int[n];
      	Arrays.fill(dp, Integer.MAX_VALUE);
      	dp[0] = 0;
      	for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	}
      	System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 34604
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<bool>> k(M,vector<bool>(N,false));
  for(int i=0; i<M; i++){
    int K;
    cin >> K;
    for(int j=0; j<K; j++){
      int s;
      cin >> s;
      s--;
      k[i][s] = true;
    }
  }
  vector<int> q(M);
  for(int i=0; i<M; i++){
    cin >> q[i];
  }
  int sum=0;
  for(int bit=0; bit<(1<<N); bit++){
    bool can=true;
    vector<int> count(M,0);
    for(int j=0; j<M; j++){
      for(int i=0; i<N; i++){
        if(bit&(1<<i) && k[j][i]){
          count[j]++;
        }
      }
    }
    for(int i=0; i<M; i++){
      if(count[i]%2 != q[i]){
        can = false;
      }
    }
    if(can){
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#define r(i,n) for(int i=0;i<n;i++)
#define debug(x) cerr << #x << ": " << x << endl;
using namespace std;

int main(){
  string s1,s2;
  cin >> s1 >> s2;

  r(i,s1.length()){
    if(s1==s2){
      cout << "Yes" << endl;
      return 0;
    }
    s1.insert(s1.begin(),s1[s1.length()-1]);
    s1.pop_back();
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = S_LIST()
if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 5144
#include <stdio.h>
//105,135,165,189,195
int main(){
  int k,n;
  scanf("%d",&n);

  if(n<105) printf("0");
  else if(n<135) printf("1");
  else if(n<165) printf("2");
  else if(n<189) printf("3");
  else if(n<195) printf("4");
  else printf("5");
}


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

int main() {
	string s;
    getline(cin,s);
    int count=0;
    for(int i=0;i<4;i++){
      if(s.at(i) == '+'){
        count++;
      }
      else{
        count--;
      }
    }
    cout << count << endl;
}


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;
const int INF = 1e9;

int prime[200000];

int main() {
    for (int i = 2; i < 200000; ++i) {
        if(prime[i] == 0){
            prime[i] = 1;
            for (int j = 2; i * j < 200000; ++j) {
                prime[i * j] = -1;
            }
        }
    }

    int x;
    cin >> x;
    int res;
    for (int i = x; i < 200000; ++i) {
        if(prime[i] == 1){
            res = i;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
string s;
int len, last[26], a[26], ans;
int main()
{
    cin >> s;
    len = ans = s.length();
    for (int i = 0; i < len; ++i) {
        a[s[i] - 'a'] = max(a[s[i] - 'a'], i - last[s[i] - 'a']);
        last[s[i] - 'a'] = i + 1;
    }
    for (int i = 0; i < 26; ++i) {
        ans = min(ans, max(a[i], len - last[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
graph = [[] for i in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    graph[u].append([v, w])
    graph[v].append([u, w])
d = [0 for i in range(N)]
visited = [False for i in range(N)]
def bfs(v):
    Q = []
    visited[v] = True
    Q.append(v)
    while len(Q) > 0:
        v = Q.pop(0)
        for u, w in graph[v]:
            if not visited[u]:
                visited[u] = True
                d[u] = d[v] + w
                Q.append(u)
bfs(0)
for i in range(N):
    if d[i] % 2 == 0:
        print('1')
    else:
        print('0')

Measured memory_bytes: 49848
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll inf = 998244353;
class BIT{
private:
    vector<ll> bit;
    int n;
public:
    BIT(){};
    BIT(int N){
        init(N);
    }
    void init(int N){
        n = N;
        bit.clear();
        bit.resize(N+1,0);
    }
    ll sum(int i){
        ll s = 0;
        while(i>0){
            s += bit[i];
            i -= i&-i;
        }
        return s;
    }
    ll sum_range(int l,int r){
        if(l>r) return 0;
        return (sum(r)-sum(l-1));
    }
    void add(int i,ll x){
        while(i<=n){
            bit[i] += x;
            i += i&-i;
        }
    }
    ll sum0(int i){
        return sum(i);
    }
    void add0(int i,ll x){
        add(i,x);
    }
};

int main(){
    int N;
    cin >> N;
    map<int,int> mx,my;
    vector<P> v(N+1);
    vector<int> X(N+1,0),Y(N+1,0);
    for(int i=1;i<=N;i++){
        cin >> X[i] >> Y[i];
        v[i] = {X[i],Y[i]};
    }
    sort(X.begin()+1,X.end());
    sort(Y.begin()+1,Y.end());
    for(int i=1;i<=N;i++){
        mx[X[i]] = i;
        my[Y[i]] = i;
    }
    for(int i=1;i<=N;i++){
        v[i] = {mx[v[i].first],my[v[i].second]};
    }
    sort(v.begin(),v.end());
    vector<vector<ll>> cnt(N+1,vector<ll>(4,0));
    BIT bit(N+1);
    for(int i=1;i<=N;i++){
        int nowy = v[i].second;
        cnt[i][0] = bit.sum_range(1,nowy);
        cnt[i][1] = bit.sum_range(nowy,N);
        bit.add(nowy,1);
    }
    bit.init(N);
    for(int i=N;i>=1;i--){
        int nowy = v[i].second;
        cnt[i][3] = bit.sum_range(1,nowy);
        cnt[i][2] = bit.sum_range(nowy,N);
        bit.add(nowy,1);
    }
    ll ans = 0;
    vector<ll> beki(N+1,1);
    for(int i=1;i<=N;i++) beki[i] = 2*beki[i-1]%inf;
    for(int i=1;i<=N;i++){
        ll now = (beki[N]-1+inf)%inf;
        for(int k=0;k<4;k++){
            (now += -(beki[cnt[i][k]+cnt[i][(k+1)%4]]-1+inf)%inf+inf)%=inf;
            (now += (beki[cnt[i][k]]-1+inf)%inf)%=inf;
        }
        (ans += now)%=inf;
    }
    cout << ans << endl;
}

Measured memory_bytes: 39296
/* Filename: ABC049A.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			char c = input.next().charAt(0);

			switch (c) {
			case 'a':
			case 'e':
			case 'i':
			case 'o':
			case 'u':
				System.out.println("vowel");
				break;
			default:
				System.out.println("consonant");
				break;
			}
		}
	}

}


Measured memory_bytes: 8916
n,m = gets.split.map(&:to_i)
a = m.times.map{gets.to_i}
dp = Array.new(n+2,0)
mod = 10**9+7
dp[0] = 1
j = 0
n.times do |i|
    j += 1 if j < m && a[j] <= i
    if !(j < m && a[j] == i+1)
        dp[i+1] += dp[i]
        dp[i+1] %= mod
    end
    if !((j < m && a[j] == i+2) || (j+1 < m && a[j+1] == i+2))
        dp[i+2] += dp[i]
        dp[i+2] %=  mod
    end
end
# p dp
puts dp[n]

Measured memory_bytes: 3764
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <functional>
#pragma warning(disable : 4996)

using namespace std;

void solve_case();

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

	solve_case();

	return 0;
}

void solve_case() {
	int a, b;

	cin >> a >> b;

	if (b % a == 0)
		cout << a + b << "\n";
	else
		cout << b - a << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
using namespace std;

int a[220000];
int b[220000];

int cmp(int x,int y){
    return x<y;
}

int main()
{
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    int k=0,no=1;
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            no++;
        }
        else{
            b[k++]=no;no=1;
        }
    }
    b[k++]=no;
    sort(b,b+k,cmp);
    long long sum=0;
    for(int i=0;i<k-q;i++)sum+=b[i];

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1792
/*
入力例 0 2 3 4 5
出力例 1 
*/
function main(input){
  input = input.split(" ");
  for(var i=0; i<input.length; i++){
    if(input[i]==0){console.log(i+1);}
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29580
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
ld dp[301][301][301];
ld find(ld dp[301][301][301],ll x,ll y,ll z,ll n)
{
    if(x==0&&y==0&&z==0)
        return 0;
    if(dp[x][y][z]!=-1)
        return dp[x][y][z];
    ld ans=0;
    if(x>0)
        ans+=(x*find(dp,x-1,y,z,n));
    if(y>0)
        ans+=(y*find(dp,x+1,y-1,z,n));
    if(z>0)
        ans+=(z*find(dp,x,y+1,z-1,n));
    ans/=((1.0)*(x+y+z));
    ans+=(((1.0)*n)/((1.0)*(x+y+z)));
    dp[x][y][z]=ans;
    return ans;
}
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll x=0,y=0,z=0,a;
    
    for(ll i=1;i<=n;i++)
    {
        cin>>a;
        if(a==1)
            x++;
        else if(a==2)
            y++;
        else
            z++;
    }
    for(ll i=0;i<=300;i++)
    {
        for(ll j=0;j<=300;j++)
        {
            for(ll k=0;k<=300;k++)
            {
                dp[i][j][k]=-1;
            }
        }
    }
    cout<<fixed<<stp<<find(dp,x,y,z,n);
}


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


int main(){
  int n,k;
  cin >> n >> k;
  int l[n];
  for(int i=0;i<n;i++){
      cin >> l[i];
  }
  int ans = 0;
  sort(l,l+n,greater<int>());
  for(int j=0;j<k;j++){
      ans += l[j];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;


int main(){
  int n;
  cin >> n;
  string a[n+10];
  bool ans=0;
  for (int i=0;i<n;i++){
    cin >> a[i];
    if (i>0){
      int t=a[i-1].length();
      if(a[i].at(0)!=a[i-1].at(t-1)) ans=1;
    }
    for (int j=0;j<i;j++) if(a[i]==a[j]) ans =1;
  }
  if(ans) cout << "No" << endl;
  else cout << "Yes" << endl;

    
}

Measured memory_bytes: 768
import sys
import math

n = int(sys.stdin.readline())
x, y = (list(map(int, line.strip().split())) for line in sys.stdin.readlines()[0:2])


def distance(p):
    return math.pow(sum(abs(x[i] - y[i]) ** p for i in range(n)), 1/p)


def distance_inf():
    return max(abs(x[i] - y[i]) for i in range(n))


for i in range(1, 4):
    print('{0:.8f}'.format(distance(i)))

print('{0:.8f}'.format(distance_inf()))



Measured memory_bytes: 5712
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int lower;
    int bigger;
    if (a > b) {
      lower = b;
      bigger = a;
    } else {
      lower = a;
      bigger = b;
    }
    int tmp = bigger % lower;
    while(lower != 0) {
      tmp = bigger % lower;
      bigger = lower;
      lower = tmp;
    }
    System.out.println(bigger);
  }
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e19;
const int INF=(1<<30);

int H,W;
char g[51][51];
int dist[51][51];

struct pos{
  int x;
  int y;
};

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

int main(){
  cin >> H >> W;
  REP(i,H)REP(j,W)cin>>g[i][j];
  REP(i,H)REP(j,W)dist[i][j] = INF;

  stack<pos> st;

  st.push({0,0});
  dist[0][0] = 0;

  int ans = 0;
  REP(i,H)REP(j,W)if(g[i][j]=='.')ans++;

  while(!st.empty()){
    pos p = st.top(); st.pop();

    REP(i,4){
      int nx = p.x + dx[i];
      int ny = p.y + dy[i];

      if(nx<0 || nx >= H || ny <0 || ny >= W)continue;
      if(g[nx][ny] == '#')continue;
      if(dist[nx][ny] <= dist[p.x][p.y] + 1)continue;

      dist[nx][ny] = dist[p.x][p.y] + 1;
      st.push({nx,ny});
    }
  }

  if(dist[H-1][W-1]==INF){
    cout << -1 << endl;
  }else{
    cout << ans - dist[H-1][W-1] - 1 << endl;
  }
}



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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

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

    int N; cin >> N;
    string s1, s2; cin >> s1 >> s2;
    ll ans = 0;

    int i = 0;
    int prev_n;
    if(s1[i] == s2[i]) { ans+=3; i++; prev_n = 1; }
    else { ans+=6; i+=2; prev_n = 2; }
    while(i<N) {
        if(s1[i] == s2[i]) {
            if(prev_n == 1) {
                ans = (ans*2) % 1000000007;
            }
            i++; prev_n = 1;
        } else {
            if(prev_n == 1) {
                ans = (ans*2) % 1000000007;
            } else {
                ans = (ans*3) % 1000000007;
            }
            i+=2; prev_n = 2;
        }
    }

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


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

int main() {
  int W, H, x, y, r;
  string result;
  int rectangle_top, rectangle_right, rectangle_bottom, rectangle_left;
  int circle_top, circle_right, circle_bottom, circle_left;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  rectangle_top = H;
  rectangle_right = W;
  rectangle_bottom = 0;
  rectangle_left = 0;


  circle_top = y + r;
  circle_right = x + r;
  circle_bottom = y - r;
  circle_left = x - r;

  if (
    circle_top <= rectangle_top &&
    circle_right <= rectangle_right &&
    circle_bottom >= rectangle_bottom &&
    circle_left >= rectangle_left
  ) {
    result = "Yes";
  } else {
    result = "No";
  }

  printf("%s\n", result.c_str());
}



Measured memory_bytes: 3284