akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int INF=100000000;

// eXªwè³ê½FÉÈéÜÅÌÅ¬X^vñ
int dp[1<<16];
char field[5][5];
vector<pair<int,int> > stumps;
int n;

char color[]={'R','G','B'};

int dfs(int s){
    if(s==0)
        return 0;
    if(dp[s]!=INF)
        return dp[s];
    int cnt=INF;
    // TCYÒÁ½è ¤êðIñÅX^vðßµÄ¢­
    for(int k = 0; k < stumps.size(); k++){
        int h=stumps[k].first;
        int w=stumps[k].second;
        // ¶ãÌÀWðè
        for(int i = -h+1; i < 4; i++){
            for(int j = -w+1; j < 4; j++){
                int ns=s;
                bool first=false;
                bool b=false;
                char cc=0;
                // Iñ¾ÍÍªS¯¶FÅ é©Ç¤©ð`FbN·é
                for(int k = i; k<min(i+h,4); k++){
                    for(int l = j; l < min(j+w,4); l++){
                        if(!(k>=0&&l>=0&&k<4&&l<4))
                            continue;
                        // hçêÄ¢éêÌÝl¶·é
                        if((s>>(k*4+l))&1){
                            if(!first){
                                cc=field[k][l];
                                first=true;
                            }
                            else{
                                if(field[k][l]==cc){
                                    //ok
                                }
                                else{
                                    b=true;
                                    break;
                                }
                            }
                        }
                    }
                    if(b)
                        break;
                }
                // SðÅ«éê,hèÂÔµððµÄAÄA
                if(!b&&first){
                    for(int k = i; k<min(i+h,4); k++){
                        for(int l = j; l < min(j+w,4); l++){
                            if(!(k>=0&&l>=0&&k<4&&l<4))
                                continue;
                            ns&=~(1<<(k*4+l));
                        }
                    }
                    cnt=min(cnt,dfs(ns)+1);
                }
            }
        }
    }
    return dp[s]=cnt;
}

void solve(){
    fill(dp,dp+(1<<16),INF);
    cin>>n;
    int h,w;
    for(int i = 0; i < n; i++){
        cin>>h>>w;
        stumps.push_back(make_pair(h,w));
    }
    for(int i = 0; i < 4; i++)
        for(int j = 0; j < 4; j++)
            cin>>field[i][j];
    cout<<dfs((1<<16)-1)<<endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 0
def test():
    n = int(input())
    p = list(map(int,input().split()))
    count = 0
    for i in range(1,n-1):
        if p[i] > p[i-1] and p[i] < p[i+1]:
            count += 1
        elif p[i] < p[i-1] and p[i] > p[i+1]:
            count += 1

    print(count)


if __name__ == "__main__":
    test()


Measured memory_bytes: 2940
import math

a,b,h,m=map(float,input().split())

hh=360.0*h/12.0+30.0*m/60.0
mm=360.0*m/60.0

theta=abs(hh-mm)/180.0*math.pi

ans=(a*a+b*b-2.0*a*b*math.cos(theta))**0.5

print(ans)

Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
int main(){
    int fcnt=0, scnt=0;
	int ara[3];cin>>ara[0]>>ara[1]>>ara[2];
	for(int i=0; i<3; i++){
        if(ara[i]==5)fcnt++;
        else if(ara[i]==7)scnt++;
	}
	if(fcnt==2 && scnt==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


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

int main(){
    int N,M;cin>>N>>M;
    int L=1,R=N;
    rep(i,M){
        int tmpL,tmpR;cin>>tmpL>>tmpR;
        L = max(L,tmpL);
        R = min(R,tmpR);
    }
    if((R-L+1)<0){
        cout<<0<<endl;
    }else{
        cout<<(R-L+1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = [int(e) for e in input().split(' ')]

tmp = sorted(p)

count = 0
for i in range(len(p)):
    if p[i] != tmp[i]:
        count += 1

if count == 2 or count == 0:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b){
  return a % b ? gcd(b, a % b) : b;
}
long long lcm(long long a, long long b){
  return a * b / gcd(a, b);
}
long long gen_num(long long n, long long c, long long d){
  return n - n / c - n / d + n / lcm(c, d);
}
int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long ans = gen_num(b, c, d) - gen_num(a - 1, c, d);
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;


int n;
int a[100100][3];
int dp[100100][3];

int main()
{

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < 3; ++j)
            scanf("%d", &a[i][j]);

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            for (int k = 0; k < 3; ++k)
                if (j != k)
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
        }
    }
    printf("%d\n", *max_element(dp[n], dp[n] + 3));

    return 0;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>

using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
	string s, t;
	cin >> s >> t;
	bool f = true;
	rep(i, s.size()) {
		if (s[i] != t[i]) {
			f = false;
			break;
		}
	}
	if (f)  cout << "Yes" << endl;
	else  cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <limits.h>
#include <cstdlib>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;

int main(void){
  int a,b;
  char n[10] = "";
  cin >> a >> n >> b;

  char pt = n[b-1];
  for(int i = 0;i < a;++i){
    if(n[i] != pt){
      n[i] = '*';
    }
  }

  cout << n << endl;
}


Measured memory_bytes: 256
module Main where

main :: IO ()
main = do
    _ <- getLine
    ns <- (map read) . words <$> getLine
    putStrLn . show . makeInv . sumInvs $ ns

makeInv :: Fractional a => a -> a
makeInv x = 1 / x

sumInvs = foldr f 0
    where
        f a b = makeInv a + b


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

const int M = 998244353;
const int N = 1e5+7;
const long long B = 1000000000000000000;
typedef long long LL;

LL pb[N];
void pre() {
    pb[0] = 1;
    LL b = B%M;
    for (int i=1; i<N; i++)
        pb[i] = (pb[i-1]*b)%M;
}

vector<int> bfs(vector<vector<int>>adj) {
    int n = adj.size()-1;
    vector<int> col(n+1, N);

    vector<bool> vis(n);
    for (int i=n; i>0; i--) {
        for (int v: adj[i]) {
            if (v > i)    vis[col[v]] = 1;
        }

        for (int ii=0; ii<=n; ii++)
            if (!vis[ii]) {
                col[i] = ii;
                break;
            }

        for (int v: adj[i]) {
            if (v > i)    vis[col[v]] = 0;
        }
    }
    return col;
}

int m[3];
vector<vector<int>> adj[3];
vector<int> dis[3];
vector<LL> con[3];

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

    int n;
    cin>>n;
    const int MX = 1<<17;

    for (int g=0; g<3; g++) {
        cin>>m[g];
        adj[g].resize(n+1);
        for (int i=0; i<m[g]; i++) {
            int u, v;
            cin>>u>>v;
            adj[g][u].push_back(v);
            adj[g][v].push_back(u);
        }
        dis[g] = bfs(adj[g]);

        con[g].resize(MX);
        for (int i=1; i<=n; i++) {
            con[g][dis[g][i]] = (con[g][dis[g][i]] + pb[i])%M;
        }
    }
    LL ans = 0;
    for (int i=0; i<MX; i++) {
        if (con[0][i] == 0) continue;
        for (int j=0; j<MX; j++) {
            if (con[1][j] == 0)  continue;
            ans = (ans + ((con[0][i]*con[1][j])%M)*con[2][i^j])%M;
        }
    }
    cout<<ans<<endl;
}


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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int) 1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

i64 dp[2200];

i64 f(int s)
{
    if(s == 0) return 1;
    if(s < 0) return 0;
    i64 &ret = dp[s];
    if(ret != -1) return ret;
    ret = 0;
    for(int i = 3; i <= 2000; i++) {
        ret += f(s - i);
        ret %= mod;
    }
    return ret;
}


int main()
{
    memset(dp, -1, sizeof dp);
    int s;
    cin >> s;
    cout << f(s) << "\n";
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define inf 0x3f3f3f
#define PI acos(-1.0)
using namespace std;

typedef long long ll;

int num[100];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        num[a]++;
        num[b]++;
    }
    for(int i=1;i<=n;i++)
        cout << num[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

const int MAXN = 1010;
const int MAXV = MAXN*(MAXN-1)/2;

vint to[MAXV];
int id[MAXN][MAXN];

bool visited[MAXV];
int dp[MAXV];
bool calculated[MAXV];

int dfs(int a){
  if(visited[a]){
    if(!calculated[a]){
      return -1;
    }
    return dp[a];
  }
  visited[a] = true;
  dp[a] = 1;
  for(int p:to[a]){
    int u = dfs(p);
    if(u == -1){
      return -1;
    }
    dp[a] = max(dp[a],u+1);
  }
  calculated[a] = true;
  return dp[a];
}

int toID(int a,int b){
  if(a < b) swap(a,b);
  return id[a][b];
}

signed main(){
  int n;
  cin >> n;
  vvint A(n,vint(n-1));
  rep(i,0,n){
    rep(j,0,n-1){
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  int v = 0;
  rep(i,0,n){
    rep(j,0,n){
      if(i > j){
        id[i][j] = v;
        v++;
      }
    }
  }
  rep(i,0,n){
    rep(j,0,n-1){
      A[i][j] = toID(i,A[i][j]);
    }
  }
  rep(i,0,n){
    rep(j,0,n-2){
      to[A[i][j+1]].push_back(A[i][j]);
    }
  }
  int ans = 0;
  rep(i,0,v){
    int res = dfs(i);
    if(res == -1){
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans,res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 48640
#include <bits/stdc++.h>
#include <string>
using namespace std;
void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}
long long gcd(long long a,long long b){
if(b==0)
 return a;
 else return gcd(b,a%b);

}
int main() {
    init();
long long  n,x,y,D=0;
cin>>n>>x;
long long ar [n];
vector <long long> v(n);
for(int i=0;i<n;i++){
            cin>>v[i];
        v[i]=abs(v[i]-x);

}
sort(v.begin(),v.end());

for(int i:v) D=gcd(D,i);
    cout<<D;
}





Measured memory_bytes: 1024
import java.util.*;


public class Main{ 

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int operationNum = scan.nextInt();
		BinarySearchTree tree = new BinarySearchTree();
		scan.nextLine();
		for(int i=0; i<operationNum; i++)
			tree.operation(scan);
		// ArrayList<BinarySearchTreeNode> list = 
		//  tree.inOrderConnect(new ArrayList<BinarySearchTreeNode>());

	}

}
class BinarySearchTree{
	private BinarySearchTreeNode root=null;
	public BinarySearchTree(){
		//root = new BinarySearchTreeNode();
	}
	public void operation(Scanner sc){
		String op = sc.next();
		if(op.equals("print"))
			print();
		else if(op.equals("find")){
			if(root.findNode(Integer.parseInt(sc.next())))
				System.out.println("yes");
			else
				System.out.println("no");
		}else
			insert(Integer.parseInt(sc.next()));		
	}
	public void insert(int key){
		if(root==null)
			root = new BinarySearchTreeNode(key);
		else
			root.insertNode(key);
	}
	public void print(){
		ArrayList<BinarySearchTreeNode> list = new ArrayList<BinarySearchTreeNode>();
		keyOrderToString(this.root.inOrderConnect(list));
		list.clear();
		keyOrderToString(this.root.preOrderConnect(list));
	}
	private static void keyOrderToString(ArrayList<BinarySearchTreeNode> list){
		for(Iterator<BinarySearchTreeNode> iter = list.iterator(); iter.hasNext();)
			System.out.print( new StringBuilder().append(" ").append(iter.next().getKey()));
		System.out.println("");	
	}

}



class BinarySearchTreeNode{
	protected int key;
	protected BinarySearchTreeNode parent = null;
	protected BinarySearchTreeNode LeftChild = null;
	protected BinarySearchTreeNode RightChild = null;
	public BinarySearchTreeNode(int key){
		this.key = key;
	}
	public BinarySearchTreeNode(int key, BinarySearchTreeNode parent){
		this.key = key;
		this.parent = parent;
	}
	public boolean findNode(int key){
		if(this.key == key)
			return true;
		if(key < this.key && LeftChild!=null)
			return LeftChild.findNode(key);
		else if(key > this.key && RightChild!=null)
			return RightChild.findNode(key);
		else
			return false;
	}
	void insertNode(int key){
		if(key < this.key){
			if(this.LeftChild ==null)
				this.LeftChild = new BinarySearchTreeNode(key, this);
			else
				this.LeftChild.insertNode(key);
			return;
		}else{
			if(this.RightChild ==null)
				this.RightChild = new BinarySearchTreeNode(key, this);
			else
				this.RightChild.insertNode(key);
			return;
		}
	}
	public ArrayList<BinarySearchTreeNode> preOrderConnect(ArrayList<BinarySearchTreeNode> list){
		list.add(this);
		if(LeftChild!=null)
			LeftChild.preOrderConnect(list);
		if(RightChild!=null)
			RightChild.preOrderConnect(list);
		return list;
	}
	public ArrayList<BinarySearchTreeNode> inOrderConnect(ArrayList<BinarySearchTreeNode> list){
		if(LeftChild!=null)
			LeftChild.inOrderConnect(list);
		list.add(this);
		if(RightChild!=null)
			RightChild.inOrderConnect(list);
		return list;
	}	
	public int getKey(){
		return this.key;
	}

}

Measured memory_bytes: 190908
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a<1 || a>9){
    cout << -1 << endl;
    return 0;
    }
    if(b<1 || b>9){
    cout << -1 << endl;
    return 0;
    }
    cout << a*b << endl;
}

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

using namespace std;

#define ll long long

int main()
{
	priority_queue<int> q1; // aの前半分
	ll sumq1 = 0;
	priority_queue<int, vector<int>, greater<int>> q2; // aの後ろ半分
	ll sumq2 = 0;
	ll sumb = 0;
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int que;
		cin >> que;
		if (que == 1) { // 更新
			int a, b;
			cin >> a;
			cin >> b;
			sumb += b;
			if (q1.size() == 0 || q1.top() >= a) {
				q1.push(a);
				sumq1 += a;
			}
			else {
				q2.push(a);
				sumq2 += a;
			}
			if (q1.size() + 1 == q2.size()) {
				int t = q2.top();
				q2.pop();
				sumq2 -= t;
				q1.push(t);
				sumq1 += t;
			}
			else if (q1.size() > q2.size() + 1) {
				int t = q1.top();
				q1.pop();
				sumq1 -= t;
				q2.push(t);
				sumq2 += t;
			}
		}
		else { // 求値
			cout << q1.top() << " ";
			ll ans = -sumq1 + sumq2 + sumb;
			if ((q1.size() + q2.size()) % 2 == 1)
				ans += q1.top();
			cout << ans << endl;
		}
	}
	return  0;
}

Measured memory_bytes: 3452
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let k: i64 = input();
    println!(
        "{}",
        (0..n).fold(1, |acc, _| std::cmp::min(acc * 2, acc + k))
    )
}


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

#define MAXN (500010)

const int MAX = 1 << 19;

int n, k;
char s[MAXN], t[MAXN];
int pre[MAXN];

int seg[MAX << 1];

void modify(int sit, int x){
    seg[sit += MAX] = x;
    for (sit >>= 1; sit; sit >>= 1){
        seg[sit] = std::min(seg[sit << 1], seg[sit << 1 | 1]);
    }
}

int query(int l, int r){
    int min = INT_MAX;
    for (l += MAX, r += MAX + 1; l < r; l >>= 1, r >>= 1){
        if (l & 1) min = std::min(min, seg[l ++]);
        if (r & 1) min = std::min(min, seg[-- r]);
    }
    return min;
}

int main() {
    scanf("%d%d", &n, &k);
    scanf("%s%s", s + 1, t + 1);
    pre[1] = 1;
    for (int i = 2; i <= n; ++i) {
        pre[i] = pre[i - 1] + (t[i] != t[i - 1]);
    }
    int dp = 0;
    modify(0, 0 + 0 - 1);
    for (int i = 1; i <= n; ++i) {
        if (s[i] != t[i]) {
            int tmp = query(std::max(0, i - k), i - 1);
            dp = (tmp + pre[i] + 1) / 2 + 1;
        }
        modify(i, dp + dp - pre[i + 1]);
    }
    printf("%d\n", dp);
    return 0;
}



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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,C;
  cin >> N >> C ;
  vvl d(C,vl(C)),c(N,vl(N)),cost(3,vl(C));
  rep(i,C) rep(j,C) cin >> d[i][j] ;
  rep(i,N) rep(j,N) cin >> c[i][j] ;
  rep(mm,3) rep(color,C){
    rep(i,N) rep(j,N){
      if((i+j)%3!=mm) continue;
      cost[mm][color] += d[c[i][j]-1][color];
    }
  }
  ll ans = LINF;
  rep(x,C) rep(y,C){
    if(x==y) continue;
    rep(z,C){
      if(z==x||z==y) continue;
      chmin(ans,cost[0][x]+cost[1][y]+cost[2][z]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b,a%b);
}


int main() {
  ll n,m;

  cin >> n >> m;
   vector<ll> a(n);
   for(int i = 0; i < n; i++) {
     cin >> a[i];
     a[i] /= 2;
   }

   ll kou = a[0];
   ll g = a[0];
   for(int i = 1; i < n; i++) {
     g = gcd(a[i],kou);
     kou *= a[i];
     kou /= g;
   }


   for(int i = 0; i < n; i++) {
     if((kou / a[i]) & 1) continue;
     cout << 0 << endl;
     return 0;
   }
   // cout << kou << endl;

   ll ans = m / kou;


  
   
     if(ans & 1) {
     cout << ans / 2 + 1 << endl;
     }
     
   else {
     cout << ans / 2 << endl;
   }
}
 

  


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

int main(void)
{
	ll n, v;
	cin >> n >> v;
	vector<ll> vs[4];
	rep(i,4){
		rep(j, n) {
			ll a; cin >> a;
			vs[i].push_back(a);
		}
	}
	unordered_map<ll, ll> ms[2];
	rep(i, 2) {
		ll a = i * 2;
		ll b = a + 1;
		rep (j, n) {
			rep(k, n) {
				ms[i][vs[a][j] + vs[b][k]]++;
			}
		}
	}
	ll sum = 0;
	for (auto p : ms[0]) {
		ll t = v - p.first;
		sum += p.second * ms[1][t];
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 121580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
    int n;
      cin >> n;
    vector <ll> v(n);
      for(int i=0; i<n; i++) cin >> v.at(i);

    ll cnt=1, bef=v.at(0), op=0;
      for(int i=1; i<v.size();i++){
        if((bef<=v.at(i) && op==1) || (v.at(i)<=bef && op==-1)){
          bef = v.at(i);
          continue;
        }
        if(op==0){
          if(bef<v.at(i)) op = 1;
          else if(v.at(i)<bef) op = -1;
          bef = v.at(i);
          continue;
        }else{
          op = 0;
          bef = v.at(i);
        }
        cnt += 1;
      }
      cout << cnt << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String args[]) {
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      double ar[]=new double[n];
      for(int i=0;i<n;i++){
          ar[i]=sc.nextDouble();
      }
      int num = (int)Math.ceil((n+1)/2);
      double dp[][]=new double[n+1][n+1];
      for(double arr[]:dp){
          Arrays.fill(arr, -1.0);
      }
      double sum=0.0;
      for(int i=num;i<=n;i++){
          
          sum+=findCoins(dp, i, n, ar,0);
      }
      System.out.println(sum);
    }
    public static double findCoins(double[][] dp, int heads, int coins, double ar[], int st){
        
        if(heads > coins){
            return dp[coins][heads]=0.0;
        }
        if(coins==0){
            return  dp[coins][heads]=1.0;
           
        }
        if(dp[coins][heads]!=-1.0){
            return dp[coins][heads];
        }
        if(heads>0) {
            dp[coins][heads]=ar[st]*findCoins(dp,heads-1, coins-1,ar,st+1)+(1-ar[st])*findCoins(dp,heads, coins-1,ar,st+1);
        }
        else{
            dp[coins][heads] = (1-ar[st])*findCoins(dp,heads, coins-1,ar,st+1);
        }
        return dp[coins][heads];
    }
    
}

Measured memory_bytes: 124680
N = int(input())
L = [list(map(int, input().split())) for k in range(N)]
m = 0
for l in L:
    m = max(m,l[2])

for x in range(101):
    for y in range(101):
        for h in range(m,m+101):
            f = 1
            for l in L:
                if l[2]!=max(h-abs(l[0]-x)-abs(l[1]-y),0):
                    f = 0
                    break
            if f:
                print(x,y,h)
                exit(0)

Measured memory_bytes: 45020
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,k,d = LI()
    if x < 0:
        x = -x
    m = x//d
    if k < m:
        print(x-k*d)
        return
    x -= d*m
    k -= m
    k &= 1
    x -= d*k
    print(abs(x))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 67236
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define bugprint(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	int n,w;
	cin>>n>>w;
	int dp[w+1];
	init(dp,0);
	loop(i,1,n+1)
	{
		int wi,vi;
		cin>>wi>>vi;
		for(int j=w;j>0;j--)
			if(j + wi <= w) 
				dp[j + wi] = max(dp[j + wi], dp[j] + vi);
		if(wi <= w) dp[wi] = max(dp[wi], vi);
	}
	int ans = 0;
	loop(i,0,w+1) ans = max(ans, dp[i]);
	cout<<ans<<endl;
	return 0;		
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        //int c = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //int num[] = new int[];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        //int sum = 0;
        //boolean flag = true;
        //for(int i = 0; i < s.length(); i++){
        //}
 
        if(a * 500 >= b){
            System.out.println("Yes");
        } else{
            System.out.println("No");
        }
 
 
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}

Measured memory_bytes: 23636
package main

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

const (
	initialBufSize = 64 * 1024
	maxBufSize     = 10000000
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	// scanner.Buffer(make([]byte, maxBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	k, x := scanInt(), scanInt()

	if (k * 500) >= x {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}


Measured memory_bytes: 640
n = int(input())
input_list = list(map(int, input().split()))
count = 0

while True:
    exist_odd = False

    for i in range(n):
        if input_list[i] % 2 != 0:
            exist_odd = True

    if exist_odd:
        break

    for i in range(n):
        input_list[i] /= 2

    count += 1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int x[100009];

int main(){
	DRI(n);
	REP(i,n){
		RI(x[i]);
		if(i==0){x[i]=1;continue;}
	}
	LL ans=1;
	set<int> s;
	int ci=-1;
	REP(i,n){//things taken away
		while(ci+1<n){
			if(SZ(s)>=2){
				int v1=*(prev(s.end(),1));
				int v2=*(prev(s.end(),2));
				if(v2==v1-1){
					s.erase(v1);break;
				}
			}
			if(SZ(s)>=1)s.insert(min(x[ci+1],*s.rbegin()+2));
			else s.insert(1);
			ci++;
		}
		ans=(ans*(ci+1-i))%MOD;
	}
	printf("%lld",ans);
}


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

#define ll long long
#define PB push_back
#define MP make_pair
#define PF push_front
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define ft first
#define sc second

#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(i, a, b, c) for(int i = (a); i <= (b); i += (c))
#define FORL(i, a, b) for(int i = (a); i < (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define ROFL(i, a, b) for(int i = (a); i > (b); i--)
#define LLFOR(i, a, b) for(ll i = (a); i <= (b); i++)
#define LLFORL(i, a, b) for(ll i = (a); i < (b); i++)
#define LLROF(i, a, b) for(ll i = (a); i >= (b); i--)
#define LLROFL(i, a, b) for(ll i = (a); i > (b); i--)


using namespace std;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

const int mod = 1e9 + 7;
const double PI = acos(-1);

ll exp(ll x,ll n){
    if(n == 0) return 1;
    if(n == 1) return x;
    if(n%2 == 0) return exp((x*x)%mod,n/2);
    if(n%2 == 1) return (x*exp((x*x)%mod,n/2))%mod;
}

ll modpow(ll b, ll p, ll m)
{
    ll r = 1;
    while(p){
        if(p & 1) r = r*b%m;
        b = b*b%m;
        p /= 2;
    }

    return r;
}

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

    int n;
    int count = 0;
    cin >> n;

    for(int i = 1; i <= n-1; i++){
        int k = ceil((double)n/i);
        //cout << k << '\n';
        count += (k-1);
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 3656
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
M = 10 ** 5 + 1
K = 10
A = [(0, 0)] * max(N + 1, 1 << K)
X = [[], [-1] * M]
X[1][0] = 0
v, w = map(int, input().split())
X[1][w] = v
A[1] = (v, w)
for i in range(2, min(N + 1, 1 << K)):
    v, w = map(int, input().split())
    if i % 2 == 0:
        X.append(X[i // 2][:])
    else:
        X.append([])
        X[i] = X[i // 2]
    
    for j in range(w, M)[::-1]:
        if X[i][j-w] >= 0:
            X[i][j] = max(X[i][j], X[i][j-w] + v)
    
    A[i] = (v, w)

for i in range(1 << K, N + 1):
    v, w = map(int, input().split())
    A[i] = (v, w)

if len(X) < 1 << K:
    for i in range(len(X), 1 << K):
        X.append([-1] * M)

for i in range(1 << K - 1, 1 << K):
    for j in range(1, M):
        X[i][j] = max(X[i][j], X[i][j-1])

Q = int(input())
for _ in range(Q):
    i, maw = map(int, input().split())
    if i < 1 << K - 1:
        V = []
        W = []
        while i:
            v, w = A[i]
            V.append(v)
            W.append(w)
            i //= 2
        k = len(V)
        ma = 0
        WW = [0] * (1 << k)
        VV = [0] * (1 << k)
        for i in range(1, 1 << k):
            a = i & (-i)
            b = a.bit_length() - 1
            ww = WW[i-a] + W[b]
            WW[i] = ww
            if ww > maw: continue
            vv = VV[i-a] + V[b]
            VV[i] = vv
            ma = max(ma, vv)
        print(ma)
    else:
        V = []
        W = []
        while i >= 1 << K:
            v, w = A[i]
            V.append(v)
            W.append(w)
            i //= 2
        ii = i
        k = len(V)
        WW = [0] * (1 << k)
        VV = [0] * (1 << k)
        ma = X[ii][maw]
        for i in range(1, 1 << k):
            a = i & (-i)
            b = a.bit_length() - 1
            ww = WW[i-a] + W[b]
            WW[i] = ww
            if ww > maw: continue
            vv = VV[i-a] + V[b]
            VV[i] = vv
            ma = max(ma, X[ii][maw - ww] + vv)
        print(ma)


Measured memory_bytes: 867852
#include<iostream>
using namespace std;
int m,s,l,i,n;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>l;
		if(m<l)m=l;
		s+=l;
	}
	cout<<(s>m*2?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
X = int(input())
fork = 1
Done = False
while not Done:
    for A in range(-fork, fork+1):
        for B in range(-fork, fork+1):
            if A**5 - B**5 == X:
                Done = True
                break
            
        if Done:
            break
    fork += 1
print(A, B)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            return;
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
int main (void) {
    string s1, s2, s3;

    cin >> s1 >> s2 >> s3;

    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);

    cout << s1[0] << s2[0] << s3[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
  int n, k, d;
  int count = 0;
  cin >> n >> k;
  int table[n];

  for (int i = 0; i < n; i++)
  {
    table[i] = 0;
  }

  for (int i = 0; i < k; i++)
  {
    cin >> d;
    for (int j = 0; j < d; j++)
    {
      int idx;
      cin >> idx;
      table[idx - 1] += 1;
    }
  }

  for (int i = 0; i < n; i++)
  {
    if (table[i] == 0)
    {
      count++;
    }
  }

  cout << count;

  return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <algorithm>

using namespace std;
typedef unsigned long long llong;

#define MAX 4000
const llong mod = 1000000000 + 7;

int main()
{
  int N;
  char S[MAX];
  llong Rlen = 0, Glen = 0, Blen = 0;
  llong ans = 0;

  scanf("%d", &N);
  scanf("%s", S);

  for (int i = 0; i < N; i++)
  {
    switch (S[i])
    {
    case 'R':
      Rlen++;
      break;
    case 'G':
      Glen++;
      break;
    case 'B':
      Blen++;
      break;
    }
  }
  ans = Rlen * Glen * Blen;

  for (int i = 0; i < N; i++)
  {
    for (int j = i; j < N; j++)
    {
      int k = j + j - i;
      if (k < N && S[i] != S[j] && S[j] != S[k] && S[k] != S[i])
        ans--;
    }
  }

  printf("%llu\n", ans);

  return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' ||c == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	string s="NO";
	if(a==5&&b==5&&c==7)s="YES";
	if(a==5&&b==7&&c==5)s="YES";
	if(a==7&&b==5&&c==5)s="YES";
	cout << s << endl;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    set<int> a;
    rep(i, m){
        int t;
        cin >> t;
        a.insert(t);
    }
    int now = x, ans = IINF, cnt = 0;
    while(now > 0){
        --now;
        if(a.count(now)){
            ++cnt;
        }
    }
    ans = min(ans, cnt);
    now = x, cnt = 0;
    while(now < n){
        ++now;
        if(a.count(now)){
            ++cnt;
        }
    }
    ans = min(ans, cnt);
    cout << ans << endl;
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int r,c,m;
  cin >> r >> c >> m;
  vector<int> h(m);
  vector<int> w(m);
  for (int i=0;i<m;i++) {
    cin >> h[i] >> w[i];
  }
  vector<int> bsh(r+1,0);
  vector<int> bsw(c+1,0);
  for (int i=0;i<m;i++) {
    bsh[h[i]]++;
    bsw[w[i]]++;
  }
  int bshmax = 0;
  int bswmax = 0;
  for (int i=0;i<=r;i++) {
    bshmax = max(bshmax,bsh[i]);
  }
  for (int i=0;i<=c;i++) {
    bswmax = max(bswmax,bsw[i]);
  }
  int hmaxs = 0;
  int wmaxs = 0;
  for (int i=0;i<=r;i++) {
    if (bsh[i] == bshmax) hmaxs++;
  }
  for (int i=0;i<=c;i++) {
    if (bsw[i] == bswmax) wmaxs++;
  }
  int cross = 0;
  for (int i=0;i<m;i++) {
    if (bsh[h[i]] == bshmax && bsw[w[i]] == bswmax) {
      cross++;
    }
  }
  if (cross == hmaxs*wmaxs) {
    cout << bshmax+bswmax-1 << endl;
  } else {
    cout << bshmax+bswmax << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];

  int max_cnt = 0;
  int cnt = 0;
  for (int i = 0; i < N-1; i++) {
    if (H[i] >= H[i+1]) {
      cnt++;
      max_cnt = max(max_cnt, cnt);
    } else {
      cnt = 0;
    }
  }
  cout << max_cnt << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    ll n,a,b;
    cin>>n>>a>>b;
    vl x(n);
    cin>>x;
    ll ans=0;
    REP(i,n-1){
        ll l=x[i+1]-x[i];
        ans+=min(l*a,b);
    }
    cout<<ans<<endl;
}


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


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    h, w, k = map(int, input().split())
    ch = []
    for _ in range(h):
        ch.append(next_line())

    # print(ch)

    res = 0
    for i in range(1 << h):
        for j in range(1 << w):
            count = 0
            for l in range(h):
                for m in range(w):
                    if ch[l][m] == "#" and (i & (1 << l) == 0) and (j & (1 << m) == 0):
                        count += 1
            if count == k:
                res += 1
    print(res)


if __name__ == '__main__':
    main()


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

using namespace std;

constexpr int MOD = 1'000'000'007;

void dfs(int u, int p, const vector<vector<int>> &g, vector<pair<int, int>> &dp) {
    dp[u].first = dp[u].second = 1;
    for (int v : g[u]) {
        if (v != p) {
            dfs(v, u, g, dp);
            dp[u].first = (1LL * dp[u].first * (dp[v].first + dp[v].second)) % MOD;
            dp[u].second = (1LL * dp[u].second * dp[v].first) % MOD;
        }
    }
}

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<vector<int>> g(N);
    for (int i = 0; i < N - 1; ++i) {
        int x, y;
        cin >> x >> y;
        g[x - 1].push_back(y - 1);
        g[y - 1].push_back(x - 1);
    }
    
    vector<pair<int, int>> dp(N);
    dfs(0, -1, g, dp);
    cout << (dp[0].first + dp[0].second) % MOD << "\n";


    return 0;
}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll long long
//#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

ll n,k;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(){
  cin>>n>>k;
  k=min(k,n);
  mint ans=0;
  combination c(n);
  for(ll i=0;i<=k;i++){
    ans+=c(n,i)*c(n-1,i);
  }
  cout<<ans.x<<endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
 
int main() {
  
    int D, T, S;
    cin >> D >> T >> S;
 

    int dist = S * T;
 
    
    if (dist >= D) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include <fstream>
#include<list>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define loopj(x,y) for(int j = x;j<(y);j++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)


#define nl cout<<"\n";
#define ll long long int
#define mod  1000000007


using namespace std;

int main()
{

	ios :: sync_with_stdio(false);
	cin.tie(nullptr);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int h, w, m;
	cin >> h >> w >> m;

	vector<int> row(h + 1, 0);
	vector<int> col(w + 1, 0);

	vector <pair<int, int >> point;

	for (int i = 0; i < m; i++)
	{
		int p, q;
		cin >> p >> q;
		point.push_back(make_pair(p, q));
		row[p]++;
		col[q]++;
	}


	int maxrow = *max_element(row.begin(), row.end());
	int maxcol = *max_element(col.begin(), col.end());

	ll aa = 0, bb = 0;

	map<int, int> indexrow;
	for (int i = 1; i <= h; i++)
	{
		if (row[i] == maxrow)
		{
			aa++;
			indexrow[i] = 1;
		}
	}

	map<int, int> indexcol;
	for (int i = 1; i <= w; i++)
	{
		if (col[i] == maxcol)
		{
			bb++;
			indexcol[i] = 1;
		}
	}

	ll count = 0;
	for (int i = 0; i < m; i++)
	{
		int x = point[i].first;
		int y = point[i].second;

		if (indexrow.find(x) != indexrow.end() && indexcol.find(y) != indexcol.end() )
			count++;
	}
	// cout << aa << " " << bb << " " << count << " ";
	if (count < aa * bb)
		cout << maxcol + maxrow;
	else
		cout << maxcol + maxrow - 1;


	return 0;
}

Measured memory_bytes: 36084