akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int,int>;

int main() {
  int N,ans = 0;
  cin >> N;
  vector<int> s(N);
  rep(i,N) cin >> s.at(i);
  sort(s.begin(),s.end());
  rep(i,N-2) {
    for(int j=i+1; j<N-1; j++) {
      int xr = N-1;
      int xl = j+1;
      if( s.at(i) + s.at(j) > s.at(xr)) {
        ans += xr-j;
      } else if(s.at(i) + s.at(j) <= s.at(xl)){ 
        ans += 0;
      } else {

        while( xr-xl > 1) {
        
          int x = (xr + xl) /2;
        
          if(s.at(i) + s.at(j) > s.at(x)) {
         
            xl = x;
        
          } else {
          xr = x;
        
          }
        }
      
        ans += xl - j;
      }
    }
  }
  cout << ans << endl;    
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int cmp(const void *a, const void *b)
{
	return strcmp((char *)a, (char *)b);//昇順
							   //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
	long long N,i,j,k,l;
	char(*s)[12] = (char(*)[12])
	malloc(100010*12 * sizeof(char));
	long long ans = 0;
	
	scanf("%lld", &N);
	for (i = 0;i < N;i++)
	{
		scanf("%s", s[i]);
		
		
	}
	for (i = 0;i < N;i++)
	{
		qsort((void *)s[i], 10, sizeof(char)
			, cmp);

		
	}
	
		qsort((void *)s, N, sizeof(s[0])
			, cmp);

	j = 0;
	k = 0;
	l = 0;
	while (j < N)
	{
		if (strcmp(s[j],s[k+1])==0) {
			ans++;
			ans += l;
			k++;
			l++;
		}
		else
		{
			j=k+1;
			k = j;
			l = 0;
		}
	}
	printf("%lld\n", ans);
	free(s);
	return 0;
}

Measured memory_bytes: 2556
import java.io.*;

public class Main {

	public static void main(String[] args) {
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int length = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			
			int[] array = new int[length];
			for (int i = 0 ; i< length ; i++){
				array[i] = Integer.parseInt(str[i]);
			}
			
			InsertionSort.Sort(array);
			
		}catch(Exception e){
			System.out.println("??¨??????");
		}
	}
}

class InsertionSort{

	static void Sort(int[] array){
		for (int i = 0 ; i< array.length ; i++){
			OneSort(array,i);
			Display(array);
		}
	}
	
	static void OneSort(int[] array, int index){
		int v = array[index];
		while (index != 0 && array[index-1] > v){
			array[index] = array[index-1];
			index--;
		}
		array[index] = v;
	}
	
	static void Display(int[] array){
		
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < array.length-1; i++){
			sb.append(Integer.toString(array[i]));
			sb.append(" ");
		}
		sb.append(Integer.toString(array[array.length-1]));
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 27892
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

template<class U,class T>ostream& operator<<(ostream& out, pair<U,T> & P){
    return out << "[" << P.first << ", " << P.second << "]";
}
template<class T>ostream& operator<<(ostream& out, vector<T> & V){
    if(!V.empty())out << "[";
    for(int i = 0; i < sz(V); i++)out << V[i] << (i+1==sz(V)?"]":", ");
    return out;
}

vector<int> V;

int main(){
    ios_base::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    V.resize(N);
    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    sort(all(V), greater<int>());

    long long res = 0;

    for(int i = K; i < V.size(); i++){
        res+=V[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int n;
    std::cin >> n;
    int d[100];
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }
    long long int sum=0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            sum+=d[i]*d[j];
        }
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

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

	if (a == 0) {
		cout << b / c + 1 << endl;
	}
	else {
		cout << (b / c) - ((a - 1) / c) << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define int                  int64_t
#define double               long double
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               (a).begin(),(a).end()
#define rall(a)              (a).rbegin(),(a).rend()
#define PI                   3.1415926535897932384626433832795
#define read(a)              for(auto& x:a) cin>>x
#define speak(a)             for(auto x:a) cout<<x<<' '
#define rep(i,s,n)           for(int i=s;i<n;++i)
#define repe(i,s,n)          for(int i=s;i<=n;++i)
#define repr(i,n,s)          for(int i=n;i>=s;--i)
#define endl                 '\n'
#define gap                  ' '
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s,x;cin>>s>>x;
    int c=0;
    rep(i,0,s.size()) c+=(s[i]!=x[i]);
    cout<<c;
}


Measured memory_bytes: 3796
import sys
r=sys.stdin.readline
def s():
 def b(M,x,y,n=1):
  M[x][y]=0;a=n
  if M[x-1][y]:a=max(a,b(M,x-1,y,n+1))
  if M[x][y-1]:a=max(a,b(M,x,y-1,n+1))
  if M[x+1][y]:a=max(a,b(M,x+1,y,n+1))
  if M[x][y+1]:a=max(a,b(M,x,y+1,n+1))
  M[x][y]=1
  return a
 for e in iter(r,'0\n'):
  n,m=int(e),int(r())
  P=[[0]*(n+2)for _ in[0]*(m+2)]
  for i in range(m):P[i+1][1:-1]=map(int,r().split())
  print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j]))
if'__main__'==__name__:s()


Measured memory_bytes: 5736
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_TOWN_MAX		8										// 最大町数

// 内部構造体 - 座標情報
typedef struct Point {
	int miX, miY;												// 座標
} Point;

// 内部変数
static FILE *szpFpI;											// 入力
static Point sz1Town[D_TOWN_MAX];								// 町
static int siTCnt;												// 町数
static double sdSum;											// 距離合計

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 距離合計 - セット
int
fSetSum(
	int piTCnt					// <I> 町数
	, int *pipDone				// <I> 処理済
	, int *pipOrd				// <I> 順番
	, double pdLen				// <I> 距離
)
{
	int i;

	// 町数
	if (piTCnt == siTCnt) {

		// 距離合計 - 加算
		sdSum += pdLen;

		return 0;
	}

	// 町数でループ
	for (i = 0; i < siTCnt; i++) {

		// 処理済
		if (pipDone[i] != D_OFF) {
			continue;
		}
		pipDone[i] = D_ON;

		// 順番
		pipOrd[piTCnt] = i;

		// 距離
		double ldLen;
		if (piTCnt == 0) {
			ldLen = 0.0;
		}
		else {
			double ldX = sz1Town[i].miX - sz1Town[pipOrd[piTCnt - 1]].miX;
			double ldY = sz1Town[i].miY - sz1Town[pipOrd[piTCnt - 1]].miY;
			ldLen = sqrt(ldX * ldX + ldY * ldY) + pdLen;
		}

		// 下位へ
		fSetSum(piTCnt + 1, pipDone, pipOrd, ldLen);

		// 処理済 - 解除
		pipDone[i] = D_OFF;
	}

	return 0;
}

// 実行メイン
double
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 町数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siTCnt);

	// 町 - 取得
	for (i = 0; i < siTCnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &sz1Town[i].miX, &sz1Town[i].miY);
	}

	// 距離合計 - セット
	int li1Done[D_TOWN_MAX], li1Ord[D_TOWN_MAX];
	memset(li1Done, D_OFF, sizeof(li1Done));
	fSetSum(0, li1Done, li1Ord, 0.0);

	// 距離平均 - 取得
	double ldAvg = sdSum;
	for (i = siTCnt; i > 1; i--) {
		ldAvg /= (double)i;
	}

	return ldAvg;
}

// １回実行
int
fOne(
)
{
	double ldRet;
	char lc1Buf[1024];

	// データ - 初期化
	sdSum = 0.0;												// 距離合計

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	ldRet = fMain();

	// 出力
	sprintf(lc1Buf, "%.7lf\n", ldRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,sum=0;
    cin>>x>>y;
    int arr[y];
    for(int i=0;i<y;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<y;i++)
    {
        sum+=arr[i];
    }
    if(sum>=x)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    bool dp[d5];
    for(int i=0;i<d5;i++)dp[i]=false;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]>=0){
                if(!dp[i-a[j]])dp[i]=true;
            }
        }
    }
    //for(int i=0;i<=k;i++)cout<<dp[i]<<' ';
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var S string
	var Days = [7]string{
		"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT",
	}
	fmt.Scan(&S)
	for i := 0; i < 7; i++ {
		if S == Days[i] {
			fmt.Println(7 - i)
			break
		}
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int s_length = int(s.length());
    int count = 0;

    for (int i = 1; i < s_length; i++) {
        if (s[i-1] == s[i]) {
            s[i] = s[i] == '0' ? '1' : '0'; 
            count++;
        }
    }
    int ans = (count > (s_length - count)) ? (s_length - count) : count;
    cout << ans << endl;
}


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

using namespace std;

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

  int64_t answer = 0;
  for (int i = 1; i <= N; i++) {
    int64_t K = N / i;
    answer += (K * (K + 1)) / 2 * i;
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 3632
def resolve():
    n, m = map(int, input().split())
    ks = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ans = 0
    for i in range(2**n):
        switch = [0]*n
        flag = True
        for j in range(n):
            if (i >> j) & 1:
                switch[j] = 1
        for k in range(m):
            test = ks[k][1:]
            on = 0
            for l in range(len(test)):
                if switch[test[l]-1] == 1:
                    on += 1
            if on % 2 != p[k]:
                flag = False
        if flag:
            ans += 1
    print(ans)

resolve()

Measured memory_bytes: 42480
from sys import stdin, stdout
from collections import Counter
for _ in range(1):#int(stdin.readline())
    n=int(stdin.readline())
    a=list(map(int, stdin.readline().split()))
    xor=0
    for v in a:xor^=v
    ans=[]
    for v in a:
        ans+=[v^xor]
    print(*ans)


Measured memory_bytes: 31476
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def solve():
    X,Y = map(int, input().split())

    X_,Y_ = (2*X-Y)//3, (2*Y-X)//3
    if (X+Y) % 3 != 0 or X_ < 0 or Y_ < 0: 
        print(0)
        return
    
    print(cmb(X_+Y_,Y_, mod))
    
solve()

Measured memory_bytes: 123768
from itertools import product

n = int(input())

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

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


# 全探索
best_score = float("-inf")

for i in product((0, 1), repeat=10):
    if sum(i) == 0:
        continue

    score = 0
    for k in range(n):
        num = sum([p * q for p, q in zip(i, F[k])])
        score += P[k][num]

    best_score = max(best_score, score)

print(best_score)


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  cout << min(N*A,B)<<endl;

  
  return 0;
}


Measured memory_bytes: 256
n, m =map(int,input().split())
s = list(map(int,input().split()))
free = n
i = 0
while i < m :
     free -= s[i]
     if free < 0 :
          break
     i += 1
if free < 0 :
     print("-1")
elif free >= 0 :
     print(str(free))

Measured memory_bytes: 9988
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> a(n), a2(n, 0);
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  rep(i, 0, n - 1) {
    if (a[i] & 1 && a[i+1]) {
      a[i]--;
      a[i + 1]++;
    }
  }

  rep(i, 0, n) { ans += a[i] / 2; }

  cout << ans << endl;
}


Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

    int a,b;
    while(cin>>a>>b&&!(a==0&&b==0)){
    int data[4];
    int minNum=-1;
    for(int i = 1; i*i<=a; i++){
        if(a%i!=0)continue;
        for(int j = 1; j*j<=b; j++){
            if(b%j!=0)continue;
            data[0]=i;data[1]=a/i;
            data[2]=j;data[3]=b/j;
            sort(data,data+4);
            int sum=0;
            for(int k = 1; k < 4; k++)
                sum+=(data[k-1]-data[k])*(data[k-1]-data[k]);
            if(sum==19){
       //         cout<<endl;
            }
            if(minNum==-1||minNum>sum)
                minNum=sum;
        }
    }
    cout<<minNum<<endl;
    }

    return 0;
}

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

using namespace std;
int main()
{
    int n,x,k;
    cin>>n;
    cin>>k;
    vector<int> v,dp(n+1,0);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    v.insert(v.begin(),0);
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
       int mini=INT_MAX;
        for(int j=1;j<=k && i-j>=1;j++)
        {
            mini=min(dp[i-j]+abs(v[i-j]-v[i]),mini);
        }
        dp[i]=mini;
    }
    cout<<dp[n];
}

Measured memory_bytes: 4232
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        n: i32,
        s: String,
    }

    let mut ans = 0;
    let mut count = 0;

    for c in s.chars() {
        if c == 'I' {
            count += 1;
        }

        if c == 'D' {
            count -= 1;
        }

        ans = cmp::max(ans, count);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib>
#include <typeinfo>

using namespace std;

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


int i,j;

int main(void){
    
    string a,b;
    cin>>a>>b;
    int alen = a.length();
    int blen = b.length();
    
    if(alen>blen){
        cout<<"GREATER";
        return 0;
    }
    else if(alen<blen){
        cout<<"LESS";
        return 0;
    }
    else if(alen==blen){
        FOR(i,alen){
            if(a[i]>b[i]){
                cout<<"GREATER";
                return 0;
            }
            else if(a[i]<b[i]){
                cout<<"LESS";
                return 0;
            }
        }
    }
    
    cout<<"EQUAL";
    
    
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N; cin >> N;
    vector<string>grid(N);
    for(auto& s : grid) cin >> s;
    vector<vector<int>>edge(N);
    vector<vector<int>>dis(N,vector<int>(N,INF));
    for(int i = 0; i < grid.size(); ++i){
        for(int j = 0; j < grid[i].size(); ++j){
            char c = grid[i][j];
            if(c == '1'){
                edge[i].push_back(j);
                dis[i][j] = 1;
            }
        }
    }
rep(i,N)dis[i][i]=0;
    rep(k,N)rep(i,N)rep(j,N) cmin(dis[i][j],dis[i][k]+dis[k][j]);
    vector<int>d(N,-1);
    bool valid = true;
    function<void(int,int)>visitor = [&](int v,int crt){
        d[v] = crt;
        for(auto nv : edge[v]){
            if(d[nv] == -1)
                visitor(nv,(not crt));
            else if(d[nv] == d[v])
                valid = false;
        }
    };
    int root  = 0;
    visitor(root,0);
    if(not valid) return puts("-1") * 0;
    int ans = 0;
    for(int i = 0; i < dis.size(); ++i)
        cmax(ans, *max_element(dis[i].begin(), dis[i].end()));
    cout << ans + 1 << endl;
    
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <int> v(n);
    generate(all(v),nxt);
    int test=0;
    int i=0;
    while(i<n)
    {
        int x=i;
        while(i+1<n&&v[i+1]<=v[i])
            i++;
        test=max(test,i-x);
        i++;
    }
    cout<<test<<endl;
    
    
    return 0;   
}


 
 


Measured memory_bytes: 640
n=int(input())
p=list(map(int,input().split()))
p_=[]
b=False
c=0
while b==False:
  p_=list(map(lambda in_:in_%2,p))
  b = 1 in p_
  p=list(map(lambda in_:int(in_/2),p))
  c+=1
print(c-1)

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,M;
  cin >> N >> M;
  string S,T;
  cin >> S >> T;

  ll lcm_NM = lcm(N,M);
  string LS="";
  string LT="";
  for(int i=0;i<N;i+=lcm_NM/M)  LS+=S.at(i);
  for(int i=0;i<M;i+=lcm_NM/N)  LT+=T.at(i);
  if(LS==LT)  cout << lcm_NM << endl;
  else  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 3856
def resolve():
    '''
    code here
    '''
    import bisect
    N = int(input())
    Ds = [int(item) for item in input().split()]
    M = int(input())
    Ts = [int(item) for item in input().split()]
    Ds.sort()
    Ts.sort()

    for item in Ts:
        index = bisect.bisect_left(Ds, item)
        if Ds[index] != item:
            print('NO')
            break
        else:
            Ds[index] = -1
    else:
        print('YES')
        



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 41472
/* Coder: @SumitRaut
 * Date: 29-08-2020 17:49:26
 */
#include <bits/stdc++.h>
#define debug1(x) cout<<#x<<' '<<x<<'\n'
#define debug2(x,y) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<'\n'
#define debug3(x,y,z) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<'\n'
#define ll long long
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
vector<int> par, sz;
int find(int cur) {
    return par[cur] == 0 ? cur : par[cur] = find(par[cur]);
}
void solve() {
    int n,m;
    cin>>n>>m;
    par.resize(n+1),sz.resize(n+1,1);
    int ans=1;
    int a,b;
    while(m--) {
        cin>>a>>b;
        a=find(a),b=find(b);
        if(a!=b) {
            if(sz[a]>sz[b])swap(a,b);
            sz[b]+=sz[a];
            sz[a]=0;
            par[a]=b;
            if(ans<sz[b]) ans=sz[b];
        }
    }
    cout<<ans<<'\n';
}
int main()
{
    speedup;
    // int t; cin>>t; while(t--)
    solve();
    // system("pause");
    return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <bitset>
#include <math.h>
#define INPUT(X) cin >> X
#define OUTPUT(X) cout << X << endl
#define REPEAT(i,n) for(int i=0;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;
#define INF 10000000000000


inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

template<class T>
bool inline ChangeMinimum( T &a, T b )
{
	if( a > b ){
		a = b;
		return true;
	}
	return false;
}

class Tree
{
	public:
//		Tree(int _root);
		int root;
		vector<int> next;
		int value = 0;
};

template<class T>
class Vec3
{
	public:
		T act[3];
};

int Stair( int now, vector<ll> &H )
{
	if( H[now] >= H[now+1] ){}
	
}

int main(void) {


	int N;
	INPUT(N);
	vector<ll> H(N);
	REPEAT(i,N)INPUT(H[i]);
	
	int now = 0;
	int ans = 0;
	
	while(now < N-1){
		int dan = 0;
		for(;;){
			if( H[now] >= H[now+1] ){
				dan++;
			}else{
				break;
			}
			now++;
			if(now == N-1)break;
		}
		if(dan >= ans ) ans = dan;
		now++;
	}
	OUTPUT(ans);
	
		
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(r: i64, g: i64, b: i64, n: i64);
    let mut tot = 0;
    for i in 0..n + 1 {
        for j in 0..n + 1 {
            let rem = n - r * i - g * j;
            if rem >= 0 && rem % b == 0 {
                tot += 1;
            }
        }
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007 
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        cout<<(a*b)<<"\n";
    }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>S;
	FOR(y,S.size()) FOR(x,y) if(S[x]=='C' && S[y]=='F') return _P("Yes\n");
	_P("No\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())

items = []
for i in range(N):
	a, b = map(int, input().split())
	items.append((a, -b))

items.sort()

scores = [None] * T
scores[0] = 0
max_d = 0

def search_max():
	max = 0
	for i in range(T):
		s = scores[i]
		if s != None and s > max:
			max = s
	return max

for i in range(N):
	a, b = items[i]
	b = -b
	d = search_max() + b
	if d > max_d:
		max_d = d
	for j in range(T - 1, -1, -1):
		s = scores[j]
		if s != None:
			s += b
			t = j + a
			if t < T:
				prev_s = scores[t]
				if prev_s == None or prev_s < s:
					scores[t] = s

print(max_d)


Measured memory_bytes: 47848
s = input()

def kaibun(string):
    if string==string[::-1]:
        return True
    else:
        return False

a = s.replace('x', '')

if kaibun(a) == True:
    cnt = 0
    i = 0
    j = len(s) - 1
    while i < j:
        if s[i] != s[j]:
            if s[i] == 'x':
                cnt += 1
                i += 1
            elif s[j] == 'x':
                cnt += 1
                j -= 1
        else:
            i += 1
            j -= 1

    print(cnt)
else:
    print('-1')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

namespace flow {
  const int N = 200010, M = 200010, INF = 0x3f3f3f3f;
  struct edge {
    int la,b,cap;
  } con[M << 1];
  int tot = 1, fir[N];
  void add_edge(int from,int to,int capc) {
    con[++tot] = (edge) {fir[from], to, capc};
    fir[from] = tot;
    con[++tot] = (edge) {fir[to], from, 0};
    fir[to] = tot;
  }
  int st, en, n, cur[N], dis[N];
  int dfs(int pos,int imp) {
    if (pos == en || !imp) return imp;
    int ret = 0, tmp;
    for (int &i = cur[pos]; i; i = con[i].la) {
      if (dis[con[i].b] == dis[pos] + 1) {
	tmp = dfs(con[i].b, min(con[i].cap, imp));
	con[i].cap -= tmp;
	con[i^1].cap += tmp;
	imp -= tmp;
	ret += tmp;
	if (!imp) break;
      }
    }
    return ret;
  }
  bool bfs() {
    queue<int> q;
    memset(dis, 0x3f, sizeof dis);
    dis[st] = 0;
    q.push(st);
    for (int pos; !q.empty(); q.pop()) {
      pos = q.front();
      for (int i = fir[pos]; i; i = con[i].la)
	if (con[i].cap > 0 && dis[con[i].b] > dis[pos] + 1) {
	  dis[con[i].b] = dis[pos] + 1;
	  q.push(con[i].b);
	}
    }
    if (dis[en] == INF) return false;
    rep (i, 1, n) cur[i] = fir[i];
    return true;
  }
  int solve() {
    int ret = 0;
    while (bfs())
      ret += dfs(st, INF);
    return ret;
  }
}

const int N = 100010;
int n, val[2][N], bel[2][N], ans;
int main() {
  read(n);
  rep (k, 0, 1) rep (i, 1, n) read(val[k][i]), ++ val[k][i];
  rep (k, 0, 1) {
    rep (i, 1, n) {
      for (int j = i; !bel[k][j]; j = val[k][j])
	bel[k][j] = i + k * n;
    }
  }
  ans = n;
  flow::n = 2 * n;
  flow::st = ++ flow::n, flow::en = ++ flow::n;
  rep (i, 1, n) {
    if (val[0][i] == val[1][i]) {
      if (val[0][i] == i) -- ans;
      else {
	flow::add_edge(bel[1][i], bel[0][i], 1);
	flow::add_edge(bel[0][i], bel[1][i], 1);
      }
    } else {
      if (val[0][i] == i) {
	flow::add_edge(bel[1][i], flow::en, 1);
      } else if (val[1][i] == i) {
	flow::add_edge(flow::st, bel[0][i], 1);
      } else {
	flow::add_edge(bel[1][i], bel[0][i], 1);
      }
    }
  }
  ans -= flow::solve();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10496
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  print . showAnswer $ solve n

type Input  = (Int)
type Output = Int

solve :: Input -> Output
solve = flip div 3

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
  int c = 0;
 string S;
 cin >> S;
 for(int i = 0; i < 4; i++){
  if(S.at(i) == '+'){
    c++;
  }else if(S.at(i) == '-'){
    c--;
  }
 }
 cout << c << endl;
}


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

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)
#print(person_list)
#print(syogen_list)

for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        #print(bin(bit))
        if break_flag:
            break
        if (bit >> i) & 1: #人iが正直
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): #矛盾　：　正直としているのに証言が食い違えばbreak
                    break_flag = 1
                    #print("1_break",bit>>(person_list[i][j]-1))
                    break
#                if j == len(syogen_list[i])-1:
#                    bit_1_cnt += 1
        if break_flag==0 and i==n-1:
            #ans = max(ans, bit_1_cnt)
            ans = max(ans, bin(bit).count("1"))
print(ans)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
int b=0;

int main() {
  int N, L;
  cin >>N>>L;
  vector<int> apple(N);
  vector<int> apple_abs(N);
  int mini=9999;
  int mini_idx;
  
  for(int i; i<N; i++){
    apple[i] = L+i;
    b += (L+i);
    
    if(L+i>=0){
      apple_abs[i] = L+i;
    }else{
      apple_abs[i] = -(L+i);
    }
    
    if(apple_abs[i] < mini){
      mini = apple_abs[i];
      mini_idx = i;
    }    
  }

  cout << (b-apple[mini_idx]) << endl;

}

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

int main() {
	long int X;
	cin >> X;

	for (int a = -118; a < 120; a++) {
		for (int b = -118; b < 120; b++) {
			if (pow(a, 5) - pow(b, 5) == X) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 4092
N = int(input())
S = list(input())

numE = S.count('E')
numTurn = numE
numW = 0

for i in range(N):
    if S[i] == 'E':
        numE -= 1
    else:
        numW += 1
    if numTurn > numE + numW:
        numTurn = numE + numW

print(numTurn)


Measured memory_bytes: 5792
NQ = input().split()
N = int(NQ[0])
Q = int(NQ[1])

S = input()


t = [0]

for i in range(N):
    if S[i:i+2] == "AC":
        t.append(t[i]+1)
    else:
        t.append(t[i])
        
for i in range(Q):
    lr = input().split()
    l = int(lr[0])
    r = int(lr[1])
    cnt = t[r-1] - t[l-1]
    print(cnt)

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int i, j, count = 0, ans = 0;
  vector<int> a(26), b(26);
  for(i = 1; i < n; i++){
    string t, u;
    t = s.substr(0, i);
    u = s.substr(i, n - i);
    for(j = 0; j < t.size(); j++){
      a.at(t.at(j) - 97)++;
    }
    for(j = 0; j < u.size(); j++){
      b.at(u.at(j) - 97)++;
    }
    for(j = 0; j < 26; j++){
      if(a.at(j) > 0 && b.at(j) > 0) count++;
    }
    ans = max(ans, count);
    count = 0;
    for(j = 0; j < 26; j++){
      a.at(j) = b.at(j) = 0;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sc(n) scanf("%d",&n)
#define scll(n) scanf("%lld",&n)
using namespace std;
int main(){
int n,a[300005],t,l,k,j,o,w,e,i;
sc(n);
getchar();
memset(a,0,sizeof(a));
for(i=0,w=0;i<n;i++){
   a[i]=getchar();
   if(a[i]=='W'){w++;}
}
if(a[0]=='W'){w--;}
e=w;
for(i=0;i<n-1;i++){
    if(a[i]=='E'){w++;}
    if(a[i+1]=='W'){w--;}
    e=max(e,w);
}
printf("%d",n-1-e);
return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class133
    {
        static void Main()
        {
            var DG = Console.ReadLine().Split().Select(long.Parse).ToArray();
            int D = (int)DG[0];long G = DG[1];
            var p = new int[D];
            var c = new int[D];
            for(int i = 0; i < D; i++)
            {
                var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = r[0];
                c[i] = r[1];
            }
            int ans = int.MaxValue;
            for(int i = 0; i < (1 << D); i++)
            {
                long sum = 0;
                int count = 0;
                for(int j = 0; j < D; j++)
                {
                    if ((i & (1 << j)) > 0)
                    {
                        sum += (j + 1) * 100 * p[j] + c[j];
                        count += p[j];
                    }
                }
                if (sum < G)
                {
                    for(int j = D - 1; j >= 0; j--)
                    {
                        if ((i & (1 << j)) == 0)
                        {
                            if(G-sum>=p[j]*(j+1)*100)
                            {
                                count = int.MaxValue;break;
                            }
                            else
                            {
                                count +=(int) Math.Ceiling((double)(G - sum) / ((j + 1) * 100));
                                break;
                            }
                        }
                    }
                    
                }
                ans = Math.Min(ans, count);
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main(){
  int hMax,hMin = 0,wMax,wMin = 0,N,x,y,a;
  cin >> wMax >> hMax >> N;
  for(int i = 0; i < N; i++){
    cin >> x >> y >> a;
    switch (a) {
      case 1:
        wMin = max(wMin,x);
        break;
      case 2:
        wMax = min(wMax,x);
        break;
      case 3:
        hMin = max(hMin,y);
        break;
      case 4:
        hMax = min(hMax,y);
        break;
    }
  }

  cout << max(0,wMax - wMin) * max(0,hMax - hMin) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<int> v1,v2;
vector<P> t1,t2;
bool used[100005];

int check(int a){
	if(used[a])return 0;
	used[a]=true;
	return check(t2[t1[a].second].second)+1;
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		v1.push_back(a);
		t1.push_back(make_pair(a,i));
	}
	for(i=0;i<n;i++){
		cin>>a;
		v2.push_back(a);
		t2.push_back(make_pair(a,i));
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	a=0,b=0;
	for(i=0;i<n;i++){
		if(v1[i]>v2[i])a=1;
		if(i<n-1 && v2[i]>=v1[i+1])b=1;
	}
	if(a)cout<<"No"<<endl;
	else if(b)cout<<"Yes"<<endl;
	if(a+b)return 0;
	sort(t1.begin(),t1.end());
	sort(t2.begin(),t2.end());
	i=0;
	for(auto &node:t2){
		swap(node.first,node.second);
		node.second=i++;
	}
	sort(t2.begin(),t2.end());
	
	a=check(0);
	if(a!=n)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define int long long
#define pp pair<int,int>
#define ff first
#define dd second
#define pb push_back
#define N 3003
using namespace std;

int n, m;

int binn[N][N];
int stirr[N][N];

int p2[N];
int pp2[N];

unordered_map<int,int> powxx;

int binomialOwn(int n ,int k) {
    if(k > n) return 0;
    if(k == n) return 1;
    if(k == 0) return 1;
    if(binn[n][k] != -1) return binn[n][k];
    binn[n][k] = (binomialOwn(n-1,k) + binomialOwn(n-1,k-1)) % m;
    return binn[n][k];
}

int stirlingOwn(int n, int k) {
    if(k > n) return 0;
    if(k == n) return 1;
    if(k == 0) return 0;
    if(k == 1) return 1;
    if(stirr[n][k] != -1) return stirr[n][k];
    stirr[n][k] = (stirlingOwn(n-1,k-1) + k*stirlingOwn(n-1,k) % m) % m;
    return stirr[n][k];
}

int pow2(int x) {
    if(x == 0) return 1; if(x == 1) return 2;
    if(x & 1) return 2*pow2(x-1) % m;
    int k = pow2(x/2);
    return k*k%m;
}

// i = 2, j = 0
int ways2(int i, int j) {
    int res = (stirlingOwn(i,j+1)*(j+1) + stirlingOwn(i,j)) % m;
    //cout << res << " res\n";
    res *= pow2((n-i)*j);
    res %= m;
    res *= pp2[n-i];
    return (res % m);
}

int ways(int i) {
    int res = 0;
    for(int x = 0; x <= i; ++x) {
        res += ways2(i,x);
    }
    return (res % m);
}

main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    p2[0] = 1; pp2[0] = 2;
    for(int i = 1; i  < N; ++i) {
        p2[i] = p2[i-1]*2 % m;
        pp2[i] = pp2[i-1]*pp2[i-1]%m;
    }
    for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) { binn[i][j] = stirr[i][j] = -1; }
    int ans = 0;
    for(int i = 0; i <= n; ++i) {
        int temp = binomialOwn(n, i) * ways(i) % m;
        if (i & 1) {
            ans = ans + m - temp;
        } else {
            ans = ans + temp;
        }
    }
    cout << (ans % m) << "\n";
}


Measured memory_bytes: 141440
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){

    int n; cin >> n;
    int cnt = 0;
    for(int i = 2; i <= 55555; i++){
        if(divisor(i).size() == 2 && i%5 == 1){
            cout << i;
            cnt++;
            if(cnt == n) break;
            cout << " ";
        } 
    }
    cout << endl;
    return 0;   
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
     int r,g,b,k; cin>>r>>g>>b>>k;
     int check=0;
     while(g<=r){
         check++;
         g*=2;
     }
     while(b<=g){
         check++;
         b*=2;
     }
     if(check>k)  cout<<"No"<<endl;
     else cout<<"Yes"<<endl;
     

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
 int n,y;
 cin >> n >> y;
 int ans = 0;
 y = y / 1000;
 y-=n;
 for(int i=0;;++i){
  if(((y-4*i) % 9) == 0){
    int z =  n - ((y-4*i)/9) - i;
    if(z < 0) continue;
    cout << (y-4*i)/9 << " " << i << " " << z;
    return 0;
  }
  else if(y-4*i<0){
    puts("-1 -1 -1");
    return 0;
  }
 }


  
}

Measured memory_bytes: 256
from collections import deque

mod = 10 ** 9 + 7

n, k = map(int, input().split())
es = tuple(set() for _ in range(n))
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    es[a].add(b)
    es[b].add(a)

ans = k

q = deque()

can_use = k - 1
# vに隣接する未着色の頂点を塗るのに使える色の数
# k色 - (親、自分)
for u in es[0]:
    ans = (ans * can_use) % mod
    can_use -= 1
    q.append((u, 0))

while q:
    v, pr = q.popleft()
    can_use = k - 2
    # vに隣接する未着色の頂点を塗るのに使える色の数
    # k色 - (親、自分)
    for u in es[v]:
        if u == pr:
            continue
        ans = (ans * can_use) % mod
        can_use -= 1
        q.append((u, v))

print(ans)


Measured memory_bytes: 43904