akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a < c) {
		if (b > c) {
			if (d < b)cout << d - c;
			else cout << b - c;
		}
		else {
			cout << 0;
		}
	}
	else {
		if (d > a) {
			if (b < d)cout << b - a;
			else cout << d - a;
		}
		else {
			cout << 0;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
cs = {k: v*(v-1)//2 for k, v in c.items() if v!=1}
s = sum(cs.values())

for v in a:
    if v in cs:
        print(s-(c[v]-1))
    else:
        print(s)

Measured memory_bytes: 26780
#define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		int out_cou = 0, point = 0;
		bool rui[4] = { 0 };
		while (out_cou < 3) {
			string ev;
			cin >> ev;
			if (ev == "HIT") {
				rui[0] = true;
				for (int i = 3; i >= 1; --i) {
					if (rui[i] == true && i == 3) { ++point; rui[i] = false; }
					if (rui[i - 1] == true) { rui[i] = true; rui[i - 1] = false; }
				}
			}
			else if (ev == "OUT") {
				++out_cou;
			}
			else if (ev == "HOMERUN") {
				for (int i = 1; i < 4; ++i) {
					if (rui[i] == true) { ++point; }
					rui[i] = false;
				}
				++point;
			}
		}
		printf("%d\n", point);
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define MP make_pair
#define PB push_back
int inf = 100000000;
int main(){
    int n,m,cap,src,dst;
    string s,t;
    while(cin >> n >> m >> cap&&n!=0){
        cin >> s >> t;
        cap*=10;
        int id = 0;
        map<string,int>mp;
        mp[s] = id;
        src = id;
        id++;
        mp[t] = id;
        dst = id;
        id++;
        vector<pair<pair<int,int>,int> > v;
        for(int i=0;i<n;i++){
            string ss,tt;
            int x;
            cin >> ss >> tt >> x;
            if(mp.find(ss)==mp.end()){
                mp[ss]= id;
                id++;
            }
            if(mp.find(tt)==mp.end()){
                mp[tt] = id;
                id++;
            }
            v.PB(MP(MP(mp[ss],mp[tt]),x));
        }
        set<int> st;
        rep(i,m){
            string sx;
            cin >> sx;
            st.insert(mp[sx]);
        }
        if(s==t){
            cout << 0 << endl;
            continue;
        }
        int ns = mp.size();
        vector<vector<pair<int,int> > > g(ns);
        for(auto p:v){
            g[p.first.first].PB(MP(p.first.second,p.second));
            g[p.first.second].PB(MP(p.first.first,p.second));
        }
        vector<vector<int> > dp(ns,vector<int>(cap+1,inf));
        priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int > > ,greater<pair<pair<int,int>,int > >  > pq;
        pq.push(MP(MP(0,cap),0));
        while(!pq.empty()){
            auto xxx = pq.top();
            int x,y,now;
            x = xxx.first.first;
            y = xxx.first.second;
            now = xxx.second;
            pq.pop();
            if(dp[now][y]<x)continue;
            for(auto v:g[now]){
                int next = v.first;
                int d = v.second;
                if(y<d)continue;
                if(st.count(next)){
                    if(dp[next][cap]>x+d){
                        dp[next][cap] = x+d;
                        pq.push(MP(MP(x+d,cap),next));
                    }
                }else{
                    if(dp[next][y-d]>x+d){
                        dp[next][y-d] = x+d;
                        pq.push(MP(MP(x+d,y-d),next));
                    }
                }

            }
        }
        int mi = inf;
        rep(i,cap+1){
            mi = min(mi,dp[1][i]);
        }
        if(mi>=inf){
            cout << -1 << endl;
        }else{
            cout << mi << endl;
        }
    }



    return 0;
}



Measured memory_bytes: 51764
s=int(input())

a=[s]+[0]*1000000

if s%2==0:
    a[1]=s//2
else:
    a[1]=3*s+1
#print(a)
i=1
while a[i] not in a[:i]:
    if a[i]%2==1:
        a[i+1]=3*a[i]+1
    else:
        a[i+1]=a[i]//2
    i+=1

print(i+1)


Measured memory_bytes: 18676
N = int(input())
P = [int(input()) for _ in range(N)]

V = [-1] * (N+1)
for i in range(N):
    V[P[i]] = i+1
# print(V)

c = 0
ans = 0
for i in range(1, N+1):
    if V[i-1] > V[i]:
        c = 1
    else:
        c += 1
    ans = max(c, ans)

print(N-ans)


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

int main() {
  string s;
  long long int k;
  cin>>s>>k;
  for(int i=0;i<s.size();i++){
    char a=s.at(i);
    int b=a-'0';
    if(b==1){
      if(k==1){
        cout<<'1'<<endl;
        return 0;
      }
      else{
        k-=1;
      }
    }
    else{
      cout<<s.at(i)<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
while True:
	l = raw_input().split()
	a = int(l[0])
	op = l[1]
	b = int(l[2])
	if op == '+':
		print a+b
	elif op == '-':
		print a-b
	elif op == '*':
		print a*b
	elif op == '/':
		print a/b
	else:
		break

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

int n, a[100001];
long long sum[100001];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	for(int i = n; i > 1; i--) {
		if(sum[i-1]*2 < a[i]) cout << n-i+1, exit(0);
	}
	cout << n;
}


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

int main() {
    int a,b,i,n;
    cin>>a>>b;
    
    n=((a*2)-1)/2;
    for(i=0;i<n;i++)
    {
        a--;
        cout<<b-a<<" ";
    }
    cout<<b<<" ";
    a=0;
    for(i=n+1;i<2*n+1;i++)
    {
        a++;
        cout<<b+a<<" ";
    }
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pii pair<ll,ll>
#define x  first
#define y second
#define ll long long
using namespace std;

int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll ans[4] = {a*c,a*d,b*c,b*d};
    sort(ans,ans+4);
    cout << ans[3] << endl;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

long	F(long A, long B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}

int	main() {
	long A, B;
	cin >>A >>B;
	long C=F(A, B);
	cout <<A*B/C <<endl;
	return 0;
}



Measured memory_bytes: 256
n=int(input())
k=int(input())
x=input().split()
l=0

for i in range(n):
  if int(x[i]) <=abs(int(x[i])-k):
    l=l+2*int(x[i])
  else:
    l=l+2*abs(int(x[i])-k)
print(l)

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

int main(){
	string s, sub;
	vector<string> sub_set;
	int k;
	cin >> s >> k;
	for(int i=0; i<s.length(); i++){
		for(int j=i; j-i+1 <= k && j<s.length(); j++){
			sub = s.substr(i, j-i+1);
			sub_set.push_back(sub);
		}
	}
	sort(sub_set.begin(), sub_set.end());
	sub_set.erase(unique(sub_set.begin(), sub_set.end()), sub_set.end());
	cout << sub_set[k-1] << endl;
	return 0;
}


Measured memory_bytes: 1660
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
for(var I=0;I<n;I++){
   var xy=Arr.shift().split(" ").map(Number);
   var X=xy[0];
   var Y=xy[1];
   var p=Arr.shift()-0;
   var xx=[];
   var yy=[];
   for(var i=0;i<p;i++){
      var v=Arr.shift().split(" ").map(Number);
      if(v[0]==v[2])yy.push([Math.max(v[1]+1,v[3]+1),v[0]+1].join(","));
      else xx.push([v[1]+1,Math.max(v[0]+1,v[2]+1)].join(","));
   }
   var YX=[];
   for(var i=0;i<=Y+1;i++){
      YX[i]=[];
      for(var j=0;j<=X+1;j++){
         YX[i][j]=0;
      }
   }
   YX[1][1]=1;
   for(var y=1;y<=Y+1;y++){
      for(var x=1;x<=X+1;x++){
         if(y==1 && x==1)continue;
         var str=[y,x].join(",");
         if(yy.indexOf(str)!=-1 && xx.indexOf(str)!=-1)YX[y][x]=0;
         else if(yy.indexOf(str)!=-1)YX[y][x]=YX[y][x-1];
         else if(xx.indexOf(str)!=-1)YX[y][x]=YX[y-1][x];
         else YX[y][x]=YX[y-1][x]+YX[y][x-1];
      }
   }
   console.log((YX[Y+1][X+1]==0)?"Miserable Hokusai!":YX[Y+1][X+1]);
}

Measured memory_bytes: 10420
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	int N, L;
	cin >> N >> L;

	vector<string> S(200);
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
	}

	sort(S.begin(), S.begin() + N);
	for (int i = 0; i < N; i++)
	{
		cout << S[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

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


    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int H,W;
const int Maxn = 105;
const int INF = 1000000;
char Map[Maxn][Maxn];
int dp[Maxn][Maxn];
int Path[Maxn][Maxn];// 1 表示向下 -1 表示向右 
int main()
{
	cin>>H>>W;
	for(int i=1;i<Maxn;i++)
		for(int j=1;j<Maxn;j++)
			dp[i][j] = INF;
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			cin>>Map[i][j];
	if(Map[H][W] == '#') dp[H][W] = 1;
	else	dp[H][W] = 0;
	for(int i=H;i>=1;i--)
		for(int j=W;j>=1;j--)
		{
			if(i==H&&j==W)	continue;
			if(Map[i][j]=='.')
				dp[i][j] = min(dp[i+1][j],dp[i][j+1]);
			else
			{
				if(Map[i+1][j]=='.')
					dp[i][j] = min(dp[i][j],dp[i+1][j]+1);
				else
					dp[i][j] = min(dp[i][j],dp[i+1][j]);
				if(Map[i][j+1]=='.')
					dp[i][j] = min(dp[i][j],dp[i][j+1]+1);
				else
					dp[i][j] = min(dp[i][j],dp[i][j+1]); 
			}
		}
	cout<<dp[1][1];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, add[maxn], rem[maxn];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;
        add[l]++;
        rem[r]++;
    }
    int ans = 0, cur = 0;
    for(int i = 1; i <= n; i++)
    {
        cur += add[i];
        if(cur == m)
            ++ans;
        cur -= rem[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	int h, w; cin >> h >> w;
	vector<string> s(h);
	rep(i, h)cin >> s[i];
	vector<vector<int>> table(h, vector<int>(w, 0));
	vector<vector<int>> table2(h, vector<int>(w, 0));
	int t = 1;
	rep(i, h)rep(j, w)
	{
		if (s[i][j] == '.')table[i][j] += t++;
		else t = 1;
		if (j == w - 1)t = 1;
	}
	rep(i, h)rrep(j, w)
	{
		if (j - 1 >= 0 && table[i][j] > 0 && table[i][j-1] > 0)
			table[i][j - 1] = table[i][j];
	}
	rep(j, w)rep(i, h)
	{
		if (s[i][j] == '.') table2[i][j] += t++;
		else t = 1;
		if (i == h - 1)t = 1;
	}
	rep(j, w)rrep(i, h)
	{
		if (i - 1 >= 0 && table2[i][j] > 0 && table2[i - 1][j] > 0)
			table2[i - 1][j] = table2[i][j];
	}
	rep(i, h)rep(j, w)
	{
		table[i][j]+=table2[i][j];
	}
	int ans = 0;
	rep(i, h)rep(j, w)chmax(ans, table[i][j] - 1);
	co(ans);
	return 0;
}

Measured memory_bytes: 35712
fun main(args: Array<String>) {
    val mod = 1000000007
    var (N,K) = readIntList()
    var pre = 'N'
    var nonHappy = 0
    var ans = 0
    for (c in readString()) {
        if (c == pre) {
            ans++
        } else {
            nonHappy++
        }
        pre = c
    }
    ans += if (K >= nonHappy/2) nonHappy-1 else K*2
    println (ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 38924
#include<bits/stdc++.h>
using namespace std;using I=int;I main(char c){I n,x,y,t=1e7;map<I,map<I,I>>X,Y,S,D;for(cin>>n;n--;X[x][y]=Y[y][x]=S[x+y][x-y]=D[x-y][x+y]=c%5)cin>>x>>y>>c;auto f=[&](auto M,I a,I b){for(auto[z,m]:M){y=-3e7;for(auto[x,c]:m)y=c-a?y:x,t=c-b?t:min(t,x-y);}};f(X,0,3);f(Y,2,1);f(S,2,0);f(S,3,1);f(D,0,1);f(D,2,3);t<1e7?cout<<t*5:cout<<"SAFE";}

Measured memory_bytes: 124296
#include <stdio.h>
#include <iostream>

using namespace std;

    int main(){
    int n;
    cin >> n;
    int problems[n+5];
    int sum = 0;

    for (int i=1; i<=n; i++){
        cin >> problems[i];
        sum += problems[i];
    }

    int m;
    cin >> m;
    int drinks[m+5];
    int times[m+5];

    for (int i=1; i<=m; i++){
        cin >> drinks[i] >> times[i];
    }

    for (int i=1; i<=m; i++){
        int ans = sum;
        ans -= problems[drinks[i]];
        ans += times[i];
        printf("%d\n", ans);
    }

}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	REP(i,s.size()){
		if(s[i] == '1')s[i] = '9';
		else if(s[i] == '9')s[i] = '1';
	}
	dump(s);
	return 0;
}

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

A.sort(reverse=True)
sum = 0
if N % 2 == 0:
    for i in range(1, N // 2, 1):
        sum = sum + A[i]
    answer = sum * 2 + A[0]
else:
    for i in range(1, N // 2, 1):
        sum = sum + A[i]
    answer = sum * 2 + A[0] + A[N // 2]

print(answer)

Measured memory_bytes: 31632
x = input().split()
N = int(x[0])
K = int(x[1]) - 1
str_input = input()
str = list(str_input)

if str[K] == 'A':
    str[K] = 'a'
elif str[K] == 'B':
    str[K] = 'b'
elif str[K] == 'C':
    str[K] = 'c'

for i in str:
    print(i,end = "")


Measured memory_bytes: 3060
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use num_traits::real::Real;
use std::ops::Bound;
use text_io::*;

fn main() {
    let n: usize = read!();
    let mut hs = vec![0; n * 2];
    for i in 0..n {
        let h: isize = read!();
        hs[i] = h;
    }
    
    const INF: isize = 1000000000000000;
    
    let mut dp = vec![INF; n * 2];
    dp[0] = 0;
    
    for i in 0..n {
        dp[i + 1] = dp[i + 1].min(dp[i] + (hs[i] - hs[i + 1]).abs());
        dp[i + 2] = dp[i + 2].min(dp[i] + (hs[i] - hs[i + 2]).abs());
    }
    
    println!("{}", dp[n - 1]);
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r, g, b, x;
  cin >> r >> g >> b;
  x = 10*g + b ;
  if(x%4 == 0){
  cout << "YES" << endl;
  }else{
  cout << "NO"  << endl; 
  };
}

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

import static java.lang.Integer.parseInt;

/**
 * Weather Forecaster
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		line = br.readLine();
		int H, W;
		H = parseInt(line.substring(0, line.indexOf(' ')));
		W = parseInt(line.substring(line.indexOf(' ') + 1));

		int[][] forecast = new int[H][W];

		for (int i = 0; i < H; i++) {
			line = br.readLine();
			for (int j = 0; j < W; j++) {
				if (line.charAt(j) == 'c') {
					forecast[i][j] = 0;
				} else {
					if (j == 0) {
						forecast[i][j] = -1;
					} else {
						if (forecast[i][j - 1] == -1) {
							forecast[i][j] = -1;
						} else {
							forecast[i][j] = forecast[i][j - 1] + 1;
						}
					}
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (j == 0) {
					sb.append(forecast[i][j]);
				} else {
					sb.append(" " + forecast[i][j]);
				}
			}
			sb.append("\n");
		}
		System.out.print(sb.toString());
	}
}

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

int main(){
   string s;
   int cnt=0;
   cin>>s;
   for(int i=0;i<s.size();i++){
       if(s[i]=='1'){
           cnt++;
       }
   }
   cout<<cnt<<endl;
}

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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

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

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
//const ll M = 1000000007;
signed main() {
    ll k,q;
    cin>>k>>q;
    vector<ll> D(k);
    cin>>D;
    REP(_,q){
        ll n,x,m;
        cin>>n>>x>>m;
        ll a=x;
        ll c=n-1;
        REP(i,k){
            ll t=(n-1)/k+(i<(n-1)%k?1:0);
            if(D[i]%m==0){
                c-=t;
            }
            a+=D[i]%m*t;
        }
        c-=(a/m-x/m);
        cout<<c<<endl;
    }
}


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

int main(){
  int64_t A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K%2==0){
    cout << A-B << endl;
  }else{
    cout << B-A << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(void)
{
    int i,n,m;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        m=i;
        if(m % 3 == 0){
            printf(" %d",i);
        }else{
            while(m!=0){
                if(m % 10 == 3){
            printf(" %d",i);
            break;
                }
        m=m/10;
            }
        }
    }
      printf("\n");
    return 0;
}


Measured memory_bytes: 2088
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  int n,m;
  while(cin>>n>>m){
    if(n==0) break;
    int c[101]={0};
    REP(i,n)REP(j,m){
      int tmp;
      cin>>tmp;
      if(tmp==1) c[j]++;
    }
    vector<P> date;
    REP(i,m){
      date.push_back(P(-c[i],i));
    }
    sort(date.begin(),date.end());
    bool f = false;
    REP(i,m){
      if(f) cout<<" ";
      f = true;
      cout<<date[i].second+1;
    }
    cout<<endl;
  }
  return 0;
}

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

int main(){
	int a, b, c, d, e, f;
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
	std::pair <int, int> max{1, -1};
	for (int i = 0; i <= 30; ++ i){
		for (int j = 0; j <= 30; ++ j){
			if (!(i + j)) continue;
			for (int k = 0; k <= 3000; ++ k){
				int x = 100 * i * a + 100 * j * b + k * c;
				if (x > f){
					continue;
				}
				if (e * (i * a + j * b) < k * c) continue;
				int u = std::min(e * (i * a + j * b) - k * c, f - x) / d;
				std::pair <int, int> ans = {100 * i * a + 100 * j * b, k * c + u * d};
				if (ans.second * max.first > ans.first * max.second){
					max = ans;
				}
			}
		}
	}
	printf("%d %d\n", max.first + max.second, max.second);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const ll MOD = ((1e9) + 7);
 
int dp[2][5050];
 
int main()
{
    int N, L;
    scanf("%d %d", &N, &L);
    vector<int> x(N), a(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &x[i]);
    }
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
    }
 
    fill(dp[0], dp[0] + L, 1);    
    for (int i = 0; i < N; i++) {
        int curr = i & 1, next = !curr;
        for (int j = x[i]; j < L; j += a[i]) {
            if (j > 0) {
                dp[next][j] += dp[curr][j-1];
            } else {
                dp[next][j] = dp[curr][j];
            }
            dp[next][j] %= MOD;
            if (a[i] == 0) break;
        }
         
        for (int j = x[i]; j < L; j++) {
            dp[next][j+1] += dp[next][j];
            dp[next][j+1] %= MOD;
        }
        fill(dp[curr], dp[curr] + L, 0);
    }
    printf("%d\n", dp[N&1][L-1]);
    return 0;
}

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

const int N = 100010;
int next[N];
int prev[N];

void update(int n, int qi){
  int a1 = next[0];
  int aj_m1 = prev[qi];
  int aj_p1 = next[qi];
  int an = prev[n+1];
  if (n == 1){
    return;
  }

  if (a1 == qi){
    next[0] = aj_p1;
    next[qi] = n+1;
    prev[qi] = an;
    prev[aj_p1] = 0;
    next[an] = qi;
    prev[n+1] = qi;
  } else if (an == qi){
    next[0] = qi;
    prev[a1] = qi;
    next[aj_m1] = n+1;
    next[qi] = a1;
    prev[qi] = 0;
    prev[n+1] = aj_m1;
  } else {
  next[0] = aj_p1;
    prev[a1] = qi;
    next[aj_m1] = n+1;
    next[qi] = a1;
    prev[qi] = an;
    prev[aj_p1] = 0;
    next[an] = qi;
    prev[n+1] = aj_m1;
  }
}

int main(){
  int n, q;
  cin >> n >> q;
  vector<int> tmp(n+2);
  tmp[0] = 0;
  for(int i = 0;i < n;i++){
    cin >> tmp[i+1];
  }
  tmp[n+1] = n+1;
  for(int i = 0;i < n+2;i++){
    if (i != 0){
      prev[tmp[i]] = tmp[i-1];
    }
    if (i + 1 != n+2){
      next[tmp[i]] = tmp[i+1];
    }
  }

  for(int i = 0;i < q;i++){
    int query;
    cin >> query;
    update(n, query);
  }

  int now = next[0];
  for (int i = 0;i < n;i++){
    if (i)cout << " ";
    cout << now;
    now = next[now];
  }
  cout << endl;

  return 0;
}



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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int k,s;
    cin>>k>>s;
    int ans=0;
    rep(i,k+1)
        rep(j,k+1)
            if(0<=s-i-j&&s-i-j<=k)ans++;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define M 1000000007
#define deb(x) cout<<#x<<'='<<x<<endl
using namespace std;
const int N=1e6;
signed main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int c[3]={0};
	for(int i=0; i<s.length(); i++)
	{
		if (s[i]=='R')
			c[0]++;
		else if (s[i]=='G')
			c[1]++;
		else if (s[i]=='B')
			c[2]++;
	}
	int md=floor((n-1)/2);
	int p=0;
	for(int dist=1; dist<=md; dist++)
	{
		int i=0;
		int j=i+dist;
		int k=j+dist;
		while(k<n)
		{
			if (s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k])
				p++;
			i++;
			j=i+dist;
			k=j+dist;
		}
	}
	int ans=c[0]*c[1]*c[2];
	cout<<ans-p;
}

Measured memory_bytes: 3632
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n,c=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
stc.sort(key=lambda x: x[2])
# print(stc)
lst=[[0]*(10**5+5) for i in range(c)]
for i in range(len(stc)):
    s,t,c=stc[i]
    for j in range(s-1,t):
        lst[c-1][j]+=1
anslst=[0]*(10**5+5)
for i in range(c):
    for j in range(10**5+5):
        if lst[i][j]!=0:
            anslst[j]+=1
print(max(anslst))

Measured memory_bytes: 110424
s = gets.chomp.chars.map(&:ord).sort
t = gets.chomp.chars.map(&:ord).sort.reverse
s << 0
t << -1

t.length.times{ |i|
  s_min = s[i]
  t_max = t[i]
  if s_min < t_max
    puts 'Yes'
    break
  elsif s_min > t_max
    puts 'No'
    break
  end
}


Measured memory_bytes: 1788
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    float n = sc.nextFloat();
    float d = sc.nextFloat();
    float nd = n/((2*d)+1);
    int nd2 = (int)n/((2*(int)d)+1);
    if(n%((2*d)+1)>0){
      System.out.println(nd2+1);
    }else{
      System.out.println(nd2);
    } 
  }
}

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

#define INF 1e9;

using namespace std;

double diff(double a, double b) {
    if (a < b) return b - a;
    return a - b;
}

int main() {
    int n, t, ansN = -1;
    double a, h, ansD = INF;
    cin >> n >> t >> a;
    for (int i = 1; i <= n; ++i) {
        cin >> h;
        if (diff(t - h * 0.006, a) < ansD) {
            ansN = i;
            ansD = diff(t - h * 0.006, a);
        }
    }
    cout << ansN << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 bool is_prime(int x)
 {
   for(int i=2;i<=(int)sqrt(x);i++)
   {
     if(x%i==0) return false;        
   }     
   return true;
 }
 
 int main()
 {
   int N;
   while(cin>>N)
   {
     int min=N;
     int max=N;
     while(min--) if(is_prime(min)) break;   
     while(max++) if(is_prime(max)) break;
     cout<<min<<" "<<max<<endl;            
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3084
#abc149-d
n,k=map(int,input().split())
s,p,r=map(int,input().split())
f={'s':s,'p':p,'r':r}
t=str(input())
ans=0
for i in range(k):
    a=i+k
    last=t[i]
    ans+=f[last]
    while a<n-k:
        if t[a]==last:
            if t[a+k]==last:
                if last=='s':
                    last='r'
                else:
                    last='s'
            else:
                if last=='s':
                    if t[a+k]=='r':
                        last='p'
                    else:
                        last='r'
                elif last=='r':
                    if t[a+k]=='s':
                        last='p'
                    else:
                        last='s'
                else:
                    if t[a+k]=='r':
                        last='s'
                    else:
                        last='r'
        else:
            last=t[a]
            ans+=f[last]
        a+=k
    
    if a<n:
        if t[a]!=last:
            ans+=f[t[a]]

print(ans)

Measured memory_bytes: 9252
using System;

namespace ABC124B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());              //旅館の数をＮに読み込む
            int[] H = new int[N];                                               //整数型の変数配列ＨをＮ個準備するH[0]～H[N-1]
            string[] inputH = Console.ReadLine().Split(' ');  //スペース区切りの数値を読み込む
            for (int i = 0; i < N; i++)
            {
                H[i] = int.Parse(inputH[i]);                                //読み込んだ数値を配列に記録しておく
            }
            int ans = 1; //答えを入れる整数型の変数を準備する

            int min = H[0];//一番西側の旅館
            for (int i = 1; i < N; i++)
            {
                if (H[i] >= min) //もしも山の高さがmin以上だったら海を眺めることができるから、ansに1を加える。
                {
                    ans = ans + 1;
                    min = H[i];
                }
            }
            Console.WriteLine(ans);//答えを出力する
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class T> inline T re(){
	T N = 0; char c = getchar(); bool neg = 0;
	for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';
	for (; c >= '0' && c <= '9'; c = getchar())
		N = (N<<3)+(N<<1) + c - '0';
	return neg ? -N : N;
}

LL a, b, c;
int cnt = 0;
int main(){
	a = re<LL>(); b = re<LL>(); c = re<LL>();
	if (a == b && a == c && a % 2 == 0){
		return 0*printf("-1\n");
	}
	while ((a%2 == 0) && (b%2 == 0) && (c % 2 == 0)){
		cnt++;
		LL A = (b + c) / 2, B = (c + a) / 2, C = (a + b) / 2;
		a = A, b = B, c = C;
	//	cout << a << ' ' << b << ' ' << c << '\n';
	//	getchar();
	}
	cout << cnt << '\n';
	return 0;
}


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

/*alias*/
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using ll=long long;

using namespace std;

/*input*/
int n;
int v[100];
int c[100];

/*funcs*/


/*main*/
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(v[i]-c[i]>0){
            sum=sum+v[i]-c[i];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        char c = char.Parse(Console.ReadLine());
        int i = (int)c;
        if (97 <= i && i <= 122) Console.WriteLine('a');
        else Console.WriteLine('A');

    }

    

}

Measured memory_bytes: 25884
# import itertools
# import math


def solve(N, X, L):
    ans = 1
    now = 0
    for ll in L:
        now += ll
        if now <= X:
            ans += 1
    return ans


# N = int(input())
# S = input()
N, X = map(int, input().split())
L = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss  = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, X, L))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

ll long_search(const int start, const vvll& E, vll& dp){
  if(dp[start]>=0) return dp[start];

  ll ans = 0;
  for(auto end : E[start]){
    ans = max(ans, long_search(end, E, dp)+1);
  }

  return dp[start] = ans;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N >> M;
  vvll E(N);
  rep(i, 0, M){
    ll x, y;
    cin >> x >> y;
    E[x-1].push_back(y-1);
  }

  vll dp(N+1, -1);
  ll ans=0;
  rep(i, 0, N){
    ans = max(ans, long_search(i, E, dp));
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

int main() {
	string s;
	cin >> s;
	int A = s[0] - '0', B = s[1] - '0', C = s[2] - '0', D = s[3] - '0';
	int ans;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				ans = A;
				if (i % 2 == 0) ans += B;
				else ans -= B;
				if (j % 2 == 0) ans += C;
				else ans -= C;
				if (k % 2 == 0) ans += D;
				else ans -= D;
				if (ans == 7) {
					if (i % 2 == 0) cout << A << "+" << B;
					else cout << A << "-" << B;
					if (j % 2 == 0) cout << "+" << C;
					else cout << "-" << C;
					if (k % 2 == 0) cout << "+" << D;
					else cout << "-" << D;
					cout << "=7" <<endl;
					return 0;
				}
			}
		}
	}
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D ;

  if (A+B == C+D) {
    cout << "Balanced"  << endl;
  }

  else if (A+B > C+D) {
    cout << "Left"  << endl;
  }

  else if (A+B < C+D) {
    cout << "Right"  << endl;
  }

}

Measured memory_bytes: 3452
a,b,c,d=map(int,input().split())
if a>=0 and c>=0:
  print(b*d)
elif a<0 and c>=0:
  if b>=0:
    print(b*d)
  else:
    print(b*c)

elif c<0 and a>=0:
  if d>=0:
    print(b*d)
  else:
    print(d*a)    
else:
  if b<0 or d<0:
    print(a*c)
  else:
    if a*c<=b*d:
      print(b*d)
    else:
      print(a*c)
  

Measured memory_bytes: 9192
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
using namespace std::chrono;
long long int p=1e9 +7;
int n;
bool compatibility[21][21];
ll ans[21][1ll<<21];
ll solve(int N,int left){
    ll currans=0;//initialise with 0
    if(ans[N-1][left]!=-1){//check if we have already found the answer
        return ans[N-1][left];
    }
    if(N==1){
        for(int j=0;j<n;j++){
            int x=1<<j;
            if(left & x){//check if the jth women is left
                if(compatibility[N-1][j]){ 
                    ans[N-1][left]=1;
                    return 1;//If they are compatible return 1
                }
                else{
                    ans[N-1][left]=0;
                    return 0;//If the last 2 aren't compatible return 0
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        if(left & (1ll<<i)){//If the ith women is left
            if(compatibility[N-1][i]){//If the 2 are compatible
            currans+=solve(N-1,left - (1ll<<i));
            //Find the number of pairs after pairing them
            //and add all of them
            }
        }
    }
    currans%=p;//mod p
    ans[N-1][left]=currans;//memoise
    return ans[N-1][left];
}
ll solve(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1ll<<n);j++){
            ans[i][j]=-1;//memoisation initialisation
            //ans[i][j] represents i people left and
            //j is the bitmask for women left
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>compatibility[i][j];
        }
    }
    return solve(n,(1<<n)-1);//all men available, all women available because all bits set in mask
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout<<solve()<<"\n";
}


Measured memory_bytes: 344320
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

ll d[1010];
ll c[1010];
ll dp[1010][1010];
const int INF = 1 << 30;

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

	int n, m;
	cin >> n >> m;

	for(int i = 0; i < n; ++i){
		cin >> d[i];
	}

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

	for(int i = 0; i < m + 1; ++i){
		for(int j = 0; j < n + 1; ++j){
			dp[i][j] = INF;
		}
	}

	for(int i = 0; i < m + 1; ++i){
		dp[i][0] = 0;
	}

	for(int i = 0; i < m + 1; ++i){
		for(int j = 0; j < n; ++j){
			dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i][j] + d[j] * c[i]);
		}
	}
/*
	for(int i = 0; i < m + 1; ++i){
		for(int j = 0; j < n + 1; ++j){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
*/
	cout << dp[m][n] << endl;

	return 0;
}

/*
i??\??????j???????????¨??????????°?????????´???
dp[i][j]
*/

Measured memory_bytes: 10980
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<int> h(n);
	vector<ll> dp(n + 10, 1e18);
	for (int i = 0; i < n; i++) cin >> h[i];
	dp[0] = 0;
	for (int i = 0; i < n - 2; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	dp[n - 1] = min(dp[n - 1], dp[n - 2] + abs(h[n - 2] - h[n - 1]));
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
         public static long GCM(long x,long y)
        {
            if (x < y)  GCM(y, x);


            while (y > 0)
            {
                var z = y;
                y = x % y;
                x = z;
            }
            
            return x;
        }

        



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var s = ReadLine();
            var n = s.Length;
            var c = new long[3];

            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'a') c[0]++;
                if (s[i] == 'b') c[1]++;
                if (s[i] == 'c') c[2]++;
            }
            bool f1 = (c.Max()-1) * 3 + 1 <= n;
            bool f2 = (c.Sum() - c.Max() - c.Min()-1) * 3 + 2<=n;
            bool f3 = (c.Min()-1) * 3 + 3 <= n;
            WriteLine(f1 && f2 && f3 ? "YES" : "NO");


            Console.Out.Flush();
        }
    }
}




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

int main() {
    bool a=true;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i%2!=0){
            if(s.at(i)=='L' ||s.at(i)=='U'||s.at(i)=='D'){
            }else{
                a=false;
                break;
            }
        }else{
            if(s.at(i)=='R' ||s.at(i)=='U' || s.at(i)=='D'){
            }else{
                a=false;
                break;
            }
        }
    }
    if(a==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,k; cin>>n>>k;
  ll r,s,p; cin>>r>>s>>p;
  map<char,ll> ctoi;
  ctoi['r']=p; ctoi['s']=r; ctoi['p']=s;
  
  string t; cin>>t;
  vb win(n);
  ll ans=0;
  rep(i,n){
    if(i<k){
      ans+=ctoi[t[i]];
      win[i]=1;
    }
    else{
      if(!(t[i]==t[i-k] && win[i-k])){
        ans+=ctoi[t[i]];
        win[i]=1;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512