akhauriyash/Code-Regression huggingface dataset:
//    https://youtu.be/N3oCS85HvpY

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))

int main()
{
    fast;
    llu ans=5000000000000000000;
    ll t,n,m,i,j,l,k,temp,flag,x,y,x1,x2,y1,y2;
    cin>>n>>k;
    vector<pair<ll,ll> >v;
    vector<ll>X,Y;
    for(i=0; i<n; i++)
    {
        cin>>x>>y;
        v.pb({x,y});
        X.pb(x);
        Y.pb(y);
    }
    sort(all(X));
    sort(all(Y));
    for(j=0; j<n; j++)
    {
        for(x=j+1; x<n; x++)
        {
            for(y=0; y<n; y++)
            {
                for(t=y+1,temp=0; t<n; t++)
                {
                    x1=min(X[j],X[x]);
                    x2=max(X[j],X[x]);
                    y1=min(Y[y],Y[t]);
                    y2=max(Y[y],Y[t]);
                    for(l=0,temp=0; l<n; l++)
                    {
                        if(v[l].ff>=x1 && v[l].ff<=x2 && v[l].ss>=y1 && v[l].ss<=y2)
                            temp++;
                    }
                    if(temp>=k)
                    {
                        if(ans>((llu)abs(x1-x2))*((llu)abs(y1-y2)))
                            ans=((llu)abs(x1-x2))*((llu)abs(y1-y2));
                    }
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,l,m) for(int i=l;i<=(int)(m);i++)

int main(){
  int N,a[101];
  int count=0;

  scanf("%d",&N);

  rep(i,1,N){
    scanf("%d",&a[i]);
  }

  rep(i,1,N){
    if(i%2==1 && a[i]%2==1)count++;
  }

  printf("%d\n",count);

  return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
int n, m, i, j, k, c[10005];
int main(){
	scanf("%d", &n);
	for(i=1; i<100; i++){
		for(j=1; j<100; j++){
			for(k=1; k<100; k++){
				m = i*i+j*j+k*k+i*j+j*k+i*k;
				if(m <= n) c[m]++;
			}
		}
	}
	for(i=1; i<=n; i++) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 1692
#include<cstdio>

int n,A[30];

int solve(int a,int m){
    if(m==0) return 1;
    if(a>=n) return 0;
    int x = solve(a+1,m) || solve(a+1,m-A[a]);
    return x;
}

int main(){
    int q,m;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&m);
        if(solve(0,m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<double> B(N,true);
  for(int i=0;i<K;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int A;
      cin>>A;
      B[A-1]=false;
    }
  }
  int j=0;
  for(int i=0;i<N;i++)
    if(B[i])
      j++;
  cout<<j<<endl;
}

Measured memory_bytes: 3572
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = list()
good_hill = set()
vt = [set() for _ in range(n)]
ans = 0

for _ in range(m):
    ab.append(list(map(int, input().split())))

for i in range(m):
    vt[ab[i][0]-1].add(ab[i][1]-1)
    vt[ab[i][1]-1].add(ab[i][0]-1)

for i in range(n):
    max_around = 0
    for v in vt[i]:
       if max_around < h[v]:
           max_around = h[v]
    if h[i] > max_around:
        ans += 1

print(ans)


Measured memory_bytes: 63628
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	std::string S; std::cin >> S;
	int lose = 0;
	rep(i, S.size()) {
		if (S[i] == 'x')lose++;
	}

	if (lose <= 7) {
		std::cout << "YES";
	}
	else {
		std::cout << "NO";
	}
	

	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
	int main(){
		int a[5],g,c,p,i;
		while(scanf("%d",&a[0]),a[0]){
			g=0;
			c=0;
			p=0;
			if(a[0]==1)
				g++;
			else if(a[0]==2)
				c++;
			else if(a[0]==3)
				p++;
			for(i=1;i<5;i++){
				scanf("%d",&a[i]);
				if(a[i]==1)
				g++;
			else if(a[i]==2)
				c++;
			else if(a[i]==3)
				p++;
			}
			if(g>0&&c>0&&p>0)
				for(i=0;i<5;i++)
				printf("3\n");
			else if(g==5||c==5||p==5)
				for(i=0;i<5;i++)
				printf("3\n");
			else if(g>0&&c>0)
				for(i=0;i<5;i++){
					if(a[i]==1)
						printf("1\n");
					else printf("2\n");
			}
			else if(g>0&&p>0)
				for(i=0;i<5;i++){
					if(a[i]==1)
						printf("2\n");
					else printf("1\n");
			}
			else for(i=0;i<5;i++){
				if(a[i]==2)
					printf("1\n");
				else printf("2\n");
			}
		}
		return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    string t;
    cin>>t;
    vll d(s.size());
    rep(i,s.size()){
        rep(j,t.size()){
            if(i+j<s.size()&&t[j]!=s[i+j]){
                d[i]++;
            }
        }
    }
    ll ans=10000000;
    rep(i,s.size()-t.size()+1){
        ans=min(ans,d[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
#include<stdio.h>

int main(){
	int N/*人数*/, D/*日数*/, X/*残量*/;
	scanf("%d", &N);
	scanf("%d %d", &D, &X);
	
//	printf("%d %d %d\n", N, D, X);
	
	int A[N], i;
	
	for(i=0; i<N; i++){
//		printf("\ni=%d\n", i);
		scanf("%d", &A[i]);
//		printf("%d  %d\n", i, A[i]);
	}
	
	int B[N];
	for(i=0; i<N; i++){
		int day=1, j=0;
		do{
			day += A[i];
			j++;
		}while(day<=D);
		B[i] = j;
	}
	
	for(i=0; i<N; i++)	X += B[i];
	
	printf("%d", X);

	return 0;
}



Measured memory_bytes: 128
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n){
    cout << (n % 1000 == 0 ? 0 : (1000 - n % 1000)) << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3756
#include <cstdio>
#include <cmath>

using namespace std;

int main(void){
  double x[3], y[3], cx, cy;
  double p[3];
  
  while (scanf("%lf%lf", &x[0], &y[0])>0){
    scanf("%lf%lf%lf%lf%lf%lf", &x[1], &y[1], &x[2], &y[2], &cx, &cy);
    for (int i=0; i<3; i++){
      int j=(i+1)%3;
      p[i] = (x[i]-cx)*(y[j]-cy)-(x[j]-cx)*(y[i]-cy);
    }
    puts(p[0]*p[1]<0||p[1]*p[2]<0||p[2]*p[0]<0 ? "NO": "YES");
  }
  return 0;
}


Measured memory_bytes: 2716
#include<bits/stdc++.h> 
// #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define forn(i,o,n) for(int i=o;i<n;i++)
#define int long long
// #define endl "\n"
#define mod 1000000007
#define double double
#define pb push_back
#define swap(x,y) (x^=y^=x^=y)
using namespace std;


int32_t main(){
     #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); 
    #endif
    int n;
    cin>>n;
    std::vector<double> p(n);
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }

    double dp[n+1][n+1]; ///dp[i][j]=probability of getting j heads in i coins
    dp[0][0]=1;


    for(int i=1;i<=n;i++)
        dp[0][i]=0;

    for(int i=1;i<=n;i++)
    {
        dp[i][0]= (1-p[i-1])*dp[i-1][0];
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i!=0&&j!=0)
            {
                dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
            }
          //  cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    double ans=0;
    for(int i=(n/2)+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    printf("%.10lf\n",ans );
    //cout<<ans<<endl;

}

Measured memory_bytes: 74012
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int R,S,P;
string T;

int A[100010];
int B[100010][3];
int s[5];
int g[5];
int dp[100010][3];
vector<int> G[100010];

int vs(int a,int b){
	if(a==g[b]){
		return s[a];
	}
	return 0;
}

signed main(){
	cin>>N>>K>>R>>S>>P>>T;
	REP(i,N){
		if(T[i]=='r'){
			A[i]=0;
		}
		else if(T[i]=='s'){
			A[i]=1;
		}
		else{
			A[i]=2;
		}
	}
	//0=R 1=S 2=P
	s[0]=R;
	s[1]=S;
	s[2]=P;
	g[0]=2;
	g[1]=0;
	g[2]=1;
	REP(i,N){
		G[i%K].push_back(A[i]);
	}
	int ans=0;
	REP(i,K){
		REP(j,G[i].size()+1){
			REP(k,3){
				dp[j][k]=0;
			}
		}
		REP(j,G[i].size()){
			REP(k,3){
				REP(l,3){
					if(k==l)continue;
					dp[j+1][k]=max(dp[j+1][k],dp[j][l]+vs(k,G[i][j]));
				}
			}
		}
		int M=0;
		REP(j,3){
			M=max(M,dp[G[i].size()][j]);
		}
		ans+=M;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9984
#include <stdio.h>
    
    int main(void){
        int a,b,t;
        int i;

        for(i=1;;i++){
            scanf("%d %d",&a,&b);
            if(a == 0 && b == 0){break;}
            if(a > b){printf("%d %d\n",b,a);}
            else{printf("%d %d\n",a,b);}
        }
    }


Measured memory_bytes: 2036
#![allow(non_snake_case, unused_variables, dead_code)]
//use permutohedron::LexicalPermutation as _;
//use proconio::input;
use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    proconio::input! {
        H:usize,W:usize,K:u32,
        S:[Chars;H]
    }
    let S: Vec<Vec<u32>> = S
        .iter()
        .map(|Si| Si.iter().map(|&c| (c as u8 - '0' as u8) as u32).collect())
        .collect();
    // Hの分割法を0から2^H-1まで総当たりで試す。
    // h_bar[i]==trueなら、i行目とi+1行目の間が結合していることを示す。
    // 逆にいうと、h_bar[i]==trueの行の数は、次の行の数に足す。
    // なお、H_bar[H-1]は常にfalseなので、次の行に足してしまうことは無い。
    // div がその時の分割数。
    let mut ans = H + W;
    let mut h_bar = vec![false; H];
    for h_devide in 0..(2i32.pow(H as u32 - 1)) {
        let mut div = h_devide.count_ones() as usize;
        for i in 0..H - 1 {
            h_bar[i] = (h_devide >> i) & 1 == 0;
        }
        //println!("h_devide {:?},{}", h_bar, div);
        // 以下、W方向について貪欲法。
        let mut white = vec![0; H];
        let mut w_len = 0;
        let mut w = 0;
        'outer: while w < W {
            //   println!("{}", w);
            for h in 0..H {
                // 各行を最大数がKになるまで結合していく。
                white[h] += S[h][w];
                if h_bar[h] {
                    white[h + 1] += white[h];
                    white[h] = 0;
                }
                if white[h] > K {
                    // Kを超えてしまったら、カット追加。
                    // whiteを初期化して、同じ列からやり直す。
                    // この時w_lenをリセット
                    if w_len == 0 {
                        // ただし一行も追加できかった場合は打ち切り。
                        div = H + W;
                        break 'outer;
                    }
                    div += 1;
                    white = vec![0; H];
                    w_len = 0;
                    continue 'outer;
                }
            }
            // 無事に1列追加出来たら。
            w_len += 1;
            w += 1;
        }
        //println!("h分割{:?}, 計{}", h_bar, div);
        ans = std::cmp::min(ans, div);
    }

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


Measured memory_bytes: 2252
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	
	int ans=a+b;
	ans=max(ans,a-b);
	ans=max(ans,a*b);
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

LL inputValue(){
  LL a;
  cin >> a;
  return a;
};

string inputString(){
  string a;
  cin >> a;
  return a;
};

vector<LL> inputVector(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> inputVectorString(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> inputVector2D(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, vector<LL>& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, vector<string>& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, vector<vector<LL>>& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  string c = inputString();
  if (c == "Sunny") cout << "Cloudy" << endl;
  if (c == "Cloudy") cout << "Rainy" << endl;
  if (c == "Rainy") cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n, m; cin >> n >> m;
    int a[2*n]; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; }
    for (int i = 0; i < n; i++) a[i+n] = a[i];
    long long b[2*m+2] = {};
    for (int i = 1; i < n; i++) {
        int x = a[i-1], y = a[i];
        if (y < x) y += m;
        if (y == x + 1) continue;
        b[x+2]++;
        b[y+1] -= (y-x-1)+1;
        b[y+2] += y-x-1;
    }
    // for (int i = 0; i < 2*m; i++) cout << b[i] << ' '; cout << endl;
    for (int i = 1; i < 2*m; i++) b[i] += b[i-1];
    // for (int i = 0; i < 2*m; i++) cout << b[i] << ' '; cout << endl;
    for (int i = 1; i < 2*m; i++) b[i] += b[i-1];
    // for (int i = 0; i < 2*m; i++) cout << b[i] << ' '; cout << endl;
    for (int i = 0; i < m; i++) b[i] += b[i+m];
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int x = a[i-1], y = a[i];
        if (x < y) ans += y - x;
        else ans += m + y - x;
    }
    cout << ans - *max_element(b, b+m) << endl;
}


Measured memory_bytes: 2560
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import time
start = time.time()

import numpy as np

H,W,K = map(int,readline().split())
S = np.array([list(line.rstrip()) for line in readlines()]).astype(np.int8) - ord('0')

# 下から上の順に
S = S[::-1].T

def drop(S):
    for i in range(W):
        col = S[i]
        S[i] = drop_col(col)

def drop_col(col):
    x = np.zeros(H,np.int8)
    nonzero = col[col != 0]
    x[:len(nonzero)] = nonzero
    return x

def cnt_connection(S):
    # 横につながっている個数
    x = np.ones_like(S)
    equal = (S[:-1] == S[1:])
    for i in range(1,W):
        x[i] = x[i-1] * equal[i-1] + 1
    for i in range(W-2,-1,-1):
        x[i][equal[i]] = x[i+1][equal[i]]
    return x

def simulate(S,turn):
    # 落とす -> 消去、で1セット
    drop(S)
    conn = cnt_connection(S)
    remove = (conn >= K)
    before = S.sum()
    S *= (~remove)
    after = S.sum()
    if before == after:
        # 消えなかった
        return 0
    else:
        x = simulate(S,turn+1)
        return x + ((before - after) << turn)

def calc(j):
    T = S.copy()
    T[j,0] = 0
    return simulate(T,0)

answer = 0
for i in range(H):
    x = max(calc(j) for j in range(W))
    if answer < x:
        answer = x
    H -= 1
    S = S[:,1:]
    if time.time() - start > 0.9:
        break
print(answer)

Measured memory_bytes: 12520
#include <stdio.h>

int div(int a) {
  int i, cnt = 0;
  for(i = 1; i <= a; ++i) if(!(a % i)) ++cnt;
  return cnt;
}

int main(void) {
  int i, n, ans = 0;
  scanf("%d", &n);
  for(i = 1; i <= n; i += 2) if(div(i) == 8) ++ans;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
n = gets.to_i
as = []
as << gets.strip.split.map(&:to_i)
as << gets.strip.split.map(&:to_i)

mx = 0

for i in (0...n)
  # i番目のマスで下に移動することにした場合
  upper = as[0][0..i].inject(:+)
  lower = as[1][i..-1].inject(:+)
  mx = [upper + lower, mx].max
end

puts mx

Measured memory_bytes: 1788
S = int(input())
mod = 10 ** 9 + 7

dp = [1, 0, 0]
cnt = 0
for i in range(3, S+1):
    cnt = dp[i-1] + dp[i-3]
    cnt %= mod
    dp.append(cnt)

ans = dp[S]
print(ans)

Measured memory_bytes: 9080
#include<cstdio>
int main()
{
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	int pd=1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i*m+j*n-i*j-i*j==k){
				pd=0;
				printf("Yes\n");
				goto bre;
			}
		}
	}
	bre:
	if(pd){
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
# ABC061D - Score Attack
import sys
input = sys.stdin.readline

def bellman_ford() -> int or None:
    dist = [-float("inf")] * (N + 1)
    dist[1] = 0

    # relax edges
    for i in range(N):
        for v, u, w in E:  # w: positive -> -w
            if dist[v] + w > dist[u]:
                dist[u] = dist[v] + w
                if i == N - 1 and u == N:  # detect negative cycles
                    return None
    return dist[-1]


def main():
    global N, M, E
    # reverse weights -> shortest path problem containing negative cycles
    N, M = tuple(map(int, input().split()))  # vertices, edges
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    ans = bellman_ford()
    flg = ans is not None
    print(ans if flg else "inf")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

#define MAX 101010
#define NIL -1

struct Node{
    int p, l, r;
};
struct Node T[MAX];
int n, D[MAX],H[MAX];

void setDepth(int u, int d){
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].l,d+1);
    setDepth(T[u].r,d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
    if(T[u].r != NIL) h2 = setHeight(T[u].r) + 1;
    return H[u] = max(h1,h2);
}

int getSibling(int u){
    if(T[u].p == NIL) return NIL;
    if(T[T[u].p].l != u && T[T[u].p].l != NIL) return T[T[u].p].l;
    if(T[T[u].p].r != u &&  T[T[u].p].r != NIL) return T[T[u].p].r;
    return NIL;
}

void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].p);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].l != NIL) deg++;
    if (T[u].r != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
     
    if (T[u].p == NIL)
    {
        printf("root\n");
    }
    else if (T[u].l == NIL && T[u].r == NIL)
    {
        printf("leaf\n");
    }
    else
    {
        printf("internal node\n");
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,l,r,root=0;
    cin>>n;
    REP(i,n) T[i].p = NIL;

    REP(i,n){
        cin>>v>>l>>r;
        T[v].l = l;
        T[v].r = r;
        if(l!=NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    REP(i,n) if(T[i].p == NIL) root = i;

    setDepth(root,0);
    setHeight(root);

    REP(i,n) print(i);
}


Measured memory_bytes: 3252
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N;
	cin >> N;
	ll an = 0;
	rep(i, N) {
		an += (i + 1) * (N / (i + 1)) * (N / (i + 1) + 1) / 2;
	}

cout << an << endl;
}


Measured memory_bytes: 3672
n = q = 2*10**5

fla = []


def pri(s):
    fla.append(s)


pri("+ 0 1 5")
pri("< 3 5 4")

max_log = 30

pri("+ 0 4 0")
pri("+ 1 4 1")

for i in reversed(range(max_log)):
    pri("+ 3 4 8")
    for _ in range(i):
        pri("+ 8 8 8")

    pri("+ 6 8 9")

    pri("< 9 0 %d" % (100+i))

    pri("+ %d 3 9" % (100+i))
    for _ in range(i):
        pri("+ 9 9 9")

    pri("+ 6 9 6")

for i in reversed(range(max_log)):
    pri("+ 3 4 8")
    for _ in range(i):
        pri("+ 8 8 8")

    pri("+ 7 8 9")

    pri("< 9 1 %d" % (200+i))

    pri("+ %d 3 9" % (200+i))
    for _ in range(i):
        pri("+ 9 9 9")

    pri("+ 7 9 7")


def an(i, j, k):
    pri("+ %d %d 6" % (i, j))
    pri("< %d %d 7" % (i, j))
    pri("< %d %d 8" % (j, i))
    pri("+ 7 8 7")
    pri("< 7 6 %d" % k)


for i in range(max_log):
    for j in range(max_log):
        an(100+i, 200+j, 6)
        pri("+ %d 6 %d" % (i+j+300, i+j+300))

for i in range(max_log*2):
    for _ in range(i):
        pri("+ %d %d %d" % (300+i, 300+i, 300+i))
    pri("+ %d 2 2" % (300+i))


print(len(fla))
print("\n".join(fla))


Measured memory_bytes: 67808
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define inf 99999999
int cost[10][10];
int d[10];
int pre[10];
int flag[10];
int h;
int w;



int main()
{
    int h,w;
    cin>>h>>w;
    int e[10][10],k,i,j,n,m,t1,t2,t3;
   // int inf=99999999; //用inf(infinity的缩写)存储一个我们认为的正无穷值
    //读入n和m，n表示顶点个数，m表示边的条数
    n=10;

    //初始化
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            if(i==j) e[i][j]=0;
            else e[i][j]=inf;
    //读入边
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>e[i][j];
        }
    }

    //Floyd-Warshall算法核心语句
    for(k=0;k<n;k++)
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                if(e[i][j]>e[i][k]+e[k][j] )
                    e[i][j]=e[i][k]+e[k][j];

    int len=h*w;
    ll res=0;
    int temp;
    for(int i=0;i<len;i++){
        cin>>temp;
        if(temp!=-1){
            res+=(long long)e[temp][1];
        }
    }
    cout<<res<<endl;
    return 0;
}


//int main(){
//    cin>>h>>w;
//    for(int i=0;i<=9;i++){
//        for(int j=0;j<=9;j++){
//            cin>>cost[i][j];
//        }
//    }
//    ll res=0;
//    findpath();
//    int temp;
//    int len=h*w;
//    for(int i=0;i<len;i++){
//        cin>>temp;
//        if(temp!=-1){
//            res+=(long long)(d[temp]);
//        }
//    }
//    cout<<res<<endl;
//    return 0;
//}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){ 
    string a,b;
    cin>>a>>b;
    cout << (((a>=b) and (sz(a)>=sz(b)))?((a>b)?"GREATER":"EQUAL"):"LESS")<< endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
    //[a,m),[m,b)で切った時の差
    lint cutdiff(const int a, const int b, const int m) {
        return abs(query(m, b) - query(a, m));
    }
};

int main() {
    int n;
    cin >> n;
    cumulative_sum a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.build();
    lint ans = LLONG_MAX;
    // [0,i),[i,n)で切る
    for (int i = 2; i <= n - 2; i++) {
        vector<lint> bcde(4);
        //前半の切り方を決める
        // B-A>0なる[0,ok),[ok,i)で最大のokを探す
        int ok1 = 1, no1 = i;
        while (abs(ok1 - no1) > 1) {
            int mid1 = (ok1 + no1) / 2;
            if (a.query(mid1, i) - a.query(0, mid1) > 0) {
                ok1 = mid1;
            } else {
                no1 = mid1;
            }
        }
        if (ok1 + 1 < i && a.cutdiff(0, i, ok1 + 1) < a.cutdiff(0, i, ok1)) {
            ok1++;
        }
        bcde[0] = a.query(0, ok1);
        bcde[1] = a.query(ok1, i);
        //後半の切り方を決める
        // D-C>0なる[i,ok2),[ok2,n)で最大のokを探す
        int ok2 = i + 1, no2 = n;
        while (abs(ok2 - no2) > 1) {
            int mid2 = (ok2 + no2) / 2;
            if (a.query(mid2, n) - a.query(i, mid2) > 0) {
                ok2 = mid2;
            } else {
                no2 = mid2;
            }
        }
        if (ok2 + 1 < n && a.cutdiff(i, n, ok2 + 1) < a.cutdiff(i, n, ok2)) {
            ok2++;
        }
        bcde[2] = a.query(i, ok2);
        bcde[3] = a.query(ok2, n);
        ans = min(ans, *max_element(all(bcde)) - *min_element(all(bcde)));
    }
    cout << ans << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 051_abc_d / Link: __CONTEST_URL__  ----- */
/* ------問題------

自己ループと二重辺を含まない N 頂点 M 辺の重み付き無向連結グラフが与えられます。
i(1≦i≦M) 番目の辺は頂点 ai と頂点 bi を距離 ci で結びます。
ここで、自己ループは ai=bi(1≦i≦M) となる辺のことを表します。
また、二重辺は (ai,bi)=(aj,bj) または (ai,bi)=(bj,aj)(1≦i<j≦M) となる辺のことを表します。
連結グラフは、どの異なる 2 頂点間にも経路が存在するグラフのことを表します。
どの異なる 2 頂点間の、どの最短経路にも含まれない辺の数を求めてください。

-----問題ここまで----- */
/* -----解説等-----

全点対が求まっていれば d[i][x] + edge(x->j) == d[i][j]
でも求められることは覚えておくべき

----解説ここまで---- */

LL N,M;

LL ans = 0LL;

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

	cin >> N>>M;
	VVI d(N, VI(N, INF));
	vector<pair<PII, int>>edge;
	FOR(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		d[a][b] = d[b][a] = c;
		edge.push_back(pair<PII, int>(PII(a, b), c));
	}
	FOR(i, 0, N)d[i][i] = 0;
	FOR(k, 0, N)FOR(i, 0, N)FOR(j, 0, N) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}

	FOR(i, 0, M) {
		int s, t, c;
		auto a = edge[i];
		s = a.first.first;
		t = a.first.second;
		c = a.second;
		int nouse = 1;
		FOR(j, 0, N) {
			FOR(k, 0, N) {
				if (d[j][k] == d[j][s] + c + d[t][k])nouse = 0;
			}
		}
		ans += nouse;

	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    string s;
    int cnt;
    int ans = 0;
    cin >> n >> s;
    for (int i = 1; i < n; i++){
        cnt = 0;
        for (int j = 0; j < n - i; j++){
            if (s[j] == s[i+j]){
                cnt++;
                if (cnt == i && cnt > ans) {
                    ans = i;
                    break;
                }
            }else{
                if (ans < cnt){
                    ans = cnt;
                }
                cnt = 0;
            }
        }
        if (ans < cnt){
            ans = cnt;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
vector<int> to[200010];
vector<int> ans;

void dfs(int v,int p = -1){
  for(int u : to[v]){
    if(u == p)continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
  return;
}

int main(){
  int N,Q;
  cin >> N >> Q;
  for(int i = 0;i < N-1;i++){
    int a,b;cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(N);
  for(int i = 0;i < Q;i++){
    int a,b;cin >> a >> b;
    a--;
    ans[a] += b;
  }
  dfs(0);
  for(int i = 0;i < N;i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
//using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647    //int値の最大値
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back                            //vectorヘの挿入
#define MP make_pair                            //pairのコンストラクタ
#define F first                                 //pairの一つ目の要素
#define S second                                //pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x) //小数点以下の桁数指定
template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;        
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b){
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b){

    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b){
    return a * b / gcd(a, b);
}
int sumDight(int x){
    int sum = 0;
    while (x >0) {
        sum += (x %10);
        x /= 10;
    }
    return sum;
}
int divideReverse(int x){
    int reverse = 0;
    int r;
    while (x >0){
        r = x % 10;
        reverse = reverse * 10 + r;
        x /= 10;
    }
    return reverse;
}

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

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

    int sum = 0;
    
        for (int i = a; i <= b; i++) {
            if(i==divideReverse(i)){
                sum++;
            }
        }
        cout << sum << endl;
}


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
S = str(input())

len_S = len(S) // 2
left_S = S[:len_S]
right_S = S[len_S + 1:]
print("Yes" if left_S == left_S[::-1] and right_S == right_S[::-1] and left_S == right_S else "No")

Measured memory_bytes: 2940
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		List<long[]> list = new ArrayList<>();
		for(int i=0;i<n;i++) {
			long[] line = {in.nextLong(),in.nextLong(),in.nextLong()};
			list.add(line);
		}
		long[] values = new long[8];
		values[0] = getSum(m,changeSign(1,1,1,list));
		values[1] = getSum(m,changeSign(1,1,-1,list));
		values[2] = getSum(m,changeSign(1,-1,1,list));
		values[3] = getSum(m,changeSign(1,-1,-1,list));
		values[4] = getSum(m,changeSign(-1,1,1,list));
		values[5] = getSum(m,changeSign(-1,1,-1,list));
		values[6] = getSum(m,changeSign(-1,-1,1,list));
		values[7] = getSum(m,changeSign(-1,-1,-1,list));
		long max = 0;
		for(long v : values) {
			if(v>max) {
				max = v;
			}
		}
		System.out.println(max);
	}
	
	public static List<long[]> changeSign(int xSign,int ySign,int zSign,List<long[]> list){
		List<long[]> newList = new ArrayList<>();
		for(long[] line : list) {
			long x = line[0];
			long y = line[1];
			long z = line[2];
			if(xSign<0) x = -x;
			if(ySign<0) y = -y;
			if(zSign<0) z = -z;
			long[] newLine = {x,y,z};
			newList.add(newLine);
		}
		return newList;
	}
	
	public static long getSum(int m, List<long[]> list) {
		long value = 0;
		List<Long> newList = list.stream().map(line -> line[0]+line[1]+line[2])
				.sorted((v1,v2) -> {
					if(v1>v2) return -1;
					else if(v1<v2) return 1;
					else return 0;
				})
				.limit(m)
				.collect(Collectors.toList());
		for(long v : newList) {
			value += v;
		}
		return value;
	}

}

Measured memory_bytes: 29960
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>

typedef std::vector<int> vi;

enum {
  MAXN = 100000 + 5
};

int n;
vi son[MAXN];
int deep[MAXN];
int fa[MAXN];
int rank[MAXN];

bool cmp(int x, int y) {
  return rank[x] < rank[y];
}

int topsort() {
  static int st[MAXN];
  static int sa[MAXN];
  int top(0), u, size(0);
  int d, res(0);

  st[top++] = 0;
  while (top) {
    u = st[--top];
    sa[size++] = u;
    d = deep[u];
    res = std::max(d, res);
    for (int v: son[u])
      st[top++] = v;
  }

  while (size) {
    u = sa[--size];
    std::sort(son[u].begin(), son[u].end(), cmp);    
    for (int v: son[u])
      rank[u] = std::max(rank[u], rank[v]) + 1;
  }

  return rank[0];
}

void exec() {
  int i, u;
  scanf("%d", &n);
  for (i=1; i<n; ++i) {
    scanf("%d", &u), --u;
    fa[i] = u;
    son[u].push_back(i);
  }
  printf("%d\n", topsort());
}

int main() {
  if (fopen("B.in", "r") != NULL) {
    freopen("B.in", "r", stdin);
    freopen("B.out", "w", stdout);
  }
  exec();
  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int MOD = 1000000007;


int main() {
ll n;
cin >> n;
vector<ll> vec(n);
cin >> vec.at(0);
ll cnt = vec.at(0),ans = 0;

for (int i = 1;i < n;i++) {
  cin >> vec.at(i);
  ans += vec.at(i) * cnt;
  ans %= MOD;
  cnt = cnt + vec.at(i);
  cnt %= MOD;
}

cout << ans << endl;

return 0;
}



Measured memory_bytes: 4844
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, K, M;

	public static void main(String[] args) {
		N = sc.nextInt();
		K = sc.nextInt();
		M = sc.nextInt();
		int MASK = (1 << K) - 1;
		if (N < K) {
			System.out.println(naive());
			return;
		}
		long[][][] dp = new long[2][K + 1][1 << K];
		for (int i = 0; i < (1 << K); i++) {
			int c = 0;
			boolean ok = true;
			for (int j = 0; j < K; j++) {
				if ((i & (1 << (K - 1 - j))) == 0) {
					c--;
				} else {
					c++;
				}
				if (c < 0) {
					ok = false;
					break;
				}
			}
			if (!ok) continue;
			int u = Integer.bitCount(i);
			int l = K - u;
			if (u < l) continue;
			dp[0][u - l][i] = 1;
		}
		int t = 1;
		for (int i = K; i < 2 * N; i++, t = 1 - t) {
			for (long[] a : dp[t]) {
				Arrays.fill(a, 0);
			}
			for (int j = i % 2; j <= K; j += 2) {
				int l = (i - j) / 2;
				int u = l + j;
				for (int k = 0; k < (1 << K); k++) {
					int uc = Integer.bitCount(k);
					if (0 < j && j <= uc && (l == 0 || k != MASK)) { // put lower row
						dp[t][j - 1][(k << 1) & MASK] += dp[1 - t][j][k];
						dp[t][j - 1][(k << 1) & MASK] %= M;
					}
					if (u < N && j < K && k != 0) { // put upper row
						dp[t][j + 1][((k << 1) + 1) & MASK] += dp[1 - t][j][k];
						dp[t][j + 1][((k << 1) + 1) & MASK] %= M;
					}
				}
			}
//			System.err.println(Arrays.deepToString(dp[t]));
		}
		long ans = 0;
		for (long v : dp[1 - t][0]) {
			ans += v;
		}
		System.out.println(ans % M);
	}

	static long naive() {
		ArrayList<Integer> u = new ArrayList<>();
		ArrayList<Integer> l = new ArrayList<>();
		u.add(0);
		return rec(u, l, 1);
	}

	static long rec(ArrayList<Integer> u, ArrayList<Integer> l, int cur) {
		if (cur == 2 * N) return 1;
		long ret = 0;
		if (u.size() < N) {
			u.add(cur);
			ret += rec(u, l, cur + 1);
			u.remove(u.size() - 1);
		}
		if (l.size() < u.size() && cur <= u.get(l.size()) + K) {
			l.add(cur);
			ret += rec(u, l, cur + 1);
			l.remove(l.size() - 1);
		}
		return ret % M;
	}

}



Measured memory_bytes: 28396
import heapq
import math

n,m = map(int,input().split())
a = [int(i) for i in input().split()]

a = [-1*num for num in a]

heapq.heapify(a)

for i in range(m):
    #1番高い商品の値段を求める
    maximum = heapq.heappop(a)
    #割引券により、半額にする
    add = math.trunc(maximum/2)
    #それをheapqにプッシュする
    heapq.heappush(a,add)

#-1をかけることを忘れずに！
print(-1 * sum(a))

Measured memory_bytes: 14536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const string yes = "Yes";
const string no = "No";

int main()
{
  string S; cin >> S;
  int len =  S.length();
  for (int i=0; i<len; i++) {
    if ((i%2 == 0 && S[i] == 'L') || (i%2 == 1 && S[i] == 'R')) {
      cout << no << endl;
      return 0;
    }
  }
  cout << yes << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
c=[0]*(n+1)
ans=[]
for i in range(n,0,-1):
    if sum(c[i::i])%2!=a[i-1]:
        c[i]=1
        ans.append(i)
print(len(ans))
print(" ".join(map(str,ans)))

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

const int INF = 1000;

bool is_large(int w1, int h1, int w2, int h2) {
    int diagonal1 = w1 * w1 + h1 * h1;
    int diagonal2 = w2 * w2 + h2 * h2;
    if (diagonal1 == diagonal2) {
        return h1 < h2;
    }
    return diagonal1 < diagonal2;
}

void solve(int W, int H) {
    int w_ans = INF, h_ans = INF;
    for (int h = 1;  h <= 150; h++) {
        for (int w = h + 1; w <= 150; w++) {
            if (is_large(W, H, w, h) && is_large(w, h, w_ans, h_ans)) {
                w_ans = w;
                h_ans = h;
            }
        }
    }
    cout << h_ans << ' ' << w_ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H;
    while (true) {
        cin >> H >> W;
        if (W == 0 && H == 0) break;
        solve(W, H);
    }
    return 0;
}


Measured memory_bytes: 3132
#include <cmath>
#include <cstdio>
using namespace std;

int n, used[8], a[8];
double x[8], y[8], ans;

void dfs(int b) {
  if (b == n) {
    for (int i = 0; i < n - 1; i++) {
      ans += sqrt((x[a[i]] - x[a[i + 1]]) * (x[a[i]] - x[a[i + 1]]) +
                  (y[a[i]] - y[a[i + 1]]) * (y[a[i]] - y[a[i + 1]]));
    }
    return;
  }
  for (int i = 0; i < n; i++) {
    if (used[i] == 0) {
      used[i] = 1;
      a[b] = i;
      dfs(b + 1);
      used[i] = 0;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lf%lf", &x[i], &y[i]);
  }
  dfs(0);
  for (double i = 1.0; i <= n; i++) {
    ans /= i;
  }
  printf("%f\n", ans);
}

Measured memory_bytes: 128
N,K = map(int,input().split())
S = input()
hapiness = [0 for i in range(N)]
if S[0] == 'R' and S[1]=='R':
    hapiness[0]=1
for i in range(1,N-1):
    if S[i]=='L' and S[i-1]=='L':
        hapiness[i]=1
    if S[i]=='R' and S[i+1]=='R':
        hapiness[i]=1
if S[N-1]=='L' and S[N-2]=='L':
    hapiness[N-1]=1
ans = sum(hapiness)+K*2
print(min(ans,N-1))

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

using namespace std;
#define DIM 109
#define INF -1000000000000

long long a[DIM][100009],m1[DIM],c[DIM];
long long i,j,k,l,n,m,maxi;
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>m1[i]>>c[i];
    }
    a[0][0]=1;
    for(i=1;i<=n;i++){
        for(j=0;j<=m;j++){
            if(a[i-1][j]==0)k=INF;
            else k=a[i-1][j];

            if(m1[i]<=j && a[i-1][j-m1[i]]!=0)l=c[i]+a[i-1][j-m1[i]];
            else l=INF;

            if(l==INF && k==INF)a[i][j]=0;
            else{
                a[i][j]=max(l,k);
            }
        }
    }
    for(i=1;i<=n;i++){
        for(j=0;j<=m;j++){
            maxi=max(maxi,a[i][j]);
        }
    }
    cout<<maxi-1<<endl;
    return 0;
}


Measured memory_bytes: 79360
//Don't give up too easy bhai
#pragma GCC optimize("-O3")
 
#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define double long double
#define inf 1e18

typedef pair<int,int> pii;
 
#define forall(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define vi vector<int>
#define vd vector<double>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007
#define br cout<<"\n"
#define whatis(x) cerr << "var "<<#x << " ==> " << x<<"\n"
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define T int __t;cin>>__t;while(__t--)

void solve()
{
    
}

signed main()
{
    fast;

    int a;cin>>a;

    cout<<(a + a*a + a*a*a);


    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;


int main() {
    ios::sync_with_stdio(false);
    int n, m, k, b, a[33] = {}, z = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> k;
        while (k--) cin >> b, a[b]++;
    }
    for (int i = 1; i <= m; i++) if (a[i] == n) z++;
    cout << z;
}


Measured memory_bytes: 256
n = int(input())
A = [int(input()) for _ in range(n)]

now = 0
cnt = 0
while A[now] != 2 and cnt <= n:
    now = A[now] - 1
    cnt += 1

if A[now] == 2:
    print(cnt + 1)
else:
    print(-1)


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

int main () {
	long long A;
	long long B;
	long long T;
	cin >> A;
	cin >> B;
	cin >> T;
    
    
  
    if ( T >= A ) {
    	cout << ((T/A)*B) <<endl;
    } 
    else {
    	cout << 0 << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc083/tasks/arc088_a

int main() {
    ll x, y; cin >> x >> y;

    ll curr = x;
    ll cnt = 0;

    while(curr <= y) {
        cnt++;
        curr *= 2;
    }

    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256