akhauriyash/Code-Regression huggingface dataset:
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

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

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

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

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

int N;
ll a[100000];

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

ll gcd(vector<ll> v)
{
    size_t s = v.size();
    if(s == 0) return -1;
    if(s == 1) return v[0];
    ll ret = gcd(v[0], v[1]);
    FOR(i, 2, s){
        ret = gcd(ret, v[i]);
    }
    return ret;
}

void init()
{
}

void solve()
{
    vector<ll> v(&a[0], &a[N]);
    cout << gcd(v) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    ll N,K;
    cin>>N>>K;
    vector<pair<ll,ll>> ab(N);
    rep(i,0,N)cin>>ab[i].first>>ab[i].second;
    sort(ab.begin(),ab.end());

    ll sum =0,i=0;
    while(sum < K){
        sum += ab[i].second;
        if(sum>=K)cout<<ab[i].first;
        i++;
    }

    return 0;
}

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

int main(){
    int n,ans=0;
    cin >> n;
    vector<vector<pair<int,int>>> v(n);
    for(int i = 0 ; i < n ; i += 1){
        int a;
        cin >> a;
        for(int j = 0 ; j < a ; j += 1){
            int b,c;
            cin >> b >> c;
            v[i].push_back({b-1,c});
        }
    }
    for(int i = 0 ; i < (1 << n) ; i += 1){
        bool ok = true;
        int sum = 0;
        for(int j = 0 ; j < n ; j += 1){
            if(i & (1 << j)){
                sum += 1;
                for(pair<int,int> k : v[j]){
                    if(k.second == 1 && !(i & (1 << k.first))){
                        ok = false;
                        break;
                    }else if(k.second == 0 && (i & (1 << k.first))){
                        ok = false;
                        break;
                    }
                }
            }
        }
        if(ok){
            ans = max(ans,sum);
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
//

fun main() {
    abc167b()
}

fun abc167b() {
    val (a, b, c, k) = readLine()!!.split(" ").map { it.toLong() }
    when {
        // KがAより小さいパターンが考慮漏れだった・・・
        k < a -> println(k)
        k <= a + b -> println(a)
        else -> {
            val d = k - a - b
            println(a - d)
        }
    }
}


Measured memory_bytes: 36456
package main

import "fmt"

func main() {
	var (
		A, B, C, K uint
	)
	fmt.Scanf("%d %d %d", &A, &B, &C)
	fmt.Scan(&K)
	if A >= B && A >= C {
		fmt.Println(A<<K + B + C)
	} else if B >= A && B >= C {
		fmt.Println(B<<K + A + C)
	} else {
		fmt.Println(C<<K + A + B)
	}
}


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

int main() {
	long long int n, k;
	cin >> n >> k;

	long long int f = n % k;
	long long int b = k - (n % k);

	long long int min;
	if (f < b) {
		min = f;
	} else {
		min = b;
	}

	cout << min << endl;
	return 0;
}

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

int main(void){
  ll h;
  cin >> h;
  ll cnt = 0;
  while(h != 0) {
    h = floor(h/2);
    cnt++;
  }
  ll ans = 0;
  rep(i,cnt) ans += pow(2,i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4112
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    ll hp, atk, def, spd;
    cin >> hp >> atk >> def >> spd;
    vector<ll> h, a, d, s;
    for (int i = 0; i < n; i++)
    {
        ll htmp, atmp, dtmp, stmp;
        cin >> htmp >> atmp >> dtmp >> stmp;
        if (dtmp >= atk && atmp > def)
        {
            cout << -1 << endl;
            return 0;
        }
        if (atmp <= def)
            continue;
        atmp -= def;
        h.push_back(htmp);
        a.push_back(atmp);
        d.push_back(dtmp);
        s.push_back(stmp);
    }
    n = h.size();
    vector<ll> turn(n);
    for (int i = 0; i < n; i++)
    {
        ll tmp = atk - d[i];
        turn[i] = (h[i] - 1) / tmp + 1;
    }
    vector<int> idx(n);
    for (int i = 0; i < n; i++)
        idx[i] = i;
    sort(idx.begin(), idx.end(), [&](int i, int j) { return turn[i] * a[j] < turn[j] * a[i]; });
    ll ret = 0, cnt = 0;
    for (auto i : idx)
    {
        hp -= cnt * a[i];
        ret += cnt * a[i];
        cnt += turn[i];
        if (s[i] <= spd)
            turn[i]--;
        hp -= turn[i] * a[i];
        ret += turn[i] * a[i];
        if (hp <= 0)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ret << endl;
}


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

void solve(int n){
	bool f = false;
	int a[30] = {};
	for(int i=0; i<n; ++i){
		char c;
		cin >> c;
		++a[c-'A'];
		char t = ' ';
		int p = -1;
		for(int j=0; j<26; ++j){
			if(p < a[j]){
				t = 'A'+j;
				p = a[j];
			}
		}
		char s = ' ';
		int q = -1;
		for(int j=0; j<26; ++j){
			if('A'+j != t && q < a[j]){
				s = 'A'+j;
				q = a[j];
			}
		}
		if(!f && a[t-'A'] > a[s-'A'] + n-i-1){
			cout << t << " " << i+1 << "\n";
			f = true;
		}
	}
	if(!f) cout << "TIE\n";
	return;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, a, b;
vector<vi> e(50);

int main() {
	cin >> n >> m;
	rep(i,m) {
		cin >> a >> b;
		a--, b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	rep(i,n) cout << e[i].size() << ln;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int in[3][3];
int out[3][3];
int solve(int a){
    for(int i=2;i>=0;i--){
        if(out[a][i] - in[a][i] < 0){
            out[a][i] = 60+out[a][i] - in[a][i];
            out[a][i-1]--;
        }else{
            out[a][i] = out[a][i] - in[a][i];
        }
    }
    return 0;
}

int main(){
    cin >> in[0][0] >> in[0][1] >> in[0][2];
    cin >> out[0][0] >> out[0][1] >> out[0][2];
    cin >> in[1][0] >> in[1][1] >> in[1][2];
    cin >> out[1][0] >> out[1][1] >> out[1][2];
    cin >> in[2][0] >> in[2][1] >> in[2][2];
    cin >> out[2][0] >> out[2][1] >> out[2][2];
    for(int i=0;i<3;i++){
        solve(i);
        cout << out[i][0];
        for(int j=1;j<3;j++){
            cout << ' ' << out[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>
#include<math.h>
int max(int n,int m){
    if(n>m) return n;
    return m;
}
int main(void){
    int n,k,i,m,j;
    double p=0.0;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++){
        m=i;j=0;
        while(m<k){
            j++;
            m*=2;
        }
        p+=1.0/n*pow(0.5,j);
    }
    printf("%.12f\n",p);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> L(N);
	for (Int i = 0; i < N; i++) {
		cin >> L[i];
	}

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		for (Int j = i+1; j < N; j++) {
			for (Int k = j + 1; k < N; k++) {
              
              int sum = L[i]+L[j]+L[k];
              int maxv = max({L[i],L[j],L[k]});
              
              if(sum-maxv>maxv) ans++;

			}
		}
	}

	cout << ans << "\n";
}


Measured memory_bytes: 384
#! ruby -Ks

#配列の生成
height = []

10.times{
    #標準入力を整数に変換して配列に格納
    height.push(STDIN.gets.to_i)
}

#配列の並び替え
height.sort!

p height[-1]
p height[-2]
p height[-3]

Measured memory_bytes: 5648
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int a[n];
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
        a[i]*=n;
    }
    int ret=inf;
    int ans=0;
    rep(i,n){
        if(ret>abs(sum-a[i])){
            ret=abs(sum-a[i]);
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(int argc, char *argv[])
{
    char S[(int)(2e5 + 1)];
    long long ans = 0;
    int wnum = 0, i;

    gets(S);

    for (i = 0; S[i]; i++) {
        if (S[i] == 'W') {
            ans += i - wnum;
            wnum++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli a[5][2];
    loop(i,0,5){cin>>a[i][0];a[i][1]=0;}
    lli ans=0;
    for(lli i=0;i<5;i++){
    	if(a[i][0]%10==0)ans+=a[i][0],a[i][1]=1;
    	else {
    		ans+=(a[i][0]/10 +1)*10;
    	}
    }
    lli t=10;
    for(lli i=0;i<5;i++)if(a[i][1]==0)t=min(t,a[i][0]%10);
    if(t==10){cout<<ans;return 0;}
	cout<<ans-10+t;



 	return 0;
 }

Measured memory_bytes: 256
N, M, V, P = map(int, input().split())
A = sorted([int(a) for a in input().split()])
t = A[-P]
def chk(k):
    if A[k] >= t: return 1
    u = A[k] + M
    if u < t:
        return 0
    s = sum([min(M, u - A[i]) for i in range(N-P+1)])
    if s >= M * (V - P + 1):
        return 1
    return 0

l, r = -1, N-P
while r - l > 1:
    m = (l+r) // 2
    if chk(m):
        r = m
    else:
        l = m

print(N - r)

Measured memory_bytes: 119320
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int i=1;
        while(a != 0){
            System.out.printf("Case %d: %d\n",i,a);
            i++;
            a = sc.nextInt();
        }
    }
}


Measured memory_bytes: 67144
import java.util.Scanner;

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

    double num;

    num = sc.nextInt();

    double temporaryNum = 1;
    if (num < 4) {
      System.out.println(1);
      return;
    }

    for (int i = 2; Math.pow(i, 2) <= num; i++) {
      for (int n = 2; Math.pow(i, n) <= num; n++) {
         if (temporaryNum < Math.pow(i, n)) {
           temporaryNum = Math.pow(i, n);
         }
      }
    }
    System.out.println((int)temporaryNum);
    return;
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int N = 3e5+9;
int n,Q,sum[N];
char S[N];
priority_queue<int, vector<int>, greater<int> > que;
int flag[N*4],a[N*4];
int x,al,ar,add;
void build(int root,int l,int r) {
    flag[root] = 0;
    if(l==r) {
        a[root] = sum[l];
    }else{
        int mid=(l+r)>>1;
        build(root*2,l,mid);
        build(root*2+1,mid+1,r);
        a[root]=min(a[root*2],a[root*2+1]);
    }
}
void pushdown(int t) {
    if(t<<1 >= N*4)return;
    flag[t<<1]+=flag[t];flag[t<<1|1]+=flag[t];
    a[t<<1]+=flag[t];a[t<<1|1]+=flag[t];
    flag[t]=0;
}
void update(int root,int l,int r) {
    if(flag[root]!=0)pushdown(root);
    if(al <= l && r <= ar ) {
        a[root]+=add;flag[root]+=add;
    }else{
        int mid=(l+r)>>1;
        if(al<=mid)   update(root<<1,l,mid);
        if(ar>=mid+1) update(root<<1|1,mid+1,r);
        a[root]=min(a[root*2],a[root*2+1]);
    }
}
int ask(int root,int l,int r) {
    if(flag[root])pushdown(root);
    if(al<=l&&r<=ar) return a[root];
    int mid=(l+r)>>1;
    int ans=1e9;
    if (al<=mid) ans = min(ans,ask(root<<1,l,mid));
    if (ar>mid) ans = min(ans,ask(root<<1|1,mid+1,r));
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    while(cin>>n>>Q) {
        cin>>(S+1);
        while(!que.empty())que.pop();
        for(int i=1;i<=n;i++){
            if(S[i]=='(')sum[i]=sum[i-1]+1;
            else sum[i]=sum[i-1]-1;
            if(S[i]==')') que.push(i);
        }
        build(1,1,n);
        while(Q--){
            cin>>x;
            if(S[x] == '(' ) {
                que.push(x);
                S[x] = ')';al=x;ar=n;add=-2;
                update(1,1,n);
                while(!que.empty()){
                    x = que.top();que.pop();
                    if(S[x]==')') break;
                }
                S[x]='(';al=x;ar=n;add=2;
                update(1,1,n);
            }else{
                int l=1,r=x;
                S[x]='(';al=x;ar=n;add=2;
                update(1,1,n);
                while(l<r){
                    int mid=(l+r) >> 1;
                    al=mid;ar=x;
                    if(ask(1,1,n)>=2)r=mid;
                    else l=mid+1;
                }
                S[l] = ')';que.push(l);
                al=l;ar=n;add=-2;
                update(1,1,n);
                x=l;
            }
            cout<<x<<endl;
        }
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<ll> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    ll sum = accumulate(xs.begin(), xs.end(), 0LL);

    map<ll, ll> hs;

    for (auto x : xs)
        ++hs[x];

    int Q;
    cin >> Q;

    while (Q--)
    {
        ll b, c;
        cin >> b >> c;

        ll bs = hs[b];
        hs[b] = 0;

        sum -= bs*b;
        sum += bs*c;

        hs[c] += bs;

        cout << sum << '\n';
    }

    return 0;
}


Measured memory_bytes: 9904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int t; cin>>t;
	pair<double, string> arr[t];
	for(int i=0; i<t; i++){
		pair<double, string> aux;
		cin>>aux.first>>aux.second;
		arr[i]=aux;
	}
	double ans = 0;
	for(auto&x : arr){
		if(x.second == "BTC"){
			ans+=(x.first*380000);
		}
		else ans+=x.first;
	}
	cout<<ans<<endl;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> 
bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> 
bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

vector<bool> seen;
vii G;
int ans = 0;

void dfs(int v){
    bool end = true;
    for(int i=0;i<seen.size();i++){
        if(!seen[i]&&i!=v)end = false;
    }
    if(end){
        ans++;
        return;
    }
    
    seen[v] = true;
    for(auto nv : G[v]){
        if(seen[nv])continue;
        dfs(nv);
    }
    seen[v] = false;
    return;
}

int main(){
    int n,m;cin >> n >> m;
    G.assign(n,vi());
    seen.assign(n,false);

    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double l;
    cin>>l;
    cout<<fixed<<setprecision(12);
    long double ans=l/3;
    ans=pow(ans,3);
    cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    int a, b, c=0;
    cin>>a>>b;
    if (b>=a){cout<<"1";}
    else if (b<a)
    {
        while (a>0)
        {
            a=a-b;
            c++;
        }
        cout<<c;
    }
    return 0;
}

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

int main(){
    long long a,b,r,x;
    cin>>a>>b;
    x=a*b;
    if(a<b){
        swap(a,b);
    }
    r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    
    cout<<x/b<<endl;
    return 0;
}

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

int main() {
  ll a,b,c,d,ans;
  cin >> a >> b >> c >> d;
  ans=max(max(max(a*c,a*d),b*c),b*d);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3632
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////

    string A,s,C;
    char x;
    cin>>A>>s>>C;
    x=s.at(0);
    cout<<"A"<<x<<"C"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

// 各桁の和
template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  if(s[0] == 'S')print("Cloudy");
  else if(s[0] == 'C')print("Rainy");
  else print("Sunny");

  return 0;
} 

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

int main() {
  int N;
  cin >> N;
  vector<long long> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  int count1 = 0;
  long long count2 = 1;
  int count3 = 0;
  for (int j = 0; j < N; j++) {
    if (V.at(j) == 0)
      count1++;
  }
  if (count1 > 0)
    cout << 0 << endl;
  else {
    for (int k = 0; k < N; k++) {
      if (count3 == 0 && 1000000000000000000/count2 < V.at(k)) {
        cout << -1 << endl;
        count3++;
      }
      else
        count2 *= V.at(k);
    }
    if (count3 == 0)
      cout << count2 << endl;
  }
}

Measured memory_bytes: 3992
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


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

void solve() {
    int a,b , c, d;
    cin >> a >> b >> c >> d;
    int ans = a * c;
    chkmax(ans, b * d);
    chkmax(ans, a * d);
    chkmax(ans, b * c);
    put(ans);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;

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

    int n;
    cin >> n;
    vii A(n, vi(n, 0));

    rep(i, 0, n) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int v;
            cin >> v;
            A[u - 1][v - 1] = 1;
        }
    }

    rep(i, 0, n) {
        rep(j, 0, n) {
            cout << A[i][j];
            if (j != n - 1) { cout << " "; }
            else { cout << endl; }
        }
    }

    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int x, y; cin >> x >> y;
	int ans = 0;
	if(x == 1 and y == 1) ans += 400000;
	ans += max(0, (4 - x) * 100000);
	ans += max(0, (4 - y) * 100000);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
    
n=int(input())
l=list(map(int,input().split()))

a=l[0]
b=l[n-2]

cnt=0

for i in range(n-2):
	cnt+=min(l[i],l[i+1])
	
print(cnt+a+b)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>

using namespace std;

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

	int** gmtrx = new int*[n];
	for(int i=0; i<n; ++i){
		gmtrx[i] = new int[n];
		for(int j=0; j<n; ++j){
			gmtrx[i][j] = 0;
		}
	}

	for(int i=0; i<n; ++i){
		int v, num, a;
		scanf("%d %d",&v,&num);
		for(int j=0; j<num; ++j){
			scanf("%d",&a);
			gmtrx[v-1][a-1] = 1;
		}

	}

	for(int i=0; i<n; ++i){
		for(int j=0; j<n-1; ++j){
			cout << gmtrx[i][j] << " ";
		}
		cout << gmtrx[i][n-1] << endl;
	}

	for(int i=0; i<n; ++i){
		delete[] gmtrx[i];
	}
	delete[] gmtrx;

	return 0;
}



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

int main(){
    int h;
    while(cin >> h && h != 0){
        vector<vector<int>> field(h, vector<int>(5));
        for(int i = 0; i < h; i++){
            for(int j = 0; j < 5; j++){
                cin >> field[i][j];
            }
        }
        
        int ans = 0;
        
        while(1){
            bool flag = true;
            for(int i = 0; i < h; i++){
                if(field[i][0] == field[i][1] && field[i][1] == field[i][2] && field[i][2] == field[i][3] && field[i][3] == field[i][4] && field[i][4] != 0){
                    flag = false;
                    ans += field[i][0] * 5;
                    field[i][0] = field[i][1] = field[i][2] = field[i][3] = field[i][4] = 0;
                }
            }
    
            for(int i = 0; i < h; i++){
                if(field[i][0] == field[i][1] && field[i][1] == field[i][2] && field[i][2] == field[i][3] && field[i][3] != 0){
                    flag = false;
                    ans += field[i][0] * 4;
                    field[i][0] = field[i][1] = field[i][2] = field[i][3] = 0;
                }
                if(field[i][1] == field[i][2] && field[i][2] == field[i][3] && field[i][3] == field[i][4] && field[i][4] != 0){
                    flag = false;
                    ans += field[i][1] * 4;
                    field[i][1] = field[i][2] = field[i][3] = field[i][4] = 0;
                }
            }
    
            for(int i = 0; i < h; i++){
                if(field[i][0] == field[i][1] && field[i][1] == field[i][2] && field[i][2] != 0){
                    flag = false;
                    ans += field[i][0] * 3;
                    field[i][0] = field[i][1] = field[i][2] = 0;
                }
                if(field[i][1] == field[i][2] && field[i][2] == field[i][3] && field[i][3] != 0){
                    flag = false;
                    ans += field[i][1] * 3;
                    field[i][1] = field[i][2] = field[i][3] = 0;
                }
                if(field[i][2] == field[i][3] && field[i][3] == field[i][4] && field[i][4] != 0){
                    flag = false;
                    ans += field[i][2] * 3;
                    field[i][2] = field[i][3] = field[i][4] = 0;
                }
            }
    
            for(int i = h - 2; i >= 0; i--){
                for(int j = 0; j < 5; j++){
                    if(field[i+1][j] != 0) continue;
                    for(int k = i + 1; k < h; k++){
                        if(field[k][j] != 0){
                            field[k-1][j] = field[i][j];
                            field[i][j] = 0;
                            break;
                        }
                        if(k == h - 1){
                            field[k][j] = field[i][j];
                            field[i][j] = 0;
                        }
                    }
                }
            }
            if(flag){
                cout << ans << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 3108
import numpy as np
N,K = map(int,input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N,10**10,dtype=int)
dp[0] = 0
for i in range(1,N):
    dp[i:i+K] = np.fmin(dp[i:i+K], dp[i-1] + np.abs(h[i:i+K] - h[i-1]))
        
print(dp[-1])

Measured memory_bytes: 23088
#n,m = map(int,input().split())
#h = list(map(int,input().split()))

#ab = [map(int,input().split()) for _ in range(m)]
#a,b = [list(i) for i in zip(*ab)]

n = int(input())
a = list(map(int,input().split()))

cnt=0
"""
for i in range(n-1):
    for j in range(i+1,n-1):
        if j-i==a[j]+a[i]:
            #print(i,j)
            cnt+=1

"""

R=dict()
L=dict()

for i in range(n):
    if a[i]+i+1 in R:
        R[a[i]+i+1]+=1
    else:
        R[a[i]+i+1]=1

    if i+1-a[i] in L:
        L[i+1-a[i] ]+=1
    else:
        L[i+1-a[i] ]=1


for i in R:
    if i in L:
        cnt+=R[i]*L[i]

print(cnt)


    

Measured memory_bytes: 57332
//file_name:ABC44_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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


    ll ans = 0;

    if(n>k){
        ans += (n-k)*y;
        n = k;
    }

    ans += n*x;


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



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans,m;
int a[211111],b[211111],bsum[211111];
signed main(){
	cin>>n>>m>>k;
	a[0]=0;
	rep(i,n)cin>>a[i+1];
	rep(i,m)cin>>b[i];
	rep(i,m){
		bsum[i+1]=bsum[i]+b[i];
	}
	int sum=0;
	for(int i=0;i<n+1&&sum+a[i]<=k;i++){
		sum+=a[i];
		int l=-1,r=m+1,key=k-sum;
		while(abs(r-l)>1){
			int mid=(l+r)/2;
			if(bsum[mid]<=key)l=mid;
			else r=mid;
		}
		//cout<<l<<" "<<i+1<<endl;
		ans=max(ans,l+i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8344
def main(n, a):
  a = list(a)
  for x in a:
    if(x == 0):
      print(0)
      return
   
  ans = a[0]
  for i in range(1, n):
    ans = ans * a[i]
    if(ans > 1000000000000000000):
      print(-1)
      return
  print(ans)
 
if(__name__ == '__main__'):
  n = int(input())
  a = map(int, input().split())
  main(n, a)

Measured memory_bytes: 21472
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (LL i=a;i<=b;i++)
#define FORD(i,a,b) for (LL i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n;
char s[666];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if (n>=4 && s[1]=='Y' && s[2]=='A' && s[3]=='K' && s[4]=='I')
	puts("Yes");
	else
	puts("No");
}

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

int main(void){
    char c[10000];
    int joi,ioi;
    int i;
    while(scanf("%s",c)!=EOF){
        joi=0,ioi=0;
        for(i=0;i<=strlen(c);i++){
            if(c[i]=='J' && c[i+1]=='O' && c[i+2]=='I')joi++;
            if(c[i]=='I' && c[i+1]=='O' && c[i+2]=='I')ioi++;
        }
        printf("%d\n%d\n",joi,ioi);
    }
    return 0;
}

Measured memory_bytes: 552
import itertools
N=int(input())
l=[]
#l:調査情報のリスト
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
M=max(item[2] for item in l)#高さの最大値(暫定)
s=list(itertools.product(range(0,101),repeat=2))
#s:中心座標の候補リスト
for A,B in itertools.combinations(range(N),2):
  #調査情報の全ての2つ組を用いて絞り込む
  if len(s)==1:
    break
  t=[]
  #t:新たな中心座標の候補リスト
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    #2地点の高さが異なる場合
    if l[B][2]==0:
      #B地点の高さが0ならB地点は中心から[Aの高さ]以上離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      #B地点の高さが0でなければA地点は中心から[Aの高さ-Bの高さ]だけ離れている
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    #2地点の高さが等しく0ではない場合
    #2地点からM-[Aの高さ]以上離れた地点のみ残す
    for X,Y in s:
      MM=max(1,M-l[A][2])
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]) and abs(X-l[A][0])+abs(Y-l[A][1])>=MM and abs(X-l[B][0])+abs(Y-l[B][1])>=MM:
        t.append((X,Y))
  else:
    #2地点の高さが等しく0の場合
    #2地点からM以上離れた地点のみ残す
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]
#sの要素は唯一だと思いたい
a,b=s[0][0],s[0][1]
i=0
while l[i][2]==0:
  i+=1

h=abs(a-l[i][0])+abs(b-l[i][1])+l[i][2]
print(a,b,h)


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

int N, M;
int r, q;
class Record{
public:
  int t;
  int s;
  int n;
  int m;
  bool operator<(const Record &a) const {
    if(t != a.t) return t < a.t;
    if(s != a.s) return s < a.s;
    if(m != a.m) return m < a.m;
    return n < a.n;
  }
};

Record data[1000];


int solve(int &ts, int &te, int &m) {
  int i = 0;
  int state[1001];
  int ans = 0;
  Record tr[1000];
  int pr = 0;
  fill(state, state+1000, -1);
  int num = 0;
  for(i = 0; i < r; ++i) {
    if(data[i].m != m) continue;
    if(data[i].s) {
      ++num;
      if(num == 1) {
	tr[pr].s = 1;
	tr[pr].t = data[i].t;
	++pr;
      }
    } else {
      --num;
      if(num == 0) {
	tr[pr].s = 0;
	tr[pr].t = data[i].t;
	++pr;
      }
    }
  }

  for(i = 0; i < pr; ++i) {
    if(tr[i].s) {
      state[tr[i].n] = tr[i].t;
    } else {
      int tmp = state[tr[i].n];
      state[tr[i].n] = -1;

      if(tr[i].t < ts) continue;
      if(tmp > te) continue;

      if(tmp < ts && tr[i].t > te) ans += te - ts;
      else if(tmp < ts)              ans += tr[i].t - ts;
      else if(tr[i].t > te)        ans += te - tmp;
      else                           ans += tr[i].t - tmp;
    }
  }
  return ans;
}

main() {
  while((cin >> N >> M) && (N || M)) {
    cin >> r;
    for(int i = 0; i < r; ++i) {
      cin >> data[i].t >> data[i].n >> data[i].m >> data[i].s;
    }
    sort(data, data+r);
    cin >> q;
    for(int i = 0; i < q; ++i) {
      int ts, te, m;
      cin >> ts >> te >> m;
      cout << solve(ts, te, m) << endl;
    }
  }
}

Measured memory_bytes: 0
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int n; cin >> n;
    bool appr = true;

    while (n--) {
    	int x;
    	cin >> x;
    	if (x % 2 == 0) {
    		if (x % 3 == 0 || x % 5 == 0) {
    			continue;
    		}
    		appr = false;
    	}
    }

    if (appr) cout << "APPROVED";
    else cout << "DENIED";
    cout << endl;

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    H = list(int(x) for x in input().split())

    dp = np.zeros(N, dtype=int)
    H = np.array(H)

    for i in range(1, N):
        j = max(0,i-K)
        dp[i] = min(dp[j:i] + np.abs(H[i] - H[j:i]))

    print(dp[N-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 22868
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		List<String> alphabetList = new ArrayList<String>();
		alphabetList.add("a");
		alphabetList.add("b");
		alphabetList.add("c");
		alphabetList.add("d");
		alphabetList.add("e");
		alphabetList.add("f");
		alphabetList.add("g");
		alphabetList.add("h");
		alphabetList.add("i");
		alphabetList.add("j");
		alphabetList.add("k");
		alphabetList.add("l");
		alphabetList.add("m");
		alphabetList.add("n");
		alphabetList.add("o");
		alphabetList.add("p");
		alphabetList.add("q");
		alphabetList.add("r");
		alphabetList.add("s");
		alphabetList.add("t");
		alphabetList.add("u");
		alphabetList.add("v");
		alphabetList.add("w");
		alphabetList.add("x");
		alphabetList.add("y");
		alphabetList.add("z");
		int index = alphabetList.indexOf(input);
		System.out.println(alphabetList.get(index + 1));
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner =new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[99999999];
        boolean[] booleans=new boolean[99999999];
        for(int i=0;i<99999999;i++){
            ints[i]=i+2;
            booleans[i]=true;
        }
        for(int i=0;i<Math.sqrt(99999999)+1;i++){
            if(booleans[i]==false) continue;
            for(int j=(i+2)*2-2;j<99999999;j+=i+2){
                booleans[j]=false;
            }
        }
        int result=0;
        for(int i=0;i<n;i++){
            int x=scanner.nextInt();
            if(booleans[x-2]==true) result++;
        }
        System.out.println(result);
    }

}



Measured memory_bytes: 532056
#include <stdio.h>

int main() {
  int A;
  int B;
  int C;

  scanf("%d %d %d", &A, &B, &C);
  if(A+B==C) {
    printf("Yes\n");
  }
  else if(B+C==A) {
    printf("Yes\n");
  }
  
  else if(A+C==B) {
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    string s; cin >> s;
    int n = s.length();
    s = s.substr(0,n-8);
    cout << s << endl;
    return 0;
}

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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())
#define inf          1<<25

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

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

int main() {
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    vector<ll> sum(n);
    sum[0] = a[0];
    rep(i, n-1) sum[i+1] = sum[i] + a[i+1];
    
    ll min = inf;
    
    ll c = 0;
    ll d = 0;
    rep(i, n) {
        if (i % 2 == 0 and d + sum[i] > 0) continue;
        if (i % 2 == 1 and d + sum[i] < 0) continue;
        
        c += abs(d + sum[i]) + 1;
        if (i % 2 == 0) d += abs(d + sum[i]) + 1;
        if (i % 2 == 1) d -= d + sum[i] + 1;
    }
    min = c;
    
    c = 0;
    d = 0;
    rep(i, n) {
        if (i % 2 == 0 and d + sum[i] < 0) continue;
        if (i % 2 == 1 and d + sum[i] > 0) continue;
        
        c += abs(d + sum[i]) + 1;
        if (i % 2 == 0) d -= d + sum[i] + 1;
        if (i % 2 == 1) d += abs(d + sum[i]) + 1;
    }
    chmin(min, c);
    cout << min << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    int n, l;
    scanf("%d %d", &n, &l);
    vector<int> a(n+1);
    for (int i=1; i<n+1; i++) {
        a[i] = l + i -1;
    }
    int ma = 400;
    for(int i=1; i<n+1; i++) {
        if (abs(ma) >= abs(a[i])) {
            ma = a[i];
        }
    }
    //printf("%d\n", a[2]);
    //printf("ma : %d\n", ma);
    int ans = 0;
    for(int i=1; i<n+1; i++) {
        if (a[i] == ma) {continue;}
        ans += a[i];
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {
   
   long long int A,B,V,W,T;
   cin >> A >>V >> B >>W >>T;

   if(V>W){
         if(fabs(A-B)/fabs(W-V)<=T){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   }else{
   if(A==B){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   }

}

Measured memory_bytes: 3632
N, Y = map(int, input().split())

exists = False
for a in range(N + 1):
  for b in range(N + 1):
    c = N - a - b
    if (c < 0):
      continue

    if (10000 * a + 5000 * b + 1000 * c == Y):
      print(a, b, c)
      exists = True
      break
  
  if (exists == True):
    break

if (exists == False):
  print("-1 -1 -1")

Measured memory_bytes: 40920