akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<set>
#include<algorithm>

using namespace std;

int main(){
    int num_query,command,val;
    scanf("%d",&num_query);
    set<int> int_set;
    
    for(int i = 0;i < num_query;i++){
        scanf("%d %d",&command,&val);
        if(command == 0){
            int_set.insert(val);
            printf("%d\n",int_set.size());
        }else if(command == 1){
            auto itr = int_set.find(val);
            if(int_set.end() == itr) printf("0\n");
            else printf("1\n");
        }
    }
    
    return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

ll a[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%d", &a[i]);
	}
	ll l = 2, r = 2;
	for(int i = n - 1; i >= 0; i--){
		if (a[i] > r){
			printf("-1\n");
			return;
		}
		l = (l + a[i] - 1) / a[i] * a[i];
		r = r / a[i] * a[i] + a[i] - 1;
		if (l > r){
			printf("-1\n");
			return;
		}
	}
	cout << l << " " << r << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    map<ll, ll> m;
    rep (i, N) {
        ll A;
        cin >> A;
        m[A]++;
    }

    ll cnt = 0;
    for (auto it : m) {
        if (it.second > 1) {
            cnt += (it.second-1);
        }
    }

    if (cnt%2) {
        cout << m.size()-1 << endl;
    } else {
        cout << m.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N)cin >> a[i];
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int ans = 0;
	rep(i, 0, N)ans += ((i % 2 == 0 ? 1 : (-1))*a[i]);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {
	string s; cin >> s;

	regex r("(dream|dreamer|erase|eraser)+");

	if (regex_match(s, r)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}







}

Measured memory_bytes: 39808
X = int(input())

num_list = tuple(x**5 for x in range(10**4+1))
for i, a in enumerate(num_list):
    for j, b in enumerate(num_list):
        if a-b == X:
            print(i, j)
            exit(0)
        elif a+b == X:
            print(i, -j)
            exit(0)


Measured memory_bytes: 9576
#include<stdio.h>
long long step_variation(long long n){
  long long onebf = 0;
  long long twobf = 0;
  long long result = 0;
  long long oldresult = 0;
  long long i = 0;
  if(n==0){
    return 1;
  }else if(n==1){
    return 1;
  }else if(n==2){
    return 2;
  }else{
    onebf=2;
    twobf=1;
    for(i=0;i<n-2;i++){
      result = (onebf + twobf)%1000000007;
      twobf = onebf;
      onebf = result;
    }
    return result%1000000007;
  }
}

int main(){
  int n=0;
  int m =0;
  int a[100000] ={};
  int b[100000] = {};
  long long i = 0;
  long long total = 0;
  int successable = 0;
  scanf("%d %d",&n,&m);
  
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
  }
  
  //printf("%ld/",step_variation(5));
  for(i=0;i<m;i++){
    if(i==0){
      b[i] = a[i]-1;
    }else{
      b[i] = a[i] - a[i-1] -2;
    }
  }
  b[m] = (n-2)-a[m-1]+1;
  if(m==0){
    b[0] = n;
  }
  
  /*for(i=0;i<=m;i++){
    printf("%ld/",b[i]);
  }*/
  total = 1;
  for(i=0;i<m+1;i++){
    total = (total * step_variation(b[i]))%1000000007;
  }
  for(i=0;i<m-1;i++){
    if(a[i]+1 == a[i+1]){
        total = 0;
    }
  }
  printf("%lld",total);
  
  return 0;
}
      
  
      
      
    

Measured memory_bytes: 896
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
#define int long long
#define read(a) int a; cin >> a;
#define readarr(a, n) int a[(n) + 1] = {}; fori(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori(i, 1, n) {fori(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define rz resize
#define sz(s) (int)(s.size())
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define sort1(v) sort(v.begin(), v.end()) 
#define endl '\n'
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 
     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    //start from here

    read(n); readarr(a, n);
    int cnt[n+1] = {};

    set <int> s;
    fori(i, 1, n)
    {
    	cnt[a[i]]++; s.insert(a[i]);
    }
    int c = 0;
    fori(i, 1, n)
    {
    	if(cnt[i] > 0) c += (cnt[i]*(cnt[i]-1))/2;
    }
    fori(i, 1, n)
    {
    	c -= (cnt[a[i]]*(cnt[a[i]]-1))/2;
    	cnt[a[i]]--;
    	c += (cnt[a[i]]*(cnt[a[i]]-1))/2;

    	cout << c << endl;

    	c -= (cnt[a[i]]*(cnt[a[i]]-1))/2;
    	cnt[a[i]]++;
    	c += (cnt[a[i]]*(cnt[a[i]]-1))/2;

    }


    return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t=1;
  while(cin>>n,n){
    double a[n][2],p=0;
    for(int i=0;i<n;i++)
      cin>>a[i][0]>>a[i][1];
    for(int i=0;i<n;i++)
      p-=((a[i][0]-a[(i+1)%n][0])*(a[i][1]+a[(i+1)%n][1]))/2;
    printf("%d %.1f\n",t++,p);
  }
}

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

int main() {
  string n;
  cin >> n;

  int x = 0;

  for (char c : n) {
    int d = c - '0';
    x += d;
    x = x % 9;
  }

  if (x == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

vector<int> w;
int memo[300][300];

int calcMax(int l, int r){

    if(r < l){
        return 0;
    }

    int temp = memo[l][r];
    if(temp != -1){
        return temp;
    }

    if(r == l){
        memo[l][r] = 0;
        return 0;
    }

    if(r - l == 1){
        if(abs(w[l] - w[r]) <= 1){
            memo[l][r] = 2;
            return 2;
        }
        else{
            memo[l][r] = 0;
            return 0;
        }
    }

    int ret = 0;
    if(abs(w[l] - w[r]) <= 1 && calcMax(l + 1, r - 1) == (r - l - 1)){
        ret = max(ret, calcMax(l + 1, r - 1) + 2);
    }

    for(int i = l; i < r; i++){
        ret = max(ret, calcMax(l, i) + calcMax(i + 1, r));
    }

    /* for(int i = 1; i <= 2; i++){
        ret = max(ret, calcMax(l, r - i) + calcMax(r - i + 1, r));
    }*/

    memo[l][r] = ret;
    return ret;
}

int main(){

    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        w.resize(n);
        for(int i = 0; i < n; i++){
            cin >> w[i];
        }

        memset(memo, -1, sizeof(memo));

        int ans = calcMax(0, n - 1);

        cout << ans << endl;
    }

    return 0;
}


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

int main(void){
    int n;
    cin >>n;
    for(int i =6; i>=0; i--){
        if(n>=pow(2, i)){
            cout << pow(2, i) << endl;
            return 0;
        }
    }
}

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

int main() {
  int N; cin >> N;
  vector<int> A(100010, 1000000000);
  A.at(0) = 0;
  for (int i = 0; i < N; i++) {
    A.at(i+1) = min(A.at(i+1), A.at(i) + 1);
    for (int j = 1; i + pow(6, j) <= N; j++) {
      A.at(i + pow(6, j)) = min(A.at(i + pow(6, j)), A.at(i) + 1);
    }
    for (int k = 1; i + pow(9, k) <= N; k++) {
      A.at(i + pow(9, k)) = min(A.at(i + pow(9, k)), A.at(i) + 1);
    }
  }
  cout << A.at(N) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include   <cmath>

using namespace std;

int main(){
    int a,b,c;
    int A,B,C;
    int m;
    cin >> a >> b >> c;
    A = abs(a-b);
    B = abs(b-c);
    C = abs(c-a);
    m = max(A,B);
    m = max(C,m);
    cout << A + B + C -m << endl;
}   

Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
 
int main(){
  vector<vector<int>> grid(3,vector<int> (3));
  for(auto &x:grid){
    cin>>x[0]>>x[1]>>x[2];
  }
  vector<vector<bool>> hited(3,vector<bool> (3,false)); 
  int n,tmp;
  cin>>n;
  for(int a = 0;a<n;a++){
    cin>>tmp;
    for(int i = 0;i<3;i++){
      for(int j = 0;j<3;j++){
        if(tmp==grid[i][j]){
          hited[i][j]=true;
        }
      }
    }
  }
  for(int i=0;i<3;i++){
    int rowHits=0,columHits=0;
    for(int j=0;j<3;j++){
      if(hited[i][j]){
        rowHits++;
      }
      if(hited[j][i]){
        columHits++;
      }
    }
    if(columHits==3||rowHits==3){
      cout<<"Yes"<<"\n";  
      return 0;
    }
  }
 
  int diagHits=0;
  for(int i=0;i<3;i++){//diag
      if(hited[i][i]){
        diagHits++;
      }
  }
  if(diagHits==3){
    cout<<"Yes"<<"\n";  
    return 0;
  }
  int antiDiagHit=0;
  for(int i=0;i<3;i++){
      if(hited[i][2-i]){
        antiDiagHit++;
    }
  }
  if(antiDiagHit==3){
    cout<<"Yes"<<"\n";  
    return 0;
  }
  cout<<"No"<<"\n";  
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DStaticSushi solver = new DStaticSushi();
        solver.solve(1, in, out);
        out.close();
    }

    static class DStaticSushi {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            /* INPUT BEGIN */
            int n = in.nextInt();
            long c = in.nextLong();
            long[] x = new long[n];
            long[] v = new long[n];
            for (int i = 0; i < n; i++) {
                x[i] = in.nextLong();
                v[i] = in.nextLong();
            }
            /* INPUT END */

            /* PREPROCESS BEGIN */
            long c2 = c * 2;
            long[] r = new long[n + 1];//CALORIE INCOME(R)
            long[] mrd = new long[n + 1];//MAX  CALORIE(R)
            long[] mrd2 = new long[n + 1];//MAX CALORIE(R, CONSUMPTION DOUBLED)
            long[] l = new long[n + 1];//CALORIE INCOME(L)
            long[] mld = new long[n + 1];//MAX  CALORIE(L)
            long[] mld2 = new long[n + 1];//MAX CALORIE(L, CONSUMPTION DOUBLED)
            for (int i = 1; i <= n; i++) {//LETS CALC:3
                r[i] = r[i - 1] + v[i - 1];
                mrd[i] = Math.max(mrd[i - 1], r[i] - x[i - 1]);
                mrd2[i] = Math.max(mrd2[i - 1], r[i] - (x[i - 1] << 1));
                l[i] = l[i - 1] + v[n - i];
                mld[i] = Math.max(mld[i], l[i] - c + x[n - i]);
                mld2[i] = Math.max(mld2[i], l[i] - c2 + (x[n - i] << 1));
            }
            /* PREPROCESS END */

            /* DEBUG CODE START */
            //System.out.println(Arrays.toString(r));
            //System.out.println(Arrays.toString(mrd));
            //System.out.println(Arrays.toString(mrd2));
            //System.out.println(Arrays.toString(l));
            //System.out.println(Arrays.toString(mld));
            //System.out.println(Arrays.toString(mld2));
            /* DEBUG CODE END */

            long ans = 0;
            /* WE WANT TO MAXIMIZE mrd[i] + mld[n - i] */
            for (int i = 0; i <= n; i++) {
                ans = Math.max(ans, mrd[i] + mld2[n - i]);
                ans = Math.max(ans, mrd2[i] + mld[n - i]);
            }
            out.println(ans);/* OUTPUT */
        }

    }
}



Measured memory_bytes: 92128
[a,b,c,d]=[int(i) for i in input().split()]
if a<c:
  x1=a
  x2=c
  y1=b
  y2=d
else:
  x1=c
  x2=a
  y1=d
  y2=b
if y1<x2:
   c=0
elif x2<=y1<=y2:
   c=y1-x2
else:
   c=y2-x2
print(c)

Measured memory_bytes: 3060
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
for i in range(n):
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)


Measured memory_bytes: 24372
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    int x;
    cin >> x;
    
    int y = x / 500;
    x -= y * 500;
    int z = x / 5;
    
    cout << 1000 * y + 5 * z;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define lli long long int
using namespace std;

// Problem https://atcoder.jp/contests/abc048/tasks/abc048_b
// Ref https://atcoder.jp/img/arc064/editorial.pdf

lli f(lli NUMBER,lli x){
    lli result;
    result = 0;
    if(NUMBER == -1){
        result = 0;
    }
    else{
        result = (NUMBER / x) + 1;
    }

    return result;
}

int main(void){
    lli answer;
    answer = 0;
    lli a,b,x;
    cin >> a >> b >> x ;
    answer = f(b,x) - f(a-1,x);
    cout << answer << endl;
    return 0;
}


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

int main(){
	int K,sur,sum=0;
	vector<long long> ans[10];
	cin>>K;
	for(int i=1;i<=9;i++){
		ans[0].push_back(i);
		sum++;
		if(sum==K){cout<<i;return 0;}
	}
	for(int i=0;i<9;i++){
		for(int j=0;j<ans[i].size();j++){
			sur=ans[i][j]%10;
			if(sur!=0){
				ans[i+1].push_back(ans[i][j]*10+sur-1);
				sum++;
				if(sum==K){cout<<ans[i][j]*10+sur-1;return 0;}
			}
			ans[i+1].push_back(ans[i][j]*10+sur);
			sum++;
			if(sum==K){cout<<ans[i][j]*10+sur;return 0;}
			
			if(sur!=9){
				ans[i+1].push_back(ans[i][j]*10+sur+1);
				sum++;
				if(sum==K){cout<<ans[i][j]*10+sur+1;return 0;}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1272
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
ll a[N];

ll qpow(ll a,ll b)
{
	ll ans=1;
//	if(a==0) return 1;
	while(b>0){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
ll C(ll n,ll x)
{
	ll ans=a[n]*qpow(a[x]*a[n-x]%mod,mod-2);
	return ans%mod;
}
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll ans=0;
	a[0]=1;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]*i%mod;
	}
//	cout<<pow(5,5)<<endl;
//	cout<<qpow(5,5)<<endl;
	for(ll i=0;i<=k;i++){ 
		
		ans=(ans+m*qpow(m-1,n-i-1)%mod*C(n-1,i)%mod)%mod;
		//ll fuck=
		ans%=mod;
//		cout<<ans<<endl;
//		cout<<ans<<' ';
	}
	cout<<ans;

}


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

int main() {
  string s;
  cin >> s;
  int c = 0;

  if (s[0] == '1') c++;
  if (s[1] == '1') c++;
  if (s[2] == '1') c++;

  cout << c << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
ac,wa,tle,re=0,0,0,0
for _ in range(n):
    s=input().rstrip()
    if s=='AC':
        ac+=1
    elif s=='WA':
        wa+=1
    elif s=='TLE':
        tle+=1
    else:
        re+=1

print('AC x %d' % ac)
print('WA x %d' % wa)
print('TLE x %d' % tle)
print('RE x %d' % re)


Measured memory_bytes: 67916
#include <iostream>

using namespace std;

int main(){
    int N;
    //N本の木を定義
    int D;
    //Dを定義
    cin >> N >> D;
    //N,Dの順で標準入力
        cout << (N + D * 2) / (D * 2 +1) << endl;
        //N + 2D / 2D +1を計算して出力
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 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 set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
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;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int A,B;
  cin >> A >> B;
  if(A % 2 == 1 & B % 2 == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 1010
#define MAXM 200010
using namespace std;
int n,m,u,v;
int id[MAXN][MAXN],ans1[MAXN][MAXN],ans2[MAXN][MAXN],q[MAXN][2];
int ans[MAXM];
vector<int> a[MAXN];
void dfs(int x,int fa){
    ans1[fa][x]=1;
    for(int i=0;i<a[x].size();i++)
        if(ans1[fa][a[x][i]]==0)
            dfs(a[x][i],fa);
}
void dfs1(int x,int tag,int flag){
    q[x][flag]=tag;
    for(int i=0;i<a[x].size();i++)
        if(!q[a[x][i]][flag])
            dfs1(a[x][i],tag,flag);
}
int main(){
    SF("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        SF("%d%d",&u,&v);
        u--;
        v--;
        id[u][v]=i+1;
        a[u].push_back(v);
    }
    for(int i=0;i<n;i++)
        dfs(i,i);
    for(int i=0;i<n;i++){
        memset(q,0,sizeof q);
        q[i][0]=q[i][1]=-1;
        for(int j=0;j<a[i].size();j++)
            if(!q[a[i][j]][0])
                dfs1(a[i][j],j+1,0);
        for(int j=a[i].size()-1;j>=0;j--)
            if(!q[a[i][j]][1])
                dfs1(a[i][j],j+1,1);
        for(int j=0;j<a[i].size();j++)
            if(q[a[i][j]][0]!=j+1||q[a[i][j]][1]!=j+1)
                ans2[i][a[i][j]]=1;
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(ans1[j][i]==ans2[i][j]&&id[i][j])
                ans[id[i][j]]=1;
    for(int i=1;i<=m;i++){
        if(ans[i]==1)
            PF("same\n");
        else
            PF("diff\n");
    }
}


Measured memory_bytes: 15360
r=Array.new
n=gets.to_i
v1=gets.split(' ').map(&:to_i)
v2=gets.split(' ').map(&:to_i)

for p in 1..3 do
  s=0
  n.times do |i|
    s+=((v1[i]-v2[i]).abs)**p
  end
  s=s**(1/p.to_f)
  r.push(s)
end

s=0
n.times do |i|
  s=[s,(v1[i]-v2[i]).abs].max
end
r.push(s)

r.each do |a|
  printf("%f\n",a)
end

Measured memory_bytes: 8816
h, w = map(int, input().split())
s = [input() for _ in range(h)]
sy = [0] * w
ret = 0
for y in range(h):
    seqx = 0
    seqy = 0
    for x in range(w):
        if s[y][x] == '.':
            if sy[x] == 0:
                yy = y
                while yy < h and s[yy][x] != '#':
                    yy += 1
                sy[x] = yy - y
            seqx += 1
            seqy = max(seqy, sy[x])
            ret = max(ret, seqx + seqy - 1)
        else:
            seqx = 0
            seqy = 0
            sy[x] = 0
print(ret)

Measured memory_bytes: 68696
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n,m; cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
	}
	int mx=-1;
	sort(a,a+m);
	for(int i=1;i<m;i++)
	{
		mx=max(mx,abs(a[i]-a[i-1]));
	}
    int nxt=n-a[m-1];
	mx=max(mx,abs(nxt+a[0]));
	cout<<n-mx;
	
}

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;

int main() {
    int N, r;
    cin >> N;
    r = N % 10;
    if (r == 3) cout << "bon\n";
    else if (r == 0 || r == 1 || r == 6 || r == 8) cout << "pon\n";
    else cout << "hon\n";
}

Measured memory_bytes: 3628
// AtCoder ABC134: C - Exception Handling
// 2019.8.26 bal4u

#include <stdio.h>

//// 高速入力
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

char *out(char *s, int n) { // 非負整数の表示（出力）
	int i;

	if (!n) { *s = '0', *(s+1) = 0; return s; }
	s[11] = 0, i = 11; while (n) s[--i] = n % 10 + '0', n /= 10;
	return s+i;
}

void outs(char *s) { while (*s) pc(*s++); pc('\n'); }

int a[200005]; int N;

int main()
{
	int i, f, fi, s;
	char t1[15], t2[15], *s1, *s2;
	
	N = in(); f = s = 0;
	for (i = 0; i < N; i++) {
		a[i] = in();
		if (a[i] > f) s = f, f = a[i], fi = i;
		else if (a[i] > s) s = a[i];
	}
	s1 = out(t1, f), s2 = out(t2, s);
	
	for (i = 0; i < N; i++) {
		if (i == fi) outs(s2);
		else outs(s1);
	}
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e18+7;

Int par[100005];
Int sz[100005];

int main() {
    ios::sync_with_stdio(false);   
    Int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    Int cnt = 0;
    string t = "1" + s + "1";
    for (Int i = 0; i < n + 1; i++) {
       if (t[i] == '1' && t[i + 1] == '0') cnt++;
    }
    if (cnt <= k) {
        dump(n);
        return 0;
    }
    vector<Int> a(2 * k, 0);
    // a.emplace_back(0);
    cnt = 0;
    for (Int i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) {
            cnt++;
        }
        else {
            cnt++;
            a.emplace_back(cnt);
            cnt = 0;
        }
    }
    a.emplace_back(cnt + 1);
    for (Int i = 0; i < 2 * k + 2; i++) a.emplace_back(0);
    Int m = a.size();
    for (Int i = 0; i < m - 1; i++) a[i + 1] += a[i];
    //bool x = 
    Int ma = 0;
    for (Int i = s[0] == '0' ? 0 : 1; i < (Int)a.size() - (2 * k + 1); i += 2) {
        ma = max(ma, a[i + 2 * k + 1] - a[i]);
        // cout << a[i];
    }
    /* for (Int i = 0; i < (Int)a.size(); i++) cout << a[i] << " ";
    cout << endl; */
    dump(ma);
    return 0;
}

Measured memory_bytes: 2268
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);
            var B = cin.ReadIntArray(N);
            var C = cin.ReadIntArray(N - 1);
            var ans = 0;
            var frt = -1;
            for(int i = 0; i < N; i++)
            {
                ans += B[A[i] - 1];
                if (A[i] - frt == 1) ans += C[frt - 1];
                frt = A[i];
            }
            WriteLine(ans);
        }

        public long C(long n, long r)
        {
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;cin>>N;

    int mi=N+1;
    for(int i=2;i<=N;i*=2){
        if(N%i!=i-1){
            chmin(mi,N%i+1);
        }
    }
    cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 3080
n = int(input())

d = []
for i in range(n):
    d.append(list(map(int, input().split())))

def dice():
    cnt =0
    for i in range(n):
        if d[i][0] == d[i][1]:
            cnt += 1
            if cnt == 3:
                return "Yes"
                break
        else:
            cnt = 0
    return "No"

ans = dice()

print(ans)

Measured memory_bytes: 62384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

#define int long long
const int CN = 1e6 + 5;

int read(){
    int s = 0,ne = 1; char c = getchar();
    while(c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
    while(c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
    return s * ne;
}

int n, cnt = 0, ecnt = 0, X[CN], Y[CN]; map<int, int> idx, idy;

class fs {public: int u, v, w; bool operator < (const fs &a) const {return w < a.w;}} E[CN << 1];
void add(int x, int y, int z) {E[++ecnt].u = x, E[ecnt].v = y, E[ecnt].w = z;}

class dsu{
  public: int fa[CN]; dsu() {for(int i = 1; i <= 1000000; i++) fa[i] = i;}
    int fd(int x) {return fa[x] ^ x ? fa[x] = fd(fa[x]) : x;}
    bool mg(int x, int y) {int fx = fd(x), fy = fd(y); return fx ^ fy ? fa[fx] = fy, true : false;}
} D;

signed main()
{
    // freopen("_in.in", "r", stdin);

    n = read(), cnt = n;
    for(int i = 1; i <= n; i++){
        int x = read(), y = read();
        if(!idx.count(x)) idx[x] = ++cnt, X[ ++X[0] ] = x;
        if(!idy.count(y)) idy[y] = ++cnt, Y[ ++Y[0] ] = y;
        add(i, idx[x], 0), add(i, idy[y], 0);
    }

    sort(X + 1, X + X[0] + 1), sort(Y + 1, Y + Y[0] + 1);
    for(int i = 1; i < X[0]; i++) add(idx[ X[i] ], idx[ X[i + 1] ], X[i + 1] - X[i]);
    for(int i = 1; i < Y[0]; i++) add(idy[ Y[i] ], idy[ Y[i + 1] ], Y[i + 1] - Y[i]);

    sort(E + 1, E + ecnt + 1), n = cnt, cnt = 0; int ans = 0;
    for(int i = 1; i <= ecnt; i++){
        int u = E[i].u, v = E[i].v, w = E[i].w;
        if(!D.mg(u, v)) continue;
        ans += w; if(++cnt == n - 1) break;
    }

    printf("%lld", ans);
}

Measured memory_bytes: 34984
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <functional>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll k;
  cin >> k;
  k++;
  function<vector<int>(ll)> solve = [&] (ll k) {
    if (k == 1) {
      return vector<int>{};
    } else if (k % 2 == 0) {
      auto a = solve(k / 2);
      int ids = a.size();
      a.push_back(ids);
      return a;
    } else {
      auto a = solve(k - 1);
      int ids = a.size();
      a.insert(a.begin(), ids);
      return a;
    }
  };
  auto ok = solve(k);
  cout << 2 * ok.size() << '\n';
  for (int i = 0; i < (int) ok.size(); i++) cout << i + 1 << ' ';
  for (int x : ok) cout << x + 1 << ' ';
  cout << '\n';
}


Measured memory_bytes: 256
// Aizu Vol-5 0500: Card Game
// 2017.8.30 bal4u@uu

#include <stdio.h>

int main()
{
	int n, a, b;
	int sa, sb;

	while (scanf("%d", &n) && n) {
		sa = sb = 0;
		while (n-- > 0) {
			scanf("%d%d", &a, &b);
			if (a == b) sa += a, sb += b;
			else if (a > b) sa += a + b;
			else            sb += a + b;
		}
		printf("%d %d\n", sa, sb);
	}
	return 0;
}

Measured memory_bytes: 600
///By Stephan Ramirez dsramirezc@unal.edu.co
#include<bits/stdc++.h>
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
#define N 100005
using namespace std;
int n,m;
ll arr[N][2];
int main(){
	#ifdef LOCAL
		freopen("in.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif
    scanf("%d %d",&n,&m);
    vector<pair<int,int>> pr;
    for(int i=0;i<n;i++){
        ll a,b;
        scanf("%lld %lld",&a,&b);
        pr.push_back(make_pair(a,b));
    }
    sort(pr.begin(),pr.end());
    priority_queue<int> pq;
    int ind=0;
    ll ans=0;
    for(int i=1;i<=m;i++){
        while(ind<n && pr[ind].first<=i){
            pq.push(pr[ind].second);
            ind++;
        }
        ll aux=0;
        if(pq.size()>0){
            aux=pq.top();
            pq.pop();
        }
        ans+=aux;
    }
    cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 1908
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        HashMap<Integer,Boolean> map = new HashMap<Integer,Boolean>();
        boolean flg = false;
        for(int i=0;i<m;i++){
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            if(a==1){
                if(map.containsKey(b)){
                    flg = true;
                    break;
                }
                map.put(b, true);
            }
            if(b==n){
                if(map.containsKey(a)){
                    flg = true;
                    break;
                }
                map.put(a, true);
            }
        }
        System.out.println(flg?"POSSIBLE":"IMPOSSIBLE");
    }
}


Measured memory_bytes: 78508
import sys
input=sys.stdin.readline
n,m,s,t=map(int,input().split())

en=[[]for i in range(n+1)]
sn=[[]for i in range(n+1)]

for i in range(m):
    u,v,a,b=map(int,input().split())
    en[v].append((u,a))
    en[u].append((v,a))
    sn[v].append((u,b))
    sn[u].append((v,b))
#print(en)

import numpy as np
INF=10**20

def dijkstra(S, N, paths):
    from heapq import heappush,heappop
    q=[(0,S)]
    shortest=[INF]*N
    shortest[S]=0
    while len(q)>0:
        d0, src=heappop(q)
        if d0>shortest[src]:
            continue
        for dst, d1 in paths[src]:
            if d0+d1<shortest[dst]:
                shortest[dst]=d0+d1
                heappush(q, (d0+d1, dst))
    return np.array(shortest)
    
en=dijkstra(s,n+1,en)
sn=dijkstra(t,n+1,sn)

cost=[]
for i in range(1,n+1):
    cost.append(en[i]+sn[i])
cost=cost[::-1]
#print(cost)

ans=[]
mi=cost[0]
for i in range(n):
    ans.append(min(mi,cost[i]))
    mi=min(mi,cost[i])
ans=ans[::-1]
#print(ans)
for i in ans:
    print(10**15-i)


Measured memory_bytes: 81452
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int f(int n){
    if(n%2){
        return 3*n+1;
    }else{
        return n/2;
    }
}
    int a[1000001];
int main(void){
    int s;
    cin>>s;
    a[0]=s;
     map<int,int>mp;
    mp[s]=1;
    for(int i=1;i<=1000000;i++){
        a[i]=f(a[i-1]);
        if(mp.count(a[i])){
            cout<<i+1<<endl;
            return 0;
        }
        mp[a[i]]++;
    }

 return 0;   
}

Measured memory_bytes: 256
#encoding:utf-8 No.0002 2014.9.29
numbers = []

while gets
 number = $_.split

 2.times do |i|
  number[i] = number[i].to_i
 end
 
 numbers.push number
end

i = 0
while i < numbers.length
 puts "#{numbers[i][0] + numbers[i][1]}".length
 i += 1
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int mn[2005];

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,x;
    cin>>n>>x;
    int a[2*n+1];
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[n+i]=a[i];
        mn[i]=a[i];
        tot+=a[i];
    }

    for(int i=1;i<=n;i++)
    {
        int sum=0;
        for(int j=1+n;j<=2*n;j++)
        {
            mn[j-n]=min(mn[j-n],a[j-i]);
            sum+=mn[j-n];
        }
        tot=min(tot,sum+i*x);
    }
    cout<<tot;

} 


Measured memory_bytes: 3696
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef pair<int,bool> P;
vector<P> G[600];
bool visited[600];
int a[600],b[600],cnt;
vector<int> as[600],bs[600];
int dp[601][601];
void dfs(int x,int t){
	visited[x]=true;
	if(t==0){
		a[cnt]++;
		as[cnt].pb(x);
	}else{
		b[cnt]++;
		bs[cnt].pb(x);
	}
	for(auto u:G[x]){
		int v=u.fs;
		if(!visited[v]) dfs(v,(u.sc?t:1-t));
	}
}
int main(){
	while(true){
		int N,p,q,M;
		cin>>N>>p>>q;
		M=p+q;
		if(M==0) break;
		rep(i,M) G[i].clear();
		rep(i,M) visited[i]=false;
		rep(i,M) a[i]=b[i]=0;
		rep(i,M) as[i].clear();
		rep(i,M) bs[i].clear();
		cnt=0;
		rep(i,M+1) rep(j,M+1) dp[i][j]=-1;
		rep(i,N){
			int x,y;
			string a;
			cin>>x>>y>>a;
			x--,y--;
			bool same=(a[0]=='y');
			G[x].pb(P(y,same));
			G[y].pb(P(x,same));
		}
		rep(i,M) if(!visited[i]){
			dfs(i,0);
			cnt++;
		}
		dp[0][0]=0;
		rep(i,cnt){
			rep(j,M+1){
				if(dp[i][j]==-1) continue;
				if(dp[i][j]==-2){
					dp[i+1][j+a[i]]=-2;
					dp[i+1][j+b[i]]=-2;
				}else{
					if(dp[i+1][j+a[i]]==-1) dp[i+1][j+a[i]]=1;
					else dp[i+1][j+a[i]]=-2;
					if(dp[i+1][j+b[i]]==-1) dp[i+1][j+b[i]]=2;
					else dp[i+1][j+b[i]]=-2;
				}
			}
		}
		if(dp[cnt][p]==-2) puts("no");
		else{
			vector<int> ans;
			int now=p;
			while(cnt>0){
				if(dp[cnt][now]==0){

				}else if(dp[cnt][now]==1){
					now-=a[cnt-1];
					for(auto u:as[cnt-1]) ans.pb(u);
				}else{
					now-=b[cnt-1];
					for(auto u:bs[cnt-1]) ans.pb(u);
				}
				cnt--;
			}
			sort(all(ans));
			for(auto u:ans) cout<<u+1<<endl;
			cout<<"end\n";
		}
	}
}

Measured memory_bytes: 2388
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n;
    cin >> n;
    string ans = "APPROVED";

    rep(i, n){
        ll a;
        cin >> a;
        if(a%2 == 0){
            if(a%3 == 0 || a%5 == 0){}
            else ans = "DENIED";
        }

    }

    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    stop
        return 0;
}

Measured memory_bytes: 256
n=int(input())
line=input().split()
for i in range (n):
    line[i]=int(line[i])
 
b=[]
for i in range (n):
    b.append(22000*i+1)
a=b[:]
b.reverse()
 
for i in range (1,n):
    a[line[i]-1]+=i
 
print (" ".join(map(str,a)))
print (" ".join(map(str,b)))

Measured memory_bytes: 48536
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

d = defaultdict(int)


def prime_factorization(n):  # 素因数分解
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))
    return res


for a in A:
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            cnt = 0
            while a % i == 0:
                cnt += 1
                a //= i
            d[i] = max(d[i], cnt)
    if a != 1:
        d[a] = max(d[a], 1)

ans = 0
lcm = 1
for k, v in d.items():
    lcm *= pow(k, v, mod)
    lcm %= mod

for a in A:
    if a == 1:
        ans += lcm
        continue
    l = lcm*pow(a, mod-2, mod)
    ans += l
    ans %= mod

print(ans % mod)


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

int main(){
    int n,ans=0;cin>>n;vector<int> a(n+1,0),b(n),c(n);
    for(int i=0;i<n;i++) cin>>a.at(i);
    for(int i=0;i<n;i++) cin>>b.at(i);
    for(int i=0;i<n-1;i++) cin>>c.at(i);
    for(int i=0;i<n;i++){
        ans+=b.at(a.at(i)-1);
        if(a.at(i+1)-a.at(i)==1) ans+=c.at(a.at(i)-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N];

void solve()
{    
    ll n, m ,k;
    cin >> n >> k ; 
    vector<int> height(n);
    for ( int i=0 ; i<n; i++){
    	cin>>height[i] ;
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0 ;
    dp[1] = ( abs(height[1]-height[0]) + dp[0] )  ;

    for(int i = 2; i<n; i++ ) {
    	for ( int j = i-1; j>=0 && j>= i-k; j--)
    	dp[i] = min(abs(height[i]-height[j]) + dp[j], dp[i] ) ;
    }
    cout<<dp[n-1];

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}


// Xorawar

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

  vector<int> a(n);

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

  int diffMax = 0;
  int diffMaxStart, diffMaxEnd;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      // cout << (a[0] + k) - a[n - 1] << endl;
      if ((a[0] + k) - a[n - 1] > diffMax) {
        diffMax = (a[0] + k) - a[n - 1];
        diffMaxStart = a[n - 1];
        diffMaxEnd = a[0];
      }
    } else {
      if (a[i] - a[i - 1] > diffMax) {
        diffMax = a[i] - a[i - 1];
        diffMaxStart = a[i - 1];
        diffMaxEnd = a[i];
      }
    }
  }

  // cout << diffMax << endl;
  // cout << "Start: " << diffMaxStart << endl;
  // cout << "End: " << diffMaxEnd << endl;

  if (diffMaxStart > diffMaxEnd) {
    int tmp = diffMaxStart;
    diffMaxStart = diffMaxEnd;
    diffMaxEnd = tmp;
  }
  cout << k - (diffMax);
}

Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit
def input():
    return stdin.readline().strip()

setrecursionlimit((10**5) * 2)

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    i, j = map(int, input().split())
    i -= 1
    j -= 1
    edge[i].append(j)
    edge[j].append(i)

# root: 0
# edge1: parent→children
# edge2: child→parent
# tfに探索済かどうかを保存する
tf = [False] * n
tf[0] = True
edge1 = [[] for _ in range(n)]
edge2 = [-1] * n

def divide(i):
    for j in edge[i]:
        if tf[j]:
            continue
        else:
            tf[j] = True
            edge1[i].append(j)
            edge2[j] = i
            divide(j)

divide(0)

now = n - 1
l = [n-1]
while edge2[now] != -1:
    now = edge2[now]
    l.append(now)

root = l[len(l)//2 - 1]

def divide2(i):
    ans = 1
    for j in edge1[i]:
        ans += divide2(j)
    return ans

Snuke = divide2(root)
Fennec = n - Snuke

if Snuke < Fennec:
    print('Fennec')
else:
    print('Snuke')

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

int main(){
  int n,x;
  cin >> n >> x;
  int m[150];
  for(int i=0; i<n; i++){
    cin >> m[i];
  }
  int cost=0;
  for(int i=0; i<n; i++){
    cost += m[i];
  }
  sort(m,m+n);
  int s = m[0];
  int ans = n + (x-cost)/s;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iomanip>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N;
	cin >> N;

	vector<int> t(N), v(N), time(N + 1);
	for (int i = 0; i < N; i++) cin >> t[i];
	for (int i = 0; i < N; i++) cin >> v[i];
	for (int i = 0; i < N; i++) time[i + 1] = t[i] + time[i];
	DMP(time);
	int time_end = time.back();

	vector<int> speed(2 * time_end + 1);
	for (int i = 0; i < time_end; i++) speed[i] = i;
	for (int i = time_end; i <= 2 * time_end; i++) speed[i] = 2 * time_end - i;
	DMP(speed);

	for (int i = 0; i <= 2 * time_end; i++) {
		for (int j = 0; j < N; j++) {
			if (2 * time[j] <= i && i < 2 * time[j + 1]) speed[i] = min(speed[i], 2 * v[j]);
			else if (i < 2 * time[j]) speed[i] = min(speed[i], 2 * time[j] - i + 2 * v[j]);
			else speed[i] = min(speed[i], i - 2 * time[j + 1] + 2 * v[j]);
			DMP(j);
		}
	}
	DMP(speed);

	int ans = 0;
	for (int i = 0; i < 2 * time_end; i++) {
		ans += speed[i] + speed[i + 1];
	}
	DMP(ans);
	cout << fixed << setprecision(20) << ans / 8.0 << "\n";

	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        in.nextLine();
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        long res = 0;
        final int[] mp = new int[n + 1];
        for (int i = 0; i < n; i++) {
            if (i - arr[i] >= 0) {
                res += mp[i - arr[i]];
            }
            if (arr[i] + i <= n) {
                mp[arr[i] + i]++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 60036