akhauriyash/Code-Regression huggingface dataset:
//by bestFy 2018.1
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;

inline ll read() {
	char ch = getchar(); ll x = 0; int op = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') op = -1;
	for(; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
	return x*op;
}
inline void write(ll a) {
	if(a < 0) putchar('-'), a = -a;
	if(a >= 10) write(a/10); putchar('0'+a%10);
}

const int N = 100010, M = 200010;
const int mod = 1e9 + 7;
const ll inf = 1e18;
int n, m, s, t, cnt, cnt2, ans;
int head[N], head2[N], vis[N], f[2][N], in[N];
ll dis[2][N];
struct edge {
	int to, nxt, v;
	edge() {}
	edge(int x, int y, int z) { to = x, nxt = y, v = z; }
}e[M<<1], e2[M<<1];

inline void addedge(int x, int y, int z) { e[++ cnt] = edge(y, head[x], z); head[x] = cnt; }
inline void addedge2(int x, int y, int z) { e2[++ cnt2] = edge(y, head2[x], z); head2[x] = cnt2; }
inline void upd(int &x, int y) { x += y; if(x >= mod) x -= mod; }
inline int sqr(int x) { return (ll)x*x%mod; }
inline void spfa(int p, int s) {
	queue<int> q; q.push(s); for(int i = 1; i <= n; i ++) dis[p][i] = inf; dis[p][s] = 0;
	memset(vis, 0, sizeof vis); vis[s] = 1;
	while(!q.empty()) {
		int u = q.front(); q.pop(); vis[u] = 0;
		for(int i = head[u]; i; i = e[i].nxt) {
			int v = e[i].to;
			if(dis[p][v] > dis[p][u]+e[i].v) {
				dis[p][v] = dis[p][u]+e[i].v;
				if(!vis[v]) {
					vis[v] = 1; q.push(v);
					if(dis[p][q.back()] < dis[p][q.front()]) swap(q.front(), q.back());
				}
			}
		}
	}
}
inline void tp(int p) {
	queue<int> q;
	for(int i = 1; i <= n; i ++) if(!in[i]) { q.push(i); f[p][i] = 1; }
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i = head2[u]; i; i = e2[i].nxt) {
			int v = e2[i].to; in[v] --;
			upd(f[p][v], f[p][u]);
			if(!in[v]) q.push(v);
		}
	}
}
int main() {
	n = read(), m = read(), s = read(), t = read();
	for(int i = 1; i <= m; i ++) {
		int x = read(), y = read(), z = read();
		addedge(x, y, z); addedge(y, x, z);
	}
	spfa(0, s); spfa(1, t);//两边spfa分别以s,t为起点跑最短路
	for(int u = 1; u <= n; u ++)
		for(int i = head[u]; i; i = e[i].nxt) {
			int v = e[i].to;
			if(dis[0][u]+dis[1][v]+e[i].v == dis[0][t]) { addedge2(u, v, e[i].v); in[v] ++; }
		}
	tp(0); memset(in, 0, sizeof in); cnt2 = 0; memset(head2, 0, sizeof head2);
	for(int u = 1; u <= n; u ++)
		for(int i = head[u]; i; i = e[i].nxt) {
			int v = e[i].to;
			if(dis[1][u]+dis[0][v]+e[i].v == dis[0][t]) { addedge2(u, v, e[i].v); in[v] ++; }
		}
	tp(1);//跑拓扑，f[0/1][i]表示从s/t到i的最短路个数
	ans = sqr(f[0][t]);
	for(int u = 1; u <= n; u ++)
		if(dis[0][u]*2 == dis[0][t] && dis[1][u]*2 == dis[1][s]) upd(ans, mod-sqr((ll)f[0][u]*f[1][u]%mod));
	for(int u = 1; u <= n; u ++)
		for(int i = head2[u]; i; i = e2[i].nxt) {
			int v = e2[i].to;
			swap(u, v);
			if(dis[0][u]+dis[1][u] == dis[0][t] && dis[0][v]+dis[1][v] == dis[0][t] && dis[0][u]*2 < dis[0][t] && dis[1][v]*2 < dis[0][t])
				upd(ans, mod-sqr((ll)f[0][u]*f[1][v]%mod));
			swap(u, v);
		}
	write(ans); puts("");
	return 0;
}
/*
3 3
1 3
1 2 1
2 3 1
3 1 2
*/

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

#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long


int main()
{
	sup;
    
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(ll &i : v)
        cin >> i;
    
    ll ans = 0;
    
    for(int i = 0; i < n - 1; i++) {
        if(v[i] > v[i + 1]) {
            ans += (v[i] - v[i + 1]);
            v[i + 1] = v[i];
        }
    }

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

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n + 1), b(n);
	for (int i = 0; i < n + 1; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] <= b[i]) ans += a[i], b[i] -= a[i];
		else ans += b[i], b[i] = 0;
		if (a[i + 1] >= b[i]) ans += b[i], a[i + 1] -= b[i];
		else ans += a[i + 1], a[i + 1] = 0;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
t = []
for i in range(len(s)):
    t.append(chr(((ord(s[i]) - ord('A')) + n) % 26 + 65))
print(''.join(t))

Measured memory_bytes: 68260
def is_kaibun(s):
    for i in range(len(s)//2):
        if s[i] != s[len(s)-i-1]:
            return False
    return True

def is_strong(s):
    head = s[:(len(s)-1)//2]
    tail = s[(len(s)+2)//2:]
    if not is_kaibun(s):
        return False
    if not is_kaibun(head):
        return False
    if not is_kaibun(tail):
        return False
    return True

s = input()
print("Yes" if is_strong(s) else "No")



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int N;
  int a[100001];
  cin >> N;
  rep(i, N) cin >> a[i];

  int res = -1;
  int cnt = 0, idx = 0;
  rep(i, N) {
    idx = a[idx] - 1;
    cnt++;
    if (idx == 1) {
      res = cnt;
      break;
    }
  }

  cout << res << endl;
}

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

using ll = long long;

int main(){
    ll a,b,k;
    cin >> a >> b >> k;

    cout << max(a-k,ll(0)) << " " << max(ll(0),min(b,a+b-k)) << endl;
}

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    scanf("%d", &N);

    int counts[10][10]; // first and last can only be 1-9 since there are no leading 0s

    memset(counts, 0, sizeof(counts));

    for(int i=1; i <= N; i++){

        int first = to_string(i)[0] - '0';
        int last = i % 10;

        if(first == 0 || last == 0)
            continue;

        counts[first][last]++;

    }


    long long ans = 0;
    for(int i=0; i < 10; i++){
        for(int j=0; j < 10; j++){
            ans += counts[i][j] * counts[j][i]; // first one has counts[i][j] choices, while the second one has counts[j][i] choices. So total for (a, b) there are counts[i][j] * counts[j][i] choices
        }
    }

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

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    string s;
    cin >> s;
    if( (s[0] == s[1] || s[2] == s[3] ) && s[1] == s[2] ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = input()

s = list(s)
sowth = s.count('S') if 'S' in s else 0
east  = s.count('E') if 'E' in s else 0
north = s.count('N') if 'N' in s else 0
west  = s.count('W') if 'W' in s else 0

if (sowth + north != 0 and sowth * north == 0) or\
    (west + east != 0 and west * east == 0):
    print('No')
else:
    print('Yes')


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	ll n;
	cin>>n;
	int ans=0;
	set<ll> divisores;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			divisores.insert(i);
			divisores.insert(n/i);
		}
	}
	--n;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			divisores.insert(i);
			divisores.insert(n/i);
		}
	}
	++n;
	for(ll x:divisores){
		//cout<<"x="<<x<<endl;
		if(x==1) continue;
		ll aux = n;
		while(aux%x==0)
			aux/=x;
		if(aux%x==1)
			++ans;
	}
	cout<<ans<<endl;
}

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

Measured memory_bytes: 3856
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int d=sc.nextInt();
    int[] c=new int[26];
    for(int i=0;i<26;i++){
      c[i]=sc.nextInt();
    }
    int[][] s=new int[d][26];
    for(int i=0;i<d;i++){
      for(int j=0;j<26;j++){
        s[i][j]=sc.nextInt();
      }
    }
    int[] l=new int[26];
    for(int i=0;i<d;i++){
      int choice=choice(c,s[i],l,i+1);
      l[choice]=i+i;
      System.out.println(choice+1);
    }
  }
  static int choice(int[] c,int[] s,int[] l,int td){
    int no=0;
    for(int i=0;i<26;i++){
      no=no+c[i]*(td-l[i]);
    }
    int res=0;
    int rev=c[0]*(td-l[0])+s[0];
    for(int i=1;i<26;i++){
      int iv=c[i]*(td-l[i])+s[i];
      if((rev<iv)||(rev==iv&&s[res]<s[i])){
        res=i;
        rev=iv;
      }
    }
    return res;
  }
}

Measured memory_bytes: 47084
from sys import stdin, stdout  
  
n = stdin.readline()
arr = [int(x) for x in stdin.readline().split()] 

summation = 0
for x in arr: summation += x
sqsum = 0
for x in arr: sqsum += (x*x)

ans = (summation*summation - sqsum) // 2
ans = (ans % 1000000007)

stdout.write(str(ans)) 



Measured memory_bytes: 31388
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
ll n,m,ans,hh,a[3010],f[3010][3010],b[3010][2],c[3010][2],ny;
ll ksm(ll x,ll y){
	ll sej=1;
	while(y){
		if(y&1)sej=sej*x%p;
		x=x*x%p;
		y/=2;
	}
	return sej;
}
int main(){
	ll i,j,x,y;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(i=1;i<=n;i++)
	 for(j=1;j<=n;j++)if(a[i]>a[j])f[i][j]=1;
	ny=ksm(2,p-2);hh=1;
	while(m--){
		hh=hh*2%p;
		scanf("%lld%lld",&x,&y);
		if(x>y)swap(x,y);
		for(i=1;i<=n;i++)b[i][0]=f[i][x],b[i][1]=f[x][i],c[i][0]=f[i][y],c[i][1]=f[y][i];
		for(i=1;i<=n;i++)if(i!=x&&i!=y){
			f[x][i]=(b[i][1]*ny+c[i][1]*ny)%p;
			f[i][x]=(b[i][0]*ny+c[i][0]*ny)%p;
			f[y][i]=(c[i][1]*ny+b[i][1]*ny)%p;
			f[i][y]=(c[i][0]*ny+b[i][0]*ny)%p;
		}
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])*ny%p;
	}
	//printf("%lld\n",hh);
	for(i=1;i<n;i++)
	 for(j=i+1;j<=n;j++)ans=(ans+f[i][j]*hh)%p;
	printf("%lld",ans);
}
/*
f[i,j] a[i]>a[j]的概率 
*/

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

int main(){
	int n;
	cin >> n;
	
	if (n < 3) cout << "ばなな";
	else for (int i = 1; i <= n; i++){
		int x = i;

		if (x % 3 == 0) cout << " " << i;
		else while (x > 0){
			if (x % 10 == 3){
				cout << " " << i;
				break;
			}
			else x /= 10;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 998244353
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
ll power(ll x,ll y){
  if(y<=0) return 1;
  ll z=power(x,y/2);
  if(y%2) return ((z*z)%mod)*x%mod;
  return (z*z)%mod;
}
ll fact[200003];
ll invfact[200003];
ll Cr(ll x, ll y){
  return (((fact[x]*invfact[x-y])%mod)*invfact[y])%mod;
}
void solve(){
  int n,m,k;
  cin>>n>>m>>k;
  ll ans=0;
  fact[0]=1;
  rep(i,1,n+1) fact[i]=(i*fact[i-1])%mod;
  invfact[0]=1;


  rep(i,1,n+1) invfact[i]=(power(i,mod-2)*invfact[i-1])%mod;
  rep(i,0,k+1) {
    ans+=(((Cr(n-1,i)*m)%mod)*power(m-1,n-1-i))%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    {
      solve();
    }
}


Measured memory_bytes: 6708
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

def dfs(g,root,w):
    parent = [-1]*n
    enum = [-1]*n
    q = [root]
    while q:
        v = q.pop()
        for c,i in g[v]:
            if c != parent[v]:
                parent[c] = v
                enum[c] = i
                q.append(c)
    a = 0
    #print(parent,enum)
    while w != root:
        a |= 1<<enum[w]
        w = parent[w]
    return a
    

###################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,m = [int(i) for i in readline().split()]
#d = [int(i) for i in readline().split()]
MOD = 10**9+7

n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i)-1 for i in readline().split()]
    g[a].append((b,i))
    g[b].append((a,i))

m = int(input())

#使う要素のbitmask
res = [0]*m
for i in range(m):
    v,w = [int(i)-1 for i in readline().split()]
    res[i] = dfs(g,v,w)

ans = 1<<(n-1)
M = 1<<m
#print(res)
for mask in range(1,M):
    r = 0
    for j in range(m):
        if mask&(1<<j): r |= res[j]
    
    r = popcnt(r)
    c = popcnt(mask)
    if c%2:
        ans -= 1<<(n-1-r)
    else:
        ans += 1<<(n-1-r)

print(ans)
    
    










Measured memory_bytes: 43932
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int[] b=new int[n+1];
		long ans=0;
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			b[a[i]]++;
		}

		for(int m=0;m<n+1;m++) {
			ans+=((long)b[m])*((long)b[m]-1)/2;
		}
		for(int i=0;i<n;i++) {
			if(b[a[i]]>1) {
			ans=ans-b[a[i]]+1;
			}
			System.out.println(ans);
			if(b[a[i]]>1) {
				ans=ans+b[a[i]]-1;
				}
		}
	}
}


Measured memory_bytes: 91664
#include<bits/stdc++.h>
using namespace std;
const int nax= 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax];
int dist[nax];
bool visited[nax];

void dfs(int a){
    assert(!visited[a]);
    visited[a]=true;
    for(int b: edges[a]){
        dist[b]=max(dist[b], dist[a]+1);
        --in_degree[b];
        if(in_degree[b]==0) dfs(b);
    }
}

int main(){
    int N,M;
    cin>>N>>M;
    ++M;
    while(--M){
        int a,b;
        cin>>a>>b;
        edges[a].push_back(b);
        ++in_degree[b];
    }
    for(int i=1; i<=N; ++i){
        if(!visited[i] && in_degree[i]==0) dfs(i);
    }
    int ans=0;
    for(int i=0; i<=N; ++i){
        ans=max(ans, dist[i]);
    }
    cout<<ans<<"\n";

}

Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < k; i++) {
		int x;
		cin >> x;
		while (x--) {
			int t;
			cin >> t;
			t--;
			a[t]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (!a[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m; cin>>n>>m;
    int a[123],b[123];
    int i;
    for(i=n-1;i>0;i--)
    {
       b[i]=m-i; cout<<b[i]<<" ";
    }
    for(i=0;i<n;i++)
    {
        a[i]=m+i;
        cout<<a[i]<<" ";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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 / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll h,n,a,ans;
	std::cin >> h >> n;

	rep(i, 0, n) {
		std::cin >> a;
		h -= a;
	}
	if (h <= 0) {
		outn("Yes");
	}
	else {
		outn("No");
	}
	return 0;

}


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

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;



void solve() {
    int n, k; cin >> n >> k;
    ar<int,2> arr[k];
    for (int i = 0; i < k; i++) cin >> arr[i][0] >> arr[i][1];
    vector<int> dp(n + 1);
    dp[1] = 1, dp[2] = -1;
    for (int i = 1; i <= n; i++) {
        dp[i] = (dp[i] + dp[i - 1]) % MOD;
        for (auto [l, r] : arr) {
            if (i + l <= n) dp[i + l] = (dp[i + l] + dp[i]) % MOD;
            if (i + r + 1 <= n) dp[i + r + 1] = (dp[i + r + 1] - dp[i] + MOD) % MOD;
        }
    }
    cout << dp[n] << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; tc = 1;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

Measured memory_bytes: 3968
s=input()
a=[]
for i in range(1<<4):
  l=list("AKIHABARA")
  for j in range(len(l)):
    if i&(1<<j):
      if j==0:
        l[0]=""
      elif j==1:
        l[4]=""
      elif j==2:
        l[6]=""
      elif j==3:
        l[8]=""
  a.append("".join(l))
if s in a:
  print("YES")
else:
  print("NO")

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

public class  Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String sp;
        int n = Integer.parseInt(br.readLine());
       for (int i = 0; i < n; i++) {
            sp = br.readLine();
            if (sp.startsWith("insert")) {
                list.addFirst(sp.substring(sp.indexOf(" ") + 1));
            }else if (sp.equals("deleteFirst")) {
                list.removeFirst();
            } else if (sp.equals("deleteLast")) {
                list.removeLast();
            } else if (sp.startsWith("delete")) {
                list.remove(sp.substring(sp.indexOf(" ") + 1));
            }
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder ans = new StringBuilder();
        ans.append(list.poll());
        for (String s : list) {
            ans.append(" ");
            ans.append(s);
        }
        bw.write(ans.toString());
        bw.newLine();
        bw.close();
        br.close();
    }
}



Measured memory_bytes: 160484
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void) {
	int menu[5];
	int diffMin = 10;
	int last;
	for (int i = 0; i < 5; i++) {
		scanf("%d", &menu[i]);
		if ((menu[i] - 1) % 10 < diffMin) {
			diffMin = menu[i] % 10;
			last = i;
		}
	}
	// cout << last << "\n";
	int ans = 0;
	for (int i = 0; i < 5; i++) {
		if (i == last) ans += menu[i];
		else ans += ((menu[i] - 1) / 10 + 1) * 10;
		// cout << i << " " << ans << "\n";
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool judge(const P &p1,const P &p2){
  if(p1.first==p2.first) return p1.second>p2.second;
  return p1.first<p2.first;
}
int main(){
  ll n;
  cin>>n;
  ll lm=0,rm=1e9+7;
  ll max_width=0;
  vector<P> vec;
  for(int i=0;i<n;i++){
    ll l,r;
    cin>>l>>r;
    r++;
    lm=max(lm,l);
    rm=min(rm,r);
    max_width=max(max_width,r-l);
    vec.push_back(P(l,r));
  }
  ll ans=max_width+max(rm-lm,(ll)0);
  vector<P> v2;
  for(int i=0;i<n;i++){
    ll x=max(vec[i].second-lm,(ll)0),y=max(rm-vec[i].first,(ll)0);
    v2.push_back(P(x,y));
  }
  sort(v2.begin(),v2.end(),judge);
  ll kmin=1e9+7;
  for(int i=1;i<n;i++){
    kmin=min(v2[i-1].second,kmin);
    ans=max(ans,kmin+v2[i].first);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5872
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let NQ = lines.shift().trim().split(/\s/).map((v) => v - 0);
    let N = NQ[0], Q = NQ[1];
    let S = lines.shift().trim();
    let left = 0;
    let right = N - 1;
    for (let n = Q-1; n >= 0; n--) {
        let td = lines[n].trim().split(/\s/);
        let t = td[0], d = td[1];
        if (S.charAt(left - 1) === t && d === "R") left--;
        else if (S.charAt(left) === t && d === "L") left++;
        if (S.charAt(right) === t && d === "R") right--;
        else if (S.charAt(right + 1) === t && d === "L") right++;
        if (left > right) break;
    }
    console.log(right - left + 1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36812
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  int Plan1, Plan2;
  
  cin >> N >> A >> B;
  Plan1 = A * N;
  Plan2 = B;
  
  if (Plan1 < Plan2) {
    cout << Plan1 << endl;
  }
  else
    cout << Plan2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
  ll n;
  cin>>n;
  ll l=1,r=n;
  for(ll i=2; i*i<=n; i++){
    if(n%i==0){
      l=i;
      r=n/i;
    }
  }
  cout<<l+r-2<<endl;
}

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

int mod=1000000007;
int dp[110][5][5][5];

int main(){
  int N;
  cin >> N;
  dp[0][3][3][3]=1;
  for(int len=0;len<N;len++){
    for(int i=0;i<=3;i++){
      for(int j=0;j<=3;j++){
        for(int k=0;k<=3;k++){
          if(dp[len][i][j][k]==0){continue;}
          for(int a=0;a<=3;a++){
            if(a==2 && i==1 && j==0){continue;}
            if(a==2 && i==0 && j==1){continue;}
            if(a==1 && i==2 && j==0){continue;}
            if(a==2 && i==1 && k==0){continue;}
            if(a==2 && j==1 && k==0){continue;}
            dp[len+1][a][i][j]+=dp[len][i][j][k];
            dp[len+1][a][i][j]%=mod;
          }
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<=3;i++){
    for(int j=0;j<=3;j++){
      for(int k=0;k<=3;k++){
          ans+=dp[N][i][j][k];
          ans%=mod;
      }
    }
  }
  cout << ans << endl;
}

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, K = readnums()
    _ = readnums()
    print((N - 1) // (K - 1) + 1 if (N - 1) % (K - 1) else (N - 1) // (K - 1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 10484
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskD {
        static int log(long a  , long b){
            int ans = 0;
            while (a/b!=0){a/=b;ans++;}
            return ans;
        }
        static long pow(long a , long b){
            if (b==0)return 1;
            long v = pow(a , b/2);
            long ans = v*v;
            if (b%2!=0)ans*=a;
            return ans;
        }
        static  int[] count;
        static  boolean[] visited;
        static ArrayList<Integer>[] frinds;
        static int[] color ;
        public static void dfs(int v , int val){
            visited[v]=true;
            count[val]++;
            color[v]=val;
            if (frinds[v]!=null)for (int u: frinds[v]) {
                if (!visited[u]) dfs(u , val);
            }
        }
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr= new int[n];
            int[] count = new int[n+1];
            for (int i = 0; i <n ; i++) {
                arr[i]=in.nextInt();
                count[arr[i]]++;
            }
            long ans = 0;
            for (int i = 0; i <=n ; i++) {
                ans+=((long)count[i])*(((long)count[i])-1)/2l;
            }
            for (int i = 0; i <n; i++) {
                System.out.println(ans-(count[arr[i]]-1));
            }







        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 64164
#include <iostream>
#define INF 1e+9
using namespace std;
typedef long long ll;
ll H, W;

ll min_max(ll a, ll b, ll c) {
    ll min = a, max = a;
    if(min > b) min = b;
    if(min > c) min = c;
    if(max < b) max = b;
    if(max < c) max = c;
    return max - min;
}

int main() {
    cin >> H >> W;
    ll ans = INF, a, b, c, mm;
    a = (H/3) * W;
    b = ((H - H/3)/2) * W;
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = (H/3 + 1) * W;
    b = ((H - H/3 - 1)/2) * W;
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = (H/3) * W;
    b = (H - H/3) * (W/2);
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = (H/3 + 1) * W;
    b = (H - H/3 - 1) * (W/2);
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = H * (W/3);
    b = H * ((W - W/3)/2);
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = H * (W/3 + 1);
    b = H * ((W - W/3 - 1)/2);
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = H * (W/3);
    b = (H/2) * (W - W/3);
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    a = H * (W/3 + 1);
    b = (H/2) * (W - W/3 - 1);
    c = H * W - a - b;
    mm = min_max(a, b, c);
    if(ans > mm) ans = mm;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
N_array = [0] * N
for i in range(K):
    d = int(input())
    A_array = list(map(int, input().split()))
    for j in range(len(A_array)):
        N_array[A_array[j]-1] += 1

print(N_array.count(0))

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll x, y;
  cin >> x >> y;
  x--; y--;
  vector<ll> a = {1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};

  if (a[x] == a[y]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
#define BOOST        ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define AZ(x)        x.begin(),x.end()
#define fi           first
#define se           second
#define pb           push_back
#define emp          emplace_back
#define mp           make_pair
#define mt           make_tuple 
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); degub(_it, args); }
#define For(i,a,n)   for(auto i = a; i < n; i++)
#define int          long long
 
template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;
 
typedef long long ll;
typedef long double ld;
 
 
template<typename T>
// for super_map add a parameter Y above and replace "null_type" with "Y"
 
// set with two additional super powers
    // find_by_order(int k) - returns k'th smallest element (0-indexed)
    // order_of_key(int k) - returns number of elements strictly smaller than k.
using super_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
 
void degub(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>
void degub(istream_iterator<string> it, T a, Args... args) {
    cerr << "[" << *it << " : " << a << "] ";
    degub(++it, args...);
}
 
 
ll power(ll a,ll b)
{
    // a = a;
    ll result = 1;
 
    while(b)
    {
        if(b&1)
            result = (result*a);
        b >>= 1, a = (a*a);
    }
    return result;
}
 
ll super_rand(ll n) // Random number from set [0,n-1]
{
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}
 
 
 
/*
 
 
1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.
5. ffs (positon of first set bit), clz (leading 0s, max->32), ctz (trailing 0s), popcount (set bits). Don't use any of these on 0;
 
 
*/
 
 
 
// Don't code anything above this //
 
 
 
 
 
 
const int mod = 1e9+7, N = 1e5 + 5;
const ll INF = (ll)1e18 + 7LL;
 
int32_t main()
{
    BOOST
    
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // cout << "OUTPUT \n";
    // #endif


    int n;
    cin >> n;

    int a[n];
    string ans = "APPROVED";
    for(int i = 0; i < n; i++) 
    {
        cin >> a[i];
        if(a[i] % 2 == 0)
        {
            if(a[i] % 3 != 0 && a[i] % 5 != 0)
                ans = "DENIED";
        }
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
int n, q;
string code;

int pref[100100];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>q;
    cin>>code;

    for(int i=0;i<n;i++) {
        if(i == 0) continue;
        pref[i] = pref[i-1];
        if(code[i] == 'C' && code[i-1] == 'A') pref[i]++;
    }

    int l, r;
    while(q--) {
        cin>>l>>r;
        l--; r--;
        cout<<pref[r] - pref[l]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1488
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()

for line in file_input:
    x1, y1, x2, y2 = (map(int, line.split()))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

vs_x = sorted(vs_x)

# Segment Tree(Range Sum Query)
import math

m = 2 ** math.ceil(math.log(len(vs_x), 2))
ST = [0] * (2 * m - 1)

def switch(i):
    i += m - 1
    if ST[i]:
        d = -1
    else:
        d = 1
    ST[i] += d

    while i > 0:
        i = (i - 1) // 2
        ST[i] += d

def get_sum(s, t, k, l, r):
    if r < s or t < l:
        return 0
    elif s <= l and r <= t:
        return ST[k]
    else:
        mid = (l + r) // 2
        l_sum = get_sum(s, t, k * 2 + 1, l, mid)
        r_sum = get_sum(s, t, k * 2 + 2, mid + 1, r)
        return l_sum + r_sum

# Sweep
import bisect

EP.sort()
cnt = 0

for p in EP:
    e = p[1]
    if e == l or e == u:
        vs_i = bisect.bisect_left(vs_x, p[2])
        switch(vs_i)
    else:
        l_x = bisect.bisect_left(vs_x, e)
        r_x = bisect.bisect(vs_x, p[2]) - 1
        cnt += get_sum(l_x, r_x, 0, 0, m - 1)

# Output
print(cnt)

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

int main(void) {
  stack<int> s1;
  stack<pair<int,int> > s2;
  int  i = 0;
  char ch;
  int sum = 0, a = 0;
  
  while (cin >> ch) {
    i++;
    if (ch=='\\') {
      s1.push(i);
    } else if (ch=='/' && s1.size()>0) {
      int j = s1.top();
      s1.pop();
      sum += i - j;
      a = i - j;
      while (s2.size()>0 && s2.top().first>j) {  
        a += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j,a));
    }
  }
  
  vector<int> ans;
  while (s2.size()>0) {
    ans.push_back(s2.top().second);
    s2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " " << flush;
    cout << ans[i] << flush;
  }
  cout << endl;
}

Measured memory_bytes: 3232
import sys
input = sys.stdin.readline
n = int(input())
x = list(map(int,input().split()))

#n = 10**5
#x = list(range(10**5))
mod = 10**9 + 7

li = []
for i in range(n-1):
    li.append(x[i+1] - x[i])

dp = [0] * (n-1)
dp2 = [0] * (n-1)
dp3 = [0] * n
dp3[0] = 1

for i in range(n-1):
    dp3[i+1] = dp3[i] * (i+2)
    dp3[i+1] %= mod

dp[0] = x[1] - x[0]
dp2[0] = 1

for i in range(n-2):
    dp2[i+1] = dp2[i] * (i+2) + dp3[i]
    dp2[i+1] %= mod
ans = 0
for i in range(n-2):
    dp[i+1] = dp[i] * (i+2) + (x[i+2] - x[i+1]) * dp2[i+1]
    dp[i+1] %= mod

print(dp[-1] % mod)


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

int main() {

  int S;

  cin >> S;

  int f = S / 100;
  int b = S % 100;

  if (1 <= f && f <= 12 && 1 <= b && b <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if (1 <= f && f <= 12) {
    cout << "MMYY" << endl;
  } else if (1 <= b && b <= 12) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,K;
    cin >> N >> K;
    if(K % 2 == 1){
        ll n = N / K;
        cout << n * n * n << endl;
    }
    else{
        ll al = N / K;
        ll half = (N + K / 2) / K;
        cout << al * al * al + half * half * half << endl;
    }
}

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

int main() {
  int N;
  int tot1, tot2 = 0;
  cin >> N;

  vector<int> num(N);

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

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

  for (int i = 0; i < N; i++) {
	if (i % 2 == 0) {
  		tot1 = tot1 + num[i];
	} else {
		tot2 = tot2 + num[i];
	}
  }
  
  if (tot2 >= tot1) {
	cout << tot2 - tot1 << endl;
  } else {
	cout << tot1 - tot2 << endl;
  }
}

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

int main(void){

  int num,num1,num2,count;

  while(cin >> num1 >> num2){
    num = num1 + num2;
    count = 0;
    while(num >= 10){
      num = num / 10;
      count++;
    }

    cout << count + 1 << endl;
  }
  return 0;

}

Measured memory_bytes: 1164
#include<cstdio>
#include<algorithm>
#define MAXN 100000+9
using namespace std;

int n,K;
int num[MAXN];
int maxx;
int gg;

void solve(){
	gg=num[1];
	int i;
	for(i=2;i<=n;i++){
		gg=__gcd(gg,num[i]);
	}
	if(gg==1){
		printf("POSSIBLE\n");
		return;
	}
	for(i=1;i<=n;i++){
		if(num[i]<K)
			continue;
		else{
			if((num[i]-K)%gg==0){
				printf("POSSIBLE\n");
				return;
			}
		}
	}
	printf("IMPOSSIBLE\n");
}

int main(){
	scanf("%d%d",&n,&K);
	int i;
	for(i=1;i<=n;i++){
		scanf("%d",&num[i]);
		if(K==num[i]){
			printf("POSSIBLE\n");
			return 0;
		}
		maxx=max(maxx,num[i]);
	}
	if(K>maxx){
		printf("IMPOSSIBLE\n");
		return 0;
	}
	solve();
	return 0;
}

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

def main():
    S = input().strip()

    ans = 0
    for i in range(2 ** (len(S) - 1)):
        prev = int(S[0])
        tmp = 0
        for j in range(len(S) - 1):
            if i >> j & 1:
                tmp += prev
                prev = int(S[j + 1])
            else:
                prev = prev * 10 + int(S[j + 1])
        else:
            tmp += prev

        ans += tmp

    print(ans)

    
    

if __name__ == '__main__':
    main()




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

typedef struct{
  int id;
  int parent;
  int sibling;
  int depth;
  int height;
  int degree;
  int left;
  int right;
} node;

node tree[25];


int main(){

  int n,i,j,count,k,m,l,r;
  scanf("%d",&n);

 for(i=0;i<n;i++){
   tree[i].parent = -1;
   tree[i].sibling = -1;
   tree[i].degree = 0;
   tree[i].depth = 0;
   tree[i].height = 0;

 }
 
 for(i=0;i<n;i++){
   scanf("%d",&m);
   tree[m].id = m;
   scanf("%d%d",&tree[m].left,&tree[m].right);
   tree[tree[m].left].parent = m;
   if( tree[m].left != -1) tree[m].degree++;
   tree[tree[m].left].sibling = tree[m].right ;

   tree[tree[m].right].parent = m;
   if( tree[m].right != -1) tree[m].degree++;
   tree[tree[m].right].sibling = tree[m].left;
   }

 for(i=0;i<n;i++){
   j = i;
   while(tree[j].parent != -1){
     j = tree[j].parent;
     tree[i].depth++; 
   }
 }

for(i=0;i<n;i++){
  tree[i].height= height(i);
 }



 
 for(i=0;i<n;i++){
   printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",tree[i].id,tree[i].parent,tree[i].sibling,tree[i].degree,tree[i].depth,tree[i].height);
   if(tree[i].parent == -1) printf("root\n");
   else if(tree[i].left == -1 && tree[i].right == -1) printf("leaf\n");
   else printf("internal node\n");
 }
 
 return 0;
}
    
    
int height(int x){
  int r,l;
  if(tree[x].left == -1 && tree[x].right == -1) return 0;
  if(tree[x].left == -1) l=1+0;
  else  l=1+height(tree[x].left);
  if(tree[x].right == -1) r=1+0;
  else r=1+height(tree[x].right);
  if(l<=r) return r;
  else return l;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int main(){
	ll n,a;
	scanf("%lld%lld",&n,&a);
	if(n==1){puts("1");return 0;}
	ll r=n;
	fore(i,2,50){
		ll s=0;
		ll z=(ll)(floor(pow(n,1./i))+.5),w=1;
		fore(_,0,i)w*=z,s+=z;
		while(w<n)w/=z,w*=z+1,s++;
		r=min(r,s+(i-1)*a);
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0;i<n;i++){
			int out=0,base=0,point=0;
			while(out<3){
				String s=sc.next();
				if(s.equals("OUT"))out++;
				else if(s.equals("HIT")){
					if(base<3)base++;
					else point++;
				}
				else{
					point+=base+1;
					base=0;
				}
			}
			System.out.println(point);
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<llong> h(n);
  rep(i, n) cin >> h[i];

  for(int i = 1; i < n; i++){
    if(h[i] < h[i-1]) {
      cout << "No" << endl;
      return 0;
    }
    else if(h[i] > h[i-1]){
      h[i]--;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  long double l;
  cin >> l;
  long double ans = pow(l/3.0,3);
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
#define F first
#define S second
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <ll,ll> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin>>a>>b;
    ll s=(a+b);
    if((s%2)==0)
    {
        cout<<s/2<<endl;
    }
    else
        cout<<"IMPOSSIBLE\n";
} 


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

int main(){
  int x, a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;
  int count = 0;
  for (int i = 0; i <= a; i++){
    if (i * 500 > x) break;
    for (int j = 0; j <= b; j++){
      if (i * 500 + j * 100 > x) break;
      for (int k = 0; k <= c; k++){
        if (i * 500 + j * 100 + k * 50 > x) break;
        if (i * 500 + j * 100 + k * 50 == x) count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  char c;
  while(cin >> c){
    if(c=='7'){
      cout << "Yes\n";
      return;
    }
  }
  cout << "No\n";
  return;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 3648
# coding: utf-8
# Here your code !
 
def func():
    try:
        (n,m,l) = [ int(item) for item in input().rstrip().split(" ") ]
        matrix_A = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(n) ]
        matrix_B = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(m) ]
    except:
        return inputError()
        
    matrix_C = [ [ sum([ matrix_A[i][j]*matrix_B[j][k] for j in range(m) ]) for k in range(l) ] for i in range(n) ]
    result=""

    for vector in matrix_C:
        for item in vector:
            result+=str(item)+" "
        result=result.rstrip()
        result+="\n"
    print(result.rstrip())

def inputError():
    '''
    print("input Error")
    return -1
    '''
 
    print("input Error")
    return -1
     
func()

Measured memory_bytes: 9084
s = input()
a, b = int(s[:2]), int(s[2:])
if a >= 13 and a <= 99 or a == 00:
    if b >= 1 and b <= 12:
        print("YYMM")
    else:
        print("NA")
else:
    if b >= 1 and b <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    for (int i = 0; i < 1000000; i++){
        C -= B;
        if(C < 1){
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if(A < 1){
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3652