akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
 
int main()
{
  int N,cnt=0,i;
  scanf("%d",&N);
  long a[N];
  int baketu[N+1];
  for(i=0;i<N+1;i++){
    baketu[i]=0;
  }
  
  for(i=0;i<N;i++){
    scanf("%ld",&a[i]);
    if(a[i]>N){
      cnt++;
      a[i]=0;
    }
  }
  
  for(i=0;i<N;i++){
    baketu[a[i]]++;
  }
//  printf("\n");
//  for(i=0;i<=N;i++)printf("%d ",baketu[i]);
  
  for(i=1;i<N+1;i++){
    while(baketu[i]!=i&&baketu[i]!=0){
      if(baketu[i]>i){
        baketu[i]--;
        cnt++;
      }
      if(baketu[i]<i){
        cnt = cnt+baketu[i];
        baketu[i]=0;
      }   
    }
  }
/*  
  printf("\n");
  for(i=0;i<=N;i++)printf("%d ",baketu[i]);
  printf("\n");
*/  printf("%d",cnt);
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    ll n;
    scanf("%lld", &n);
    ll ans = 0, m = n - 1;
    for (ll i = 2; i * i <= m; i++) {
        if (m % i == 0) {
            ans++;
            if (m / i != i) ans++;
        }
    }
    if (m > 1) ans++;
    auto query = [&](ll m, ll d) {
        while (m % d == 0) m /= d;
        return m % d == 1;
    };
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ans += query(n, i);
            if (n / i != i) ans += query(n, n / i);
        }
    }
    ans += 1;
    printf("%lld\n", ans);
}


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

using namespace std;
int main(){
  string S;
  cin >> S;
  int min = 754;
  for(int i = 0; i < (int)S.length()-2;i++){
    string T = S.substr(i, 3);
    int comp = stoi(T);
    comp = abs(753-comp);
    if(comp < min) min = comp;
  }
  cout << min << endl;
  return 0;
}


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

long long N;
long long A[105];
int main(){
	cin >> N;
	for(long long i = 0; i < N; i++) {
		cin >> A[i];
	}

	bool ok = true;
	for(long long i = 0; i < N; i++) {
		if(A[i] %2 == 0) {
			if(A[i] % 3 != 0 && A[i] % 5 != 0) {
				ok = false;
			}
		}
	}
	if(ok) {
		cout << "APPROVED" << endl;
	} else {
		cout << "DENIED" << endl;
	}
}


Measured memory_bytes: 3640
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t=input()
l=["" for i in range(n)]

ans=0
for i in range(k):
  if t[i]=="r":
    l[i]="p"
    ans+=p
  elif t[i]=="p":
    l[i]="s"
    ans+=s
  else:
    l[i]="r"
    ans+=r

for i in range(k,n):
  if t[i]=="r":
    if l[i-k]!="p":
      l[i]="p"
      ans+=p

  elif t[i]=="p":
    if l[i-k]!="s":
      ans+=s
      l[i]="s"

  else:
    if t[i]=="s":
      if l[i-k]!="r":
        ans+=r
        l[i]="r"

print(ans)


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> D;
    for (int i = 1; i * i <= M; i++) if (M % i == 0) D.push_back(i);
    for (int i = D.size() - 1; i >= 0; i--) if (D[i] * D[i] != M) D.push_back(M / D[i]);
    int ans = 1;
    for (int d : D) if (M / d >= N) ans = max(ans, d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;
 
ll mod = 1000000007;
 
int main(){
    ll N; cin >> N;
    vll d(N);
    for(int i=0; i<N; i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    ll k = d[N/2-1]; ll l = d[N/2];
    cout << l-k;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main (){
	int a, b, n;
	int dp[16][16];
	while (1){
		memset(dp, 0, sizeof(dp));
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		
		cin >> n;
		
		for (int i = 0; i < n; i++){
			int x, y;
			scanf("%d%d", &x, &y);
			dp[y-1][x-1] = -1;
		}
		
		dp [0][0] = 1;
		
		for (int i = 0; i < b; i++){
			for (int j = 0; j < a; j++){
				if (i == 0 && j == 0) continue;
				
				if (dp[i][j] == -1) dp[i][j] = 0;
				else if (i-1 < 0) dp[i][j] = dp[i][j-1];
				else if (j-1 < 0) dp[i][j] = dp[i-1][j];
				else dp[i][j] = dp[i-1][j]+dp[i][j-1];
			}
		}
		cout << dp[b-1][a-1] << endl;
	}
	
	return 0;
}

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

int main () {
  int N = 0;
  cin >> N;

  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  for (int i = N - 1; i >= 0; i--) {
    if (i == 0){
      cout << data.at(i) << endl;
    }
    else {
      cout << data.at(i) << " ";
    }
  }
}



Measured memory_bytes: 3092
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))
B = list(map(int, input().strip().split(' ')))

result = 0
for i in range(N):
  f = min(A[i], B[i])
  s = min(A[i+1], B[i]-f)
  result += s+f
  A[i+1] -= s
  
print(result)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
// ans = x + (1-p)*ans ans = x/p
// p = 1/2^m x = 1900m + 100(n-m)
int main() {
    ll n, m;
    cin >> n >> m;
    ll time = 1900LL * m + 100L * (n-m);
    ll k = 1LL<<m;
    ll ans = time * k;
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h,vector<char>(w));
    REP(i,h){
      REP(j,w){
        cin >> c[i][j];
      }
    }
    
    int ans = 0;

    REP(bit1,1<<h){
      REP(bit2,1<<w){
        int black = 0;
        REP(i,h){
          REP(j,w){
            if(bit1&1<<i && bit2&1<<j && c[i][j]=='#'){
              black++;
            }
          }
        }
        if(black == k) ans ++;
      }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
require 'pp'

N = readline.to_i
A = readline.chomp.split.map(&:to_i)

sign = 0
A.each do |i|
  sign += 1 if i < 0
end

if sign % 2 == 0
  puts A.map {|a| a.abs }.inject(:+)
else
  m = A.min_by {|a| a.abs}
  puts( A.map {|a| a.abs }.inject(:+) - 2*m.abs )
end


Measured memory_bytes: 12204
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  c:char;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(c);

    if (c='a') or (c='i') or (c='u') or (c='e') or (c='o') then
      Writeln('vowel')
    else
      Writeln('consonant');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 128
#include<stdio.h>

main(){
  double a,b,c,d,e,f;

  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
  double x,y;
  y=((d*c)-(a*f))/((b*d)-(a*e));
  x=(c-b*y)/a;

  y+=0.00005;
  x+=0.00005;  
  
  printf("%0.3lf %0.3lf\n",x,y);

  }
  return 0;
}

Measured memory_bytes: 656
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e9+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

struct Job
{
	int day;
	int reward;
};

bool cmp(const Job &a, const Job &b)
{
	return a.day < b.day;
}

int main()
{
	int ans = 0;
	int n, m;
	cin >> n >> m;

	vector<Job> v(n);
	for (int i = 0; i < n; ++i)
	{
		int a, b;
		cin >> a >> b;
		v[i].day = a;
		v[i].reward = b;
	}

	sort(ALL(v), cmp);

	priority_queue<int> p_pue;
	int vid = 0;

	for (int i = 1; i <= m; ++i)
	{
		while (v[vid].day <= i)
		{
			p_pue.push(v[vid].reward);
			++vid;
		}

		if (!p_pue.empty())
		{
			ans += p_pue.top();
			p_pue.pop();
		}
	}

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

Measured memory_bytes: 1660
#include<stdio.h>

int main(void)

{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (a <= b && c <= d) {

		printf("%d\n", a + c);

	}
	else if (a <= b && c > d) {
		printf("%d\n", a + d);

	}
	else if (a > b && c <= d) {

		printf("%d\n", b + c);

	}
	else if (a > b && c > d) {


		printf("%d\n", b + d);
	}
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n, m, i, j, k;
	char a[80], b[80], c;
	string str;
	bool flg = false;
	while (cin >> n && n)
	{
		str = "";
		for (i = 0; i < n; i++)
		{
			cin >> a[i] >> b[i];
		}
		cin >> m;
		for (i = k = 0; i < m; i++)
		{
			cin >> c;
			for (j = flg = 0; j < n && !flg; j++)
			{
				if (c == a[j])
				{
					str +=  b[j];
					flg = true;
				}
			}
			if (!flg)
				str += c;
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    ll n, k;
    cin >> n >> k;
    vi a(n);
    rep (i, n) {
        cin >> a[i];
        a[i]--;
    }

    vi first(n, -1);
    first[0] = 0;
    int now = 0;
    int shuki;
    rep1 (i, n) {
        now = a[now];
        if (i == k) {
            cout << now + 1 << endl;
            return 0;
        }
        if (first[now] == -1) first[now] = i;
        else {
            shuki = i - first[now];
            break;
        }
    }

    k -= first[now];
    k %= shuki;
    rep (i, k) {
        now = a[now];
    }
    cout << now + 1 << endl;
}

Measured memory_bytes: 6364
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val A = readLine()!!.split(" ").map{it.toLong()}

    val Q = PriorityQueue<Long>(N, Comparator<Long> { a: Long, b: Long -> (b - a).toInt() })
    A.forEach { Q.add(it) }

    var m = M
    while (m > 0) {
        val p = Q.poll()

        Q.add(p / 2)

        m--
    }

    println(Q.sum())
}


Measured memory_bytes: 71864
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    long long n,k,b,ans=0;
    cin>>n>>k;
    if (k==0)
        ans=n*n;//排除0的干扰
    else
    {
        for (int i=1;i<=n-k;i++)
            //只有比k大的数做除数（a/b中的b）才能得到大于等于k的余数
        {
            b=i+k;
            //b为比k大,小于等于n的所有数
            ans+=(n/b)*i;
            //对于任意b，在0到n的范围内任意a，a%b的余数有（n/b）个完整的循环，每个循环内有i个大于等于k的余数
            if(n%b-k>=0)
                ans+=n%b-k+1;
            //如果还存在不完整的循环，计算在这个不完整循环内a%b的大于等于k的余数个数
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<set>
#include<queue>
#define IL inline
#define RG register
#define db double
#define inf 0x3f3f3f3f
#define LL long long
#define N 500005
using namespace std;
IL int gi()
{
	RG int res=0,s=1;RG char ch;
	for(ch=getchar(); (ch<'0'||ch>'9')&&ch!='-' ;ch=getchar());
	if(ch=='-') s=-1,ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
	return res*s;
}
int n,k,a[N],ans[N];
int head[N],to[N<<1],ne[N<<1],num,du[N];
struct node
{
	int p,v;
	node(RG int pp=0,RG int vv=0){p=pp,v=vv;}
	bool operator < (const node &o) const {
		return v<o.v;
	}
	bool operator == (const node &o) const {
		return p==o.p&&o==o.v;
	}
};
set<node>s; set<node>::iterator it;
priority_queue<int>h;
//建反图
IL void adde(RG int u,RG int v) {
	to[++num]=v,ne[num]=head[u],head[u]=num; du[v]++;
}
int main()
{
	//freopen("permutation.in","r",stdin);
	//freopen("permutation.out","w",stdout);
	n=gi(),k=gi();
	for(RG int i=1;i<=n;++i) a[i]=gi();
    for(RG int i=1;i<=n;++i) {
		if(i-k>0) s.erase(node(i-k,a[i-k]));
		s.insert(node(i,a[i]));
		it=s.upper_bound(node(i,a[i]));
		if(it!=s.end()) adde((*it).p,i);
	}
	s.erase(s.begin(),s.end());
	for(RG int i=n;i>=1;--i) {
		if(i+k<=n) s.erase(node(i+k,a[i+k]));
		s.insert(node(i,a[i]));
		it=s.upper_bound(node(i,a[i]));
		if(it!=s.end()) adde((*it).p,i);
	}
	for(RG int i=1;i<=n;++i) if(!du[i]) h.push(i);
	RG int pos,tot=n;
	while(!h.empty()) {
		pos=h.top(); h.pop();
		ans[pos]=tot; tot--;
		for(RG int i=head[pos];i;i=ne[i]) {
			du[to[i]]--;
			if(!du[to[i]]) h.push(to[i]);
		}
	}
	for(RG int i=1;i<=n;++i) printf("%d\n",ans[i]);
	//fclose(stdin);fclose(stdout);
	return 0;
}

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

// Step1 i = 0: A(0) = B(0)とする
// Step2 i = i: A(i) = min{B(i-1), B(i)}

int main() {
    int N;
    cin >> N;
    long long A[N], B[N];
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }

    int ans = 0;

    for (int i = 0; i < N; i++) {
        if (i == 0) A[i] = B[i];
        if (i == N-1) A[i] = B[i-1];
        else A[i] = min(B[i-1], B[i]);
    }

    for (int i = 0; i < N; i++) {
        ans += A[i];
    }

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

Measured memory_bytes: 256
if __name__ == '__main__':
    S = input()
    if(S=='SUN'): print(7)
    elif(S=='MON'): print(6)
    elif(S=='TUE'): print(5)
    elif(S=='WED'): print(4)
    elif(S=='THU'): print(3)
    elif(S=='FRI'): print(2)
    elif(S=='SAT'): print(1)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int inf = 1e9;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ワーシャルフロイド
  int n,m;// 頂点、辺
  cin >> n >> m;
  int a[100], b[100], c[100], dist[100][100];
  CLR(a);CLR(b);CLR(c);
  FOR(i,0,m){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    c[i] = 1;
  }
  int ans = 0;
  FOR(t,0,m) {
    FOR(i,0,n){
      FOR(j,0,n){
        if(i==j) dist[i][j] = 0;
        else dist[i][j] = inf;
      }
    }
    // 連結してるとこはcを代入
    FOR(i,0,m){
      if(i == t) continue;
      dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
      dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }
    FOR(k,0,n) FOR(i,0,n) FOR(j,0,n) {
      dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    bool brk = false;
    FOR(i,0,n) {
      FOR(j,0,n) {
        if(dist[i][j] == inf) {
          ans++;
          brk = true;
          break;
        }
      }
      if(brk) break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
ToNode = Struct.new(:id, :weight)

_ = gets

$graph       = {}

while (line = gets)
  node_id, _, *nodes = line.split(' ').map(&:to_i)
  $graph[node_id] = nodes.each_slice(2).map{|id, weight| ToNode.new(id, weight)}
end

$visited_nodes = []



$start_node_id = 0
# Min Distance '0' to `key`
$weights = {$start_node_id => 0}
$visited_nodes.push($start_node_id)


loop do
  # Node which should be visited
  next_visit_node =
    $visited_nodes
      .flat_map{|node_id|
        to_nodes = $graph[node_id]
        w        = $weights[node_id]
        to_nodes
          .map{|n| {id: n.id, weight: w + n.weight} }
          .reject{|e| $visited_nodes.include?(e[:id])}
      }
      .min_by{|e| e[:weight]}

  if next_visit_node.nil?
    break
  end

  $visited_nodes.push(next_visit_node[:id])
  $weights[next_visit_node[:id]] = next_visit_node[:weight]
end

$weights
  .sort_by{|k, v| k}
  .each{|node, weight|
    puts("#{node} #{weight}")
  }



Measured memory_bytes: 9712
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    a, b, c, k = [int(x) for x in stdin.readline().rstrip().split()]
    if a >= k:
        print(k)
    elif a + b >= k:
        print(a)
    else:
        nokori = k - (a + b)
        print(a - nokori)

main()

Measured memory_bytes: 9964
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    N, M, X = map(int, input().strip().split())
    C, A = [], []
    for i in range(N):
        line = list(map(int, input().strip().split()))
        C.append(line[0])
        A.append(line[1:])
    return N, M, X, C, A


def solve(N, M, X, C, A, INF = 10**8):
    stats = [0 for i in range(M)]
    
    def dfs(n):
        if all([s >= X for s in stats]):
            return 0
        if n >= N:
            return INF
        
        c1 = dfs(n+1)
        for i in range(M):
            stats[i] += A[n][i]
        c2 = dfs(n+1) + C[n]
        for i in range(M):
            stats[i] -= A[n][i]
        return min(c1, c2)

    c = dfs(0)
    return c if c < INF else -1


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<Edge>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}



bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
//N以下の3or5or7からなる数字を列挙
void dfs(string S,vector<ll> &v,const ll N){
  ll c3 = stoll(S+'3');
  ll c5 = stoll(S+'5');
  ll c7 = stoll(S+'7');
  
  if(c3 > N) return;
  else v.push_back(c3);
  
  if(c5 > N) return;
  else v.push_back(c5);
  
  if(c7 > N) return;
  else v.push_back(c7);
  
  dfs(S+'3',v,N);
  dfs(S+'5',v,N);
  dfs(S+'7',v,N);
}


int main(){
  ll N;
  cin >> N;
  vector<ll> v;
  dfs("",v,N);
  
  int ans = 0;
  /*rep(i,v.size()){
    cout << v[i] << endl;
  }*/
  for(int i = 0;i<v.size();i++){
    bool flag3 = false;
    bool flag5 = false;
    bool flag7 = false;
    string s = to_string(v[i]);
    int n = s.size();
    for(int j = 0;j<n;j++){//3or5or7が少なくとも一つ含まれているか
      if(s[j] == '3') flag3 = true;
      if(s[j] == '5') flag5 = true;
      if(s[j] == '7') flag7 = true;
    }
    if(flag3 && flag5 && flag7) ans++;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 640
import sys

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


def resolve():
    x, y = map(int, input().split())
    A = [1, 3, 5, 7, 8, 10, 12]
    B = [4, 6, 9, 11]
    C = [2]
    if x in A and y in A:
        print("Yes")
    elif x in B and y in B:
        print("Yes")
    elif x in C and y in C:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct PP
{
	char name[100];
	int t;
} P;

P Q[LEN];
int head,tail,n;

void enqueue(P x)
{
	Q[tail] = x;
	tail = (tail+1)%LEN;
}
P dequeue()
{
	P x = Q[head];
	head = (head+1)%LEN;
	return x;
}
int main()
{
	int elaps=0;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++)
	{
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=0;
	tail=n;
	while(head!=tail)
	{
		u=dequeue();
		if(u.t>q)
		{
			elaps+=q;
			u.t-=q;
			enqueue(u);
		}
		else
		{
			elaps+=u.t;
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}

Measured memory_bytes: 12712
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  string s, t;
  cin >> s >> t;
  int s_sz = s.size(), t_sz = t.size();
  vector<vector<int> > dp(s_sz+1, vector<int>(t_sz+1, 0));
  rep(i, s_sz) rep(j, t_sz) {
    if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
    else chmax(dp[i+1][j+1], max(dp[i][j+1], dp[i+1][j]));
  }
  int ci = s_sz, cj = t_sz;
  string ans = "";
  while(ci && cj) {
    if(s[ci-1] == t[cj-1]) {
      ans += s[ci-1]; ci--; cj--;
    } else if(dp[ci][cj] == dp[ci-1][cj]) {
      ci--;
    } else {
      cj--;
    }
  }
  reverse(ALL(ans));
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 38536
#include<stdio.h>
#include<string.h>

int main()
{
   char s[3] ;
   int i;
   scanf("%s",s);
  if(s[0] != s[1] && s[1] != s[2] && s[2] != s[3])
    printf("Good");
  else{
    printf("Bad");
  }

return 0;



}


Measured memory_bytes: 128
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)
    
n = getInt()
dish = []
bsum = 0
for _ in range(n):
    a, b = getInts()
    bsum += b
    dish.append(a+b)
dish.sort(reverse=True)
print(sum(dish[::2]) - bsum)

Measured memory_bytes: 7492
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll a,b,k;
    cin >> a >> b >> k;
    ll r = min(a,k);
    cout << a - r << " " << max(0LL,b - (k - r)) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int ft_min(int num1, int num2)
{
    return num1 > num2 ? num2 :num1;
}

int ft_gcd(int a, int b, int c){
    int gcd = 0;
    int minimum;
    minimum = ft_min(a, ft_min(b, c));
    
    for (int i = 1; i <= minimum; i++) {
        if ((a % i == 0) && (b % i == 0) && (c % i == 0)) {
            gcd = i;
        }
    }
    return gcd;
}

int main(void) {
    
    int k;
    int result = 0;
    cin >> k;


    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                result += ft_gcd(a, b, c);
            }
        }
    }
    printf("%d",result);

    return 0;
}

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

int main() {
    
    long long int n,d,x,y,point=0;
    cin>>n;
    cin>>d;
    
    for(long long int i=0;i<n;i++){
    	cin>>x;
    	cin>>y;
    	if ((x*x +y*y)<=(d*d))
    		point++;
	}
    cout<<point<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int k,x;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> k >> x;
    for(int i = -k+1;i < k; ++i){
        cout << x + i <<" ";
    }
    return 0;
}

Measured memory_bytes: 256
S=input()

for i in range(2**3):
    p=['-']*3
    ans=''
    for j in range(3):
        if((i>>j)&1):
            p[j]='+'
    for j,k in zip(S,p+['']):
        ans+=j+k
    if(eval(ans)==7):
        print(ans+'=7')
        exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  int mn1=n-1, mn2=n-1;
  map<int, int> cnt1, cnt2;
  ll cnt = 0;
  rep(_, q) {
    int t, x; cin >> t >> x;
    x--;
    if(t == 1) {
      if(x > mn1) {
        cnt += (--cnt1.upper_bound(x))->second;
      } else {
        cnt += mn2-1;
        cnt1[x] = mn2-1;
      }
      chmin(mn1, x);
    } else {
      if(x > mn2) {
        cnt += (--cnt2.upper_bound(x))->second;
      } else {
        cnt += mn1-1;
        cnt2[x] = mn1-1;
      }
      chmin(mn2, x);
    }
  }
  cout << 1LL*(n-2)*(n-2) - cnt << endk;
  return 0;
}


Measured memory_bytes: 12884
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)
ans = 0
tmp = 0
inf = 10 ** 20
INF = float("INF")
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
ddn9 = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, a = wi()
x = wi()
X = max(x)
dp = [[[0] * (n + 1) for j in range(X * n + 2)] for i in range(n)]
dp[0][0][0] = 1
dp[0][x[0]][1] = 1

for p in range(1, n):
    for k in range(X * n + 2):
        for usenum in range(n):
            dp[p][k][usenum] += dp[p - 1][k][usenum]
            if k - x[p] >= 0:
                dp[p][k][usenum + 1] += dp[p - 1][k - x[p]][usenum]

for k in range(X * n + 2):
    for usenum in range(n + 1):
        if usenum != 0:
            if k / usenum == a:
                ans += dp[n - 1][k][usenum]
print(ans)

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


char s[200005];

signed main() {
    //my-code
    string T; cin >> T;
    REP(i, T.length()) {
        if (T[i] == 'P') {
            s[i] = 'P';
        } else if (T[i] == 'D') {
            s[i] = 'D';
        } else {
            if (i > 0 && s[i-1] == 'P') {
                s[i] = 'D';
            } else if (i > 0 && s[i-1] == 'D' && i+1 < T.length() && T[i+1] == '?' || T[i+1] == 'D') {
                s[i] = 'P';
            } else {
                s[i] = 'D';
            }
        }
    }

    REP(i, T.length()) {
        cout << s[i];
    }
    cout << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

int X,Y;
vector<vector<int>> s;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
using P = pair<int,int>;

int solve(int y, int x, set<P> st){
    if((int)st.size() > 10) return INF;
    int res = INF;
    rep(k,4){
        int d = 1;
        while(true){
            int ny = y+d*dy[k], nx = x+d*dx[k];
            if(!(ny>=0 && nx>=0 && ny<Y && nx<X)) break;
            if(s[ny][nx] == 3) {
                // for(auto p : st){
                    // printf("(%d,%d)",p.first,p.second);
                // }
                // cout<<endl;
                return st.size();
            }
            if(s[ny][nx] == 1 && st.count({ny,nx})==0){
                if(d > 1){
                    st.insert({ny,nx});
                    res = min(solve(ny-dy[k],nx-dx[k],st),res);
                    st.erase({ny,nx});
                }
                break;
            }
            d++;
        }
    }
    return res;
}

int main(void){
    while(cin>>X>>Y, X|Y){
        s.clear(); s.resize(Y);
        int sy=0,sx=0;
        rep(y,Y){
            s[y].resize(X);
            rep(x,X){
                cin>>s[y][x];
                if(s[y][x] == 2) sy = y, sx = x;
            }
        }
        int res = solve(sy,sx,{{sy,sx}});
        cout<<(res>10 ? -1 : res)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 200005
#define inf 2e9
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll dp[100005] ={0};
int main()
{
    fast;
    ll n,W;
    cin>>n>>W;
    vector<int >v,w;
    v.pb(0);
    w.pb(0);
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        w.pb(x);
        v.pb(y);
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=W;j>=w[i];j--)
        {
            dp[j] = max( dp[j],v[i]+dp[j-w[i]] ) ;
        }
    }
    cout<<dp[W]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
vector<vector<int>> P;
int N, M, ans;
void dfs(int v, int cnt, vector<int> vs)
{
  cnt++;
  if (cnt == N) ans++;
  if (vs[v]) return;
  vs[v] = 1;
  for (auto t : P[v]) {
    if (vs[t]) continue;
    dfs(t, cnt, vs);
  }
}

int main(void)
{
  cin >> N >> M;
  P.resize(N);
  rep(i, M) {
    int x, y;
    cin >> x >> y;
    x--;  y--;
    P[x].push_back(y);
    P[y].push_back(x);
  }
  
  vector<int> vs(N, 0);
  dfs(0, 0, vs);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        s: Chars
    };

    let odd_chars = vec!['R', 'U', 'D'].into_iter().collect::<HashSet<_>>();
    let even_chars = vec!['L', 'U', 'D'].into_iter().collect::<HashSet<_>>();
    let is_ok = s.into_iter().enumerate().all(|(i, ch)| {
        let i = i + 1;
        if i % 2 == 0 {
            even_chars.contains(&ch)
        } else {
            odd_chars.contains(&ch)
        }
    });
    let res = if is_ok { "Yes" } else { "No" };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2280
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N = ir()
    A = lr()
    for a in A:
        if a%2 == 0:
            if a%3 != 0 and a%5 != 0:
                print('DENIED')
                return
    print('APPROVED')
resolve()

Measured memory_bytes: 3060
N = int(input())
a = list(map(int, input().split()))

c = [0] * 8
r = 0

for i in a:
    col = i // 400
    if col <= 7:
        c[col] = 1
    else:
        r += 1

c = sum(c)

print(max(1, c), r+c)

Measured memory_bytes: 9128
import java.util.Scanner;

public class Main {

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

        int h = scanner.nextInt();
        int w = scanner.nextInt();
        while (h + w > 0) {
            
            
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
            
            
            
            h = scanner.nextInt();
            w = scanner.nextInt();
        }
    }
}



Measured memory_bytes: 35768
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, k, s[210000], ans;
map<ll, ll> m;
int main() {
	cin >> n >> k;
	REPO(i, n) cin >> s[i];
	REP(i, n) {
		s[i + 1] += s[i];
		s[i + 1] %= k;
	}
	REP(i, n + 1) {
		s[i] -= i;
		s[i] = (s[i] + k * (i + 1)) % k;
		//cout << s[i] << " ";
	}
	REP(i, n + 1) {
		m[s[i]]++;
		if (i - k >= 0) m[s[i - k]]--;
		ans += m[s[i]] - 1;
	}
	cout << ans << endl;

}


Measured memory_bytes: 14464
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC149B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABK = Console.ReadLine().Split(' ');
            long A = long.Parse(ABK[0]);
            long B = long.Parse(ABK[1]);
            long K = long.Parse(ABK[2]);
            long[] ans = new long[2];
            if (A >= K)
            {
                ans[0] = A - K;
                ans[1] = B;
            }
            else if(A+B>=K)
            {
                ans[0] = 0;
                ans[1] = A + B - K;
            }
            else
            {
                ans[0] = 0;
                ans[1] = 0;
            }
            Console.WriteLine(string.Join(" ", ans));
        }
    }
}


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

const long long int MOD = 1000000007;
const long long int INI = -1;
int n, m;
long long int a[101010];

long long int fibo(long long int x){
  if(a[x] != INI){
    return a[x];
  }
  a[x] = fibo(x - 1) + fibo(x - 2);
  a[x] %= MOD;
  return a[x];
}

int main(){
  cin >> n >> m;
  rep(i, n + 1){
    a[i] = INI;
  }
  a[0] = 1; a[1] = 1;
  rep(i, m){
    int tmp;
    cin >> tmp;
    a[tmp] = 0;
  }
  //rep(i, n) cerr << a[i] << " "; cerr << endl;
  cout << fibo(n) << endl;
  //rep(i, n) cerr << a[i] << " ";
  return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char ch[4] = {'L','R'};

int main(){
  	string S;
  	cin >> S;
  	int l = S.size();

  	for(int i=0;i<l;i++){
  		if(S[i]==ch[i%2]){
  			cout << "No" <<endl;
  			return 0;
  		}
  	}
  	cout << "Yes" <<endl;

    return 0;
}

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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
string s;

bool read() {
    if (!(cin >> n >> s))
        return false;

    return true;
}

void solve() {
    s = "00" + s + "00";
    n = s.size();
    vector< vector<int> > b;

    for (int i = 0; i < n; ++i)
        if (s[i] == '1') {
            if (s[i - 1] == '1') {
                ++b.back().back();
            } else if (s[i - 2] == '1') {
                b.back().emplace_back(1);
            } else {
                b.push_back({ 1 });
            }
        }

    auto ans = 0;

    for (const auto& vec : b) {
        if (vec.size() == 1)
            continue;

        vector< vector<int> > dp(vec.size(), vector<int>(3));
        dp[0][1] = dp[0][2] = -MOD;

        for (int i = 1; i < vec.size(); ++i) {
            dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
            dp[i][1] = dp[i - 1][0] + vec[i - 1];
            dp[i][2] = dp[i - 1][0] + vec[i];

            if (vec[i - 1] != 1) {
                dp[i][1] = max({dp[i][1], dp[i - 1][1] + vec[i - 1] - 1, dp[i - 1][2]});
                dp[i][2] = max({dp[i][2], dp[i - 1][1] + vec[i], dp[i - 1][2] - 1 + vec[i]});
            }
        }

        auto res = max({dp.back()[0], dp.back()[1], dp.back()[2]});
        ans += res;
    }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 7468
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
int main(){
	stack<int> train;
	int n;
	while(cin>>n){
		if(n!=0){
			train.push(n);
		}else{
			cout<<train.top()<<endl;
			train.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair

int main(){
  int x1, x2, x3, x4;
  int y1, y2, y3, y4;
  cin >> x1 >> y1;
  cin >> x2 >> y2;

  pii v21 = mp(x1-x2, y1-y2);
  pii v23 = mp(v21.se, -v21.fi);

  x3 = x2 + v23.fi;
  y3 = y2 + v23.se;

  x4 = x3 + v21.fi;
  y4 = y3 + v21.se;

  printf("%d %d %d %d\n", x3, y3, x4, y4);

  return 0;
}


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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int n, m;
    cin>>n>>m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256