akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#define int unsigned long long
using namespace std;
int n,p,x;
int cnt;
int ans=1;
int pr[10000010],c[10000010];
int pp(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=res*a;
		a=a*a;
		b>>=1;
	}
	return res;
}
signed main()
{
	scanf("%lld%lld",&n,&p);
	if(n==1)
	{
		cout<<p;
		return 0;
	}
	int ss;
	ss=sqrt(p);
	for(int i=2;i<=ss;i++)
	{
		if(p%i==0)
		{
			cnt++;
			pr[cnt]=i;
			c[i]=0;
			while(p%i==0)
			{
				p=p/i;
				c[i]++;
			}
		}
		if(p==1)
			break;
	}
	int s;
	for(int i=1;i<=cnt;i++)
	{
		if(c[pr[i]]>=n)
		{
			s=c[pr[i]]/n;
			ans=ans*pp(pr[i],s);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 4352
# Aizu Problem 0003: Is it a Right Triangle?
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for __ in range(N):
    a, b, c = sorted([int(_) for _ in input().split()])
    print("YES" if c**2 == a**2 + b**2 else "NO")

Measured memory_bytes: 7756
#include <iostream>
             
            using namespace std;
            int main(){
            int A,B,K;
              cin>>A;
              cin>>B;
              cin>>K;
             
            int ans[1000];
              int c = 0;
              for(int i = 1;i < 1000;i++){
                if(A % i == 0 & B % i == 0){
         
            	ans[c] = i;
                c++;
                 }
              }
            cout<<ans[c - (K)];
              return 0;
            }

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

int main(void) {
  int a, b;
  cin >> a >> b;

  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,j,n,m;
    int a[100][100], b[100],answer[100]={};
    scanf("%d %d", &n, &m);
    for(i = 0; i < n; i++){
        for(j = 0;j < m;j++){
            scanf("%d ", &a[i][j]);
        }
    }
    for(i = 0;i < m;i++){
        scanf("%d", &b[i]);
    }
    
    for(i = 0;i < n;i++){
        for(j = 0;j < m;j++){
            answer[i] += (a[i][j]*b[j]);
        }
    }
    for(i = 0;i < n;i++){
        printf("%d\n", answer[i]);
    }
    return 0;
}



Measured memory_bytes: 1848
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <iostream>


using namespace std;

typedef long long ll;

int main(){
    ll A, B;
    cin >> A >> B;

    ll AA = ceil((double)A * 12.5);
    ll BB = ceil((double)B * 10);
    if (floor(AA * 0.1) == B){
        cout << AA << endl;
    }
    else{
        if (floor(BB * 0.08) == A){
            cout << BB << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <stdlib.h>
using namespace std;
int main(){
    stack<int> D;
    string S;
    while (cin>>S){
		if (S == "+"|| S=="-" || S=="*"){
			int b = D.top();
            D.pop();
            int a = D.top();
            D.pop();
            if (S=="+"){
			    D.push(b+a);
			}
			if (S=="-"){
				D.push(a-b);
			}
			if (S == "*"){
				D.push(a*b);
			}
		}
		else{
			D.push(atoi(S.c_str()));
		}
	}

	cout << D.top() << endl;

	return 0;
}


Measured memory_bytes: 3232
import java.util.Scanner;

public class Main{
        public static void main(final String[] args){
            final Scanner sc = new Scanner(System.in);
            final int a = sc.nextInt();
            final int b = sc.nextInt();
            if(a > b){
                System.out.println("a > b");
            }else if(a <  b){
                System.out.println("a < b");
            }else{
                System.out.println("a == b");
            }
            sc.close();
        }
}


Measured memory_bytes: 26196
# -*- coding: utf-8 -*-
"""
Created on Mon May 13 18:16:09 2019

@author: avina
"""

N, M, C = map(int , input().strip().split())
B = list(map(int , input().strip().split()))
l = [];cnt = 0
for i in range(N):
  g = list(map(int , input().strip().split()))
  l.append(g)
for i in range(N):
  sums = 0
  for j in range(M):
    sums += l[i][j]*B[j]
  if sums + C > 0:
    cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

int ds[100000][3];

int main() {
    std::size_t n{}, m{};
    std::cin >> n >> m;
    std::vector<std::vector<int>> to(n);
    for(std::size_t i = 0; i < m; ++i){
        int u{}, v{};
        std::cin >> u >> v;
        to[u - 1].emplace_back(v - 1);
    }
    std::size_t s{}, t{};
    std::cin >> s >> t;
    for(auto& d : ds){
        for(auto& e : d)
            e = -3;
    }
    std::queue<std::pair<int, int>> q{};
    q.emplace(--s, 0);
    ds[s][0] = 0;
    while(!q.empty()){
        const auto& f = q.front();
        const auto v = f.first;
        const auto l = f.second;
        for(auto u : to[v]){
            const auto nl = (l + 1) % 3;
            auto& d = ds[u][nl];
            if(d < 0){
                d = ds[v][l] + 1;
                q.emplace(u, nl);
            }
        }
        q.pop();
    }
    std::cout << ds[t - 1][0] / 3 << std::endl;
    return 0;
}

Measured memory_bytes: 6912
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()),b=Long.parseLong(sc.next()),k=Long.parseLong(sc.next());
        if(k>=a){
            k-=a;
            b = Math.max(b-k,0);
            System.out.println(0+" "+b);
        } else {
            System.out.println(a-k+" "+b);
        }
    }
}

Measured memory_bytes: 22996
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    ll a,b,c;
    cin >> a >> b >> c;
    cout << (a+b+c > 21 ? "bust" : "win") << endl;
}


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

int main()
{
    string s;
    cin >> s;
    char flag = '0';
    char color = '0';
    int temp = 0;

    for (int i = 0; i < s.length(); i++) {
        color = (char)s[i];
        // cout << "flag: " << flag << " color: " << color << endl;

        if (flag == color) temp += 1;

        if (flag == '1') flag = '0';
        else flag = '1';
    }

    if (2*temp < s.length()) {
        // cout << "s.length() - temp = " << s.length() - temp << endl << "temp = ";
        cout << temp << endl;
    } else {
        // cout << "temp = " << temp << endl << "s.length() - temp = ";
        cout << s.length() - temp << endl;
    }

    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))

b = a[0]
c = a[1]
d = a[2]
e = sum(a[3:n])
p = 0
q = 1
r = 2
while r+1 <= n-2 and abs((d+a[r+1])-(e-a[r+1])) < abs(d-e):
    r += 1
    d += a[r]
    e -= a[r]
m = max(b,c,d,e) - min(b,c,d,e)

while q <= n-4:
  q += 1
  c += a[q]
  d -= a[q]
  while p+1 <= q-1 and abs((b+a[p+1])-(c-a[p+1])) <= abs(b-c):
    b += a[p+1]
    c -= a[p+1]
    p += 1
  while r+1 <= n-2 and abs((d+a[r+1])-(e-a[r+1])) <= abs(d-e):
    d += a[r+1]
    e -= a[r+1]
    r += 1
  m = min(m,max(b,c,d,e) - min(b,c,d,e))
print(m)
  

Measured memory_bytes: 25672
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
map<char,int>::iterator it;
  vector<int>v;
int main()
{
  int n,a,mx=0,c=0,b;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      cin>>a;

if(i!=0)
{
    if(b>=a){c++;}
    else{c=0;}

}
if(mx<c){mx=c;}
b=a;


  }


cout<<mx<<endl;

}


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();
        int List [] = new int[100001];
        int root = sc.nextInt();
        List[root]++;
        long opt = 1;
        int max = 0;
        for(int i=1;i<N;i++){
            int num = sc.nextInt();
            List[num]++;
            if(max<num) max= num;
        }
        if(root==0&&List[0]==1){
            for(int i=1;i<max;i++){
                if(List[i]!=0&&List[i+1]!=0){
                    long each = 1;
                    for(int j=0;j<List[i+1];j++)  each=each*List[i]%998244353;
                    opt = opt*each%998244353;
                }
                else{
                    opt = 0;
                    break;
                }
            }
        }
        else opt =0;
        System.out.println(opt);
    }
}

Measured memory_bytes: 51928
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

ptnp = list(permutations(p))
ptnq = list(permutations(q))

ptnp.sort()
ptnq.sort()

a = 0

for i in range(len(ptnp)):
    if ptnp[i] == p:
        a = i
        break

b = 0

for i in range(len(ptnq)):
    if ptnq[i] == q:
        b = i
        break

print(abs(a-b))

Measured memory_bytes: 12788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL n;
    LL k;
    cin>>n>>k;
    n=n%k;
    if(n>k/2){n=k-n;}
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
	var line = input.split('\n');
	var n = parseInt(line[0], 10);
	line.sort();
	var count = 1;
	var anser = new Array();
	var anserN = new Array();
	anser.push(line[2]);
	for(var i=3; i<n+2; i++){
		if(line[i] == line[i-1]){
			count++;
		}else{
			anser.push(line[i]);
			anserN.push(count);
			count = 1;
		}
	}
	anserN.push(count);
	var max = 0;
	for(var i=0; i<anserN.length; i++){
		if(anserN[i] > max){
			max = anserN[i];
		}
	}
	var ans = new Array();
	for(var i=0; i<anserN.length; i++){
		if(anserN[i] == max){
			ans.push(anser[i]);
		}
	}
	for(var i=0; i<ans.length; i++){
		console.log(ans[i]);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 52164
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#define priority_queue __gnu_pbds::priority_queue
typedef long long LL;
typedef long double LD;
typedef unsigned long long ul;
#define ri register int
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define FO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef vector<int> vi;
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define G \
	struct node { int v; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v) { e[++z].v = v; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v) { adde(u, v); adde(v, u); }
#define W \
	struct node { int v, w; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v, int w) { e[++z].v = v; e[z].w = w; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v, int w) { adde(u, v, w); adde(v, u, w); }
inline int _() // ret >= 0
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	do { ret = ret * 10 + ch - '0'; ch = getchar(); } while('0' <= ch && ch <= '9');
	return ret;
}
inline void _(int x) // x >= 0
{
	if(x < 10) { putchar(x + '0'); return ; }
	_(x / 10); putchar(x % 10 + '0');
}
void What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(16);
}
/* Default Code Ends Here. */

#define maxn 2010
#define maxm 4010
int n, k;
G
namespace s1
{
	int dfs(int x, int fa, int dep)
	{
		if(dep == k / 2)
			return 1;
		int ret = 1;
		ae(x)
			if(p->v != fa)
				ret += dfs(p->v, x, dep + 1);
		return ret;
	}
	void solve()
	{
		int Ans = 0;
		enum(i, 1, n)
			Ans = max(Ans, dfs(i, 0, 0));
		cout << n - Ans << endl;
	}
}
namespace s2
{
	int dfs(int x, int fa, int dep)
	{
		if(dep == k / 2)
			return 1;
		int ret = 1;
		ae(x)
			if(p->v != fa)
				ret += dfs(p->v, x, dep + 1);
		return ret;
	}
	void solve()
	{
		int Ans = 0;
		enum(i, 1, n)
			ae(i)
				Ans = max(Ans, dfs(i, p->v, 1) + dfs(p->v, i, 1));
		cout << n - Ans << endl;
	}
}
int main()
{
	What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us();
	
	cin >> n >> k;
	k ++;
	int u, v;
	enum(i, 1, n - 1)
	{
		cin >> u >> v;
		addrev(u, v);
	}
	if(k & 1)
		s1::solve();
	else
		s2::solve();
	return 0;
}


Measured memory_bytes: 384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//18:08~
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	int n,i,j,ans=-1;cin>>n;
	vector<vector<int>>sen(n+1,vector<int>(n));
	for(i=0;i<n;i++){
		for(j=0;j<n-1;j++){
			cin>>sen[i][j];sen[i][j]--;
		}
		sen[i][n-1]=n;
		REV(sen[i]);
	}
	sen[n]=vector<int>(1,n);
	
	vector<int>kou(n);
	for(i=0;i<n;i++){kou[i]=i;}
	while(kou.size()){
		ans++;
		vector<bool>ugo(n+1);
		for(auto it:kou){
			//cerr<<it<<endl;
			if(sen[sen[it].back()].back()==it){
				ugo[sen[it].back()]=true;
				ugo[it]=true;
			}
		}
		kou.clear();
		for(i=0;i<n;i++){
			if(ugo[i]){kou.pub(i);sen[i].pob();}
			
		}
	}
	for(i=0;i<n;i++){if(sen[i].back()!=n){cout<<-1<<endl;return 0;}}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <map>
typedef long long lld;
const int MAXN = 2e5+5;
const int MOD = 1e9+7;
int size[MAXN][2]{ };
int  two[MAXN];
lld A, B;
int K, N;
int ret, zero;

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

struct Frac {
  lld A, B;

  // Overflow potential  
  bool operator < (const Frac& o) const {
    return (A != o.A) ? (A < o.A) : (B < o.B);
  }
  
  void reduce() {
    lld G = gcd(A, B);
    A /= G;
    B /= G;
    return this->sign();
  }
  
  void sign() {
    if (B > 0) return;
    if ((A >= 0) && (B >= 0)) return;
    // Skip: [+,+] [+,=] [=,+] [=,=] [-,+]
    // Flip: [+,-] [=,-] [-,=] [-,-]
    A *= -1;
    B *= -1;
  }
};
std::map<Frac, int> C;
Frac f;

void compute(int i) {
  if (!f.A && !f.B) {
    ++zero;
    return;
  }
  f.reduce();
  if (C.count(f)) {
    ++size[C.at(f)][0];
    return;
  }
  Frac g = {-f.B, f.A};
  g.sign();
  if (C.count(g)) {
    ++size[C.at(g)][1];
    return;
  }
  C[f] = K++;
  ++size[C.at(f)][0];
}

void init() {
  two[0] = 1;
  for (int i = 1; i <= N; ++i) {
    two[i] = 2LL * two[i-1] % MOD;
  }
}

int main() {
  scanf("%d", &N);
  init();
  zero = 0;
  for (int i = 1; i <= N; ++i) {
    scanf(" %lld%lld", &f.A, &f.B);
    compute(i);
  }
  ret = 1;
  for (int i = 0; i < K; ++i) {
    int cnt = (1LL * two[size[i][0]] + two[size[i][1]]) % MOD;
    cnt = (1LL * cnt - 1 + MOD) % MOD;
    ret = 1LL * ret * cnt % MOD;
  }
  ret = (1LL * ret - 1 + MOD) % MOD;
  ret = (1LL * ret + zero) % MOD;
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 18028
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
//#define double long double
#define INF (int)1e9
#define pb push_back
using namespace std;

long long int ncm(long long int n,long long int m){
  if(m>0) return (ncm(n,m-1)*(n-m+1))/m;
  else return 1;
}

int main(void){
  long long int n;
  vector<long long int> v;
  long long int a,b,i,ave;
  double x,lastv,resave;
  long long int numlv,allv,res;
  long long int nave;
  cin>>n>>a>>b;
  for(i=0;i<n;i++){
    cin>>x;
    v.pb(x);
  }
  sort(v.begin(),v.end(),greater<double>());
  res=0;
  nave=0;
  ave=0;
  lastv=-1;
  numlv=0;
  
  for(i=0;i<a;i++){
    if(lastv==v[i]) numlv++;
    else numlv=1;
    nave++;
    ave+=v[i];
    lastv=v[i];
  }
  
  allv=0;
  i=a-1;
  while(i>=0&&v[i]==lastv){
    allv++;
    i--;
  }
  i=a;
  while(i<n&&v[i]==lastv){
    allv++;
    i++;
  }

  res+=ncm(allv,numlv);
  resave=(double)ave/(double)nave;
  for(i=nave;i<b;i++){
    //if(resave!=((ave+v[i])/(nave+1))) break;
    if(ave*(nave+1)!=(ave+v[i])*nave) break;
    else{
      numlv++;
      ave+=v[i];
      nave++;
      res+=ncm(allv,numlv);
    }
  }
  printf("%.6f\n",resave);
  printf("%lld\n",res);
  
  return 0;
}

Measured memory_bytes: 256
import sys


def input(): return sys.stdin.readline().rstrip()


class Combi():
    def __init__(self, N, mod):
        self.power = [1]*(N+1)
        self.rev = [1]*(N+1)
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod


def main():
    mod = 10**9+7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    c = Combi(N, mod)
    res = 0
    for i, v in enumerate(A):
        res += c.com(i, K-1)*v
        res -= c.com(N-1-i, K-1)*v
        res %= mod
    print(res)
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 21172
university = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    university[b - 1][f - 1][r - 1] += v
c1 = c2 = 0
for building  in university:
    c2 = 0
    for floor in building:
        for room in floor:
            print(' {}'.format(room), end = '')
        if c2 != 2:
            print('')
        c2 += 1
    if c1 != 3:
        print('\n####################')
    c1 += 1
print('')



Measured memory_bytes: 5628
#include <iostream>
#include <vector>
#include <cstdlib>
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; }

const int MAX_N = 30;

int main() {
    while (true) {
        // input
        int n; cin >> n;
        
        if (n == 0) break;

        // initialize DP table
        int dp[MAX_N + 1];
        for (int i = 0; i <= n; i++) dp[i] = 0;

        // initial condition
        dp[0] = 1;

        for (int i = 1; i <= n; i++) {
            dp[i] = dp[i - 1];
            if (i > 1) dp[i] += dp[i - 2];
            if (i > 2) dp[i] += dp[i - 3];
        }

        int year = (dp[n] + 3649) / 3650;
        cout << year << endl;
    }
    return 0;
}


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

using ll = long long;
static const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  ll keep = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    keep += a.at(i);
  }
  keep %= MOD;
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    keep = (keep + MOD - a.at(i)) % MOD;
    ans += (a.at(i) * keep) % MOD;
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 4752
s = input()
l = len(s)
c = 0
ans = [0] * l
cnt = 0

for c in range(l):
	if s[c] == 'R':
		cnt += 1
	elif s[c] == 'L':
		ans[c-1] += cnt // 2 + cnt % 2
		ans[c] += cnt // 2
		cnt = 0

for d in range(l-1, -1, -1):
	if s[d] == 'L':
		cnt += 1
	elif s[d] == 'R':
		ans[d+1] += cnt // 2 + cnt % 2
		ans[d] += cnt // 2
		cnt = 0

print(*ans)


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;
    vector<int> p(N+1);
    vector<vector<int>> tree(N+1);
    rep(i,1,N+1){
        cin >> p[i];
        tree[p[i]].push_back(i);
    }

    i64 mod=1000000007;
    vector<deque<vector<i64>>> dp(N+1);
    vector<i64> count_depth(300000);
    function<void(int,int,int)> rec=[&](int u,int p,int d){
        ++count_depth[d];

        for(int v:tree[u]){
            if(v==p) continue;
            rec(v,u,d+1);
            if(dp[u].size()<dp[v].size()) swap(dp[u],dp[v]);
        }

        int max_depth=0;
        for(int v:tree[u]){
            if(v==p) continue;
            max_depth=max(max_depth,(int)dp[v].size());
        }

        {
            deque<vector<i64>> dv;
            rep(i,0,max_depth){
                auto a=dp[u].front();
                dp[u].pop_front();
                a[0]=(a[0]+a[2])%mod;
                a[2]=0;
                dv.push_back(a);
            }
            rep(i,0,max_depth){
                dp[u].push_front(dv.back());
                dv.pop_back();
            }
        }

        for(int v:tree[u]){
            deque<vector<i64>> dv;
            while(!dp[v].empty()){
                auto a=dp[u].front(),b=dp[v].front();
                dp[u].pop_front();
                dp[v].pop_front();
                dv.push_back({a[0]*(b[0]+b[2])%mod,((a[1]*(b[0]+b[2])%mod)%mod+b[1]*a[0]%mod)%mod,((a[1]+a[2])*b[1]%mod+a[2]*(b[0]+b[2])%mod)%mod});
            }
            while(!dv.empty()){
                dp[u].push_front(dv.back());
                dv.pop_back();
            }
        }

        dp[u].push_front({1,1,0});
    };

    rec(0,-1,0);

    i64 table[300000]={};
    table[0]=1;
    rep(i,1,300000) table[i]=table[i-1]*2%mod;

    i64 ans=0;
    int d=0;
    while(!dp[0].empty()){
        auto tmp=dp[0].front();
        dp[0].pop_front();
        ans+=tmp[1]*table[N+1-count_depth[d]]%mod;
        ans%=mod;
        ++d;
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 248692
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	fmt.Println(s[0 : len(s)-8])
}


Measured memory_bytes: 640
KEY_MIN = -2000000001


H = int(input())

A = [KEY_MIN] * (H + 1)

for cnt, key in enumerate(map(int, input().split())):
    A[cnt + 1] = key

index_min = 1
index_max = len(A) - 1

def index_exsist(i):
    if index_min <= i <= index_max:
        return i
    else:
        return 0

def max_heapify(A, i):
    l = index_exsist(2 * i)
    r = index_exsist(2 * i + 1)

    largest = i
    if A[l] > A[largest]:
        largest = l
    if A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)

def build_maxheap(A):
    for i in range(1, (H // 2) + 1)[::-1]:
        max_heapify(A, i)


build_maxheap(A)
print("", *A[1:])



Measured memory_bytes: 63720
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int ans = -10000;

    ans = max(ans, a+b);
    ans = max(ans, a-b);
    ans = max(ans, a*b);

    cout << ans << endl;
}


Measured memory_bytes: 888
/*
    Author      : Dinesh Verra
    College     : ABV-IIITM
    Date        : 02/08/2020
    Source		: 
    Explanation : 
*/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
using namespace std;
typedef long long ll;
// typedef unsigned long long ll;
#define cu continue
#define br break
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define inf INT_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define vpll vector <pll>
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define all(v) v.begin(),v.end()
#define nl cout<<'\n'

template <typename A1>
void prn(A1&& arg)
{
	cout<<arg<<'\n';
}
template <typename A1, typename... A>
void prn(A1&& arg, A&&... args)
{
	cout<<arg<<' ';
	prn(args...);
}

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

	ll n,m;
	cin>>n>>m;
	ll root=ceil(1.0*sqrt(1.0*n));
	ll a[n+5],f[n+5];
	for(ll i=1;i<=n;i++) 
	{
		cin>>a[i];
		f[i]=0;
	}
	vector <pair<ll,pll>> q(m);
	for(ll i=0;i<m;i++)
	{
		cin>>q[i].S.F>>q[i].S.S;
		q[i].F=i;
	}
	sort(all(q),[&root](pair<ll,pll>& a, pair<ll,pll>& b){
		if(a.S.F/root==b.S.F/root)
			return a.S.S<b.S.S;
		return a.S.F/root<b.S.F/root;
	});
	ll ans=0,curl=0,curr=0,l,r,b[m];
	for(ll i=0;i<m;i++)
	{
		l=q[i].S.F,r=q[i].S.S;
		while(curr<r)
		{
			++curr;
			f[a[curr]]++;
			if(f[a[curr]]==1) ans++;
		}
		while(curr>r)
		{
			f[a[curr]]--;
			if(f[a[curr]]==0) ans--;
			--curr;
		}
		while((curl+1)<l)
		{
			++curl;
			f[a[curl]]--;
			if(f[a[curl]]==0) ans--;
		}
		while((curl+1)>l)
		{
			f[a[curl]]++;
			if(f[a[curl]]==1) ans++;
			curl--;
		}
		b[q[i].F]=ans;
	}
	for(ll i=0;i<m;i++) prn(b[i]);
}

Measured memory_bytes: 27252
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>

#define N 100000
 
using namespace std;
 
int n;
 
list<int> e[N+1];
 
vector<int> p;
bool used[N+1];
 
int dfs_goal(int s, int g){
  for (auto it = e[s].begin();it != e[s].end();it++) {
    int i = *it;
    if (!used[i]) {
      if (i==g) {
	p.push_back(i);
	return(i);
      }
      used[i] = true;
      int result = dfs_goal(i, g);
      if (result > 0) {
	p.push_back(i);
	return(i);
      }
    }
  }
  return(0);
}
 
int dfs_count(int s){
  int c = 0;
  for (auto it = e[s].begin();it != e[s].end();it++) {
    int i = *it;
    if (!used[i]) {
      c++;
      used[i] = true;
      //      cout << "i:" << i << endl;
      int result = dfs_count(i);
      //      cout << "result:" << result << endl;
      c += result;
    }
  }
  return(c);
}
 
int main(){
  cin >> n;
  for (int i=0;i<n-1;i++) {
    int a, b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  for (int i=0;i<=n;i++)used[i] = false;
  used[1] = true;
  dfs_goal(1, n);
  p.push_back(1);
  /*  for (auto it=p.begin();it!=p.end();it++)
    cout << *it << " ";
    cout << endl;*/
 
  
  int m = p.size()/2;
 
  for (auto it = e[p[m]].begin();it != e[p[m]].end();it++) {
    if (*it == p[m-1]) {
      e[p[m]].erase(it);
      break;
    }
  }
  for (auto it = e[p[m-1]].begin();it != e[p[m-1]].end();it++) {
    if (*it == p[m]) {
      e[p[m]].erase(it);
      break;
    }
  }
  
 
  for (int i=0;i<=n;i++)used[i] = false;
  int fenec = dfs_count(1);
  for (int i=0;i<=n;i++)used[i] = false;
  int snuke = dfs_count(n);
 
  
  if (fenec > snuke)
    cout << "Fennec" << endl;
  else
    cout << "Snuke" << endl;
  return(0);
}


Measured memory_bytes: 13440
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            // 07:00
            int N = scanner.nextInt();
            int M = scanner.nextInt();
            long[] A = new long[N];
            int[] B = new int[N];
            TreeMap<Long, Integer> map = new TreeMap<>();
            for (int i = 0; i < N; i++) {
                long cost = scanner.nextLong();
                int num = scanner.nextInt();
                map.compute(cost, (k,v) -> v == null? num : num + v);
            }
            long totalCost = 0;
            int bought = 0;
            for (final Map.Entry<Long, Integer> kv : map.entrySet()) {
                long cost = kv.getKey();
                int maxnum = kv.getValue();
                int buyCount = Math.min(maxnum, M - bought);
                totalCost += buyCount * cost;
                bought += buyCount;
                if (bought >= M) {
                    break;
                }
            }
            System.out.println(totalCost);
        }
    }
}


Measured memory_bytes: 98732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  if(a%3==0 || b%3==0||(a+b)%3==0){
    cout << "Possible" <<endl;
  }else{
    cout << "Impossible" <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int mul(vector<int> a, vector<int> b){
    int v = 0;
    rep(i,a.size()){
        v+=a[i]*b[i];
    }
    return v;
}

int main() {
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> bv(m);cin>>bv;
    int cnt=0;
    rep(i,n){
        vector<int>av(m);cin>>av;
        if(mul(av,bv)+c>0)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}





Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int main(){
string s,t;
s="", t="";
cin >> s;
for (char c: s) {
if(c=='0') t += '0';
else if (c == '1') t += '1';
//else t.pop_back();
else if (t.size()) t.pop_back();
}
cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	string s;
	cin>>s;
	
	cout<<(s.find('7')==-1?"No":"Yes");

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
const long long mod = 998244353;
int n, k;
long long m;
long long fact[MAX_N], inv_fact[MAX_N];

long long power(long long  x, long long y, long long p) {
    long long res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0) {
        if ((y & 1) == 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

void pre(){
    int i = 0;
    fact[0] = 1;
    for(i = 1; i < MAX_N; i++){
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
    inv_fact[MAX_N - 1] = power(fact[MAX_N - 1], mod - 2, mod);
    for(i = MAX_N - 2; i >= 0; i--){
        inv_fact[i] = inv_fact[i + 1] * (i + 1);
        inv_fact[i] %= mod;
    }
}

long n_choose_k(int n, int r){
    if(n < r)
        return 0;
    long long ans = fact[n];
    ans *= inv_fact[r];
    ans %= mod;
    ans *= inv_fact[n - r];
    ans %= mod;
    return ans;
}
void solve(){
    long long ans = 0;
    int i = 0;
    for(i = n - k; i <= n; i++){
        long long curr = n_choose_k(n - 1, i - 1);
        curr *= m;
        curr %= mod;
        curr *= power(m - 1, i - 1, mod);
        curr %= mod;
        ans += curr;
        ans %= mod;
    }
    if(m == 1){
        if(k == n - 1)
            ans = 1;
        else
            ans = 0;
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    cin >> n >> m >> k;
    solve();
    return 0;
}

Measured memory_bytes: 6792
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <bitset>

int main(void){
	std::string k;
	std::cin >> k;
	int len = k.length();
	uint64_t mod50, div50;
	if(len >= 3){
		uint64_t mod100 = std::stoll(k.substr(len - 2));
		uint64_t div100 = std::stoll(k.substr(0,len - 2));
		mod50 = mod100 % 50;div50 = div100 * 2 + mod100 / 50;
	}
	else{
		mod50 = std::stoi(k) % 50;
		div50 = std::stoi(k) / 50;
	}
	std::cout << "50" << std::endl;
	for(int i=0;i<50;i++){
		uint64_t x = 49 + div50 - mod50;
		if(mod50 > i)x += 51;
		std::cout << x << " ";
	}
	std::cout << std::endl;
	return 0;
}


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

vector<pair<ll, ll>> v;

int main(){
  ll h,w;
  int n;
  cin>>h>>w>>n;
  for(int i=0;i<n;i++){
    ll x,y; cin>>x>>y;
    for(int i=-2;i<=0;i++){
      for(int j=-2;j<=0;j++){
        if(1<=x+i&&x+i<=h-2&&1<=y+j&&y+j<=w-2){
          v.push_back({x+i,y+j});
        }
      }
    }
  }
  sort(v.begin(),v.end());
  ll j[10]={};
  for(int i=0;i<v.size();i++){
    int count=1;
    while(i+1<v.size()&&v[i]==v[i+1]){
      count++;
      i++;
    }
    j[count]++;
  }
  j[0]=(h-2)*(w-2);
  for(int i=1;i<10;i++) j[0]-=j[i];
  for(int i=0;i<10;i++){
    cout<<j[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 18792
#include <bits/stdc++.h>
using namespace std;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,m,ans=2e9,SUM,dis[17][17],num[33000],dp[33000][17];
int main(){
	read(n),read(m);
	for (int i=0;i<m;i++){
		int x,y,c;read(x),read(y),read(c);SUM+=c;
		dis[x-1][y-1]=dis[y-1][x-1]=c;
	}
	for (int i=1;i<(1<<n);i++){
		int cnt;
		for (int j=0;j<n;j++) if ((1<<j)&i){
			cnt=j;break;
		}
		num[i]=num[i^(1<<cnt)];
		for (int k=0;k<n;k++) if ((1<<k)&i) num[i]+=dis[k][cnt];
	}
	for (int i=0;i<33000;i++) for (int j=0;j<17;j++)dp[i][j]=-5e8;
	dp[1][0]=0;
	for (int i=1;i<(1<<n);i++){
		for (int j=0;j<n;j++){
			for (int k=0;k<n;k++) if ((i&(1<<j))>0 && (i&(1<<k))>0 && dis[j][k]) dp[i][j]=max(dp[i][j],dp[i^(1<<j)][k]+dis[j][k]);
			for (int k=i;k>=0;k=(k-1)&i){
				if (k&(1<<j)) dp[i][j]=max(dp[i][j],dp[i^k|(1<<j)][j]+num[k]);
				if (k==0) break;
			}
		}
		if ((1<<(n-1))&i) ans=min(ans,SUM-dp[i][n-1]);
	}
	write(ans);
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

string S;
signed main() {
    cin>>S;
    int ans=0;
    for(int i=0;i<4;i++){
        if(S[i]=='+')ans++;
        else ans--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <bitset>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;

char map[52][52];
int flag[52][52];

int main(){
    int h,w,sum_w=0;
    cin >> h >> w;
    for(int i=0;i<=h+1;i++){
        for(int j=0;j<=w+1;j++){
            if(i==0||j==0||i==h+1||j==w+1){flag[i][j]=1; map[i][j] = '#';}
            else {cin >> map[i][j]; flag[i][j] =0;}
            if(map[i][j]=='.') sum_w++;
        }
    }
    queue< pair<pair<int, int>, int> > q;
    q.push(make_pair(make_pair(1,1),0));
    int get_flag=0,min_time=0;
    while(!q.empty()){
        int x,y,t;
        t = q.front().second;
        x = q.front().first.first;
        y = q.front().first.second;
        if(x==h&&y==w){
            get_flag=1;
            min_time=t;
            break;
        }
        q.pop();
        if(map[x+1][y]=='.'&&flag[x+1][y]==0){flag[x+1][y]=1; q.push(make_pair(make_pair(x+1,y), t+1));}
        if(map[x-1][y]=='.'&&flag[x-1][y]==0){flag[x-1][y]=1; q.push(make_pair(make_pair(x-1,y), t+1));}
        if(map[x][y+1]=='.'&&flag[x][y+1]==0){flag[x][y+1]=1; q.push(make_pair(make_pair(x,y+1), t+1));}
        if(map[x][y-1]=='.'&&flag[x][y-1]==0){flag[x][y-1]=1; q.push(make_pair(make_pair(x,y-1), t+1));}
    }
    if(get_flag==0) cout << "-1" << endl;
    else cout << (sum_w - min_time - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	ll m,n;
	cin>>m>>n;
	vector<ll> v(n);
	for(ll i=0;i<n;i++)
		cin>>v[i];
	sort(v.begin(),v.end());
    ll ans = -1;
    if(n<=m)
    {
        ll sum = 0;
		for(ll i=0;i<n;i++)
			sum += v[i];
		ans = max(-1ll,m-sum);
    }
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define mod 1000000007
template<class T>
void printQueue(T& q)
{while (!q.empty()){cout << q.top() << endl;q.pop();}}


ll power(ll a,ll b)
{
    ll r=1;
    while(b!=0)
    {
        if(b%2!=0){r=r*a;}
        a=a*a; b=b/2;
    }
    return r;
}


int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n; cin>>n;
        ll ast[n+1];
        for(ll i=1;i<=n;i++){
            cin>>ast[i];
        }

        ll dp[n+1];
        dp[n]=0;
        dp[n-1]=abs(ast[n]-ast[n-1]);
        for(int i=n-2;i>=1;i--){
            dp[i]= min((dp[i+1]+abs(ast[i+1]-ast[i])),(dp[i+2]+abs(ast[i+2]-ast[i])));
        }

        cout<<dp[1]<<endl;
    }
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int N = 303;
char cake[N][N];
int ans[N][N];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int h, w, k;
	scanf("%d%d%d", &h, &w, &k);
	for (int i = 0; i < h; i++) scanf("%s", cake[i]);

	int pr = -1;
	for (int i = 0; i < h; i++) {
		int pc = -1;
		for (int j = 0; j < w; j++) {
			if (cake[i][j] == '#') {
				for (int x = pr+1; x <= i; x++)
					for (int y = pc+1; y <= j; y++) ans[x][y] = k;
				--k;
				pc = j;
			}
		}

		if (pc >= 0) {
			for (int x = pr+1; x <= i; x++)
				for (int y = pc+1; y < w; y++) ans[x][y] = ans[i][pc];
			pr = i;
		}
	}
	assert(k == 0);

	for (int x = pr+1; x < h; x++)
		for (int y = 0; y < w; y++) ans[x][y] = ans[pr][y];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) printf("%d ", ans[i][j]);
		puts("");
	}
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define MOD 1000000007
using namespace std;
map<pair<int,int>,vector<pair<int,int>>> g;
vector<vector<int>> vis;
map<pair<int,int>, int > dis;
bool dfs(pair<int,int> node)
{
	vis[node.x][node.y]=1;
	dis[node]=0;
	for(auto it:g[node])
	{
		if(vis[it.x][it.y]==1){return 0;}
		else if(vis[it.x][it.y]==0)
		{
			if(dfs(it)==0){return 0;}
		}
		dis[node]=max(dis[node],1+dis[it]);
	}
	vis[node.x][node.y]=2;
	return 1;
}
int main(){

	int n;cin>>n;
	for(int i=0;i<n;++i)
	{
		std::vector<int> inp(n-1);
		for(int j=0;j<n-1;++j)
		{
			cin>>inp[j];--inp[j];
		}
		for(int j=1;j<n-1;++j)
		{
			g[{min(i,inp[j-1]),max(i,inp[j-1])}].push_back({min(i,inp[j]),max(i,inp[j])});
		}
	}
	vis.resize(n,vector<int>(n,0));
	int ans=0;
	for(int i=0;i<n;++i)
	{
		for(int j=i+1;j<n;++j)
		{
			if(!vis[i][j])
			{
				bool b=dfs({i,j});
				if(b==0){cout<<-1;return 0;}
			}
			ans=max(ans,dis[{i,j}]);
		}
	}
	cout<<ans+1;
	return 0;
}

Measured memory_bytes: 92288
public class Main {

  private static void solve() {
    int n = ni();
    int a = ni();
    
    if (n % 500 <= a) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
 
#define ll long long

 
int main() {
  
  	ll S, W;
  	cin >> S >> W;
  
  	if(S>W){
    	cout << "safe" << endl;
    }
  	else{
      	cout << "unsafe" << endl;
    }

}

Measured memory_bytes: 3600
#include <stdio.h>

int pop();
int empty();
void push(int);

int data[100] = {0};
int ind = -1;

int main(void){
  int a;

  while(scanf("%d",&a) != EOF){
    if(a) push(a);
    else {
      if(empty() == -1) break;
      printf("%d\n",pop());
    }
  }

  return 0;
}

int pop(){
  ind--;
  return data[ind+1];
}

int empty(){
  return ind;
}

void push(int a){
  ind++;
  data[ind] = a;
}

Measured memory_bytes: 600