akhauriyash/Code-Regression huggingface dataset:
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
ll n;
ll a[21][21],dp[21][(1<<21)];
ll solve(ll current,ll bitmask)
{
	if(current==n)
		return 1;
	if(dp[current][bitmask]!=-1)
		return dp[current][bitmask];

	ll &res=dp[current][bitmask];
	res=0;

	for(ll j=0;j<n;j++)
	{
		if(a[current][j]&&(!((bitmask>>j)&1)))
		{
			res+=(solve(current+1,bitmask|1<<j));
			res%=mod;
		}
	}


	return res;

}

int main()
{	
	
	IOS
	
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(ll i=0;i<n;i++)
		for(ll j=0;j<n;j++)
			cin>>a[i][j];

	ll ans=solve(0,0);
	cout<<ans;
	
}
    
 
    
    


Measured memory_bytes: 344448
package main

import (
	"container/heap"
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	am := make(map[int]int)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		am[a[i]]++
	}

	ss := make([]int, 0)
	bm := make(map[int]int, 0)
	for v, c := range am {
		if c > 1 {
			bm[v] = c
		} else {
			ss = append(ss, v)
		}
	}

	pq := make(PriorityQueue, len(bm))
	i := 0
	for value, priority := range bm {
		pq[i] = &Item{
			value:    value,
			priority: priority,
			index:    i,
		}
		i++
	}
	heap.Init(&pq)

	ans := len(ss)

	for pq.Len() > 0 {
		item1 := heap.Pop(&pq).(*Item)
		if pq.Len() == 0 {
			if item1.priority%2 == 1 {
				ans++
			}
			break
		}

		item2 := heap.Pop(&pq).(*Item)
		item1.priority--
		item2.priority--

		if item1.priority == 1 {
			ans++
		} else {
			heap.Push(&pq, item1)
		}

		if item2.priority == 1 {
			ans++
		} else {
			heap.Push(&pq, item2)
		}
	}

	fmt.Println(ans)
}

// Item .
type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

// Push .
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

// Pop .
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}
 
template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}


//vector<pair<int,int>> pairs;  pairs[i] = make_pair(value, value);
//sort(a.begin(),a+index_number);

//cin>>  cout<<'\n'

/*
vector<int> vec(100,-1);全ての値に-1をセット
vector<std::vector<int>> vec{{ 1, 2, 3 },{ 4, 5, 6 }};
vec.size() vec[i].size()
vec.emplace_back(20);追加
*/

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

	 int n,x;
    int ans = 1;
    cin >> n >> x;

    int l[n];

    rep(i,n)
     cin >> l[i];


    int d = 0;
    rep(i,n){
        d = d + l[i];
        if(d <= x) 
            ans++;
        else
            break;
     
    }

    /*
    string s;
    cin >> s;
    */
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func gcd(m, n int) int {
	if m < n {
		m, n = n, m
	}
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}
func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n int
	fmt.Sscan(getNextLine(scanner), &n)
	aa := getIntList(scanner)
	dp := make([]int, n)
	dp2 := make([]int, n)
	dp[0] = aa[0]
	dp2[0] = aa[n-1]
	for i := 1; i < n; i++ {
		dp[i] = gcd(dp[i-1], aa[i])
		dp2[i] = gcd(dp2[i-1], aa[n-1-i])
	}
	max := 0
	var ans int
	for i := 0; i < n; i++ {
		if i == 0 {
			ans = dp2[n-2-i]
		} else {
			if i == n-1 {
				ans = dp[i-1]
			} else {
				ans = gcd(dp[i-1], dp2[n-2-i])
			}
		}
		if max < ans {
			max = ans
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 19072
#include <iostream>

int main(void){
	using namespace std;
	int card[4][13] = {0};
	int i, n, b;
	char a;
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> a >> b;
		switch (a){
			case 'S':
				card[0][b-1] = 1;
				break;
			case 'H':
				card[1][b-1] = 1;
				break;
			case 'C':
				card[2][b-1] = 1;
				break;
			case 'D':
				card[3][b-1] = 1;
				break;
		}
	}
	for(i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
		switch (i){
			case 0:
				if(card[0][j] == 0)
					cout << "S " << j+1 << endl;
				break;
			case 1:
				if(card[1][j] == 0)
					cout << "H " << j+1 << endl;
				break;
			case 2:
				if(card[2][j] == 0)
					cout << "C " << j+1 << endl;
				break;
			case 3:
				if(card[3][j] == 0)
					cout << "D " << j+1 << endl;
				break;
				}
			}
}
return 0;
}


Measured memory_bytes: 3100
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, _ := strconv.Atoi(input())
	m, _ := strconv.Atoi(input())
	leftMax := 1
	rightMin := n
	for i := 0; i < m; i++ {
		left, _ := strconv.Atoi(input())
		right, _ := strconv.Atoi(input())
		if left > leftMax {
			leftMax = left
		}
		if right < rightMin {
			rightMin = right
		}
	}

	if leftMax > rightMin {
		fmt.Println(0)
	} else {
		fmt.Println(rightMin - leftMax + 1)
	}
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
const int inf=2e3;
#define maxx 1005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

ll findProductSum(ll A[], int n)
{
    ll array_sum = 0;
    for (int i = 0; i < n; i++)
        array_sum = (array_sum + A[i])%mod;

    ll array_sum_square = (array_sum* array_sum)%mod;

    ll individual_square_sum = 0;
    for (int i = 0; i < n; i++)
        individual_square_sum = (individual_square_sum+(A[i]*A[i])%mod)%mod;
    return (((array_sum_square- individual_square_sum+mod)%mod)*500000004)%mod;
}
int main(){
    FASTIO;
    int n;
    cin>>n;
    ll a[n];
    REP(i,0,n) cin>>a[i];
    cout<<findProductSum(a,n)<<endl;
    return 0;
}


Measured memory_bytes: 5188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int n, k; cin>>n>>k;
    if(k == 1) cout << 0 << endl;
    else cout << n - k << endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    while(1){
        ll n,x,cnt = 0;
        cin >>n>>x;
        if(n == 0 && x == 0) break;
        rep2(i,n){
            rep3(j,i+1,n){
                if(i+j+j+1 <= x && i+j+n >= x){
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    
    
    return 0;
    

}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std ;
// const int MAXN = 6 ;
#define f(i,s,n) for(int i=s;i<n;i++)
char mat[6][6] ;
int main()
{
    int h,w,k;cin>>h>>w>>k ;
    int totalBlacks = 0 ;
    f(i,0,h) f(j,0,w) cin>>mat[i][j],totalBlacks+=mat[i][j]=='#' ;

    int ways = 0 ;
    f(i,0,(1<<h))
    {
        f(j,0,(1<<w))
        {
            int total = 0 ;
            f(r,0,h)
            {
                f(c,0,w) 
                {
                    if(((i&(1<<r))>0) || ((j&(1<<c))>0)) total+=(mat[r][c]=='#') ;
                }
            }
            if(totalBlacks-total==k) ways++ ;
        }
    }
    cout<<ways<<"\n" ;
}

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

int chk[1001];


int main()
{
	int X;
	cin >> X;
	
	chk[1] = true;
	for (int i = 2; i <= 1000; i++) {
		for (int j = 2;; j++) {
			int next = (int)pow(i, j);
			if (next >1000)
				break;
			chk[next] = true;
		}
	}
	for (int i = X; i >= 0; i--) {
		if (chk[i]) {
			cout << i;
			break;
		}
	}
	return 0;
	

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

const int nax = 2e3+10;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int S;
    while(cin>>S){
        ll ans = 0;
        vl dp(nax);
        fore(i,3,S+1) dp[i] = 1;
        add_self(ans, dp[S]);

        // fore(i,1,667){
        //     vl ndp(nax);
        //     fore(s,3*(i-1),S+1){
        //         if(dp[s]==0) continue;
        //         for(int ns=3; s+ns<=S; ++ns)
        //             add_self(ndp[s+ns], dp[s]);
        //     }
        //     dp = ndp;
        //     add_self(ans, dp[S]);
        // }
        
        fore(i,1,667){
            vl ndp(nax);
            fore(s,3*(i-1), S+1){
                if(dp[s]==0) continue;
                int st = 3, ed = S-s;
                if(st>ed) continue;
                add_self(ndp[s+st], dp[s]);
                add_self(ndp[s+ed+1], -dp[s]);
            }
            fore(i,1,nax) 
                add_self(ndp[i], ndp[i-1]);

            dp = ndp;
            add_self(ans, dp[S]);
        }

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

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

typedef struct Card{
	char type;
	int num;
}card;

int main(void)
{
	int i, s,  n, min, c;
	c = 0;
	
	scanf( "%d", &n );
	card a[n];
	card b[n];
	card x;
	for( i = 0; i < n; i++ ){
		scanf( " %c%d", &a[i].type, &a[i].num );
		b[i] = a[i];
	}
	
	for( i = 0; i < n; i++ ){
		for( s = n-1; s > i; s-- ){
			if( a[s].num < a[s-1].num ){
				x = a[s];
				a[s] = a[s-1];
				a[s-1] = x;
			}
		}
	}
	
	for( i = 0; i < n; i++ ){
		min = i;
		for( s = i; s < n; s++ ){
			if( b[s].num < b[min].num ){
				min = s;
			}
		}
		if( i != min ){
			x = b[i];
			b[i] = b[min];
			b[min] = x;
		}
	}
	
	printf( "%c%d", a[0].type, a[0].num );
	for( i = 1; i < n; i++ ){
		printf( " %c%d", a[i].type, a[i].num );
	}
	printf( "\nStable\n" );
	
	printf( "%c%d", b[0].type, b[0].num );
	for( i = 1; i < n; i++ ){
		printf( " %c%d", b[i].type, b[i].num );
	}
	
	for( i = 0; i < n; i++ ){
		if( a[i].type == b[i].type ){
			if( a[i].num == b[i].num ){
			}else{
				c = 1;
			}
		}else{
			c = 1;
		}
	}
	
	if( c == 0 ){
		printf( "\nStable\n" );
	}else{
		printf( "\nNot stable\n");
	}
	
	return 0;
}


Measured memory_bytes: 2092
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define sd1(a) scanf("%d",&a)
#define slld1(a) scanf("%lld",&a)
#define sd2(a,b) scanf("%d%d",&a,&b)
#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd1(a) printf("%d\n",a)
#define plld1(a) printf("%lld\n",a)

int n,cnt,cnt1,i,j;int a[205]={0};
int main(){
	//ios::sync_with_stdio(false);
	for(i=1;i<203;i+=2){
		cnt=0;
		for(j=1;j<=i;j++){
			if(i%j==0){
				cnt++;
			}
		}
		if(cnt==8){
			cnt1++;
		}
		a[i]=cnt1;
		a[i+1]=cnt1;
	}
	while(sd1(n)!=EOF){
		pd1(a[n]);
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
struct LB {
  const static int L = 64; // insert(x) 0 <= x < (1 << L)
  ull a[L];
  LB() { this->init(); }
  void init() { memset(a, 0, sizeof a); }
  ull &operator[](const size_t &id) { return a[id]; }
  const ull &operator[](const size_t &id) const { return a[id]; }
  // 询问x是否在线性基中可以仿造下面的函数来写
  // 即将`return true;`上面三行删去 然后把返回值取反
  // 插入一个数x ==> obj(x) 一边插入一边高斯消元 O(L)
  bool count(ull x) {
    for(int i = L - 1; ~i; i--) {
      if((x >> i) & 1) {
        if(!a[i]) {
          return false;
        } else {
          x ^= a[i];
        }
      }
      if(!x) {
        return true;
      }
    }
    return false;
  }
  bool operator()(ull x) {
    for(int i = L - 1; ~i; i--) {
      if((x >> i) & 1) {
        if(!a[i]) {
          for(int j = 0; j < i; j++) if((x >> j) & 1) x ^= a[j];
          for(int j = i + 1; j < L; j++) if((a[j] >> i) & 1) a[j] ^= x;
          a[i] = x;
          return true;
        } else {
          x ^= a[i];
        }
      }
      if(!x) {
        return false;
      }
    }
    return true;
  }
  // 线性基求交 O(L^2)
  friend LB operator&(const LB &A, const LB &B) {
    LB C, D, E;
    for(int i = L - 1; ~i; i--) {
      if(A[i]) {
        C(A[i]);
        D[i] = 1ull << i;
      }
    }
    for(int i = 0; i < L; i++) {
      if(!B[i]) {
        continue;
      }
      bool can = true;
      ull v = 0, x = B[i];
      for(int j = L - 1; ~j; j--) {
        if((x >> j) & 1) {
          if(C[j]) {
            x ^= C[j], v ^= D[j];
          } else {
            can = false, C[j] = x, D[j] = v;
            break;
          }
        }
      }
      if(can) {
        ull m = 0;
        for(int j = L - 1; ~j; j--) {
          if((v >> j) & 1) {
            m ^= A[j];
          }
        }
        E(m);
      }
    }
    return E;
  }
  // 线性基求并 O(L^2)
  friend LB operator|(const LB &x, const LB &y) {
    LB z;
    for(int i = 0; i < L; i++) if(x[i]) z(x[i]);
    for(int i = 0; i < L; i++) if(y[i]) z(y[i]);
    return z;
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int T; cin >> T;
  while(T--) {
    int n; cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++) {
      cin >> a[i];
    }
    LB o;
    string s; cin >> s;
    bool ok = false;
    for(int i = n - 1; i >= 0; i--) {
      if(s[i] == '0') {
        o(a[i]);
      } else {
        if(!o.count(a[i])) {
          ok = true;
          break;
        }
      }
    }
    cout << (ok ? "1\n" : "0\n");
  }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N, K;
ll i, j, k;
ll ans;

int main(){
    scanf("%lld%lld", &N, &K);
    fornum(i,0,N+1){
        j += i;
        k += N - i;
        if(i+1>=K){
            (ans += k - j + 1)%=MOD;
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const int N = 100005;

int n, a[N], b[N], typ[N];
long long su = 0, x = 0, y = 1;
vector<pair<int, int>> ve;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] <= b[i]) {
            typ[i] = 2;
            su += b[i] - a[i];
            ve.push_back({-b[i], i});
        } else {
            ve.push_back({-a[i], i});
        }
    }
    sort(ve.begin(), ve.end(), greater<pair<int, int>>());
    for (int i = 0; i < n; i++) {
        if (su + ve[i].fi < 0) {
            for (int j = 1; j <= n; j++) {
                long long tsu;
                if (typ[j] == 0) {
                    tsu = su;
                } else if (typ[j] == 2) {
                    tsu = su - (b[j] - a[j]);
                } else {
                    tsu = su + a[j] + ve[i].fi;
                }
                long long tx = b[j] - a[j] + tsu, ty = b[j];
                if (1.0 * tx / ty > 1.0 * x / y) {
                    long long g = __gcd(tx, ty);
                    x = tx / g;
                    y = ty / g;
                }
            }
            x += i * y; y *= n;
            long long g = __gcd(x, y);
            x /= g; y /= g;
            return cout << x << " " << y, 0;
        } else {
            su += ve[i].fi;
            typ[ve[i].se] = 1;
        }
    }
}


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

int main() {
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if(s == u) a--;
    else b--;
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int v[3];
  REP(i, 3) std::cin >> v[i];
  int sum = 0;
  int max_ = 0;
  REP(i, 3) {
    sum += v[i];
    max_ = max(max_, v[i]);
  }
  sum -= max_;
  std::cout << sum << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	int c1 = scan.nextInt();
        	int c2 = scan.nextInt();
        	int c3 = scan.nextInt();
        	int count = 0;
        	for(int i = 1;i < 11;i++){
        		if(c1 == i || c2 == i || c3 == i){
        			continue;
        		}
        		if(c1+c2+i <= 20){
        			count++;
        		}
        	}
        	System.out.println(((double)count/7.0 >= 0.5)?"YES":"NO");
        }
    }
}

Measured memory_bytes: 15364
// Prime Numbers
#include <stdio.h>

int primeNumber(int);

int main(){
  int n, i, A[10000], count=0;
    
  scanf("%d", &n);
  for(i=0; i < n; i++){
    scanf("%d", &A[i]);
    if(primeNumber(A[i]) == 1)count++;
  }
  printf("%d\n", count);
  
  return 0;
}

int primeNumber(int x){
  int i;
  if(x == 2)return 1;
  if(x % 2 == 0)return 0;
  
  for(i=3; i*i <= x; i+=2){
    if(x % i == 0)return 0;
  }
  return 1;
}


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

import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()
cnt = [0] * (len(S) + 1)

for i in range(len(S)):
    if S[i] == '<':
        cnt[i + 1] = max(cnt[i + 1], cnt[i] + 1)

for i in range(len(S) - 1, -1, -1):
    if S[i] == '>':
        cnt[i] = max(cnt[i], cnt[i + 1] + 1)

print(sum(cnt))

Measured memory_bytes: 47116
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
        cin>>v[i];
    }
    vector<ll> dp(n,INF);
    dp[0] = 0;
    for(ll i=0;i<n-1;i++){
        dp[i+1] = min(dp[i+1],dp[i]+abs(v[i+1]-v[i]));
        dp[i+2] = min(dp[i+2],dp[i]+abs(v[i+2]-v[i]));
    }
    
    cout<<dp[n-1];

    return 0;
}






Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main()
{
    string s;
    cin >> s;
    int N[10];
    int B[10];
    int len=(int)(s.length());
    int A[3];
    for (int i = 0; i < len; ++i)
    {

        N[i] = (int)(s[i] - '0');  //str[i]　はchar型なのでchar→intへ変換
        B[i] = 1;

        //確認のため表示
    }
    int now = 10000;
    for (int i = 0; i < len-2; i++)
    {
        if(abs(N[i]*100+N[i+1]*10+N[i+2]-753)<now){
            now = abs(N[i]*100+N[i+1]*10+N[i+2]- 753);
            
        }
    }
    
    cout << now << endl;

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  long long count=0;
  for(long long i=0;i<k;i++)
  {
    if(a>0)
    {
      count+=1;a--;
    }
    else if(b>0)
    {
      b--;
    }
    else
    	count--;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	int a, b, c;
	cin >> a >> b >> c;

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

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

Measured memory_bytes: 3192
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  writeln((scanElem-1)*(scanElem-1));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	const int c = 10000;
	int n,dp[110][10010] = {},a[110];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	int mi = 0,mii = 0,mi2 = 0;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < c;j++){
			dp[i][j] = (j != mii ? mi : mi2) + (a[i] != j);
		}
		mi = INF;
		mi2 = INF;
		for(int j = 0;j < c;j++){
			if(mi2 > dp[i][j]) swap(mi2,dp[i][j]);
			if(mi > mi2){
				swap(mi,mi2);
				mii = j;
			}
		}
	}
	cout << mi << endl;
}

Measured memory_bytes: 8832
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;

const int Maxn = 500005;

int N, M;
int sum[30][Maxn];
char S[Maxn];

void Inite() {
    memset(sum, 0, sizeof(sum));
}

int lowbit(int x) {
    return x & (-x);
}

void add(char tt, int x, int k) {
    for (int i = x; i <= N; i += lowbit(i)) sum[tt - 'a'][i] += k;
}

int ask(int tt, int x) {
    int ans = 0;
    for (int i = x; i != 0; i -= lowbit(i)) ans += sum[tt][i];
    return ans;
}

void Solve() {
    scanf("%d", &N);
    scanf("%s", &S[1]);
    scanf("%d", &M);

    char tp;
    int op, l, r, ans;

    for (int i = 1; i <= N; ++i) add(S[i], i, 1);

    for (int i = 0; i < M; ++i) {
        cin >> op;
        if (op == 2) {
            cin >> l >> r;
            ans = 0;
            for (int j = 0; j < 26; ++j) {
                if (ask(j, r) - ask(j, l - 1)) ans++;
                //cout << ask(j, r) << " " << ask(j, l - 1) << endl;
            }
            cout << ans << endl;
        }
        else {
            cin >> l >> tp;
            add(S[l], l, -1);
            add(tp, l, 1);
            S[l] = tp;
        }
    }
}

int main() {
    Inite();
    Solve();
    return 0;
}


Measured memory_bytes: 59392
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 2e5 + 10, MOD = 1e9 + 7, INF = 1e9 + 5;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	char x;
	cin >> x;
	if(x > 'Z')
		cout << "a\n";
	else
		cout << "A\n";
}


Measured memory_bytes: 3616
h, w = map(int, input().split())
grid = [str(input()) for _ in range(h)]
dp = [[0 for _ in range(w)] for _ in range(h)]
mod = 10 ** 9 + 7
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            continue
        if i>=1:
            dp[i][j]+=dp[i-1][j]
        if j>=1:
            dp[i][j]+=dp[i][j-1]
        dp[i][j]%=mod
print(dp[-1][-1])
        

Measured memory_bytes: 54236
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;

    int l = s.size();
    if(l%2 != 0){
        cout << "No" << endl;
        return 0;
    }
    int num[l] = {};
    for(int i=0;i<l;i++){
        if(s[i] == 'b'){
            num[i] = 1;
        }else if(s[i] == 'd'){
            num[i] = -1;
        }else if(s[i] == 'p'){
            num[i] = 2;
        }else{
            num[i] = -2;
        }
    }

    for(int i=0;i<l/2;i++){
        if(num[i] + num[l-1-i] != 0){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

}

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

int func(int x, int a) {
  int cnt = 0;
  while (x > 0) {
    cnt += x%a;
    x /= a;
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  int ans = 999999999;
  for (int i = 0; i <= n; i++) {
    int tmp = func(i, 6) + func(n - i, 9);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<tuple>
#define all(c) c.begin(),c.end()
#define tr(x,n) for(int i=x;x<n?i<n:i>=n;x<n?i++:i--)
#define ll long long int
#define pb push_back
#define em emplace_back
#define mp make_pair
#define mt make_tuple
#define debug(c) cout<<c<<endl;
#define isro ios_base::sync_with_stdio(false);
#define find(v,x) find(all(v),x)!=v.end()


using namespace std;
typedef vector<ll>vi;
typedef vector<vi>vii;
typedef pair<ll,ll>pi;
typedef tuple<ll,ll,ll>ti;

ll mod=pow(10,9)+7;

int main(){
    isro;

    ll n,m;
    cin>>n>>m;

    vi v(m,0);

    for(ll i=0;i<m;i++){
       cin>>v[i];
    }

    vi step(n+1,1);

    for(ll i=0;i<m;i++){
        step[v[i]]=-1;
    }

    
    if(step[0]!=-1){
        step[0]=1;
    }
    if(step[1]!=-1){
      step[1]=1;
    }
    ll i=2;
    ll f=0;
    while(i<=n){
        if(step[i]!=-1){
            if(step[i-1]==-1 and step[i-2]==-1){
                f+=1;
                break;
            }
            
            else if (step[i-1]!=-1 and step[i-2]!=-1){
                step[i]=(step[i-1]+step[i-2])%mod;
            }
            else{
                if(step[i-1]!=-1 and step[i-2]==-1){
                    step[i]=step[i-1];
                }
                else if(step[i-1]==-1 and step[i-2]!=-1){
                    step[i]=step[i-2];
                }
            }    
            }
        
        i++;
        }

    if(f!=0){
      cout<<0<<endl;      
    }
    else{
      cout<<(step[n])%mod<<endl;
    } 
    }



Measured memory_bytes: 1792
#include <stdio.h>

int isprime(int n);

int main(void)
{
	int i,n;

	while(scanf("%d",&n)){
		if(n==0)
			break;
		for(i=n; i>=2; i--)
			if(isprime(i) && isprime(i-2)){
				printf("%d %d\n",i-2,i);
				break;
			}
	}

	return 0;
}

int isprime(int n)
{
	int i;

	if(n<=1)
		return 0;
	for(i=2; i*i<=n; i++)
		if(n%i==0)
			return 0;
	return 1;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

template<typename T, typename K> struct P{
    T a;
    K b;
};

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N;
	cin >> N;
	map<int, int> mp;
	rep(i,0,N){
		int input;
		cin >> input;
		mp[input]++;
	}
	for(auto m:mp){
		if (m.second != 1){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#define rep(i,n) for(int i = 0; i <n; ++i)
using namespace std;
typedef long long ll;


int main() {

int x,y;
cin>>x>>y;
if (y-2*x >= 0 && 4*x-y>=0 && (y-2*x)% 2==0 && (4*x-y) % 2== 0 )
{
	cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;

return 0;
}



Measured memory_bytes: 3644
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class CSumOfProductOfPairs {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        ll n;
        cin>>n;
        ll a[n],b[n];
        for (int i=0;i<n;i++)
            cin>>a[i];
        b[n-1]=a[n-1];
        for (int i=n-2;i>=0;i--){
            b[i]=a[i]+b[i+1];
            b[i]%=mod1;
        }
        ll sum=0;
        for (int i=0;i<n-1;i++){
            sum+=((a[i]%mod1)*(b[i+1]%mod1))%mod1;
            sum%=mod1;
        }
        cout<<sum;
	}
};


int main() {
	CSumOfProductOfPairs solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 6776
n = int(input())
l = list(map(int,input().split()))
l.sort()
max = len(l)
l.append(10000000000)
ans = 0
for i in range(max-2):
    for j in range(i+1,max-1):
        if l[i] != l[j]:
            k = j+1
            while l[j] == l[k]:
                k += 1
            while l[i] + l[j] > l[k]:
                ans += 1
                k += 1
print(ans)

Measured memory_bytes: 9160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(){

    int n;

    cin >> n;

    if(n >= 1000){
        cout << "ABD" << endl;
    }else{
        cout << "ABC" << endl;
    }

    return 0;
}


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

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) { ll d; return b == 0 ? (x = 1, y = 0, a) : (d = extgcd(b, a % b, y, x), y -= a / b * x, d); }
ll modinv(ll a, ll mod = 1e9 + 7) { ll x = 0, y = 0; extgcd(a, mod, x, y); return (x + mod) % mod; }
ll modpow(ll a, ll b, ll mod = 1e9 + 7) { ll r = 1; a %= mod; while(b) { if(b & 1) r = r * a % mod; a = a * a % mod; b >>= 1; } return r; }

int sol() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if(b > d) return 0;
  if(a < b) return 0;
  if(b <= c) return 1;
  ll g = gcd(b, d);
  a %= b;
  a += (b - 1 - a) / g * g;
  if(a > c) return 0;
  return 1;
}

#define POS(x) cout<<((x)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define Pos(x) cout<<((x)?"Possible":"Impossible")<<endl;
#define YES(x) cout<<((x)?"YES":"NO")<<endl;
#define Yes(x) cout<<((x)?"Yes":"No")<<endl;
#define yes(x) cout<<((x)?"yes":"no")<<endl;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int t; cin >> t;
  while(t--) {
    Yes(sol());
  }
  return 0;
}



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

int n;
double memo[N][N][N];

double e(int ones, int twos, int threes) {
    if ((ones | twos | threes) == 0) return 0.0;

    double &m = memo[ones][twos][threes];
    if (m != 0.0) return m;

    double mult = 1.0 * n / (ones + twos + threes);
    double sum = 0;
    sum += ones == 0 ? 0 : 1.0 * ones / n * e(ones - 1, twos, threes);
    sum += twos == 0 ? 0 : 1.0 * twos / n * e(ones + 1, twos - 1, threes);
    sum += threes == 0 ? 0 : 1.0 * threes / n * e(ones, twos + 1, threes - 1);
    return m = mult * (1 + sum);
}

int main() {
    scanf("%d", &n);
    int cnt[3 + 1]; memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; i++) {
        int v; scanf("%d", &v);
        cnt[v]++;
    }
    printf("%.12lf\n", e(cnt[1], cnt[2], cnt[3]));
}



Measured memory_bytes: 140024
n,k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10**9

for i in range(n-k+1):
    if x[i]>=0:
        ans = min(ans, x[i+k-1])
    elif x[k+i-1]<=0:
        ans = min(ans,-x[i])
    else:
        ans = min(ans, x[k+i-1]*2-x[i], x[k+i-1]-x[i]*2)

print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define REYNA(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, pair <int, ll> > PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
const int maxn = 1e5 + 5;
string s;
int t[maxn];
int deg[maxn], n;
vector <int> v[maxn];
vector <int> ch[maxn];
int BEST = 0;

int UP[maxn], DOWN[maxn]; //DOWN to takie ktore licza dolny wierzcholek

inline int fun(int x)
{
	if (t[x]) return 1;
	return -1;
}

void DFS(int x, int par)
{
	bool leaf = 1;
	int downbest = 0, upbest = 0;
	for (auto u : ch[x])
		if (u != par)
		{
			DFS(u, x);
			leaf = 0;
			BEST = max(BEST, downbest + UP[u] + fun(x));
			BEST = max(BEST, upbest + DOWN[u] + fun(x));
			downbest = max(DOWN[u], downbest);
			upbest = max(UP[u], upbest);
		}

	if (leaf)
	{
		UP[x] = 1;
		DOWN[x] = 1 + fun(x);
	}
	else
	{
		UP[x] = 1; DOWN[x] = 1 + fun(x);
		for (auto u : ch[x])
		if (u != par)
		{
			UP[x] = max(UP[x], UP[u] + 1 + fun(x));
			DOWN[x] = max(DOWN[x], DOWN[u] + 1 + fun(x));
		}
	}
	
	BEST = max(BEST, UP[x] - 1);
	BEST = max(BEST, DOWN[x] - 1);
}

int main()
{
	boost;
	cin >> n;
	FOR(i, 2, n)
	{
		int a, b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
		deg[a]++; deg[b]++;
	}
	
	cin >> s;
	int sum = 0;
	for (int i=0; i<n; ++i)
	{
		if (s[i] == 'W') t[i + 1] = 1;
		else t[i + 1] = 0;
		sum += t[i + 1];
	}
	
	if (!sum) OUT(0);
	if (sum == 1) OUT(1);
	//istnieje juz jakies sensowne drzewo
	queue <int> q;
	FOR(i, 1, n)
		if (deg[i] == 1 && !t[i]) q.push(i);

	int flag = n;
	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		flag--;
		deg[x] = 0;
		for (auto u : v[x])
		{
			if (deg[u] > 1) deg[u]--;
			if (deg[u] == 1 && !t[u]) q.push(u);
		}
	}
	int result = 2 * (flag - 1);
	FOR(i, 1, n)
	{
		if (deg[i] == 0) continue;
		t[i] ^= (deg[i] % 2);
		result += t[i];
	}

	FOR(i, 1, n)
	{
		UP[i] = DOWN[i] = -1;
		if (!deg[i]) continue;
		for (auto u : v[i])
			if (deg[u]) ch[i].pb(u);
	}
	
	FOR(i, 1, n)
		if (deg[i]) 
		{
			DFS(i, 0);
			break;
		}

	cout << result - BEST;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int res = 0;
  for (int i = 0; i + 2 < N; ++i) {
    if (S.substr(i, 3) == "ABC") ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cmath>
#include <algorithm>

int main()
{
    int A, B, K;
    scanf("%d %d %d", &A, &B, &K);
    int C = std::min(A, B);
    int D = std::max(A, B);
    int count = 0;
    for (int i = C; i >= 1; --i)
    {
        int rc = C % i;
        int rd = D % i;
        if (rc == 0 && rd == 0)
        {
            ++count;
        if (count == K)
        {
            printf("%d\n", i);
            return 0;
        }
        }
    }
    return 0;
}

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

using namespace std;

const int N=2e5+10;

int n,p[N];
int h[N];
vector <int> v[N];
int BFS(int st){
        vector <int> p1,p2;
        queue <int> q;
        h[st]=1;
        q.push(st);
        while (!q.empty()){
                int x=q.front();q.pop();
                p1.push_back(x),p2.push_back(p[x]);
                for(auto y:v[x]) if (!h[y]){
                        h[y]=1;
                        q.push(y);
                }
        }
        sort(p1.begin(),p1.end());
        sort(p2.begin(),p2.end());
        int n1=p1.size();
        int ans=0;
        for(int i=0,j=0;i<n1&&j<n1;i++){
                while (j<n1&&p2[j]<p1[i]) j++;
                if (j<n1) ans+=p2[j]==p1[i];
        }
        return ans;
}
int main(){
        int m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>p[i];
        while (m--){
                int x,y;
                cin>>x>>y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        int ans=0;
        for(int i=1;i<=n;i++) if (!h[i]) ans+=BFS(i);
        cout<<ans;
}


Measured memory_bytes: 10448
#include <stdio.h>

int main(void) {
   
   int K,N;
   
   scanf("%d%d", &K, &N);
   
   int i;
   int A[N];
   
   for (i = 0; i < N; i++) {
      scanf("%d", &A[i]);
   }
   
   int Distance[N];
   
   for (i = 0; i < N - 1; i++) {
      Distance[i] = A[i+1] - A[i];
   }
   Distance[N-1] = K - A[N-1] + A[0];
   
   int max_distance = 0;
   
   for (i = 0; i < N; i++) {
      if (max_distance <= Distance[i]) {
         max_distance = Distance[i];
      }
   }
 
   printf("%d\n", K - max_distance);
   
   
   return 0;
}



Measured memory_bytes: 1792
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

int n, a[51], ans, tar;

ll dp[51][2501][51];

ll solve(int i, int sum, int cnt){
    if(i == n){
        if(!cnt)return 0;
        return (sum % cnt == 0 && sum / cnt == tar);
    }
    ll &ret = dp[i][sum][cnt];
    if(~ret)return ret; ret = 0;
    ret += solve(i + 1, sum, cnt);
    ret += solve(i + 1, sum + a[i], cnt + 1);
    return ret;
}

int main(){
    scanf("%d %d", &n, &tar);
    for(int i = 0 ; i < n ; ++i)
        scanf("%d", a + i);
    memset(dp, -1, sizeof dp);
    printf("%lld\n", solve(0, 0, 0));
}

Measured memory_bytes: 51200