akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<long int, int> P;
static const long int INF = 1e16;

struct edge
{
	long int to;
	int height;
	edge(long int to, int height) : to(to), height(height){};
};

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	long int X;
	cin >> N >> M >> X;
	vector<long int> treeHeight(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> treeHeight[i];
	}
	vector< vector<edge> > treeNode(N);
	for (int i = 0; i < M; ++i)
	{
		int from, to, cost;
		cin >> from >> to >> cost;
		--from; --to;
		treeNode[from].push_back(edge(to, cost));
		treeNode[to].push_back(edge(from, cost));
	}
	bool used[1000001];
	memset(used, 0, sizeof(used));
	priority_queue<P> pque;
	pque.push(P(X, 0));
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		if (p.second == N - 1)
		{
			cout << X + treeHeight[N - 1] - p.first * 2 << endl;
			return;
		}
		if (used[p.second]++) continue;
		for (int i = 0; i < treeNode[p.second].size(); ++i)
		{
			edge e = treeNode[p.second][i];
			if (e.height > treeHeight[p.second])
			{
				continue;
			}
			pque.push(P(min(p.first - e.height, treeHeight[e.to]), e.to));
		}
	}
	cout << -1 << endl;
}

int main()
{
	solve();
	return(0);
}

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

typedef long long ll;
typedef pair <int, int> pii;

#define fr first
#define sc second
#define pb push_back
#define mpr make_pair
#define ppb pop_back()
#define ins insert
#define sz(s) int(s.size())
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
const int N = 1e5 + 1;
ll p[N];
int a[N], n;
bool check(int x){
	ll sum = p[x];
	for(int i = x + 1;i <= n; ++ i){
		if(a[i] > sum * 2)return 0;
		sum += a[i];
	}
	return 1;
}
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.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){
		p[i] = p[i - 1] + a[i];
	}
	int l = 1,r = n;
	while(l < r){
		int mid = (l + r) / 2;
		if(check(mid))r = mid;
		else l = mid + 1;
	}
	cout << n - l + 1;
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
int main() {
  int k, S;
  string s;
  cin >> k >> s;
  S = s.size();
  if (S <= k){
    cout << s << endl;
  }else if (S > k){
    std::string substr = s.substr(0, k);
    cout << substr << "..." << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j,k,d[10000],x,y,g,h;
int mp[1001][1001],bd[1001][1001],a[10000][100],b[10000][100];
char s[1001][1001];
int main(void)
{
	cin>>n>>m;
	for(i=1;i<=m;i++) cin>>s[i];
	for(i=0;i<n-1;i++){
		cin>>d[i];
		for(j=0;j<d[i];j++) scanf("%d %d",&a[i][j],&b[i][j]);
	}
	for(i=1;i<=m;i++){
		for(j=0;j<m;j++){
			if(s[i][j]=='1') mp[i][j+1]=1;
			else mp[i][j+1]=0;
		}
	}
	k=0;
	for(i=1;i<=m;i++) for(j=1;j<=m;j++) bd[i][j]=0;
	for(i=1;i<=m/2;i++){
		for(j=1;j<=m/2;j++){
			if(mp[i][j]!=mp[m-i+1][j]||
				mp[i][j]!=mp[i][m-j+1]||
				mp[i][j]!=mp[m-i+1][m-j+1]){
					bd[i][j]=1;
					bd[m-i+1][j]=1;
					bd[i][m-j+1]=1;
					bd[m-i+1][m-j+1]=1;
					k++;
				}
		}
	}/*
	for(g=1;g<=m;g++){
		for(h=1;h<=m;h++) cout<<bd[g][h];
		cout<<endl;
	}
	cout<<endl;*/
	int sum=0;
	if(k==0) sum=1;
	for(i=0;i<n-1;i++){
		for(j=0;j<d[i];j++){
			x=a[i][j]; y=b[i][j];
			if(mp[x][y]==0) mp[x][y]=1;
			else mp[x][y]=0;
			if(m/2<x) x=m-x+1;
			if(m/2<y) y=m-y+1;
			if(mp[x][y]!=mp[m-x+1][y]||
				mp[x][y]!=mp[x][m-y+1]||
				mp[x][y]!=mp[m-x+1][m-y+1]){
					if(bd[x][y]==0) k++;
					bd[x][y]=1;
					bd[m-x+1][y]=1;
					bd[x][m-y+1]=1;
					bd[m-x+1][m-y+1]=1;
				}
			else {
				if(bd[x][y]==1) k--;
				bd[x][y]=0;
				bd[m-x+1][y]=0;
				bd[x][m-y+1]=0;
				bd[m-x+1][m-y+1]=0;
			}
		}/*
		for(g=1;g<=m;g++){
			for(h=1;h<=m;h++) cout<<bd[g][h];
			cout<<endl;
		}
		cout<<endl;*/
		if(k==0) sum++;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 19924
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=2002;
int n,k,f[N][N],fac[N*N],inv[N*N],ans;
int C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	scanf("%d%d",&n,&k);
	if(k==1){puts("1");return 0;}
	fac[0]=1;for(int i=1;i<=n*k;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;for(int i=2;i<=n*k;i++)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=2;i<=n*k;i++)inv[i]=1ll*inv[i-1]*inv[i]%mod;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	for(int j=i;~j;j--)
	f[i][j]=(f[i][j]+1ll*f[i-1][j-1]*C(k*i-j-1,k-2)%mod+f[i][j+1])%mod;
	f[n][0]=1ll*f[n][0]*fac[n]%mod;
	printf("%d",f[n][0]);
}

Measured memory_bytes: 47232
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 998244353
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];

// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  ll N,A,B,K,ans=0;
  cin>>N>>A>>B>>K;
  COMinit();
  
  for(int i=0; i<=N; ++i){
    if((K-A*i)%B==0){
      ll j=(K-A*i)/B;
      ans+=COM(N,i)*COM(N,j)%MOD;
      ans%=MOD;
    }
  }
  
  if(ans<0) ans+=MOD;
  co(ans);
  return 0;
}

Measured memory_bytes: 119808
#include <stdio.h>
int main(void){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while(1)
    {
        if((C=C-B) <= 0){
            printf("Yes\n");
            break;
        }
        if((A=A-D) <= 0){
            printf("No\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1660
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int X,Y;
    cin>>X>>Y;

    cout<<X+(Y/2)<<endl;

}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//うーん

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[1 << 18];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int n = (1 << N);
	int S[1 << 18];
	rep(i, (1 << N)) {
		S[i] = getint();
	}
	pakuri_sort(n, S);
	int A0[1 << 16], A1[1 << 16], A2[1 << 17];
	A0[0] = S[n - 1];
	int OK = 1;
	rep(i, N - 1) {
		int p = n - 1;

		if (i % 2 == 0) {
			for (int j = (1 << i) - 1; j >= 0; j--) {
				while (p >= 0 && S[p] >= A0[j]) p--;
				if (p < 0) {
					OK = 0;
					break;
				}
				A1[j] = S[p];
				S[p] = 1e9;
				p--;
			}
			if (!OK) break;

			int p1 = 0, p2 = 0;
			rep(k, 1 << (i + 1)) {
				if (p1 == (1 << i)) A2[k] = A1[p2++];
				else if (p2 == (1 << i)) A2[k] = A0[p1++];
				else if (A0[p1] < A1[p2]) A2[k] = A0[p1++];
				else A2[k] = A1[p2++];
			}
		}
		else {
			for (int j = (1 << i) - 1; j >= 0; j--) {
				while (p >= 0 && S[p] >= A2[j]) p--;
				if (p < 0) {
					OK = 0;
					break;
				}
				A1[j] = S[p];
				S[p] = 1e9;
				p--;
			}
			if (!OK) break;

			int p1 = 0, p2 = 0;
			rep(k, 1 << (i + 1)) {
				if (p1 == (1 << i)) A0[k] = A1[p2++];
				else if (p2 == (1 << i)) A0[k] = A2[p1++];
				else if (A2[p1] < A1[p2]) A0[k] = A2[p1++];
				else A0[k] = A1[p2++];
			}
		}
	}
	int i = N - 1;
	int p = n - 1;
	if (i % 2 == 0) {
		for (int j = (1 << i) - 1; j >= 0; j--) {
			while (p >= 0 && S[p] >= A0[j]) p--;
			if (p < 0) {
				OK = 0;
				break;
			}
			p--;
		}
	}
	else {
		for (int j = (1 << i) - 1; j >= 0; j--) {
			while (p >= 0 && S[p] >= A2[j]) p--;
			if (p < 0) {
				OK = 0;
				break;
			}
			p--;
		}
	}

	if (OK) printf("Yes");
	else printf("No");

	Would you please return 0;
}

Measured memory_bytes: 3328
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count=0
for a in [a*500 for a in range(A+1)]:
    for b in [b*100 for b in range(B+1)]:
        for c in [c*50 for c in range(C+1)]:
            if a+b+c==X:
                count+=1
print(count)

Measured memory_bytes: 3064
#include<cstdio>
int main(void){
int a[4][13];
char c[10];
int x;
int n;
scanf("%d",&n);
for(int i=0;i<4;i++){
for(int j=0;j<13;j++)a[i][j]=0;
}
for(int i=0;i<n;i++){
scanf("%s %d",c,&x);
if(c[0]=='S')a[0][x-1]=1;
if(c[0]=='H')a[1][x-1]=1;
if(c[0]=='C')a[2][x-1]=1;
if(c[0]=='D')a[3][x-1]=1;
}
for(int i=0;i<13;i++){
if(a[0][i]==0)printf("S %d\n",i+1);
}
for(int i=0;i<13;i++){
if(a[1][i]==0)printf("H %d\n",i+1);
}
for(int i=0;i<13;i++){
if(a[2][i]==0)printf("C %d\n",i+1);
}
for(int i=0;i<13;i++){
if(a[3][i]==0)printf("D %d\n",i+1);
}
return 0;
}

Measured memory_bytes: 2680
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long

int main() {
    
    ll n;
    cin >> n;
    ll h[n];
    bool ans=true;
    for(ll i=0;i<n;i++){
        cin >> h[i];
    }
    for(ll i=n-2;i>=0;i--){
        if(h[i]>h[i+1]) {
            h[i]--;
        }
        if(h[i]>h[i+1]){
            ans=false;
            break;
        }
    }
    if(ans) cout <<"Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 1024
package main

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

func main() {
	n := getInt()
	ts := make([]int, n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		ts[i] = getInt()
		as[i] = getInt()
	}

	T := ts[0]
	A := as[0]

	for i := 1; i < n; i++ {
		t := ts[i]
		a := as[i]
		if T <= t && A <= a {
			T = t
			A = a
		} else {
			tmpT := T + (t-T%t)%t
			tmpA := A + (a-A%a)%a
			if tmpT/t > tmpA/a {
				T = tmpT
				A = tmpT / t * a
			} else if tmpT/t < tmpA/a {
				T = tmpA / a * t
				A = tmpA
			} else {
				T = tmpT
				A = tmpA
			}
		}
	}

	fmt.Println(T + A)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())
edges = [tuple(map(int1, input().split())) for _ in range(M)]
G = [set() for _ in range(N)]
for s, t in edges:
    G[s].add(t)


def E(dp, i):
    return sum(dp[x] for x in G[i]) / len(G[i]) + 1


dp0 = [0] * N
for i in range(N - 2, -1, -1):
    dp0[i] = E(dp0, i)

ans = dp0[0]
for i in range(N - 1):
    if len(G[i]) == 1:
        continue

    maxE = 0
    maxE_ind = None
    for x in G[i]:
        if dp0[x] > maxE:
            maxE_ind = x
            maxE = dp0[x]

    dp = dp0.copy()
    G[i].remove(maxE_ind)
    for j in range(i, -1, -1):
        dp[j] = E(dp, j)
    ans = min(ans, dp[0])
    G[i].add(maxE_ind)

print(ans)


Measured memory_bytes: 106400
#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())

    N = int(input())
    Vs = list(map(int, input().split()))


    for i in range(N-1):
        Vs = sorted(Vs)
        two = sum(Vs[:2]) / 2
        Vs.pop(0)
        Vs.pop(0)
        Vs.append(two)

    print(two)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int ans = 0;
		while (n > 0) {
			n /= k;
			ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22228
#include<stdio.h>
#include<math.h>

int main(){
    int a,b,ans = 0;
    scanf("%d%d",&a,&b);
    ans += fmax(a,b);
    if (a > b) a--;
    else b--;
    ans += fmax(a,b);
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int x,a,b;
	
	scanf("%d %d %d",&x,&a,&b);
	
	if(abs(a-x)<abs(b-x)){
		printf("A\n");
	}else{
		printf("B\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>



int main() {
	ll n, m;
	cin >> n >> m;
	cout << (n == m ? "Yes" : "No") << endl;
}


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

int main() {
	/*int N;
	cin >> N;
	vector<int>h(N);
	int i;
	for (i = 0; i < N; i++) {
		cin >> h[i];
	}
	vector<int>c(N);
	c[0] = 0;
	c[1] = abs(h[1]-h[0]);
	for (i = 1; i < N - 1; i++) {
		c[i + 1] = min(c[i] + abs(h[i + 1] - h[i]), c[i - 1] + abs(h[i + 1] - h[i - 1]));
	}
	cout << c[N - 1] << endl;*/

	int N, K;
	cin >> N >> K;
	vector<int>h(N);
	int i, j;

	for (i = 0; i < N; i++) {
		cin >> h[i];
	}
	vector<int>c(N);
	c[0] = 0;
	c[1] = abs(h[1] - h[0]);
	for (i = 1; i < N - 1; i++) {
		c[i + 1] = c[i] + abs(h[i + 1] - h[i]);
		for (j = 1; j <= K && i + 1 - j >= 0; j++) {
			c[i + 1] = min(c[i + 1], c[i + 1 - j] + abs(h[i + 1] - h[i + 1 - j]));
		}
	}
	cout << c[N - 1] << endl;
}

Measured memory_bytes: 1024
S=list(input())
N=len(S)

ans=[0]*N
r=0
for i in range(N):
  if S[i]=="R":
    r+=1
  else:
    if r%2==0:
      ans[i-1]+=r//2
      ans[i]+=r//2
    else:
      ans[i-1]+=r//2+1
      ans[i]+=r//2
    r=0

S.reverse()
ans.reverse()
l=0
for i in range(N):
  if S[i]=="L":
    l+=1
  else:
    if l%2==0:
      ans[i-1]+=l//2
      ans[i]+=l//2
    else:
      ans[i-1]+=l//2+1
      ans[i]+=l//2
    l=0

ans.reverse()
print(" ".join(map(str,ans)))

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

int main(){
	int x,y;
	while(1){
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y){
			int k;
			k = y;
			y = x;
			x = k;
		}
		cout << x <<" "<< y << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import itertools
n,m=map(int,input().split())
l=[input() for i in range(2*m)]
l=l[1::2]
a=[]
for j in l:
    a.append(j.split())
b=list(itertools.chain.from_iterable(a))
c=[int(j) for j in b]
d=list(set(c))
e=[]
for k in range(1,n+1):
    e.append(k)
print(len(e)-len(d))

Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  long long N, A, B;
  cin >> N >> A >> B;
  long long ans = 0;
  long long n1 = N / (A + B);
  long long n2 = N % (A + B);
  ans = n1 * A;
  if (n2 <= A)
    ans += n2;
  else
    ans += A;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int ans(int index,int time,int t,vector<pair<int,int>>& v,vector<vector<int>>& value){
	if(index>=v.size())
		return 0;
	if(time>=t)
		return 0;
	if(value[index][time]!=-1)
		return value[index][time];
	int returnVal=0;
	returnVal = v[index].second + ans(index+1,time+v[index].first,t,v,value);
	returnVal = max(returnVal,ans(index+1,time,t,v,value));
	value[index][time]=returnVal;
	return returnVal;
}

int main() {
	IOS;
	int n,t;
	cin>>n>>t;
	vector<pair<int,int>> v;
	for(int i=0;i<n;i++){
		int p,q;
		cin>>p>>q;
		v.push_back({p,q});
	}
	sort(v.begin(),v.end());
	std::vector<vector<int>> va(n+1,vector<int> (t+1,-1));
	cout<<ans(0,0,t,v,va);

	return 0;
}

Measured memory_bytes: 38784
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a,b,c;cin >> a >> b >> c;
cout << min(a*b, c) << endl;
}


Measured memory_bytes: 256
def main():
    N,K=map(int,input().split())
    p=list(map(int,input().split()))

    E=[]

    for i in p:
        E.append((1+i)/2)

    S=[0]

    s=0
    for i in E:
        s+=i
        S.append(s)

    max=0
    right=0
    left=right+K

    while left<len(S):
        res=S[left]-S[right]
        if res>=max:
            max=res
        right+=1
        left=right+K

    print(max)

if __name__=="__main__":
    main()


Measured memory_bytes: 112924
import numpy as np
N = int(input())
l = []
for _ in range(5):
    l.append(int(input()))
l = np.array(l)
l_min = np.min(l)
if N < l_min:
    print(5)
else:
    if l_min == 1:
        result = 5 + (N//l_min) - 1
    else:
        result = 5 + (N//l_min)
    print(result)

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int main()
{
  string s;
  cin>>s;
  int n = s.length();
  for(int i=0; i<n;i++)
  {
    if(i+1 < n)
    {
      if(s[i] == s[i+1])
      {
        cout<<i+1<<" "<<i+2<<endl;
        return 0;
      }
    }
    if(i+2 < n)
    {
      if(s[i] == s[i+2])
      {
        cout<<i+1<<" "<<i+3<<endl;
        return 0;
      }
    }
  }
  cout<<"-1 -1"<<endl;
}


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

using namespace std;
int N;
int main(){
  cin >> N;
  int kusi[201];
  for(int i=0;i!=2*N;i++){
    cin >> kusi[i];
  }
  sort(kusi,kusi+(2*N),greater<int>());
  int ans=0;
  for(int i=0;i!=N*2;i+=2){
    ans+=kusi[i+1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> W;
  tools::read(W, N);

  std::vector<i64> cumsum({0});
  std::partial_sum(W.begin(), W.end(), std::back_inserter(cumsum));
  i64 answer = std::numeric_limits<i64>::max();
  for (i64 T = 1; T < N; ++T) {
    answer = std::min(answer, std::abs(cumsum[T] - (cumsum.back() - cumsum[T])));
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int bubbleSort(int a[],int n)
{
    int sum=0;
    bool flog=1;
    for(int i=0;flog;i++)
    {
        flog=0;
        for(int j=n-1;j>=i+1;j--)
        {
            if(a[j]<a[j-1])
            {
                swap(a[j],a[j-1]);
                flog=1;
                sum++;
            }
        }
    }
    return sum;
}
int main()
{
    int n,sum;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sum=bubbleSort(a,n);
    for(int i=0;i<n;i++)
    {
        if(i)
            cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    cout<<sum<<endl;
}


Measured memory_bytes: 3116
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

#if 0
	auto possible = [&](LL t) {

		return false;
	};
	LL left = 1, right = 1000000000;
	while (right - left > 1) {
		LL mid = (left + right) / 2;
		if (possible(mid)) {
			left = mid;
		} else {
			right = mid;
		}
	}
#endif

static const long long MOD = 998244353;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

void solve(long long N, long long S, std::vector<int> &A) {
	vector<modll> dp(S + 1, 0);
	dp[0] = 1;
	for (LL i = 0; i < N; ++i) {
		vector<modll> next(S + 1);
		for (LL j = 0; j <= S; ++j) {
			next[j] = dp[j] * 2;
		}
		for (LL j = S - A[i]; j >= 0; --j) {
			next[j + A[i]] += dp[j];
		}
		dp = next;
	}
	cout << dp[S] << endl;
}

int main() {
	long long N, S;
	cin >> N >> S;
	std::vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	solve(N, S, A);
	return 0;
}


Measured memory_bytes: 3676
import java.util.*;

  public class Main {
      public static void main (String[]args){
          
          Scanner scanner = new Scanner(System.in);
          
          int a = scanner.nextInt();

          String s = scanner.next();

          scanner.close();

          if (a >= 3200){
            System.out.println(s);
          } else if( a < 3200 ){
            System.out.println("red");
          } 
                  
      }
  } 

Measured memory_bytes: 21844
from collections import  Counter
N = int(input())
A = list(map(int,input().split()))

cnt = Counter(A)

ans = 0
for k,v in cnt.items():
    ans += v*(v-1)//2


for a in A:
    n = cnt[a]
    print(ans - n*(n-1)//2 + (n-1)*(n-2)//2)



Measured memory_bytes: 87884
#include<bits/stdc++.h>
#define fast ios::base_sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;
 
int main(){
    int a,b;
    cin>>a>>b;
    if(a - 2*b <= 0){
        cout<<0;
    }
    else
        cout<<a-2*b;
    return 0;
}

Measured memory_bytes: 256
/**
    __author__ : srv_twry
**/

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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}

bool ge(const ll& a, const ll& b) { return a >= b; }
bool le(const ll& a, const ll& b) { return a <= b; }
bool eq(const ll& a, const ll& b) { return a == b; }
bool gt(const ll& a, const ll& b) { return a > b; }
bool lt(const ll& a, const ll& b) { return a < b; }
int sgn(const ll& x) { return le(x, 0) ? eq(x, 0) ? 0 : -1 : 1; }
/*----------------------------------------------------------------------*/

const int N = 21;
int a[N],b[N],c[N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	int n, prev; cin>>n;
	FOR(i, 1, n+1) cin>>a[i];
	FOR(i, 1, n+1) cin>>b[i];
	FOR(i, 1, n) cin>>c[i]; 
	int res = 0;
	FOR(i, 1, n+1) {
		res += b[a[i]];
		if(prev == a[i]-1) {
			res += c[prev];
		}
		prev = a[i];
	} 
	cout<<res;
    return 0;
}

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

int main(){    
    string S, T;
    cin >> S >> T;
    int s = S.length(), t = T.length();
    vector<string> ans; 
    for(int i=0; i+t<=s; i++){
        bool match = true;
        for(int j=0; j<t; j++){
            if(S[i+j]!='?' && S[i+j]!=T[j]) match = false;
        }
        if(!match) continue;

        string tmp = "";
        if(i!=0) tmp += S.substr(0,i);
        tmp += T;
        if(i!=s-t) tmp += S.substr(i+t);
        replace(tmp.begin(), tmp.end(), '?', 'a');
        ans.push_back(tmp);
    }

    if(ans.size()==0) cout << "UNRESTORABLE" << endl;
    else{
        sort(ans.begin(), ans.end());
        cout << ans[0] << endl;
    }
}


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

int main()
{
  int a,b,c,d;
  int n,cnt;

  while(cin >> n){
    cnt = 0;
    for(a=0;a<10;a++){
      for(b=0;b<10;b++){
	for(c=0;c<10;c++){
	  for(d=0;d<10;d++){
	    if(a+b+c+d==n)cnt++;
	  }
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve . sort 

solve :: [Int] -> Int 
solve [a, b, c] = ar + br + m
    where
        (ar, am) = (c - a) `divMod` 2
        (br, bm) = (c - b) `divMod` 2 
        dm = min am bm
        m 
            | am == bm = am
            | otherwise = dm + 2

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n := input.NextInt()
  t := make([][]int,n)
  for i:=0;i<n-1;i++ {
    a,b := input.NextInts()
    t[a-1] = append(t[a-1],b-1)
    t[b-1] = append(t[b-1],a-1)
  }
  if diameter(t)%3 == 1 {
    fmt.Println("Second")
  } else {
    fmt.Println("First")
  }
}

func diameter(t [][]int) int {
  s,m := -1,-1
  var dfs func(int,int,int)
  dfs = func(u,p,d int) {
    if m < d { s,m = u,d }
    for _,v := range t[u] {
      if v != p { dfs(v,u,d+1) }
    }
  }
  dfs(0,-1,0)
  dfs(s,-1,0)
  return m
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

Measured memory_bytes: 68480
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int h, w;
char c[22][22];
int dx[4]={0, 1, 0, -1};
int dy[4]={1, 0, -1, 0};

int idx(int x, int y){
    return x*w+y;
}

int main(){
    scanf("%d%d", &h, &w);
    rep(i, h)rep(j, w) scanf(" %c", &c[i][j]);
    int d[h*w][h*w];
    rep(i, h*w){
        rep(j, h*w) d[i][j]=MAX;
        d[i][i]=0;
    }
    rep(x, h)rep(y, w)if(c[x][y]=='.'){
        rep(i, 4){
            int nx=x+dx[i], ny=y+dy[i];
            if(0<=nx && nx<h && 0<=ny && ny<w && c[nx][ny]=='.'){
                d[idx(x, y)][idx(nx, ny)]=1;
            }
        }
    }
    rep(k, h*w)rep(i, h*w)rep(j, h*w){
        chmin(d[i][j], d[i][k]+d[k][j]);
    }
    int ans=0;
    rep(i, h*w)rep(j, h*w)if(d[i][j]<MAX) chmax(ans, d[i][j]);
    printf("%d\n", ans);
}

Measured memory_bytes: 896
K, N = map(int, input().split())
a = list(map(int, input().split()))

m = 0
p = 0
for n in range(0, N):
    if (n == N - 1):
        if (K - a[n] + a[0] >= m):
            m = K - a[n] + a[0]
            p = n
    elif ((a[n + 1] - a[n]) >= m):
        m = a[n + 1] - a[n]
        p = n

if (p == N - 1):
    print(a[p] - a[0])
else:
    print(K - a[p + 1] + a[p])

Measured memory_bytes: 26444
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)

	var sum int
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += gcd(gcd(a, b), c)
			}
		}
	}

	fmt.Println(sum)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int h,w,a,b; cin >> h >> w >> a >> b;
    rep(i,h){
        rep(j,w){
            if((i<b && j<a) || (i>=b && j>=a)) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3552
import java.util.*;

public class Main {
    private final static int M = 1000000007;

    private static int solve(int N, boolean[][] a) {
        int states = 1 << N;
        int[] count = new int[states];
        boolean[] added = new boolean[states];
      
        Queue<Item> q = new ArrayDeque<>();
        q.add(new Item(0, 0));
        count[0] = 1;
      
        while (!q.isEmpty()){
          Item item = q.poll();
          int state = item.state;
          int i = item.pos;
          
          for (int j = 0; j < N; j++) {
            if (!a[i][j]) continue;

            int newState = state | (1 << j);
            if (newState == state) continue;
            count[newState] = (count[newState] + count[state]) % M;
            
            if (i+1 < N && !added[newState]){
              q.add(new Item(newState, i+1));
              added[newState] = true;
            }
          }
        }

        return count[states-1];
    }
  
   static class Item{
     public int state;
     public int pos;
     public Item(int state, int pos){
       this.state = state;
       this.pos = pos;
     }
   }

    public static int run(Scanner scanner) {
        int N = scanner.nextInt();
        boolean[][] a = new boolean[N][N];
        for (int i=0; i < N; i++)
            for (int j=0; j < N; j++)
                a[i][j] = scanner.nextInt() == 1;

        return solve(N, a);
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(run(scanner));
        }
        //Tests.run();
    }
}

Measured memory_bytes: 86336
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int H, W, h, w; cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0){
        Out("No");
        return 0;
    }

    int r = (H % h) * W + (W % w) * H - (H % h) * (W % w);
    int m = (H / h) * (W / w);
    int x = m / r + 1, y = -1 - x * (h * w - 1);
    mat a(H, vec(W, x));
    for(int i = h - 1; i < H; i += h) for(int j = w - 1; j < W; j += w) a[i][j] = y;
    Out("Yes");
    REP(i, H){
        REP(j, W) cout << a[i][j] << " ";
        cout << endl;
    } 

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for(int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if(m.find(tmp) == m.end()) {
      m[tmp] = 1;
    } else {
      m[tmp]++;
    }
  }
  int sum = 0;
  for(auto p : m) {
    int k = p.first;
    int n = p.second;
    if(k < n) {
      sum += n - k;
    } else if(n < k) {
      sum += n;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main(void)
{
    int m=0, n=0, i=0, j=0;
    int a=0;
    for (i = 0; i < 4; i++) {
        scanf("%d", &a);
        m = m + a;
    }
    n = m % 60;
    m = m / 60;
    printf("%d\n%d\n", m, n);
    return 0;
}

    

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  vector<vector<int>> G(n);
  for(int i = 0; i < n-1; i++){
    int u, v; cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  static int dp[(int)1e5+10][2];
  function< void(int,int,int,int) > dfs =
  [&](int u, int pre, int t, int d){
    dp[u][t] = d;
    for(int v : G[u]){
      if(v == pre) continue;
      dfs(v, u, t, d+1);
    }
    return;
  };
  dfs(0, -1, 0, 0);
  dfs(n-1, -1, 1, 0);

  int f = 0, s = 0;
  for(int i = 0; i < n; i++){
    f += dp[i][0] <= dp[i][1];
    s += dp[i][0] > dp[i][1];
  }
  cout << (f > s ? "Fennec" : "Snuke") << endl;

  return 0;
}


Measured memory_bytes: 18176
#include<stdio.h>
int main(){
    int a, b, ret;
    char op[2];
    scanf("%d %c %d", &a, &op, &b);
    if (op[0] == '+')
        ret = a + b;
    else
        ret = a - b;
    printf("%d\n", ret);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll a[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    ll t,cnt,cnt3=0,cnt5=0,cnt15=0,cnt25=0,cnt75=0;
    ll i;
    for(i=0;i<15;i++){
        t=a[i];
        cnt=0;
        while(t<=N){
            cnt+=N/t;
            t*=a[i];
        }
        if(cnt>=2)cnt3++;
        if(cnt>=4)cnt5++;
        if(cnt>=14)cnt15++;
        if(cnt>=24)cnt25++;
        if(cnt>=74)cnt75++;
    }
    ll ans=0;
    ans+=cnt5*(cnt5-1)*(cnt3-2)/2;
    ans+=cnt15*(cnt5-1);
    ans+=cnt25*(cnt3-1);
    ans+=cnt75;
    cout << ans;
    return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;

  if (n % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  string t1 = s.substr(0, n / 2);
  string t2 = s.substr(n / 2, n / 2);
  string ans = t1 == t2 ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

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

int stoi(string s){
	int tmp=0;
	for(int i=0;i<s.size();i++){
		tmp=tmp*10+(s[i]-'0');
	}
	return tmp;
	return (tmp+1)/2;
}

int cnt;
vector<int>KO[5000];
vector<int>SO[5000];
int OYA[5000];
int SCO[5000];

void view(){
	for(int i=0;i<=cnt;i++){
		cout<<i<<"\t"<<OYA[i]<<"\t"<<SCO[i];
		for(int j=0;j<KO[i].size();j++)cout<<"\t"<<KO[i][j];
		cout<<endl;
	}
}

void reset(){
	for(int i=0;i<5000;i++){
		KO[i].clear();
		SO[i].clear();
		OYA[i]=-1;
		SCO[i]=-1;
	}
}

void cal(string s){
	int pos=-1;
	cnt=-1;
	for(int i=0;i<s.size();i++){
		if(s[i]=='['){
			cnt++;
			OYA[cnt]=pos;
			KO[pos].push_back(cnt);
			pos=cnt;
		}
		else if(s[i]==']'){
			if(SCO[pos]<0){
				SCO[pos]=0;
				sort(SO[pos].begin(),SO[pos].end());
				for(int j=0;j<(SO[pos].size()+1)/2;j++)SCO[pos]+=SO[pos][j];
			}
			if(pos!=0){
				SO[OYA[pos]].push_back(SCO[pos]);
			}
			pos=OYA[pos];
		}
		else{
			string tmp="";
			while(true){
				tmp+=s[i];
				if(s[i+1]==']')break;
				i++;
			}
			SCO[pos]=(stoi(tmp)+1)/2;
		}
	}
}

int dfs(int pos){
	if(SCO[pos]>0)return SCO[pos];
	vector<int>V;
	for(int i=0;i<KO[pos].size();i++){
		V.push_back(dfs(KO[pos][i]));
	}
	sort(V.begin(),V.end());
	int tmp=0;
	for(int i=0;i<(V.size()+1)/2;i++){
		tmp+=V[i];
	}
	return tmp;
}

int main(){
	int n;
	for(cin>>n;n--;){
		reset();
		string s;cin>>s;
		cal(s);
		cout<<SCO[0]<<endl;
		//view();
		//cout<<dfs(0)<<endl;
	}
	return 0;
}


Measured memory_bytes: 1784
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <iomanip>
#include <utility>

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int n, m;
string ans[100001];
vector <pair <int, int> > pref[100001];

string chislo(int x)
{
	string s = "";
	while (x > 0)
	{
		s += (x % 10) + '0';
		x /= 10;
	}
	while (s.size() < 6)
		s += '0';
	reverse(s.begin(), s.end());
	return s;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("arithm.in", "r", stdin);
	//freopen("arithm.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	//pref.resize(m + 1);
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		pref[x].pb(mp(y, i));
	}
	for (int i = 1; i <= n; i++)
	{
		sort(pref[i].begin(), pref[i].end());
		string s = chislo(i);
		for (int j = 0; j < pref[i].size(); j++)
			ans[pref[i][j].second] = s + chislo(j + 1);
	}
	for (int i = 0; i < m; i++)
		cout << ans[i] << '\n';
	return 0;
}

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

using namespace std;

int main(){
  double r,are,circ;
  cin>>r;
  are=r*r*3.141592653589;
  circ=r*2.0*3.141592653589;
  printf("%f %f\n",are,circ);
  return 0;
}

Measured memory_bytes: 3212