akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const ll mod=1e9+7;
const ll sze=1e5+2;
int main(){
 ll N,K,R,S,P;
 sl(N);sl(K);
 //RSP
 sl(R);sl(S);sl(P);
 string str;
 cin>>str;
 ll i=0;
 while(str[i]!='\0'){
	 if(str[i]=='r')str[i]='p';
	 else if(str[i]=='p')str[i]='s';
	 else str[i]='r';
	 i++;
	 
 }
 i=0;
 for(i=K;i<N;i++){
	 if(str[i]==str[i-K])str[i]='x';
 }
 i=0;
 ll sum=0;
 while(str[i]!='\0'){
         if(str[i]!='x'){
		 if(str[i]=='s')sum+=S;
		 else if(str[i]=='p')sum+=P;
		 else if(str[i]=='r')sum+=R;
	 }
	 i++;
	 
 }
 cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static class UnionFind {
        int[] parent;
        int[] rank;
        int[] elmsize;

        UnionFind(int size) {
            parent = new int[size];
            rank = new int[size];
            elmsize = new int[size];

            for(int i = 0; i < size; i++) makeSet(i);
        }

        void makeSet(int x) {
            parent[x] = x;
            rank[x] = 0;
            elmsize[x] = 1;
        }

        void unite(int x, int y) {
            int xRoot = root(x);
            int yRoot = root(y);

            if(rank[xRoot] > rank[yRoot]) {
                parent[yRoot] = xRoot;
                elmsize[xRoot] += elmsize[yRoot];
            } else if(rank[xRoot] < rank[yRoot]) {
                parent[xRoot] = yRoot;
                elmsize[yRoot] += elmsize[xRoot];
            } else if(xRoot != yRoot) {
                parent[yRoot] = xRoot;
                rank[xRoot]++;
                elmsize[xRoot] += elmsize[yRoot];
            }
        }

        int root(int x) {
            if(x != parent[x]) {
                parent[x] = root(parent[x]);
            }
            return parent[x];
        }

        boolean same(int x, int y) {
            return root(x) == root(y);
        }

        int size(int x) {
            return elmsize[root(x)];
        }
    }

    static class UnionFindAlt {
        int[] d;
        UnionFindAlt(int n) {
            d = new int[n];
            Arrays.fill(d, -1);
        }
        int find(int x) {
            if(d[x] < 0) return x;
            return  d[x] = find(d[x]);
        }
        boolean unite(int x, int y) {
            x = find(x); y = find(y);
            if(x == y) return false;
            if(d[x] > d[y]) {
                int tmp = x; x = y; y = tmp;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }
        boolean same(int x, int y) { return find(x) == find(y); }
        int size(int x) { return -d[find(x)]; }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt();
        UnionFindAlt uf = new UnionFindAlt(n);
        int[] deg = new int[n];
        for(int i = 0; i < m; i++) {
            int a, b;
            a = Integer.parseInt(sc.next()); b = Integer.parseInt(sc.next());
            --a; --b;
            deg[a]++; deg[b]++;
            uf.unite(a, b);
        }
        int[][] to = new int[k][2];
        for(int i = 0; i < k; i++) {
            to[i][0] = Integer.parseInt(sc.next()) -1;
            to[i][1] = Integer.parseInt(sc.next()) -1;
        }
        int[] ans = new int[n];
        for(int i = 0; i < n ; i++) {
            ans[i] = uf.size(i) - 1 - deg[i];
        }
        for(int i = 0; i < k; i++) {
            if(uf.same(to[i][0], to[i][1])) {
                ans[to[i][0]]--;
                ans[to[i][1]]--;
            }
        }
        for(int i = 0; i < n; i++) {
            System.out.printf("%d%c", ans[i], i==n-1?'\n':' ');
        }
    }
}

Measured memory_bytes: 104212
#include <iostream>

using namespace std;

int tri(int a, int b, int c) {
	if (a > b && a > c)
		return (b*b+c*c == a*a);
	if (b > c)
		return (a*a+c*c == b*b);
	return (a*a+b*b == c*c);
}

int main(void) {
	int n;
	int a, b, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		cout << (tri(a,b,c) ? "YES" : "NO") << endl;
	}
	return 0;
}

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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int a[7];
int x;
int n=6;
int d[100001];
int ok;
int main()
{
    a[1]=100;
    a[2]=101;
    a[3]=102;
    a[4]=103;
    a[5]=104;
    a[6]=105;
    cin>>x;
    d[0]=1;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=x;j++)
        {
            if(j>=a[i])
                d[j]=max(d[j],d[j-a[i]]);
        }
    }
    cin>>x;
    ok=d[x];
    if(ok)
    {
        cout<<1;
    }
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7


col=list(set(LI()))
print(len(col))

Measured memory_bytes: 3316
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
        except EOFError:
            break
    return N

def main():
    X1, Y1, X2, Y2 = [float(x) for x in input().split()]
    
    dx = (X1 - X2)**2
    dy = (Y1 - Y2)**2

    print(math.sqrt(dx+dy))

if __name__ == '__main__':
    main()




Measured memory_bytes: 5676
def test():
    n,t = map(int,input().split())
    c = []
    d = []
    for i in range(n):
        a,b = map(int,input().split())
        c.append(a)
        d.append(b)

    e = {i:j for i,j in zip(c,d)}
    d = [i for i in e if e[i] <= t]

    if len(d) == 0:
        print("TLE")
    else:
        print(min(d))


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    string s;
    cin >> s;
    int nin = 1e9;
    string ans;
    for (int i = 0; i < s.size() - 2; i++) {
        string t = s.substr(i, 3);
        if (abs(stoi(t) - 753) < nin) {
            nin = abs(stoi(t) - 753);
            ans = t;
        }
    }
    cout << nin << endl;
}

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

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

	vector<vector<int> > f(n, vector<int>(10));

	rep(i, n){
		rep(j, 10){
			cin >> f.at(i).at(j);
		}
	}

	vector<vector<int> > p(n, vector<int>(11));

	rep(i, n){
		rep(j, 11){
			cin >> p.at(i).at(j);
		}
	}

	int max = INT_MIN;

	// cout << p[0][1] << endl;
	for(int bit = 0; bit < (1<<10); ++bit){	
		int dab[n] = {0};
		bool changed = false;
		rep(i, n){
			rep(j, 10){
				if(bit&(1<<j) && f[i][j]==1){
					dab[i]++;
					changed = true;
				}
			}
		}
		int sum=0;
		rep(i, n){
			sum += p[i][dab[i]];
		}

		if(sum > max && changed == true) {
			// cout << "changed " <<dab[0] << "sum " << sum << endl;
			// cout << "1:" << dab[0] << " 2:" << dab[1] << endl;
			// cout << p[0][1] << endl;
			max = sum;
		}else{
		
		}
	}

	cout << max << endl;
}



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

#define MAX 100000
int nArr[MAX];

void Out(int k, int nIn)
{
	if (k == 0)
	{
		cout << '[' << nArr[0] << ']';

	}
	else
	{
		cout << nArr[0];

	}
	for (int i = 1; i < nIn; i++)
	{
		if (k == i)
		{
			cout << ' ' << '[' << nArr[i] << ']';

		}
		else
		{
			cout << ' ' << nArr[i];

		}
	}
	cout << endl;
}

int Partition(int p, int r)
{
	int x = nArr[r];
	int i = p - 1;
	for (int j = p; j <= r - 1; ++j)
	{
		if (nArr[j] <= x)
		{
			i += 1;
			swap(nArr[j], nArr[i]);
		}
	}
	swap(nArr[i + 1], nArr[r]);
	return i + 1;
}

int main()
{
	int nIn;
	cin >> nIn;
	for (int i = 0; i < nIn; ++i)
	{
		cin >> nArr[i];
	}
	Out(Partition(0, nIn - 1), nIn);

	//system("pause");
	return 0;

}


Measured memory_bytes: 3396
using System;
using System.Collections.Generic;
using System.Linq;

namespace code_festival_2017_qualb_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int m = int.Parse(Console.ReadLine());
            int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Dictionary<int,int> problems = new Dictionary<int,int>();
            for (int i = 0; i < n; i++)
            {
                if (!problems.ContainsKey(x[i])) problems.Add(x[i],0);
                problems[x[i]]++;
            }
            bool ret = true;
            for (int i = 0; i < m; i++)
            {
                if (problems.ContainsKey(y[i]))
                {
                    problems[y[i]]--;
                    if (problems[y[i]] < 0) ret = false;
                }
                else ret = false;
            }
            Console.WriteLine(ret ? "YES" : "NO");
        }
    }
}

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

int N;
string S;
vector<int> D;

int solve(){
    int ans = N;
    for(auto i=1;i<N;++i){
    	if(S[i]==S[i-1]) --ans;
    }
    return ans;
}

int main(){
    while(cin>>N>>S && N>0){
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=998244353;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    compute();
    // Sieve();
    
    ll tests=1;
   
    // cin>>tests;
    while(tests--)
    {
      ll n,i,j,k,m;
      cin>>n>>m>>k;
      ll ans=0;
      // cout<<C(2,1)<<"\n";
      for(i=0;i<=k;i++)
      {
        ans+=(((m*C(n-1,i))%mod)*(expo(m-1,n-i-1,mod))%mod);
        ans%=mod;
      }
      cout<<ans;
    }
    return 0;
   }

Measured memory_bytes: 17392
#include <stdio.h>
#include <stdbool.h>

int main(void){
	int n,m,X,Y;
	scanf("%d %d %d %d",&n,&m,&X,&Y);
	int x[n],y[m];
	int i,xmax=-100,ymin=100;
	for(i=0; i<n; i++){
		scanf("%d",&x[i]);
		if (x[i] > xmax) xmax=x[i];

	}
	for(i=0; i<m; i++){
		scanf("%d",&y[i]);
		if(y[i] < ymin) ymin=y[i];
	}
	int flag=0;
	for(i=X+1;i<Y;i++){
		if(i>xmax && i<=ymin){
			flag++;
			break;
		}
	}
	if(flag!=0) printf("No War");
	else printf("War");
	return 0;
}

Measured memory_bytes: 128
a,b = input().split()
c = 0
n = 0
flag = False
c = a*(1**len(b))+b
for i in range(100000):
  n += 1
  if int(n*n) == int(c):
    flag = True
    break
if flag == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, h, a = 0;
    cin >> n >> h;
    vector<int> b(n);
    repi(i, b){
        int ta;
        cin >> ta >> *i;
        a = max(ta, a);
    }
    int gt = INT_MAX;
    int ans = 0;
    sort(b.begin(), b.end());
    for(int i = n - 1; i >= 0; --i){
        if(h <= 0 || b[i] < a){
            break;
        }
        h -= b[i];
        ++ans;
    }
    if(h > 0)
        ans += (h - 1) / a + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

public class Program
{
	public static void Main(string[] args)
	{
		while (true)
		{
			string strOfn = Console.ReadLine();
			int n = int.Parse(strOfn);
			if (n == 0)
			{
				break;
			}
			double[] doubleArray = new double[3];
			doubleArray = Console.ReadLine().Trim().Split(' ').Select(x => double.Parse(x)).ToArray();
			double sum = 0.0;
			for (int i = 0; i < doubleArray.Length; i++)
			{
				sum += doubleArray[i];
			}
			double avg = sum / doubleArray.Length;
			double siguma = 0.0;
			for (int i = 0; i < doubleArray.Length; i++)
			{
				siguma += Math.Pow(doubleArray[i]-avg, 2);
			}
			double ans = Math.Sqrt(siguma / n);
			Console.WriteLine(ans);
		}
		//var ss = new StreamScanner();
		//---------------------------------
		//????????????int, double, string?????????????????£????????????


		//int x = ss.Next<int>();
		//double d = ss.Next<double>();
		//string s = ss.Next<string>();

		//?????°???????????????????????¨?????????????????????????????????????????????????´???????
		//int[] array = ss.Next<int>(10);
		//---------------------------------

	}
}
public class StreamScanner
{
	private readonly char[] _c = { ' ' };
	private int _index = -1;
	private string[] _input = new string[0];
	private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

	public T Next<T>()
	{
		if (_index == _input.Length - 1)
		{
			_index = -1;
			while (true)
			{
				string rl = _sr.ReadLine();
				if (rl == null)
				{
					if (typeof(T).IsClass) return default(T);
					return (T)typeof(T).GetField("MinValue").GetValue(null);
				}
				if (rl != "")
				{
					_input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
					break;
				}
			}
		}
		return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
	}

	public T[] Next<T>(int x)
	{
		var ret = new T[x];
		for (var i = 0; i < x; ++i) ret[i] = Next<T>();
		return ret;
	}

	public T[][] Next<T>(int x, int y)
	{
		var ret = new T[y][];
		for (var i = 0; i < y; ++i) ret[i] = Next<T>(x);
		return ret;
	}
}

Measured memory_bytes: 9924
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

char s[105];
int main(){
    char s[105];
    scanf("%s",s);
    s[5] = s[13] = ' ';
    printf("%s\n",s);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

vector<lli> fac, invfac;

lli power(lli x, lli y) {
    // log y complexity
    // return (x^y) % MOD
    lli ans = 1;
    x = x % MOD;
    while (y > 0) {
        if (y & 1) {
            ans *= x;
            ans %= MOD;
        }
        y = y >> 1;
        x = (x * x) % MOD;
    }
    return ans;
}

lli inverseMod(lli a) {
    return power(a, MOD - 2);
}

lli nCr(lli n, lli r) {
    if (r > n) {
        return 0;
    }
    lli ans = fac[n];
    lli val = (invfac[n - r] * invfac[r]) % MOD;
    ans *= val;
    ans %= MOD;
    return ans;
}

void solve() {
    fac.resize(2005, 1);
    invfac.resize(2005, 1);

    for (lli i = 1; i < 2002; i++) {
        fac[i] = (fac[i - 1] * i) % MOD;
        invfac[i] = inverseMod(fac[i]);
    }

    lli n, a, s;
    cin >> s;

    if (s <= 2) {
        cout << "0" << endl;
        return;
    }

    n = s / 3;
    lli ans = 0;

    for (lli i = 1; i <= n; i++) {
        lli val = s - i * 3;
        lli p = nCr(val + i - 1, val);
        ans += p;
        ans %= MOD;
    }

    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 3712
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> red, green, blue;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            red.emplace_back(i);
        else if (s[i] == 'G')
            green.emplace_back(i);
        else
            blue.emplace_back(i);
    }
    vector<pair<int, int>> brown, syan, purple, brown2, syan2, purple2;
    for (int i = 0; i < red.size(); i++)
    {
        for (int j = 0; j < green.size(); j++)
        {
            if (red[i] < green[j])
                brown.emplace_back(make_pair(red[i], green[j]));
            else
                brown2.emplace_back(make_pair(green[j], red[i]));
        }
    }
    for (int i = 0; i < green.size(); i++)
    {
        for (int j = 0; j < blue.size(); j++)
        {
            if (green[i] < blue[j])
                syan.emplace_back(make_pair(green[i], blue[j]));
            else
                syan.emplace_back(blue[j], green[i]);
        }
    }
    for (int i = 0; i < blue.size(); i++)
    {
        for (int j = 0; j < red.size(); j++)
        {
            if (blue[i] < red[j])
                purple.emplace_back(make_pair(blue[i], red[j]));
            else
                purple.emplace_back(make_pair(red[j], blue[i]));
        }
    }
    ll cnt = 0;
    for (int i = 0; i < brown.size(); i++)
    {
        for (int j = 0; j < blue.size(); j++)
        {
            if (brown[i].second - brown[i].first != blue[j] - brown[i].second && brown[i].second < blue[j])
                cnt++;
        }
    }
    for (int i = 0; i < syan.size(); i++)
    {
        for (int j = 0; j < red.size(); j++)
        {
            if (syan[i].second - syan[i].first != red[j] - syan[i].second && syan[i].second < red[j])
            {
                cnt++;
            }
        }
    }
    for (int i = 0; i < purple.size(); i++)
    {
        for (int j = 0; j < green.size(); j++)
        {
            if (purple[i].second - purple[i].first != green[j] - purple[i].second && purple[i].second < green[j])
                cnt++;
        }
    }

    for (int i = 0; i < brown2.size(); i++)
    {
        for (int j = 0; j < blue.size(); j++)
        {
            if (brown2[i].second - brown2[i].first != blue[j] - brown2[i].second && brown2[i].second < blue[j])
                cnt++;
        }
    }
    for (int i = 0; i < syan2.size(); i++)
    {
        for (int j = 0; j < red.size(); j++)
        {
            if (syan2[i].second - syan2[i].first != red[j] - syan2[i].second && syan2[i].second < red[j])
            {
                cnt++;
            }
        }
    }
    for (int i = 0; i < purple2.size(); i++)
    {
        for (int j = 0; j < green.size(); j++)
        {
            if (purple2[i].second - purple2[i].first != green[j] - purple2[i].second && purple2[i].second < green[j])
                cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 55916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
int main()
{
    fastio;
    //fopen();
    int h,w,n,x,y;
    cin>>h>>w>>n>>x>>y;
    string s,t;
    cin>>s>>t;
    int  tl=0,tr=0,tu=0,td=0;
    int sr=0,sl=0,su=0,sd=0;
    rep(i,n)
    {
        if(s[i]=='L')tl+=1;
        else if(s[i]=='R')tr+=1;
        else if(s[i]=='U')tu+=1;
        else td+=1;
        if(y-tl+sr<1 || y+tr-sl>w || x-tu+sd<1 || x+td-su>h)cout<<"NO",exit(0);
        if(t[i]=='R' && y-tl+sr<w)sr++;
        else if(t[i]=='L' && y+tr-sl>1)sl++;
        else if(t[i]=='D' && x-tu+sd<h)sd++;
        else if(t[i]=='U' && x+td-su>1)su++;
    }
    cout<<"YES";
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,X;
  int count = 0, keep = 0;
  int i,j,k,price = 0;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
    // 500 coin 0 ~ A
    for (i = 0; i <= A; i++){     
      // 100 coin 0 ~ B
      for (j = 0; j <= B; j++){
        // 50  coin 0 ~ C
        for (k = 0; k <= C; k++){
          price = 500 * i + 100 * j + 50 * k;
          if(price == X) count++;
        }
      }
    }
  cout << count << endl;
}

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

int main(int argc, char const *argv[])
{
    long long k, a, b; cin >> k >> a >> b;
    if (a>=b) cout << k+1 << endl;
    else {
        long long c=1LL, z;
        if(b-a>2LL) {
            if(k>a+1LL) {
                k-=a+1LL;
                c=b;
            }
        }
        if(b-a>3) {
            z = max(0LL,a-c);
            while(k>=2LL+z) {
                if(z==0LL) {
                    c+=(b-a)*(k/2LL);
                    k=k%2LL;
                }
                else {
                    k-=2LL+z;
                    c+=b-(a-z);
                }
                z = max(0LL,a-c);
            }
        }
        c+=k;
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int n; cin >> n;
    int A[110];
    rep(i,n){
        cin >> A[i];
    }
    int ans = 0;
    rep(i,n){
        if(i % 2 != 0) continue;

        if(A[i] % 2 != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
  
  // 標準入力  
  ll  N,K;
  cin >> N >> K;
  
  // 最小値が0の場合
  if(N%K==0) {
    cout << 0 << endl;
    return 0;
  }
  
  // 最小値が0以外の場合
  ll output = N%K;
  output = min(abs(output-K),output);
  
  // 標準出力
  cout << output << endl;
  
  return 0;

}

Measured memory_bytes: 256
a, b = map(int, input().split())
result_a = a + a - 1
result_b = b + b - 1
result_a_b = a + b
if (result_a_b >= result_a) and (result_a_b >= result_b):
    print(result_a_b)
elif (result_a >= result_b) and (result_a >= result_a_b):
    print(result_a)
elif (result_b >= result_a) and (result_b >= result_a_b):
    print(result_b)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    vector<int> conf;
    for (int i = 1; i <= 100; ++i) {
        if (a % i == 0 && b % i == 0) {
            conf.emplace_back(i);
        }
    }

    cout << conf[conf.size()-k] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int N, M, Q, L[200009], R[200009], X[509][509] , C[509][509] ;
int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; ++i) {
		cin >> L[i] >> R[i];
		X[L[i]][R[i]]++;
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			C[i][j] = C[i][j - 1] + X[i][j];
		}
	}
	for (int i = 1; i <= Q; ++i) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; ++j) {
			sum += C[j][q] - C[j][p - 1];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4480
import java.util.*;
 
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    if(
      s.charAt(0)==t.charAt(2)&&
      s.charAt(1)==t.charAt(1)&&
      s.charAt(2)==t.charAt(0)
    ){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>k) cout<<k<<endl;
  else if(a+b>k) cout<<a<<endl;
  else  {
    ll d=k-a-b;
    cout<<a-d<<endl;
  }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

// string s;
// int n;
const int mxn = 1e5+99;
ll dp[mxn][13];
const int modi = 1e9+7;

ll binpow(int a,int b,int p){
	ll res = 1;
	while(b>0){
		if(b&1)
			res = res*a%p;
		a = a*a%p;
		b>>=1;
	}
	return res;
}

void solve(){
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int suff[n+1];
	suff[n] = 0;
	for(int i =n-1;~i;i--){
		suff[i] = (suff[i+1] + (s[i]-'0')*binpow(10,n-i-1,p))%p;
		// cout << suff[i] << endl;
	}
	ll ans = 0;
	if(p==2 || p==5){
		for(int i =0;i<n;i++){
			if((s[i]-'0')%p==0){
				ans+=(i+1)*1ll;
			}
		}
	}
	else{
		map<int,ll> cnt;
		cnt[0]++;
		for(int i =n-1;~i;i--){
			ans+=cnt[suff[i]];
			cnt[suff[i]]++;
			// cout << ans << endl;/
		}
	}
	cout << ans << endl;
}

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

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 4904
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N;
int* marked_boss,*height;

struct Info{
	bool isMarked;
	vector<int> Children;
};

Info*info;

void update(int new_marked_boss_id){

	int current_boss_id = marked_boss[new_marked_boss_id],id;
	marked_boss[new_marked_boss_id] = new_marked_boss_id;
	queue<int> Q;

	for(int i = 0; i < info[new_marked_boss_id].Children.size();i++){

		if(marked_boss[info[new_marked_boss_id].Children[i]] == current_boss_id){
			marked_boss[info[new_marked_boss_id].Children[i]] = new_marked_boss_id;
			Q.push(info[new_marked_boss_id].Children[i]);
		}
	}

	while(!Q.empty()){
		id = Q.front();
		Q.pop();

		for(int i = 0; i < info[id].Children.size();i++){
			if(marked_boss[info[id].Children[i]] == current_boss_id){
				marked_boss[info[id].Children[i]] = new_marked_boss_id;
				Q.push(info[id].Children[i]);
			}
		}
	}
}

int main(){

	int Q,value;
	char buf[2];
	ll ans;

	marked_boss = new int[100001];
	height = new int[100001];
	info = (Info*)malloc(sizeof(Info)*(100001));

	while(true){
		scanf("%d %d",&N,&Q);
		if(N == 0 && Q == 0)break;

		for(int i = 1; i <= N; i++){
			marked_boss[i] = 1;
			height[i] = 0;
			info[i].isMarked = false;
			info[i].Children.clear();
		}

		info[1].isMarked = true;

		for(int i = 2; i <= N; i++){
			scanf("%d",&value);
			info[value].Children.push_back(i);
		}

		ans = 0;

		for(int i = 0; i < Q; i++){

			scanf("%s %d",buf,&value);

			if(buf[0] == 'Q'){ //?????¨???
				ans += marked_boss[value];
			}else{ //???????????????
				info[value].isMarked = true;
				update(value);
			}
		}

		printf("%lld\n",ans);
	}

	return 0;
}

Measured memory_bytes: 10228
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s;
	int k;
	k=s.size();	
	for(int i=0;i<=k-1;i=i+2)
	{
		t=t+s[i];
	}
	cout<<t;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename M>
class Enumeration{
private:
  static vector<M> fact,finv,invs;
public:
  static void init(Int n){
    n=min<decltype(M::mod)>(n,M::mod-1);

    Int m=fact.size();
    if(n<m) return;

    fact.resize(n+1,1);
    finv.resize(n+1,1);
    invs.resize(n+1,1);

    if(m==0) m=1;
    for(Int i=m;i<=n;i++) fact[i]=fact[i-1]*M(i);
    finv[n]=M(1)/fact[n];
    for(Int i=n;i>=m;i--) finv[i-1]=finv[i]*M(i);
    for(Int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1];
  }

  static M Fact(Int n){
    init(n);
    return fact[n];
  }
  static M Finv(Int n){
    init(n);
    return finv[n];
  }
  static M Invs(Int n){
    init(n);
    return invs[n];
  }

  static M C(Int n,Int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k]*finv[k];
  }
};
template<typename M>
vector<M> Enumeration<M>::fact = vector<M>();
template<typename M>
vector<M> Enumeration<M>::finv = vector<M>();
template<typename M>
vector<M> Enumeration<M>::invs = vector<M>();

//INSERT ABOVE HERE
signed main(){
  using M = Mint<Int, 998244353>;
  using E = Enumeration<M>;
  Int m,n,k;
  cin>>m>>n>>k;

  M ans=M(m).pow(n);
  vector<M> dp(k,0);
  M res=1;
  for(Int i=1;i<k;i++){
    dp[i]=M(i).pow(n);
    for(Int j=1;j<i;j++)
      dp[i]-=E::C(i,j)*dp[j];
    res*=M(m+1-i);
    res/=M(i);
    ans-=res*dp[i];
  }
  cout<<ans<<endl;
  return 0;
}



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

long long pow9[4];

inline long long NchooseK(int N, int K) {
	long long res = 1;
	for (int i = 1; i <= K; i++, N--) {
		res = res * N / i;
	}
	return res;
}

int main() {
	pow9[0] = 1;
	for (int i = 1; i < 4; i++) {
		pow9[i] = pow9[i - 1] * 9;
	}
	string N;
	int K;
	cin >> N >> K;
	long long res = 0;
	for (int index = 0; K <= N.size() - index && index <= N.size(); index++) {
		if (index == N.size()) {
			if (K == 0) res++;
			break;
		}
		if (N[index] == '0') continue;
		int remain = N.size() - index - 1;
		if (remain >= K) {
			res += NchooseK(remain, K) * pow9[K];
		}
		if (remain >= K - 1) {
			int size = N[index] - '0' - 1;
			res += NchooseK(remain, K - 1) * pow9[K - 1] * size;
		}
		K--;
	}
	cout << res << endl;
}


Measured memory_bytes: 764
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include <utility>

template <class T, class U> constexpr T power(T x, U exp) {
  T ret = static_cast<T>(1);
  while (exp) {
    if (exp % static_cast<U>(2) == static_cast<U>(1))
      ret *= x;
    exp /= static_cast<U>(2);
    x *= x;
  }
  return ::std::move(ret);
}

#include <iostream>
#include <vector>

int main() {
  using mint = modint<1000000007>;

  int b, w;
  std::cin >> b >> w;
  int n = b + w;

  std::vector<mint> fact(n);
  fact[0] = 1;
  for (int i = 1; i < n; ++i) {
    fact[i] = fact[i - 1] * i;
  }
  const auto comb = [&fact](int n, int r) {
    return fact[n] / fact[r] / fact[n - r];
  };

  mint p = 0, q = 0;

  for (int i = 1; i <= n; ++i) {
    std::cout << ((mint(1) - p + q) / 2).value() << std::endl;

    if (i >= b) {
      p += comb(i - 1, b - 1) / power(mint(2), i);
    }
    if (i >= w) {
      q += comb(i - 1, w - 1) / power(mint(2), i);
    }
  }

  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(15);
    cout<<fixed;
    lli d=0ll,n=0ll,m=0ll;
    cin>>n>>m>>d;
    --m;
    if(d==0ll)
    	cout<<(long double)(m)/n;
    else
    	cout<<(long double)(2ll*m*(n-d))/(1ll*n*n);
    cout<<endl;
}

Measured memory_bytes: 3792
N = int(input())
a = list()
ans = 0
ptr = 0

for i in range(N):
    a.append(int(input()))

A = sorted(a)

while(ptr < N):
    cc = A[ptr]
    f = 0
    
    while(ptr < N and A[ptr] == cc):
        f += 1
        ptr += 1
        
    ans += f % 2

print(ans)


Measured memory_bytes: 8276
#C
import math
n = int(input())
sho_lst = []
for i in range(1,int(math.sqrt(n))+1):
    amari = n % i  
    if amari == 0:
        sho = n // i
        sho_lst.append(sho - 1 + i - 1)
        
print(min(sho_lst))

Measured memory_bytes: 3060
A, B, C = list(map(int, input().split()))
K = int(input())
count = 0
done = 0
while (count <= K) & (done == 0):
    if B <= A:
        B = 2 * B
        count += 1
    elif C <= B:
        C = 2 * C
        count += 1
    if (C > B) & (B > A) & (count <= K):
        print("Yes")
        done = 1
if done == 0:
    print("No")



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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 20;

int n, m;
string s;
long long dp[maxn][maxn], ans;

int main() {
	cin >> n >> s; m = n * 2;
	for (int t = 0; t < (1 << n); ++t) {
		string r, b;
		for (int i = 0; i < n; ++i) if((t >> i) & 1) r += s[i]; else b += s[i];
//		cout << r << '\t' << b << endl;
		memset(dp, 0, sizeof dp);
		dp[0][0] = 1;
		for (int i = 0; i <= r.size(); ++i) for (int j = 0; j <= b.size(); ++j) if(i || j) {
			char c = s[m - i - j];
			if(i && c == r[i - 1]) dp[i][j] += dp[i - 1][j];
			if(j && c == b[j - 1]) dp[i][j] += dp[i][j - 1];
//			cout << "\tdp[" << i << "][" << j << "] = " << dp[i][j] << endl;
		}
		ans += dp[r.size()][b.size()];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>>g(n);
    vector<vector<int>>a(n,vector<int>(n));
    rep(i,n){
        string s;
        cin >> s;
        rep(j,n){
            if(s[j] == '1'){
                g[i].push_back(i);
                g[j].push_back(i);
                a[i][j] = a[j][i] = 1;
            }
        }
    }
    int ans = -1;
    rep(s,n){
        queue<int>q;
        q.push(s);
        vector<int> dist(n, -1);
        dist[s] = 0;
        vector<vector<int>>b(n);
        while(q.size()){
            int x = q.front();
            q.pop();
            for(int v : g[x]){
                if(dist[v] == -1){
                    dist[v] = dist[x] + 1;
                    q.push(v);
                }
            }
        }
        bool f = true;
        rep(i,n){
            rep(j,n){
                if(a[i][j]){
                    if(dist[i] + 1 == dist[j] or dist[j] + 1 == dist[i])continue;
                    f = false;
                }
            }
        }
        if(f){
            ans = max(ans, *max_element(dist.begin(), dist.end()) + 1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int H, N;
        int[] A;
        Input(out H, out N);
        InputArray(out A);
        int sum = 0;
        for(int i = 0; i < N; i++) {
            sum += A[i];
        }
        if(H <= sum) {
            Console.WriteLine("Yes");
        } else {
            Console.WriteLine("No");
        }
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

Measured memory_bytes: 25308