akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

const long long INF = 1LL << 60;

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

int N, K;
long long h[100010];
long long dp[100100];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];
    
    for (int i = 0; i < 100100; ++i) dp[i] = INF;
    
    dp[0] = 0;
    
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

template <class RandomIt, class T>
bool makeable(RandomIt first, RandomIt last, T x) {
  std::vector<T> dp(x+1, -1);
  dp[0] = 0;
  for (RandomIt it=first; it<last; ++it) {
    for (T j=0; j<=x; ++j) {
      if (dp[j] >= 0) {
        dp[j] = 1;
      } else if (j < *it || dp[j-*it] <= 0) {
        dp[j] = -1;
      } else {
        dp[j] = dp[j-*it] - 1;
      }
    }
  }

  return dp[x] >= 0;
}

int main() {
  char buf[8192];
  scanf("%s", buf);
  std::string s=buf;
  s += 'T';

  int x, y;
  scanf("%d %d", &x, &y);

  std::vector<int> t[2];
  size_t k=0;
  int cur=0;
  for (size_t i=0; i<s.length(); ++i) {
    if (s[i] == 'F') {
      ++cur;
    } else {
      t[k].push_back(cur);
      k ^= 1;
      cur = 0;
    }
  }

  x -= t[0][0];
  for (size_t i=0; i+1<t[0].size(); ++i)
    t[0][i] = t[0][i+1];

  t[0].back() = 0;

  if (x < 0) x = -x;
  if (y < 0) y = -y;

//   for (size_t i=0; i<2; ++i)
//     for (size_t j=0; j<t[i].size(); ++j)
//       fprintf(stderr, "%d%c", t[i][j], j+1<t[i].size()? ' ':'\n');
  
  int sx=0, sy=0;
  for (size_t i=0; i<t[0].size(); ++i)
    sx += t[0][i];
  for (size_t i=0; i<t[1].size(); ++i)
    sy += t[1][i];

  if (sx < x || sy < y)
    return !printf("No\n");
  if ((sx-x) % 2 != 0 || (sy-y) % 2 != 0)
    return !printf("No\n");

  if (!makeable(t[0].begin(), t[0].end(), (sx-x)/2))
    return !printf("No\n");
  if (!makeable(t[1].begin(), t[1].end(), (sy-y)/2))
    return !printf("No\n");

  printf("Yes\n");
}


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

int main(){
	int X;
	cin >> X;
	int ans = 0;
	int l = 0;
	while (l < X) {
		ans++;
		l += ans;
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>

using namespace std;

int t,n;
int s,f;

int main()
{
	while(cin>>t)
	{
		if(!t) return 0;

		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>s>>f;
			t-=(f-s);
		}

		if(t>0) cout<<t<<endl;
		else cout<<"OK"<<endl;

	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max({x,y,z})
#define MX4(x,y,z,p) max({x,y,z,p})
#define MX5(x,y,z,p,q) max({x,y,z,p,q})
#define MN3(x,y,z) min({x,y,z})
#define MN4(x,y,z,p) min({x,y,z,p})
#define MN5(x,y,z,p,q) min({x,y,z,p,q})
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

const int MAX = 3000 + 10;

int dp[MAX<<1];
vector<pair<int,int>> rec;

void solve() {

    int n;
    int t;
    SI(n); SI(t);
    REP(i, n) {
        int x, y;
        SI(x); SI(y);
        rec.push_back(make_pair(x, y));
    }
    sort(rec.begin(), rec.end());

    REP(i, n) {
        int x = rec[i].first, y = rec[i].second;
        for(int i = t-1 ; i > 0 ; i--) {
            if(dp[i] > 0) {
                amax(dp[i+x], dp[i] + y);
            }
        }
        amax(dp[x], y);
    }

    int ans = 0;
    REP(i, 6001) {
        amax(ans, dp[i]);
    }   
    printf("%d\n", ans);
}

void init() {
    


}

int main () {
    init();
    solve();
    return 0;
}


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

int main() {
    int n;cin >> n;
    map<string, int> poll;
    for (int i = 0; i < n; i++)
    {
        string str;cin >> str;
        poll[str]++;
    }
    int max = 0;
    list<string> str;
    for(auto p: poll){
        if(p.second == max)str.push_back(p.first);
        else if(p.second > max){
            str = {p.first};
            max = p.second;
        }
    }
    str.sort();
    for(auto i: str)cout << i << endl;
    

    return 0;
}

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

int main()
{
    int a,ans=1;
    cin >> a;
    if(a>8){
        ans=0;
    }
    cin >> a;
    if(a>8){
        ans=0;
    }
    if(ans){
        cout << "Yay!" << endl;
    }else{
        cout << ":("<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=200005,inf=1000000007;
pii a[N];int vis[N],ans[N];
vector<pii>e[N];
int dfs(int v){
	vis[v]=1;
	int s=e[v].size(),u,b=a[v].se;
	while(s--)if(!vis[u=e[v][s].fi]&&dfs(u)){b^=1;ans[e[v][s].se]=1;}
	return a[v].se=b;
}
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,m,i,L,R,l,r;
    scanf("%d%d",&n,&m);
    rep(i,1,n)scanf("%d%d",&a[i].fi,&a[i].se);
	sort(a+1,a+n+1);
	//rep(i,1,n)printf("%d %d\n",i,a[i].se);
	per(i,n+1,2)a[i].se^=a[i-1].se;
	rep(i,1,m){
		scanf("%d%d",&L,&R);
		l=lower_bound(a+1,a+n+1,mp(L,0  ))-a;
		r=upper_bound(a+1,a+n+1,mp(R,inf))-a;
		//printf("i=%d l=%d r=%d\n",i,l,r);
		e[l].pb(mp(r,i));
		e[r].pb(mp(l,i));
	}
	rep(i,1,n)if(!vis[i]&&dfs(i)){puts("-1");return 0;}
	l=0;
	rep(i,1,m)if(ans[i])++l;
	printf("%d\n",l);
	rep(i,1,m)if(ans[i])printf("%d ",i);
    return 0;
}

Measured memory_bytes: 18048
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"




def main():
    a,b,c = mi()
    if c-a-b<=0:
        print(no)
        exit()
    else:
        if (c-a-b)**2 > 4*a*b:
            print(yes)
        else:
            print(no)
        
    


main()



Measured memory_bytes: 5076
import sys

def LI(): return([int(x) for x in sys.stdin.readline().split()])
def LI_(): return([int(x)-1 for x in sys.stdin.readline().split()])

def main():
    N,M = LI()
    keys = []
    for _ in range(M):
        a,b = LI()
        C = LI_()
        key_bit = 0
        for c in C:
            key_bit += (1 << c)
        keys.append([a,key_bit])

    dp = [10**10] * (1 << N)
    dp[0] = 0
    for i in range(0,M):
        for key_bit in range(1 << N):
            dp[key_bit|keys[i][1]] = min(dp[key_bit|keys[i][1]],dp[key_bit]+keys[i][0])
    if(dp[(1<<N)-1] == 10**10):
        return(-1)
    return(dp[(1<<N)-1])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 42716
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

count=0
for i in range(a-1):
    if f[i]!=f[i+1]-1:
        f[i+1]=i+2
        count+=1
if count==2 or count==0:
    print("YES")
else:
    print("NO")

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

int main() {
	bool a[55556];
	int ans[60];
	memset(a, 0, sizeof(a));
	
	int cnt = 0;
	int ai = 1;
	for(int i = 2; i <= 55555 && ai <= 55; i++){
		if(!a[i]){
			if(i%5 == 1){
				ans[ai] = i;
				ai++;
			}
			for(int j = 2; i*j <= 55556; j++){a[i*j] = true;}
		}
	}
	
	int n;
	cin >> n;
	for(int ai = 1; ai <= n; ai++){cout << ans[ai] << " ";}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i += 2)
	{
		int d = 0;
		for (int j = 1; j <= i; ++j)
		{
			if (i%j == 0)++d;
		}
		if (d == 8)++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  ll A;
  long double B;
  cin>>A>>B;

  long double ans=A*B;
  ll P=floor(ans);
  cout<<P<<endl;

  return 0;
}


Measured memory_bytes: 3736
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string S;
  	cin >> S;
  	int sz = S.size();
  	int count0 = 0;
  	int count1 = 0;
  	rep(i,sz){
      	if(S[i] == '0'){
          	count0++;
        }
      	else{
          	count1++;
        }
    }
  	cout << 2*min(count0,count1) << endl;
	return;
}

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


Measured memory_bytes: 512
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 


#define lo long long int



int main() {
	int a, b;
	cin >> a >> b;
	cout << a - 1 + (a <= b);
	//system("pause");
	return 0;

}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> like(M + 1, 0);
    for (int i = 0; i < N; ++i) {
        int K;
        cin >> K;
        vector<bool> check(K + 1, true);
        for (int j = 0; j < K; ++j) {
            int temp;
            cin >> temp;
            if (check[temp]) {
                check[temp] = false;
                ++like[temp];
            }
        }
    }
    int answer = 0;
    for (int i = 0; i <= M; ++i) {
        if (like[i] == N) ++answer;
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
from bisect import bisect_right
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
CA = [0 for _ in range(N+1)]
for i in range(N):
    CA[i+1] = A[i]+CA[i]
CB = [0 for _ in range(M+1)]
for j in range(M):
    CB[j+1] = B[j]+CB[j]
cmax = 0
for i in range(N,-1,-1):
    if CA[i]<=K:
        b = K-CA[i]
        ind = bisect_right(CB,b)
        cmax = max(cmax,i+ind-1)
print(cmax)

Measured memory_bytes: 132328
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int a[200005],d[200005],b[200005];
int main(){
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }
    set<int> s;multiset<int> dis;
    for(int i=1;i<=m;i++){
        s.insert(i);dis.insert(0);d[i]=0;
    }
    for(int i=1;i<=n;i++){
        int mi=1e9;
        auto it=s.lower_bound(a[i]);
        while(it!=s.end()&&*it<=b[i]+1){
            int x=*it;s.erase(it);
            it=s.lower_bound(a[i]);
            dis.erase(dis.lower_bound(d[x]));
            mi=min(mi,d[x]+b[i]+1-x);d[x]=1e9;
        }
        if(b[i]+1<=m&&mi<1e9){
            d[b[i]+1]=min(d[b[i]+1],mi);
            dis.insert(d[b[i]+1]);s.insert(b[i]+1);
        }
        if(dis.size()==0) cout<<-1<<endl;
        else cout<<*dis.begin()+i<<endl;
    }
} 

Measured memory_bytes: 24656
s = input()
K = int(input())

substrings = []
for i in range(len(s)):
    for j in range(len(s)-i+1):
        # print('i={}, i+j={}, s[i:i+j]={}'.format(i, i+j, s[i:i+j]))
        if j <= K and s[i:i+j] != '':
            substrings.append(s[i:i+j])
substrings = sorted(set(substrings))
print(substrings[K-1])


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

int main(){
    using namespace std;
    string S;
    cin >> S;
    unsigned long K;
    cin >> K;
    vector<pair<char, unsigned long>> cnt0;
    char pc{'!'};
    unsigned long cnt{0};
    for(const auto& c : S){
        if(c != pc){
            if(cnt)cnt0.emplace_back(pc, cnt);
            pc = c;
            cnt = 1;
        }else{
            ++cnt;
        }
    }
    cnt0.emplace_back(pc, cnt);
    unsigned long N = cnt0.size(), ans{0};
    if(N == 1){
        ans = (K * cnt0[0].second) / 2;
    }else{
        for(unsigned long i = 1; i + 1 < N; ++i)ans += K * (cnt0[i].second / 2);
        if(cnt0[0].first == cnt0.back().first){
            ans += cnt0[0].second / 2 + cnt0.back().second / 2 + (K - 1) * ((cnt0[0].second + cnt0.back().second) / 2);
        }else{
            ans += K * (cnt0[0].second / 2) + K * (cnt0.back().second / 2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
      int n,i,j,k,r1=0,r2=0,res=0,rr=0;
      cin>>n;
      int a[n+10];
      for(i=1;i<=n;i++) cin>>a[i];
      for(i=1;i<=n;i++)
      {
            if(a[i]==i) 
            {
                  swap(a[i],a[i+1]);
                  res++;
            }
      }
      cout<<res;
      return 0;
      i=0;
      while(i+1<=n&&a[i+1]==i+1) i++;
      j=n+1;
      while(j-1>i&&a[j-1]==j-1) j--;
      res=(n+1-j+i)/2;
      return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;			
	   
int main() {
			fast
			// #ifndef ONLINE_JUDGE
			// freopen("input.txt","r",stdin);
			// freopen("output.txt","w",stdout);
			// #endif

			ll t;
			t=1;
			while(t--)
			{
				ll n;
                cin>>n;
				ll x=(n/1000)*1000;
				if(n%1000!=0)
				x+=1000;
				ll ans=x-n;
				cout<<ans<<endl;
                
			}
			return 0;
		 }	




Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
char s[1<<20];
#define ll long long
int main()
{
	int n;
	scanf("%s",s+1);
	n=strlen(s+1);
	int a=0,i=1;
	ll als=0;
	while(i<=n){
		if(s[i]=='A'){
			++a;
			++i;
			continue;
		}
		if(s[i]=='B'&&s[i+1]=='C'){
			als+=1LL*a;
			i+=2;
			continue;
		}
		a=0;
		i++;
	}
	printf("%lld",als);
	return 0;
}

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

const int N = 100010;

int n, m;
double ans = 0, power[N];

int main() {
	cin >> n >> m;
	double tmp = 0.5;
	for(int i = 1; i <= 100000; ++i) {
		power[i] = tmp;
		tmp /= 2.0;
	}
	for(int i = 1; i <= n; ++i) {
		int cnt = 0, now = i;
		while(now < m) now *= 2, ++cnt;
		if(!cnt) ans += 1.0 / n;
		else ans += 1.0 / n * power[cnt];
	}
	printf("%.12lf\n", ans);
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static int dp[];
  public static int dfs(List<Integer>[] g,
  int u)
  {
      if(dp[u]!=-1)
      return dp[u];
      int ans=0;
      for(int child:g[u])
      {
        ans=Math.max(ans,1+dfs(g,child));
      }
      return dp[u]=ans;
  }
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    List<Integer>[] g=
      new ArrayList[n];
    for(int i=0;i<n;i++)
    g[i]=new ArrayList<>();
    for(int i=0;i<m;i++)
    {
      int x=sc.nextInt();
      int y=sc.nextInt();
      x--; y--;
      g[x].add(y);
    }
    int max=0;
    dp=new int[n];
    for(int i=0;i<n;i++)
    dp[i]=-1;
    for(int i=0;i<n;i++)
    {
        int cnt=dfs(g,i);
        max=Math.max(max,cnt);
    }
    System.out.println(max);
  }
}
    

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

last = a[0] + k - a[n - 1]
sum = 0
l =[]

for i in range(1, n):
    l.append(a[i] - a[i - 1])

l.append(last)

print(k - max(l))


Measured memory_bytes: 100776
#include<stdio.h>

int main(void){
        int n,b,f,r,v,i;
        int s[5][4][11] = {};

        scanf("%d",&n);

        for(i=1; i<=n; i++){
                scanf("%d %d %d %d", &b, &f, &r, &v);
                s[b][f][r] += v;
        }

        for(b=1; b<=4; b++){
                for(f=1; f<=3; f++){
                        for(r=1; r<=10; r++)
                                printf(" %d",s[b][f][r]);
                        putchar('\n');
                }
                if(b!=4)
                        puts("####################");
        }
        return 0;
}

Measured memory_bytes: 612
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    print(max(A) - min(A))

    return


if __name__ == '__main__':
    main()


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

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> vec(n);//スイッチ
  for(int i=0;i<m;i++){
    int k=0;//何個のスイッチにつながっているか
    cin >> k;
    for(int j=0;j<k;j++){
      int s;//スイッチ番号
      cin >> s;
      s--;//0-originに変更
      vec[s] |= (1<<i);//s番目のスイッチが電球iにつながっていることを示す
    }
  }
  int ans = 0,p=0;
  for(int j=0;j<m;j++){
    int x;
    cin >> x;
    p |= x << j;
  }
  //探索
  for(int s = 0;s < (1<<n);s++){//スイッチのON:1/OFF:0の組み合わせ
     int t = 0;//実際にどの電球がついているか
     for(int i=0;i<n;i++){
       if(s >> i & 1){//ibit目がたっているか
         t^=vec[i];//xor,
       } 
     }
     if(t == p) ans++;  
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def iter_subset(_a): #aの部分集合を走る
    _bit = _a
    yield _bit
    while 1:
        _bit = (_bit-1) & _a 
        yield _bit
        if not _bit: break



n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

total = 1<<n
gscore = [0]*total
dp = [0]*(total)

for i in range(n):
    for k in range(1<<(i)):
        gscore[k^(1<<i)] += gscore[k]
        for j,c in enumerate(A[i]):
            if (1<<j)&k:
                gscore[k^(1<<i)] += c  

        for l in iter_subset(k):
            dp[k^(1<<i)] = max(dp[k^(1<<i)], gscore[l^(1<<i)] + dp[k^l])

#print(gscore)        
#print(dp)        
print(dp[-1])        
        

Measured memory_bytes: 43996
import java.util.*;

public class Main {
	private static int n;
	private static int m;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();

		Set<Integer>[] s = new HashSet[m];

		for (int i = 0; i < m; i++) {
			s[i] = new HashSet<>();

			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				s[i].add(sc.nextInt() - 1);
			}
		}

		int[] p = new int[m];
		for (int i = 0; i < m; i++) {
			p[i] = sc.nextInt();
		}

		int i = 1 << n;
		int a = 0;
		while (i > 0) {
			i -= 1;
			if (check(i, s, p)) a++;
		}

		System.out.println(a);
	}

	private static boolean check(int i, Set<Integer>[] s, int[] p) {
		for (int j = 0; j < s.length; j++) {
			Set<Integer> a = s[j];

			int on = 0;
			for (int k = 0; k < n; k++) {
				if (((i >> k) & 1) == 1 && a.contains(k)) on++;
			}

			if (p[j] != on % 2) return false;
		}

		return true;
	}
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N, dp[20][100010];

  void init() {
    cin >> N;
  }

  void solve() {
    vector<int> coins = {1};
    int a = 6;
    while(a <= 100000) {
      coins.push_back(a);
      a *= 6;
    }
    a = 9;
    while(a <= 100000) {
      coins.push_back(a);
      a *= 9;
    }
    sort(coins.begin(), coins.end());
    coins.erase(unique(coins.begin(), coins.end()), coins.end());
    repc(j, N) dp[0][j] = IINF;
    dp[0][0] = 0;
    rep(i, coins.size()) repc(j, N) {
      dp[i+1][j] = dp[i][j];
      if(coins[i] <= j) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-coins[i]]+1);
    }
    cout << dp[coins.size()][N] << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 6400
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
set<int> a;
ll grid[3][3];
void solve(){
	rep(i,0,3)rep(j,0,3)cin>>grid[i][j];
	ll n;
	cin>>n; 
	rep(i,0,n){
		int t;
		cin>>t;
		a.insert(t);
	}
	rep(i,0,3)rep(j,0,3)if(a.count(grid[i][j]))grid[i][j] = 0;
	rep(i,0,3)if(grid[i][0]+grid[i][1]+grid[i][2]==0||grid[0][i]+grid[1][i]+grid[2][i]==0){
		cout<<"Yes\n";
		return ;
	}
	if(grid[0][0]+grid[1][1]+grid[2][2]==0||grid[1][1]+grid[0][2]+grid[2][0]==0)
	{
			cout<<"Yes\n";
		return ;
	}
	cout<<"No\n"; 
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine


decrease :: [Integer] -> Bool
decrease [h] = True
decrease (x:y:hs)
         | x >= y = decrease (y:hs)
         | x >= y - 1 = decrease (y - 1:hs)
         | x < y  = False
         | otherwise = False

buildStairs :: Integer -> [Integer] -> String
buildStairs n h = if decrease (reverse h) then "Yes" else "No"

main = do
     n <- getInt
     h <- getIntList
     putStrLn $buildStairs n h


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

struct BellmanFord{
    struct edge {ll from, to, cost;};
    vector<edge> es;
    vector<ll> d;
    ll V=0,E=0;
    bool nloop = false;
    vector<bool> mi;

    BellmanFord(ll v, ll e){
        V = v;
        E = e;
        es.resize(E);
        d.resize(V);
        mi.resize(V);
    }

    bool fnloop(){
        rep(i,V) d[i] = 0LL;
        rep(i,V){
            rep(j,E){
                edge e = es[j];
                if(d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    if(i==V-1) nloop = true;
                }
            }
        }
        return nloop;
    }

    void shortest(int s){
        rep(i,V) d[i] = INF;
        d[s] = 0;
        ll cnt = 0;
        while(true){
            bool update = false;
            rep(i,E){
                edge e = es[i];
                if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                    if(cnt>=V) mi[e.to] = true;
                }
            }
            if(!update) break;
            cnt++;
            if(cnt == V*2) break;
        }
    }
};

int main() {
  ll N,M;
  cin>>N>>M;
  BellmanFord B(N,M);
  rep(i,M){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    B.es[i] = {a,b,-c};
  }
  B.shortest(0);
  if(B.mi[N-1]) cout<<"inf"<<endl;
  else cout<<-B.d[N-1]<<endl;
}

Measured memory_bytes: 3668
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 a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            a = a*a;
            b = b*b;
            c = c*c;
            if(a+b==c||b+c==a||c+a==b){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 23396
#include<iostream>
using namespace std;
int main(){
	int a,b;
	for(int i=0;i<2999;i++){
	cin>>a>>b;
	if(a==0&&b==0)
		break;
	if(a<b){
		cout<<a<<" "<<b<<endl;
	}else{
		cout<<b<<" "<<a<<endl;
	}
	}
}

Measured memory_bytes: 2944
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ld ans = w*h;
    ans = ans/2.0;
    cout<<fixed<<setprecision(10)<<ans;
    if(2*x==w && 2*y==h)
    {
        cout<<' '<<1<<endl;
    }
    else
    {
        cout<<' '<<0<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static class City {
    int index;
    int pref;
    int year;
    int x;
    City(int index, int pref, int year) {
      this.index = index;
      this.pref = pref;
      this.year = year;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    Map<Integer, List<City>> pref = new HashMap<>();
    for (int i = 1; i <= n; i++) {
      pref.put(i, new ArrayList<>());
    }
    List<City> cities = new ArrayList<>();
    for (int i = 0; i < m; i++) {
      int p = sc.nextInt();
      int y = sc.nextInt();
      City c = new City(i, p, y);
      cities.add(c);
      pref.get(p).add(c);
    }
    for (List<City> cs : pref.values()) {
      Collections.sort(cs, (City c1, City c2) -> c1.year - c2.year);
      for (int i = 0; i < cs.size(); i++) {
        cs.get(i).x = i + 1;
      }
    }
    StringBuilder sb = new StringBuilder();
    for (City c : cities) {
      if (sb.length() > 0) sb.append("\n");
      sb.append(String.format("%06d%06d", c.pref, c.x));
    }
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 140556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N,Q;
    cin >> N;
    vector<ll> vec(100010);
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        vec.at(A)++;
    }
    cin >> Q;
    ll ret = 0;
    for(ll i = 0;i < 100010;i++) {
        ret += vec.at(i) * i;
    }
    for(ll i = 0;i < Q;i++) {
        ll B,C;
        cin >> B >> C;
        ret -= B * vec.at(B);
        ret += C * vec.at(B);
        vec.at(C) += vec.at(B);
        vec.at(B) = 0;
        cout << ret << endl;
    }
}

Measured memory_bytes: 4052
#include <stdio.h>

int main()
{
    int i,j;
    int a[10];
    int temp;
    
    for(i=0;i<10;i++)
    {   
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
            if(a[j] > a[i])
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
                
        }
    }

    printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
        
    return 0;
}

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

typedef long long ll;

int main() {
    ll N;
    string ABC = "ABC";
    cin >> N;
    string input_str;
    cin >> input_str;
    ll sum = 0;
    for (ll i = 0; i < N - 2; i++) {
        for(ll j = 0; j < 3; j++) {
            if (input_str[j + i] == ABC[j])
            {
                if (j == 2) {
                    sum++;
                }
            } else {
                break;
            }
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

vector <int> query[SIZE];
int nm[SIZE];
int n,m;

bool check(int X)
{
	priority_queue <int,vector <int>,greater <int> > que;
	memset(nm,0,sizeof(nm));
	int cnt=X;
	int sum=0;
	for(int i=0;i<=m+1;i++)
	{
		sum+=nm[i];
		if(1<=i&&i<=m) cnt++;
		for(int j=0;j<query[i].size();j++)
		{
			int to=query[i][j];
			if(cnt>0)
			{
				cnt--;
				que.push(to);
			}
			else
			{
				que.push(to);
				int tp=que.top();que.pop();
				if(tp<=i) sum++;
				else nm[tp]++;
			}
		}
		if(1<=i&&i<=m&&cnt>=1&&sum>=1)
		{
			cnt--;
			sum--;
		}
	}
	return sum==0;
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		query[l].push_back(r);
	}
	int low=-1,up=n;
	while(up-low>1)
	{
		int d=(up+low)/2;
		if(check(d)) up=d;
		else low=d;
	}
	printf("%d\n",up);
	return 0;
}


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

int main(){
	int N, L;
	cin >> N >> L;
	vector<string> v(N);
	for(int i=0 ; i<N ; ++i){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for(int i=0 ; i<N ; ++i){
		cout << v[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;



Vi g[100100];
int u_d[100100];
int v_d[100100];

void dfs(int v, int par = -1){
  if (par == -1)
    u_d[v] = 0;
  else
    u_d[v] = u_d[par] + 1;
  
  for (auto i: g[v])
    if (i != par)
      dfs(i, v);
}

void dfs_(int v, int par = -1){
  if (par == -1)
    v_d[v] = 0;
  else
    v_d[v] = v_d[par] + 1;
  
  for (auto i: g[v])
    if (i != par)
      dfs_(i, v);

}

int ans_value = -1;
int ans;

void dfs__(int v, int par = -1){
  for (auto i: g[v])
    if (i != par)
      dfs__(i, v);

  if(u_d[v] < v_d[v] and ans_value < v_d[v])
    ans = v, ans_value = v_d[v];
}


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

  int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  
  for (int i = 0; i < n - 1; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(u);
  dfs_(v);
  dfs__(v);
  cout << ans_value - 1 << endl;
}


Measured memory_bytes: 11264
using System;

namespace TestSpace
{
    class Test
    {
        static void Main(string[] args)
        {
            string[] arrRead;
            int a, b, c, i, j;

            arrRead = Console.ReadLine().Split(' ');
            a = int.Parse(arrRead[0]);
            b = int.Parse(arrRead[1]);
            c = int.Parse(arrRead[2]);
            j = 0;

            for (i = a; i <= b; i++)
            {
                if (c % i == 0)
                {
                    j++;
                }
            }

            Console.WriteLine("{0}", j);

        }
    }
}



Measured memory_bytes: 20000
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int arr[100];
int main()
{
   int n,x,s=0;
   cin>>n>>x;
   for(int i = 0; i<n; i++)
   {
       cin>>arr[i];
   }
   sort(arr,arr+n);
   int j = 0; int f = 0;
   while (x>0 && j<n && x>=arr[j])
   {
       if(x>=arr[j])
       {
           x = x - arr[j];
           s+=1;
           f++;
       }
       j++;
   }
   bool t = false;
   if (s!=0)
    t = true;
   if (x>0 && t == true)
   {
       if (f == n)
       s--;
   }
   cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int n, s;
int main() {
    cin >> n;
    vector<string>s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    cout << s.size();
}

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long n,a,b;
    cin >> n >> a >> b;
    if(n<2){
        if(a==b) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else{
        if(a<=b) cout <<(b-a)*(n-2)+1 << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 3620
#素因数分解
def soinsu_bunkai(m):
    pf={}

    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf


# 初期入力
from collections import Counter
from collections import defaultdict
from itertools import permutations
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())

# Nの階乗の素数列挙
c =defaultdict(int)
for i in range(1,N+1):
    x =soinsu_bunkai(i)
    for j,v in x.items():
        c[j] +=v


ans=set()
for p,q,r in permutations(c.keys(),3):
    if c[p] >=74:
        ans.add(p**74)
    if c[p] >=24 and c[q] >=2:
        ans.add((p**24)*(q**2))
    if c[p] >=14 and c[q] >=4:
        ans.add((p**14)*(q**4))
    if c[p] >=4 and c[q] >=4 and c[r] >=2:
        ans.add((p**4)*(q**4)*(r**2))
    
print(len(ans))

Measured memory_bytes: 9752
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, D;
    cin>> N >> D;
    vector<plong> P(N); 
    two_sat ts(N);
    REP(i, 0, N){
        int x, y;
        cin >> x >> y;
        P[i] = {x, y};
    }
    REP(i, 0, N){
        REP(j, i + 1, N){
            if(abs(P[i].first - P[j].first) < D){
                ts.add_clause(i, false, j, false);
            }
            if(abs(P[i].first - P[j].second) < D){
                ts.add_clause(i, false, j, true);
            }
            if(abs(P[i].second - P[j].first) < D){
                ts.add_clause(i, true, j, false);  
            }
            if(abs(P[i].second - P[j].second) < D){
                ts.add_clause(i, true, j, true);    
            }
        }
    }
    if(!ts.satisfiable()){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    vector<bool> ans = ts.answer();
    REP(i, 0, N){
        if(ans[i]){
            cout << P[i].first << endl;
        }else{
            cout << P[i].second << endl;
        }
    }
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int sum = 0;
    vi T(n); for(auto& e : T) cin >> e, sum += e;

    int m; cin >> m;
    rep(i, m){
        int p, x; cin >> p >> x;
        p--;
        cout << sum - T[p] + x << endl;
    }

    return 0;
}


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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int r, d, x;
    cin >> r >> d >> x;
    rep (i, 10) {
        x = r * x - d;
        print(x);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    char tmp;
    string S;
    cin >> A >>B;
    
    if(A%3==0 || B%3==0 || (A+B)%3==0)
	puts("Possible");
    else
	puts("Impossible");
    // ans = (A-1)*(B-1);
    
    // cout <<"ABC"<<A<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> to[n + 1];
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
  }
  vector<bool> exist(n, false);
  for (auto&& e : to[1]) {
    exist[e] = true;
  }
  bool good = false;
  for (auto&& e : to[n]) {
    if (exist[e]) {
      good = true;
      break;
    }
  }
  if (good) {
    cout << "POSSIBLE" << '\n';
  } else {
    cout << "IMPOSSIBLE" << '\n';
  }
  return 0;
}

Measured memory_bytes: 15000
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
int w[50000];
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, cnt = 0;
	cin>>n>>k;
	while(k--)
	{
		int p = next<int>();
		while(p--) w[next<int>()] = 1;
	}
	R(w, 100);
	hrp(i, 1, n) if (!w[i]) cnt++;
	cout<<cnt<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(){
  int N,S=0;
  scanf("%d",&N);
  int V[30],C[30];
  for(int i=1;i<=N;i++)
    scanf("%d",V+i);
  for(int i=1;i<=N;i++){
    scanf("%d",C+i);
    C[i]=V[i]-C[i];
    if(C[i]>0) S+=C[i];
  }
  printf("%d\n",S);
  return 0;
}


Measured memory_bytes: 1732