akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
typedef pair<ll,ll> P;
#define boost ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    ll i,n=s1.size(),m=s2.size(),j;
    ll DP[n+1][m+1];
    memset(DP,0,sizeof(DP));
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                DP[i][j]=DP[i-1][j-1]+1;
            }
            else
            DP[i][j]=max(DP[i-1][j],DP[i][j-1]);
        }
    }
    //now printing the DP string//
    string s;
    i=n,j=m;
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1])
        {s=s+s1[i-1];i--;j--;}
        else if(DP[i-1][j]>=DP[i][j-1])
        {i--;}
        else
        {j--;}
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
}


Measured memory_bytes: 70656
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  string S;
  cin >> S;
  int x[2];
  cin >> x[0] >> x[1];
  vector<int> V[2];
  bool isx = 0;
  int cnt = 0;
  bool isfirst = true;
  for (auto e : S) {
    if (e == 'F') cnt++;
    else {
      if (isfirst) {
        x[0] -= cnt;
        isfirst = false;
      } else if (cnt > 0) {
        V[isx].push_back(cnt);          
      }
      cnt = 0;
      isx = !isx;
    }
  }
  if (isfirst) {
    x[0] -= cnt;
    isfirst = false;
  } else if (cnt > 0) {
    V[isx].push_back(cnt);
  }
  for (auto k = 0; k < 2; ++k) {
    int sum = 0;
    for (auto e : V[k]) {
      sum += e;
    }
    if ((x[k] + sum) %2 != 0) {
      cout << "No" << endl;
      return 0;
    }
    int mokuhyo = (x[k] + sum)/2;
    if (mokuhyo < 0 || mokuhyo > sum) {
      cout << "No" << endl;
      return 0;
    }
    bool dp[10000];
    fill(dp, dp+10000, false);
    dp[0] = true;
    for (auto e : V[k]) {
      for (auto i = 9999; i >= 0; --i) {
        if (dp[i] && i + e < 10000) {
          dp[i+e] = true;
        }
      }
    }
    if (!dp[mokuhyo]) {
      cout << "No" << endl;
      return 0;      
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#define MOD 1000000007
#define PI 3.14159265
#define seive_len 1

typedef long long int lli;

int *array;
int seive[seive_len];

long long int min(long long int a, long long int b) {
    return a<b?a:b;
}

long long int max(long long int a, long long int b) {
    return a>b?a:b;
}

int compare(const void* a, const void* b) {
    return *(int*)a-*(int*)b;
}

int cmp(const void *a, const void *b){
    int ia = *(int *)a;
    int ib = *(int *)b;
    return array[ia] < array[ib] ? -1 : array[ia] > array[ib];
}

long double abs1(long double n) {
    if(n < 0)
        return n*(-1.0);
    return n*1.0;
}

void swap(int *a, int *b) {
    *a = (*a)^(*b);
    *b = (*a)^(*b);
    *a = (*a)^(*b);
}

int binSearch(int a[], int x, int l, int r) {
    if(r >= l) {
        int mid = l + ((r-l)>>1);
        if(a[mid] == x)
            return mid;
        if(a[mid] > x) {
            return binSearch(a, x, l, mid-1);
        }
        else if(a[mid] < x) {
            return binSearch(a, x, mid+1, r);
        }
    }
    return -1;
}

void makeSeive() {
    int i;
	seive[1] = 1;
    for(i=2;i<seive_len;i++) {
        if(seive[i] == 0) {
            long long int temp=(long long int)i*i;
            while(temp <= seive_len-1) {
                seive[temp] = 1;
                temp += i;
            }
        }
    }
}

int isPrime(int n) {
    int i;
    for(i=2;i*i<=n;i++)  {
        if(n%i == 0)
            return 0;
    }
    return 1;
}

void getInput(lli a[], lli n) {
    for(lli i=0;i<n;i++)
        scanf("%lld", &a[i]);
}

int titleToNumber(char* s)
{
    int sum = 0;
    while(*s) sum = 26*sum+(*(s++)-'A'+1);
    return sum;
}

void testCase() {
    lli n, i, k=0;
    char res[100000];
    scanf("%lld", &n);
    // lli a[n];
    while(n) {
        int x = n%26;
        if(x == 0) {
            res[k++] = 'z';
            n--;
        }
        else
            res[k++] = x+96;
        n /= 26;
    }
    // printf("%d ", k);
    for(int j=k-1;j>=0;j--)
        printf("%c", res[j]);
}

int main() {
    int t=1;
    // scanf("%d", &t);
    // makeSeive();
    while(t--) {
        testCase();
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1668
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)


Measured memory_bytes: 9040
#include<iostream>
#include<stdio.h>//printf("%.15f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字)
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;
	
	int n, a;
	cin >> n >> a;

	cout << n * n - a << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
H,W = map(int,input().split())

s = [list(input()) for x in range(H)]

flg = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            #上
            if 0 < i:
                if s[i-1][j] == '#':
                    flg = False
            #左
            if 0 < j:
                if s[i][j-1] == '#':
                    flg = False
            #右
            if j < W-1:
                if s[i][j+1] == '#':
                    flg = False
            #下
            if i < H-1:
                if s[i+1][j] == '#':
                    flg = False
            if flg:
                print('No')
                exit()
            flg = True
print('Yes')


Measured memory_bytes: 3064
import sys
import json
import itertools

INFINITY = 100000000

def parse_data(input_string):
    INF = INFINITY

    first_nl = input_string.index('\n')
    n = int(input_string[:first_nl])
    fav_pattern = [int(s) * INF for s in input_string[-n - 1:-1]]

    edges = json.loads("[" + input_string[first_nl + 1:-n - 2].replace(" ", ",").replace("\n", ",") + "]")
    graph = [[] for _ in range(n)]
    graph[0].append(None)
    for i in range(0, (n - 1) * 2, 2):
        a = edges[i] - 1
        b = edges[i + 1] - 1
        graph[a].append(b)
        graph[b].append(a)
    return (n, fav_pattern, graph)

def solve():
    INF = INFINITY

    n, fav_count, graph = parse_data(sys.stdin.read())
    height1 = [0] * n
    height2 = [0] * n
    dfs_order = []

    stack = [None, 0, 0]
    while True:
        node = stack[-1]
        index = stack[-2]
        if index < len(graph[node]):
            dtr = graph[node][index]
            stack[-2] += 1
            if dtr != stack[-3]:
                stack.extend((0, dtr))
                dfs_order.append(dtr)
            else:
                graph[node][0], graph[node][index] = dtr, graph[node][0]
        else:
            del stack[-2:]
            if len(stack) <= 1: break
            parent = stack[-1]
            dtr_height = height1[node] + 1
            if dtr_height >= height1[parent]:
                height1[parent], height2[parent] = dtr_height, height1[parent]
            elif dtr_height > height2[parent]:
                height2[parent] = dtr_height
            if fav_count[node] != 0:
                fav_count[parent] += 1

    answer = 0
    if fav_count[0] >= INF:
        lb = -1
    else:
        lb = min((height1[dtr] for dtr in graph[0][1:] if fav_count[dtr] != 0), default=INF)
    ub = height2[0]
    if ub > lb:
        answer += ub - lb
    for node in dfs_order:
        parent = graph[node][0]
        has_fav_below = (fav_count[node] != 0)
        has_fav_above = fav_count[parent] > has_fav_below
        fav_count[node] += has_fav_above
        node_height = height1[node]
        if node_height + 1 == height1[parent]:
            lb = height2[parent]
            if lb <= node_height and has_fav_above:
                answer += 1
            elif lb >= node_height and has_fav_below:
                answer += 1

            parent_height = lb + 1
            if parent_height >= node_height:
                height1[node], height2[node] = parent_height, node_height
            elif parent_height > height2[node]:
                height2[node] = parent_height
        else:
            answer += has_fav_below
            lb = height1[parent]
            height1[node], height2[node] = lb + 1, node_height
        if fav_count[node] >= INF:
            lb = -1
        else:
            if not has_fav_above: lb = INF
            for dtr in itertools.islice(graph[node], 1, None):
                if fav_count[dtr] != 0:
                    lb = min(height1[dtr], lb)
        ub = height2[node]
        if ub > lb:
            answer += ub - lb

    print(answer)

solve()


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using piii = pair<pii, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

ll combination[51][51];
void comb(int n){
	REP(i, n + 1){
		REP(j, n + 1){
			if(j == 0 || j == i) combination[i][j] = 1LL;
			else combination[i][j] = (combination[i - 1][j - 1] + combination[i - 1][j]);
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, a, b;
	 cin >> n >> a >> b;
	 comb(n);
	 vector<ll> c(n);
	 REP(i, n) cin >> c[i];
	 sort(ALL(c), greater<ll>());
	 double ave = accumulate(c.begin(), c.begin() + a, 0LL) / (double)a;
	 cout << fixed << ave << "\n";
	 map<ll, int> mpa, mpb;
	 REP(i, a){
		 mpa[c[i]]++;
		 mpb[c[i]]++;
	 }
	 for(int i = a; i < n; ++i){
		 mpb[c[i]]++;
	 }
	 ll lm = LLINF;
	 int ln, k = 0;
	 for(const auto &m : mpa){
		 k++;
		if(lm > m.first){
			lm = m.first;
			ln = m.second;
		}
	 }
	 ll ans = 0;
	 if(k == 1){
		 int ch = min(b, mpb[lm]);
		 for(int i = a; i <= ch; ++i){
			 ans += combination[mpb[lm]][i];
			 //cout << combination[mpb[lm]][i] << "\n";
		 }
	 }
	 else{
		 ans += combination[mpb[lm]][mpa[lm]];
	 }
	 cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
const int maxb = 62;
typedef long long ll;
ll a[maxn];
char s[maxn];
ll b[maxn];
void init()
{
	memset(b, 0, sizeof b);
}
ll insert(ll x)
{
	for(int i = maxb - 1; ~i; --i)
		if((x >> i) & 1)
		{
			if(!b[i])
			{
				b[i] = x;
				break;
			}
			else
				x ^= b[i];
		}
	return x;
}
int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		int n;
		scanf("%d", &n);
		for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
		scanf("%s", s + 1);
		init();
		int flag = 0;
		for(int i = n; i; --i)
			if(s[i] == '0')
				insert(a[i]);
			else if(insert(a[i]))
			{
				flag = 1;
				break;
			}
		cout << flag << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n;
  cin>>n;
  int t[n];
  int sum=0;
  rep(i,n){
    cin>>t[i];
    sum+=t[i];
  }
  int m;
  cin>>m;
  rep(i,m){
    int p,m;
    cin>>p>>m;
    cout<<sum+m-t[p-1]<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#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 pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  cin>>n;
  vector<int>a(n),d(n);
  for(int i=1;i<n;i++) {
    cin>>a[i];
    a[i]--;
  }
  for(int i=1;i<n;i++){
    d[a[i]]++;
  }
  rep(i,n)
    cout<<d[i]<<endl;
}

Measured memory_bytes: 4744
l = [int(c) for c in input().split()]
H = l[0]
W = l[1]
S = [input() for c in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            cnt = 0
            for k in range(3):
                for m in range(3):
                    if 0 <= i-1+k and i-1+k <= H-1 and 0 <= j-1+m and j-1+m <= W-1:
                        if S[i-1+k][j-1+m] == "#":
                            cnt+=1
            S[i]=S[i][:j]+str(cnt)+S[i][j+1:]
    print(S[i])

Measured memory_bytes: 9148
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < b){
			System.out.println("a < b");
		}else if(a > b){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
	}
}


Measured memory_bytes: 26228
#include<bits/stdc++.h>
using namespace std;
long f[88],n;
int main()
{
	cin>>n;
	f[0]=2;
	f[1]=1;
	for(int i=2;i<=n;i++)
	{
		f[i]=f[i-1]+f[i-2];
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 
int main(){
	//in_o();
 	int a,b,c,x;
 	cin>>a>>b>>c>>x;
 	int ans=0;
 	FOR(i,0,a+1){
 		FOR(j,0,b+1){
 			FOR(k,0,c+1){
 				int tmp=i*500+j*100+k*50;
 				if(tmp==x)	ans++;
 			}
 		}
 	}
 	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int A,B,M;
  cin >> A >> B >> M;
  vector<int> a(A),b(B),x(M),y(M),c(M);
  priority_queue<int,vector<int>,greater<int> > pq,pa,pb;
  for(int i=0;i<A;i++){
    cin >> a.at(i);
    pa.push(a.at(i));
  }
  for(int i=0;i<B;i++){
    cin >> b.at(i);
    pb.push(b.at(i));
  }
  for(int i=0;i<M;i++){
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    x.at(i)--;
    y.at(i)--;
    pq.push(a.at(x.at(i))+b.at(y.at(i))-c.at(i));
  }
  pq.push(pa.top()+pb.top());
  cout << pq.top() << endl;
  return 0;
}


Measured memory_bytes: 3704
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,l[101][101],m;
  fill(l[0],l[0]+101,0);
  while(cin >> n,n+1){
    for(int i = 1;i <= n;i++){
      cin >> m;
      if(m>1&&m!=7) l[i][0] = 1;
      else l[i][0] = 0;
      if(m<4&&m>0) l[i][1] = 0;
      else l[i][1] = 1;
      if(m%2==0&&m!=4) l[i][2] = 1;
      else l[i][2] = 0;
      if(m==1||m==4||m==7) l[i][3] = 0;
      else l[i][3] = 1;
      if(m==2) l[i][4] = 0;
      else l[i][4] = 1;
      if(m==5||m==6) l[i][5] = 0;
      else l[i][5] = 1;
      if(m==1||m==4) l[i][6] = 0;
      else l[i][6] = 1;
      for(int j = 0;j <= 6;j++){
	if(l[i][j] == l[i-1][j]) cout << 0;
	else cout << 1;
      }
      cout << endl;
    }
  }
  return (0);
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static int n[][];

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()){
		n = new int[12][12];
		int cou = 0;
		for (int i = 0; i < 12; i++) {
			String text = stdIn.next();
			for (int j = 0; j < 12; j++) {
				n[i][j] = Integer.parseInt(String.valueOf(text.charAt(j)));
			}
		}
		for (int i = 0; i < 12; i++) {
			for (int j = 0; j < 12; j++) {
				if (n[i][j] == 1) {
					cou++;
					Recursion(i, j);
				}
			}
		}
		System.out.println(cou);
	}}

	public static void Recursion(int Longitudinal, int Beside) {
		if (Longitudinal < 0)
			return;
		if (Longitudinal > 11)
			return;
		if (Beside < 0)
			return;
		if (Beside > 11)
			return;
		if (n[Longitudinal][Beside] == 0)
			return;
		n[Longitudinal][Beside] = 0;
		Recursion(Longitudinal + 1, Beside);
		Recursion(Longitudinal - 1, Beside);
		Recursion(Longitudinal, Beside + 1);
		Recursion(Longitudinal, Beside - 1);
	}

}

Measured memory_bytes: 26268
#include <iostream>
#include <math.h>

using namespace std;

typedef struct Point {
    double x;
    double y;
} POINT;

double area(Point l, Point m, Point n);

int main() {
    Point a, b, c, p;
    while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> p.x >> p.y) {
        //cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> p.x >> p.y;
        //cout << area(a,b,c) << endl;
        double diff = area(a, b, c) - (area(a, b, p) + area(b, c, p) + area(c, a, p));
        //cout << diff << endl;
        if (fabs(diff) < 0.001) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        } 
    }
}

double area(Point l, Point m, Point n) {
    return fabs( (m.x - l.x) * (n.y - l.y)
            - (m.y - l.y) * (n.x - l.x)) * 0.5;
}

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

using namespace std;
#define rep(x, n)          for (int x = 0; x < n; x++)
#define REP(x, a, b)       for (int x = a; x <= b; x++)
#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).begin(), container.end()
#define sz(container)      (int) (container).size()

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define debug(...) 0
#endif
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(void) {
    int A,B,C,D;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    if(D*((C+B-1)/B-1)<A)
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 3688
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A[:K])
temp = S
for i in range(K, N):
    temp += A[i] - A[i-K]
    if temp > S:
        print("Yes")
    else:
        print("No")
    S = temp

Measured memory_bytes: 94272
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    ll n = b - a;
    ll len = n * (n+1);
    len /= 2;
    cout << len - b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <math.h>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 100005
#define MAX_M 100

long long A[MAX_N];
long long B[MAX_N];

int main()
{
    int N;
    cin >> N;
    rep(i, N + 1) cin >> A[i];
    rep(i, N) cin >> B[i];

    long long ans = 0;
    long long t = 0;

    rep(i, N)
    {
        ans += min(A[i], B[i]);
        B[i] = max(B[i] - A[i], t);
        ans += min(B[i], A[i + 1]);
        A[i + 1] = max(t, A[i + 1] - B[i]);
    }

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


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

int n;
std::string s, t;

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> s >> t;
	if (n <= 2) {
		int a = 0; for (int i = 0; i < n; ++i) a += s[i] != t[i];
		return std::cout << a << '\n', 0;
	}

	std::vector<int> S, T; if (s < t) std::swap(s, t);

	if (s[0] == '1') S.emplace_back(0);
	for (int i = 1; i < n; ++i) if (s[i] != s[i - 1]) S.emplace_back(i);
	if (t[0] == '1') T.emplace_back(0);
	for (int i = 1; i < n; ++i) if (t[i] != t[i - 1]) T.emplace_back(i);

	if (S.size() < T.size()) std::swap(S, T);
	while (T.size() < S.size()) T.emplace_back(n);

	for (int i = 0; i < n / 2; ++i) S.insert(S.begin(), 0), T.insert(T.begin(), 0);
	for (int i = 0; i < n / 2; ++i) S.emplace_back(n), T.emplace_back(n);

	// for (int i : S) std::cout << i << ' '; std::cout << std::endl;
	// for (int j : T) std::cout << j << ' '; std::cout << std::endl;

	int ans = 0x3f3f3f3f3f;
	for (int i = -int(T.size()) >> 1 << 1; i < (int) T.size(); i += 2) {
		// S[0] -> T[i]
		int sum = 0;
		for (int j = 0; j < T.size(); ++j) {
			int k = j - i, p;
			if (k < 0) p = 0;
			else if (k >= S.size()) p = n;
			else p = S[k];
			// std::cout << "match : " << T[j] << ' ' << p << ' ' << k << std::endl;
			sum += std::abs(T[j] - p);
		}
		// std::cout << i << ' ' << sum << std::endl;
		ans = std::min(ans, sum);
	}

	std::cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  a--;b--;c--;d--;
  vb rock(n,false);
  REP(i,n){
    char in;
    cin >> in;
    if(in=='#') rock[i] = true;
  }
  if(c<d){
    int i = b;
    while(i<d){
      if(!rock[++i]) continue;
      if(!rock[++i]) continue;
      puts("No");
      return 0;
    }
    i = a;
    while(i<c){
      if(!rock[++i]) continue;
      if(!rock[++i]) continue;
      puts("No");
      return 0;
    }
    puts("Yes");
    return 0;
  }else{
    int sz = 0;
    FOR(i,b-1,d+2){
      if(!rock[i]){
        sz++;
        if(sz>=3){
          //sz = i;
          break;
        }
      }
      else sz = 0;
    }
    if(sz<3){
      puts("No");
      return 0;
    }
    int i = b;
    while(i<d){
      if(!rock[++i]) continue;
      if(!rock[++i]) continue;
      puts("No");
      return 0;
    }
    i = a;
    while(i<c){
      if(!rock[++i]) continue;
      if(!rock[++i]) continue;
      puts("No");
      return 0;
    }
    puts("Yes");
    return 0;
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  if(ans == 3){
    cout << 3 << endl;
  }else if(ans == 4){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
words = lambda t : list(map(t, input().split()))
n = int(input())
h = words(int)

h[0] -= 1
ans = True
for i in range(1,n):
    if h[i-1] > h[i]:
        ans = False
        break
    elif h[i-1] == h[i]:
        continue
    else: # h[i-1] < h[i]
        h[i] -= 1
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int n;
  string s;
  cin.scan(n, s);

  long[] r = new long[2 * n], g = new long[2 * n], b = new long[2 * n];

  foreach (i; 0 .. n) {
    if (s[i] == 'R') {
      r[i] = 1;
    } else if (s[i] == 'G') {
      g[i] = 1;
    } else if (s[i] == 'B') {
      b[i] = 1;
    }
  }

  foreach (i; 1 .. 2 * n) {
    r[i] += r[i - 1];
    g[i] += g[i - 1];
    b[i] += b[i - 1];
  }

  long res;

  alias T = Tuple!(uint, "f", uint, "s", string, "str");
  T[] ar;
  string[] per = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"];

  foreach (e; per) {
    foreach (i; 0 .. n - 1) {
      foreach (j; i + 1 .. n - 1) {
        if (s[i] == e[0] && s[j] == e[1]) {
          ar ~= T(i, j, e);
        }
      }
    }
  }

  debug writeln(r);
  debug writeln(g);
  debug writeln(b);

  foreach (e; ar) {
    uint l = e.s + (e.s - e.f);
    auto sel = e.str[2] == 'R' ? r : e.str[2] == 'G' ? g : b;
    res += sel[l - 1] - sel[e.s];
    res += sel[n - 1] - sel[l];
    debug writeln(e.str, " ", e, " ", sel[l - 1] - sel[e.s], " ", sel[n - 1] - sel[l]);
  }

  writeln(res);
}


Measured memory_bytes: 210180
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

ans = 0
for i in range(n):
    sub = 0
    for j in range(n):
        if i == j:
            sub += a1[j]
            sub += a2[j]
        elif i < j:
            sub += a2[j]
        else:
            sub += a1[j]
    ans = max(sub, ans)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
const double eps=1e-10;
double dis(double x1,double y1,double x2,double y2)
{
	return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
int main()
{
    double x1,y1,r1,x2,y2,r2;
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2);
    double x=x2-x1,y=y2-y1;
    double d=dis(x1,y1,x2,y2);
    x/=d;y/=d;
    double ko=(r1*r1-r2*r2+d*d)/(2*d);
    double pre=sqrt(r1*r1-ko*ko);
    double X=x1+x*ko,Y=y1+y*ko;
    //printf("%.8f %.8f\n",X,Y);
    //printf("pre:%.8f\n",pre);
     if(fabs(x1-x2)<eps&&fabs(y1-y2)<eps&&fabs(r1-r2)<eps){
        printf("%.10f %.10f %.10f %.10f\n",x1,y1+r1,x1,y1+r1);
        return 0;
     }
    if(fabs(x1-x2)<eps){
    //printf("ko1\n");
    	double dx=1.0,dy=0.0;
    	double resx1=X-pre*dx,resy1=Y-pre*dy;
    	double resx2=X+pre*dx,resy2=Y+pre*dy;
    	if(resx1-resx2>eps){
    		printf("%.10f %.10f %.10f %.10f\n",resx2,resy2,resx1,resy1);
		}
		else
		if(fabs(resx1-resx2)<eps){
			if(resy1-resy2>eps){
				printf("%.10f %.10f %.10f %.10f\n",resx2,resy2,resx1,resy1);
			}
			else{
				printf("%.10f %.10f %.10f %.10f\n",resx1,resy1,resx2,resy2);
			}
		}
		else{
            printf("%.10f %.10f %.10f %.10f\n",resx1,resy1,resx2,resy2);
		}
	}
	else{
		//printf("ko2\n");
    double k=(y1-y2)/(x1-x2);
    double dx,dy;
    if(fabs(k)<eps){
    	dx=0.0;
    	dy=1.0;
	}
	else{
		k=(-1.0)/k;
		dx=sqrt(1.0/(k*k+1));
		dy=k*dx;
	}
	//printf("%.8f %.8f\n",dx,dy);
    double resx1=X+dx*pre,resy1=Y+dy*pre,resx2=X-dx*pre,resy2=Y-dy*pre;
    if(resx1-resx2>eps){
    		printf("%.10f %.10f %.10f %.10f\n",resx2,resy2,resx1,resy1);
		}
		else
		if(fabs(resx1-resx2)<eps){
			if(resy1-resy2>eps){
				printf("%.10f %.10f %.10f %.10f\n",resx2,resy2,resx1,resy1);
			}
			else{
				printf("%.10f %.10f %.10f %.10f\n",resx1,resy1,resx2,resy2);
			}
		}
		else{
            printf("%.10f %.10f %.10f %.10f\n",resx1,resy1,resx2,resy2);
		}
    }
    return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int N ;
  cin >> N;
  vi a = {3*5*7,3*5*11,3*5*13,27 * 5, 27 * 7};
  cout << count_if(ALL(a),[=](auto i){return i <= N;})  << endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <climits>
#include <cmath>

//using integer = unsigned long long;
using integer = signed long long;

int main(void) {
  int n, a, b, c, d;
  std::cin >> n;

  int tmp = n;
  a = tmp / 1000;
  tmp %= 1000;
  b = tmp / 100;
  tmp %= 100;
  c = tmp / 10;
  tmp %= 10;
  d = tmp;

  char op[4] = "...";
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int res = a;
        res = (i == 0) ? (res + b) : (res - b);
        res = (j == 0) ? (res + c) : (res - c);
        res = (k == 0) ? (res + d) : (res - d);
        if (res == 7) {
          op[0] = "+-"[i];
          op[1] = "+-"[j];
          op[2] = "+-"[k];
          break;
        }
      }
    }
  }

  std::cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << std::endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int o = 0, e = 0;
    int n;
    cin >> n;
    rep (i, n) {
        int x;
        cin >> x;
        if (x % 2) o++;
        else e++;
    }
    if (o % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}



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

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

  if ( N/10%111 == 0 || N%1000%111 == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const int INF = 1 << 30;

struct Edge {
    int to; int cap; int rev;
    Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
};

struct Flow {
    vector <vector<Edge>> G;
    vector<bool> used;
    Flow(int n) : G(n), used(n, false) {}
    void add_edge(int from, int to, int cap) {
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, 0, G[from].size() - 1));
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            fill(used.begin(), used.end(), false);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

string s[100];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> s[i];

    Flow fl(2*h*w + 2);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == 0 || i == h-1 || j == 0 || j == w-1) {
                if (s[i][j] == 'X') {
                    cout << -1 << '\n';
                    return 0;
                }

                fl.add_edge(i*2*w+2*j, 2*h*w+1, 1);
                continue;
            }

            if (s[i][j] == 'X') {
                fl.add_edge(2*h*w, i*2*w+2*j+1, INF);
            } else {
                fl.add_edge(i*2*w+2*j, i*2*w+2*j+1, 1);
            }

            for (int k = 0; k < 4; k++) {
                int x = i + dx[k];
                int y = j + dy[k];
                if (s[x][y] == '.') {
                    fl.add_edge(i*2*w+2*j+1, x*2*w+2*y, INF);
                }
            }
        }
    }

    cout << fl.max_flow(2*h*w, 2*h*w+1) << "\n";
    return 0;
}

Measured memory_bytes: 2432
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = 0
for num_take in range(min(N, K)+1):
    max_put = min(K - num_take, max(num_take-1, 0))
    for i in range(num_take+1):
        deque = list(V)
        gems = []
        left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)]
        for which in left_right:
            if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
        gems.sort()

        value = max([sum(gems[num_put:]) for num_put in range(max_put+1)])
        max_value = max(max_value, value)
        
print(max_value)

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

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

    while (true) {
        int n, ans = 0, mean = 0;
        cin >> n;
        if (n == 0) {
            break;
        }
        int a[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mean += a[i];
        }
        mean /= n;
        for (int i = 0; i < n; i++) {
            if (a[i] <= mean) {
                ans++;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3068
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222



vll edge[MAX];
ll dp[MAX][2];

ll dfs(ll cur,ll par, ll col) {
  if (edge[cur].size() == 1 && cur != 1) return 1;
  if (dp[cur][col]) return dp[cur][col];
  ll ret = 1;
  rep(i, edge[cur].size()) {
    if (edge[cur][i] == par) continue;
    ll cnt = 0;
    (cnt += dfs(edge[cur][i], cur, 0)) %= mod;
    if (!col) (cnt += dfs(edge[cur][i], cur, 1)) %= mod;
    (ret *= cnt) %= mod;
  }
  return dp[cur][col] = ret;
}


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


  cin >> n;
  rep(i, n - 1) {
    ll x, y;
    cin >> x >> y;
    edge[x].pb(y);
    edge[y].pb(x);
  }
  dfs(1, 0, 0);
  dfs(1, 0, 1);
  cout << (dp[1][0] + dp[1][1]) % mod << endl;





  return 0;
}

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

bool cmp(pair<int,int> a,pair<int,int> b)
{
	return a.second > b.second;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,m,t,b,c;
	priority_queue <int,vector<int>,greater<int>> pque;
	vector <pair<int,int>> q;
	cin >> n >> m;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		pque.push(t);
	}

	for(int i=0;i<m;i++)
	{
		cin >> b >> c;
		q.push_back(make_pair(b,c));
	}
	sort(q.begin(),q.end(),cmp);

	for(int i=0;i<m;i++)
	{
		if(pque.top()>=q[i].second)
		{
			break;
		}
		for(int j=0;j<q[i].first;j++)
		{
			if(pque.top()>=q[i].second)
			{
				break;
			}
			pque.pop();
			pque.push(q[i].second);
		}
	}

	long long int res = 0;
	while(!pque.empty())
	{
		res += pque.top();
		pque.pop();
	}

	cout << res << '\n';
	return 0;

}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    int X;
    cin >> X;
    cout << 10-X/200 << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
LL x_;
LL x[200001];

int main(){
  cin>>n>>x_;
  x[0]=0;
  REP(i,n)
    cin>>x[i+1];
  REP(i,n)
    x[i+1]+=x[i];
  LL ret_min=LLONG_MAX,su=0;
  FOR(k,1,n+1){
    su=0;
    REP(j,n/k+1){
      if(j==0)
	su+=5*(x[n-j*k]-x[n-(j+1)*k]);
      else
	su+=(2*j+3)*(x[n-j*k]-x[max(0,n-(j+1)*k)]);
      if((n+k)*x_+su>ret_min)break;
    }
    ret_min=min(ret_min,(n+k)*x_+su);
  }
  cout<<ret_min<<endl;
  return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in); 
		int N = input.nextInt();
		int S = input.nextInt();
		int[] A = new int[N+1];
		long[][] dp = new long[3001][3001];
		long mod = 998244353;
		long mod_inv_2 = FastExp(2,mod-2,mod);
		long lenOneSubset = FastExp(2,N-1,mod);
		for (int i = 1; i <= N; i++) {
			A[i]=input.nextInt();
		}
		for (int item = 1; item <= N; item++) {
			for (int sum = 1; sum <= S; sum++) {
				dp[item][sum]=dp[item-1][sum];
				if (A[item]==sum) dp[item][sum]+=lenOneSubset;
				dp[item][sum]%=mod;
				if (sum-A[item]>0) dp[item][sum]+=dp[item-1][sum-A[item]]*mod_inv_2;
				dp[item][sum]%=mod;
			}
		}
		System.out.println(dp[N][S]);	
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans = 1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			base*=base;
			exp/=2;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
}

Measured memory_bytes: 102904
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31); // 2147483647

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) { return (a % b + b) % b; }

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n), b(n);
    vii ab(2*n);
    ll as = 0, bs = 0;
    rep(i,0,n){
        cin >> a[i] >> b[i];
        as += a[i];
        bs += b[i];
        ab[2*i] = ii(a[i], i);
        ab[2*i+1] = ii(b[i], i);
    }
    sort(ab.begin(), ab.end());
    ll sm = 0;
    ll ans = min(as, bs);
    vector<int> used(n, 0);
    rep(i,0,n-1){
        sm += ab[i].first;
        used[ab[i].second]++;
    }
    rep(i,0,n){
        if(used[i] == 2){
            ans = min(ans, sm+ab[n-1].first);
        }
        else if(used[i] == 1){
            ans = min(ans, sm+max(a[i], b[i]));
        }
        else{
            ans = min(ans, sm+a[i]+b[i]-ab[n-2].first);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define endl "\n"
#define pque priority_queue

const int mod = 1000000007;
int a[100005], b[100005];

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, sum = 0, ex;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	ex = n * (n + 1) / 2;
	if (sum % ex != 0){
		cout << "NO";
		return 0;
	}
	int cnt = sum / ex;
    for (int i = 0; i < n; i++){
        b[i] = (a[(i + 1) % n] - a[i] - cnt);
    }
    bool flag = true;
    for (int i = 0; i < n; i++){
        if (b[i] > 0 || (-b[i]) % n != 0){
            flag = false;
            break;
        }
    }
    if (!flag){
    	cout << "NO";
    	return 0;
	}
	cout << "YES";
}


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

int main(){
    int s;
    bool memo[1000000];
    bool a = true;
    int A[100000];
    cin>>s;
    A[1]=s;
    int i =1;
    memo[s]= true;

    while(a){
        if(A[i]%2==0)A[i+1] = A[i]/2;
        else A[i+1]= 3*A[i]+1;
        if(memo[A[i+1]]==true){
            cout << i+1;
            a=false;
        }else{
            memo[A[i+1]]=true;
            i++;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}

 long long numbers[500005];

//int a[100005];

 int main(){

 long long n;
cin>>n;

 double t,a;
 cin>>t>>a;

  double mini = 100100100;
  int pos=0;

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

   double H;
   cin>>H;

    double  x = t-H*0.006;
     double diff ;

  diff = abs(x-a);

   if(diff < mini){
        mini = diff;
     pos = i; }

 }

 cout<<pos+1<<endl;


 return 0;
 }

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

int main() {
  int n;
  cin>>n;
  pair<int, int> x[n];
  for (int i=0; i<n; i++) {
    cin>>x[i].first;
    x[i].second = i;
  }
  sort(x, x + n);
  set<int> left;
  for (int i=0; i<n/2; i++) {
    left.insert(x[i].second);
  }
  for (int i=0; i<n; i++) {
    if (left.find(i) != left.end()) {
      cout<<x[n/2].first<<endl;
    } else {
      cout<<x[n/2-1].first<<endl;
    }
  }
}

Measured memory_bytes: 9600