akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    int a, b, c;
    cin >> a >> b >> c;
    bool is_poor = 0;
    if (a == b && a != c)
        is_poor = true;
    if (b == c && b != a)
        is_poor = true;
    if (a == c && b != c)
        is_poor = true;
    if (is_poor)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
 int i, c;
 printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

 if(T[u].p == NIL) printf("root, ");
 else if(T[u].l == NIL) printf("leaf, ");
 else printf("internal node, ");

 printf("[");
 for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
   if(i) printf(", ");
   printf("%d", c);
 }
 printf("]\n");

}

void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].r != NIL) calcDepth(T[u].r,p);
 if(T[u].l != NIL) calcDepth(T[u].l,p+1);
}

int main(){
 int i, j, k;
 int n;
 int id, sib, child;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

 for(i=0; i<n; i++){
   scanf("%d %d", &id, &k);
   for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
     scanf("%d", &child);
     T[child].p = id;
     if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
     else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
     sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
   }
 }

 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }

 //それぞれのノードの深さを求める (find depth of each node)
 calcDepth(root, 0);

 //出力 (output)
 for(i=0; i<n; i++) print(i);

 return 0;
}


Measured memory_bytes: 6484
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

template <typename T>
struct SegTree {
	T init_val;
	int n;
	vector<T> dat;
	
	SegTree() = default;
	SegTree(int _n, T init_val) : init_val(init_val) {
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(n * 2 - 1, init_val);
	}
	
	void update(int i, T x) {
		i += n - 1;
		dat[i] = min(dat[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	
	void set(int i, T x) {
		dat[i + n - 1] = x;
		update(i, x);
	}
	
	// 探索範囲[a,b), 現在見ているkノード[l,r)
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return min( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
};

int N, K;
int H[300], h[300];
ll dp[301][301][301];
ll smn[301][301];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", H + i);
	
	vector<int> cx(N);
	REP(i, N) cx[i] = H[i];
	cx.push_back(0);
	sort(ALL(cx));
	cx.erase(unique(ALL(cx)), cx.end());
	
	REP(i, N) h[i] = lower_bound(ALL(cx), H[i]) - cx.begin();
	
	fill(dp[0][0], dp[N + 1][0], longINF);
	
	dp[0][0][0] = 0;
	FOR(i, 1, N + 1) {
		REP(j, K + 1) {
			REP(k, N + 1) smn[j][k] = dp[i - 1][j][k];
			for (int k = N - 1; k >= 0; k--) chmin(smn[j][k], smn[j][k + 1]);
		}
		REP(j, K + 1) {
			ll mn = longINF;
			REP(k, N + 1) chmin(mn, dp[i - 1][j][k] + max(cx[h[i - 1]] - cx[k], 0));
			if (j < K) chmin(dp[i][j + 1][h[i - 1]], mn);
			
			REP(k, N + 1) {
				if (j) chmin(dp[i][j][k], smn[j - 1][k]);
				if (k) chmin(dp[i][j][k], dp[i][j][k - 1] + cx[k] - cx[k - 1]);
			}
			chmin(dp[i][j][h[i - 1]], mn);
		}
	}
	
	ll ans = longINF;
	REP(j, K + 1) REP(k, N + 1) chmin(ans, dp[N][j][k]);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 214016
n = int(input())
cnts = 0

for i in range(1,n+1):
    cnt = 0

    for j in range(1,n + 1):
        if i % j == 0:
            cnt += 1
    if (cnt == 8)&(i%2 != 0):
        cnts += 1

print(cnts)

Measured memory_bytes: 9124
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    int x = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x ^= a[i];
    }
    for (int i = 0; i < n; i++) {
        cout << (x ^ a[i]) << ' ';
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 4764
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        for _ in range(num): return []
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list,zip(*read_all))

#################

A,B = II()

if A>=B:
    s = [['#']*100 for _ in range(100)]
    B -= 1
    for i in range(1,100,4):
        for j in range(1,80,4):
            if B == 0:
                break
            s[i-1][j-1] = s[i-1][j] = s[i-1][j+1] = '.'
            s[i][j-1] = s[i][j+1] = '.'
            s[i+1][j-1] = s[i+1][j] = s[i+1][j+1] = '.'
            B -= 1
            A -= 1
        else:
            continue
        break
    for j in range(81,100,2):
        for i in range(0,100,2):
            if A==0:
                break
            s[i][j] = '.'
            A -= 1
        else:
            continue
        break

else:
    s = [['.']*100 for _ in range(100)]
    A -= 1
    for i in range(1,100,4):
        for j in range(1,80,4):
            if A == 0:
                break
            s[i-1][j-1] = s[i-1][j] = s[i-1][j+1] = '#'
            s[i][j-1] = s[i][j+1] = '#'
            s[i+1][j-1] = s[i+1][j] = s[i+1][j+1] = '#'
            A -= 1
            B -= 1
        else:
            continue
        break
    for j in range(81,100,2):
        for i in range(0,100,2):
            if B==0:
                break
            s[i][j] = '#'
            B -= 1
        else:
            continue
        break

print(100,100)
for s0 in s:
    print(*s0, sep='')

Measured memory_bytes: 40176
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	int n,h,w; cin>>n>>h>>w;
	cout<<(n-h+1)*(n-w+1)<<endl;
}

Measured memory_bytes: 256
def sieve(n):
    """
    Sieve of Eratosthenes
    """
    s = [True for _ in range(n + 1)]
    for i in range(2, int(n ** 0.5) + 1):
        if s[i]:
            for j in range(i * 2, len(s), i):
                s[j] = False
    return (i for i in range(n + 1) if s[i] and i > 1)


def main():
    n = int(input())
    primes = sieve(n)
    c = 0
    for i in range(1, n + 1, 2):
        if i in primes:
            continue
        cp = 0
        for j in range(1, i + 1):
            if i % j == 0:
                cp += 1
        if cp == 8:
            c += 1
    print(c)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n,m,k,a,b,c;
		String s=sc.next();
		s+=sc.next();
		char ch[]=s.toCharArray();
		if(ch[0]>ch[1]) {
			System.out.println(">");
		}else if(ch[0]==ch[1]) {
			System.out.println("=");
		}else {
			System.out.println("<");
		}


	}
}


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

int main() {
    map<int,int>num={};

    int N;
    cin >> N;
    int a;
    for(int i=0;i<N;i++){
        cin >> a;
        auto itr = num.find(a);
        if(itr!=num.end()){
            itr->second++;
        }else {
            num[a]=1;
        }
    }
    auto itr=next(num.end(),-1);
    long long max1=0,max2=0,ct=0,ans;
    while(itr!=next(num.begin(),-1)){
        if(itr->second>=4 && ct==0){
            max1=max2=itr->first;
            break;
        }
        if(itr->second>=2){
            if(ct==0){
                max1=itr->first;
                ct++;
            }else {
                max2=itr->first;
                break;
            }
        }
        itr=next(itr,-1);
    }
    ans=max1*max2;
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++) 

using namespace std;

int main() {
  int a,b,k;cin>>a>>b>>k;
  int cnt=0;
  for(int i=100;i>=1;i--){
    if(a%i==0&&b%i==0){
      cnt++;
      if(cnt==k){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int main()
{
	int a,b,c,d;
	int n[105];
	memset(n,0,sizeof(n));
	cin>>a>>b>>c>>d;
	for(int i=a;i<=b;i++){
		n[i]++;
	}
	for(int i=c;i<=d;i++){
		n[i]++;
	}
	int ans=0;
	for(int i=0;i<102;i++){
		if(n[i]>1){
			ans++;
		}
	}
	ans--;
	if(ans<0){
		ans=0;
	}
	cout<<ans;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(void) {
    int K, S;
    cin >> K >> S;

    int ans = 0;

    for(int i = 0; i <= K; i++) {
        for(int j = 0; j <= K; j++) {
            int Z = S - i - j;
            if(Z >= 0 && Z <= K) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
import itertools


def main():
    n, m = [int(i) for i in input().split()]
    path_matrix = [[False] * n for _ in range(n)]
    for _ in range(m):
        a, b = [int(i) for i in input().split()]
        a -= 1
        b -= 1
        path_matrix[a][b] = True
        path_matrix[b][a] = True

    ans = 0
    for path in itertools.permutations(range(n), n):
        if path[0] != 0:
            continue
        for i in range(n):
            if i == n - 1:
                ans += 1
                break
            if not path_matrix[path[i]][path[i+1]]:
                break

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 39536
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n;
    long long X = 0, x = 0, ans = 1000000000000000000LL;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        X += a[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        x += a[i];
        ans = min(ans, abs(X - 2 * x));
    }
    cout << ans << endl;
}

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

int main() {
	
	int n;
	cin >> n;
	vector<int> p(n);
	int cnt = 0;
	rep(i, n){
		cin >> p[i];
		p[i]--;
	}
	for(int i = 0; i < n; i++){
		if(i == p[i]){
			cnt++;
			i++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

void solve() {
	string a; cin >> a;
    int n = (int)a.size();
    map<int, int> mp;
    rep(i, n) {
        int s = a[i] - 'a';
        mp[s] ++;
    }
    int ans = 0;
    rep(i, 26) {
        for(int j = i + 1; j < 26; ++j) {
            ans += mp[i] * mp[j];
        }
    }
    cout << ans + 1 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 720
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int A[N][N], color[N];
int d[N], Q[N+1];
int n, q1 = 0, q2 = 0;
 
void bfs(void);
 
int main() {
  int u, v, k, i, j;
 
  scanf("%d", &n);
  for(i = 1; i <= n; i++) {
    Q[i] = -1;
    for(j = 1; j <= n; j++) {
      A[i][j] = 0;
    }
  }
  Q[n+1] = -1;
 
  for(i = 1; i <= n; i++) {
    scanf("%d", &u);
    scanf("%d", &k);
    for(j = 1; j <= k; j++) {
      scanf("%d", &v);
      A[u][v] = 1;
    }
  }
 
  bfs();
 
  for(i = 1; i <= n; i++) {
    printf("%d %d\n", i, d[i]);
  }
 
  return 0;
}
 
 
void bfs() {
  int i, u;
  for(i = 1; i <= n; i++) {
    color[i] = WHITE;
    d[i] = -1;
  }
  color[1] = GRAY;
  d[1] = 0;
  Q[q1] = 1;
  q1++;
  while(q1 != q2) {
    u = Q[q2];
    q2++;
    for(i = 1; i<= n; i++) {
      if(A[u][i] == 1) {
        if(color[i] == WHITE) {
          color[i] = GRAY;
          d[i] = d[u] + 1;
          Q[q1] = i;
          q1++;
        }
      }
    }
    color[u] = BLACK;
  }
}

Measured memory_bytes: 636
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

template <typename S, typename T>
i64 count_diff(const S& s, const T& t) {
  i64 ret{0};
  for (i64 i = 0; i < t.length(); ++i) {
    if (s[i] != t[i]) {
      ++ret;
    }
  }
  return ret;
}

int main() {
  cin.tie(nullptr);

  string s, t;
  cin >> s;
  cin >> t;
  const i64 ns = s.length();
  const i64 nt = t.length();
  i64 diff_min{nt};
  for (i64 i = 0; i < ns - nt + 1; ++i) {
    diff_min = min(count_diff(s.substr(i, nt), t), diff_min);
  }
  cout << diff_min << endl;

  return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(void) {

  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a,int b) {

  return a < b ? a : b;
}

int main(void) {
  int elaps = 0, c;
  int i, q;
  P u;

/* 入力するプロセスの個数とクオンタム */
  scanf("%d %d",&n,&q);
/* 1番目からn番目まで */
  for(i=1;i<=n;i++) {
/* i番目のプロセスへの入力 */
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1; tail = n + 1;

  /* シミュレーション 空になるまでループ*/
  while(head != tail) {
    u = dequeue();
    c = min(q,u.t);
    u.t   -= c;
    elaps += c;
    if(u.t > 0) enqueue(u); /* 先延ばし*/
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 12008
import Control.Monad

main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  input <- replicateM h $ getLine :: IO [String]
  let added = map (\x -> "#" ++ x ++ "#") input
  let ans = [replicate (w + 2) '#'] ++ added ++ [replicate (w + 2) '#']
  mapM_ putStrLn ans

  return ()

Measured memory_bytes: 1404
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>
#include<set>
#include<stack>
#include<map>

using namespace std;

typedef pair<int,long long> P;

const long long INF=1e17;

class edge{
public:
    int to;
    long long cost;
};

vector<edge> G[1000];

int main(){
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        long long c;
        cin>>a>>b>>c;
        a--; b--;
        edge e;
        e.to=b;
        e.cost=c;
        G[a].push_back(e);
    }
    long long d[1000];
    fill(d,d+N,-INF);
    d[0]=0;
    queue<P> q;
    q.push(P(0,0));
    int count=0;
    while(!q.empty() && count<10000){
        P x=q.front(); q.pop();
        int vertex=x.first;
        long long dist=x.second;
        if(dist>=d[vertex]){
            d[vertex]=dist;
            for(int j=0;j<G[vertex].size();j++){
                edge e=G[vertex][j];
                long long tmp=dist+e.cost;
                q.push(P(e.to,tmp));
            }
            count++;
        }
    }
    count=0;
    bool flag=false;
    while(!q.empty() && count<10000){
        P x=q.front(); q.pop();
        int vertex=x.first;
        long long dist=x.second;
        if(dist>d[vertex]){
            d[vertex]=dist;
            if(vertex==N-1){
                flag=true;
                break;
            }
            for(int j=0;j<G[vertex].size();j++){
                edge e=G[vertex][j];
                long long tmp=dist+e.cost;
                q.push(P(e.to,tmp));
            }
            count++;
        }
    }

    if(flag){
        cout<<"inf"<<endl;
    }else{
        cout<<d[N-1]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>                                                             
#include <cmath>                                                                
using namespace std;                                                            
                                                                                
int main (void) {                                                               
  double r;                                                                     
  cin >> r;                                                                     
  const static double pi = 4*atan(1.0);                                         
  cout << fixed;                                                                
  cout.precision(6);                                                            
  cout << pow(r,2)*pi << " " << 2*r*pi << endl;                                 
}                                                                               
                                       

Measured memory_bytes: 3236
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for d in range(n):
    for e in range(d+1, n):
        a, b = l[d], l[e]
        idx = bisect.bisect_left(l, a + b)
        ans += max(idx - e - 1, 0)
print(ans)


Measured memory_bytes: 3188
N,M=map(int,input().split())
tbl=[[0]*(N+1) for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  tbl[a][b]=1
  tbl[b][a]=1            # グラフの行列を用いた表現
def dfs(s,visited):
  if len(visited)==N:
    return 1
  
  ans=0
  for i in range(1,N+1):
    if i==s: continue
    if tbl[s][i]==1 and (i not in visited):
      visited.append(i)
      ans+=dfs(i,visited)
      visited.pop()
  return ans 

answer=dfs(1,[1,])
print(answer)
      

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

using namespace std;
typedef long long LL;

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

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r) { bool a = l>r; if (a)l = r; return a; }
template <typename T>inline bool chmax(T &l, T r) { bool a = l<r; if (a)l = r; return a; }

int N, M;
int a[112345];
int b[112345];
LL c[112345];

int dep[112345];
int used[112345];
int br[112345];
int imos[112345];
using V = vector<int>;
using VV = vector<V>;
VV g;
void latte(int v,int pe,int d) {
	dep[v] = d;
	used[v] = 1;
	for (int e : g[v]) {
		if (e == pe)continue;
		int u = a[e] ^ b[e] ^ v;
		if(used[u]==0)latte(u, e, d + 1);
	}
}
void malta(int v, int pe) {
	used[v] = 1;
	for (int e : g[v]) {
		if (e == pe)continue;
		int u = a[e] ^ b[e] ^ v;
		if (used[u] == 1) {
			if (dep[u] < dep[v]) {
				imos[v]++;
				imos[u]--;
			}
		}
		else {
			malta(u, e);
			imos[v] += imos[u];
		}
	}
	if (imos[v]==0)br[pe] = 1;
}
using T = tuple<LL, int, int>;
T ans(0, 0, 0);
LL sum = 0;

LL sub[112345];
void beet(int v, int pe) {
	used[v] = 1;
	sub[v] = 0;
	for (int e : g[v]) {
		sub[v] += c[e];
		if (e == pe)continue;
		int u = a[e] ^ b[e] ^ v;
		if (used[u] == 0) {
			beet(u, e);
			sub[v] += sub[u];
			if (br[e]) {
				LL A = (sub[u] - c[e]) / 2;
				LL B = sum - A - c[e];
				//cout << abs(A - B) << " " << a[e] + 1 << " " << b[e] + 1 << endl;
				chmin(ans, T(abs(A - B), a[e] + 1, b[e] + 1));
			}

		}
	}
}
constexpr int NG = 112340;
int main() {
	cin >> N >> M;
	g = VV(N);
	REP(i, M) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
		sum += c[i];
	}
	ans = T(sum, 0, 0);
	REP(i, N)used[i] = 0;
	latte(0, NG, 0);
	REP(i, M)br[i] = 0;
	REP(i, N)used[i] = 0;
	REP(i, N)imos[i] = 0;
	malta(0, NG);
	REP(i, M) {
		if (br[i] == 0)chmin(ans, T(sum - c[i], a[i] + 1, b[i] + 1));
	}
	REP(i, N)used[i] = 0;
	beet(0, NG);
	LL x;
	int y, z;
	tie(x, y, z) = ans;
	cout << y << " " << z << endl;
	return 0;
}



Measured memory_bytes: 13344
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;
using lli = long long int;

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<lli> s(A + (lli)2), t(B + (lli)2), x(Q);
    const lli inf = pow(10, 18);
    s[0]          = -inf;
    t[0]          = -inf;
    for (int i = 1; i <= A; i++) cin >> s[i];
    for (int i = 1; i <= B; i++) cin >> t[i];
    for (int i = 0; i < Q; i++) cin >> x[i];
    s[A + (lli)1] = inf;
    t[B + (lli)1] = inf;

    for (int i = 0; i < Q; i++) {
        const lli p = x[i];
        auto sr     = upper_bound(s.begin(), s.end(), p);
        auto sl     = sr - 1;
        auto tr     = upper_bound(t.begin(), t.end(), p);
        auto tl     = tr - 1;

        const lli ans =
            min({abs(*sl - p) + abs(*tl - *sl), abs(*sl - p) + abs(*tr - *sl),
                 abs(*tl - p) + abs(*sl - *tl), abs(*tl - p) + abs(*sr - *tl),
                 abs(*sr - p) + abs(*tl - *sr), abs(*sr - p) + abs(*tr - *sr),
                 abs(*tr - p) + abs(*sl - *tr), abs(*tr - p) + abs(*sr - *tr)});
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    map<int,int> mp;
    mp[a]; mp[b]; mp[c];

    cout << mp.size() << endl;
}

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

void input(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int gcd(int nOne, int nOtr)
{
  if (nOtr == 0)
    return nOne;
  else
    return gcd(nOtr, nOne % nOtr);
}

int calcMaxGcd(const vector<int>& cnrvnNum)
{
  vector<int> vnLeftGcd(cnrvnNum.size());
  vector<int> vnRigtGcd(cnrvnNum.size());
  int nMaxGcd = 0;

  vnLeftGcd[0] = cnrvnNum[0];
  
  for (int i = 1; i < cnrvnNum.size(); i++)
    vnLeftGcd[i] = gcd(vnLeftGcd[i - 1], cnrvnNum[i]);
  
  vnRigtGcd[cnrvnNum.size() - 1] = cnrvnNum[cnrvnNum.size() - 1];

  for (int i = cnrvnNum.size() - 2; i >= 0; i--)
    vnRigtGcd[i] = gcd(vnRigtGcd[i + 1], cnrvnNum[i]);

  for (int i = 0; i < cnrvnNum.size(); i++)
    if (i == 0)
      nMaxGcd = max(nMaxGcd, vnRigtGcd[i + 1] );
    else if (i == cnrvnNum.size() - 1)
      nMaxGcd = max(nMaxGcd, vnLeftGcd[i - 1] );
    else
      nMaxGcd = max(nMaxGcd, gcd(vnLeftGcd[i - 1], vnRigtGcd[i + 1] ));
  
  return nMaxGcd;
}
 
int main()
{
  vector<int> vnNum;

  input(vnNum);
  cout << calcMaxGcd(vnNum) << endl;

  return 0;
}

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

typedef struct {
	int *array;
	int N;
}stack;

stack *make_stack(int maxN){
	stack *s = (stack *)malloc(sizeof(stack));
	s->array = (int *)malloc(sizeof(int) * maxN);
	s->N = 0;
	return s;
}

int element_num_stack(stack *s){
	return s->N;
}

void add_data_stack(int val, stack *s){
	s->array[s->N] = val;
	s->N++;
}

int take_data_stack(stack *s){
	if(s->N == 0){
		printf("no data in the stack\n");
	}
	s->N--;
	return s->array[s->N];
}

int look_data_stack(stack *s){
	if(s->N == 0){
		printf("no data in the stack\n");
	}
	else{
		return s->array[s->N - 1];
	}
}

void flush_stack(stack *s){
	s->N = 0;
}

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

//Aの各要素は0か1
//1だけから成る長方形の面積の最大値を返す
int largest_rectangle(int H, int W, int **A){
	int i, j, garbage, ans = 0;
	int **T = (int **)malloc(sizeof(int *) * H);
	int *L = (int *)malloc(sizeof(int) * W);
	int *R = (int *)malloc(sizeof(int) * W);
	stack *sL = make_stack(W);
	stack *sR = make_stack(W);
	for(i = 0; i < H; i++){
		T[i] = (int *)malloc(sizeof(int) * W);
		for(j = 0; j < W; j++){
			if(i == 0){
				T[i][j] = A[i][j];
			}
			else{
				T[i][j] = (T[i - 1][j] + 1) * A[i][j];
			}
		}

		for(j = 0; j < W; j++){
			while(1){
				if(element_num_stack(sL) == 0){
					L[j] = 0;
					break;
				}
				else if(T[i][j] > T[i][look_data_stack(sL)]){
					L[j] = look_data_stack(sL) + 1;
					break;
				}
				garbage = take_data_stack(sL);
			}
			add_data_stack(j, sL);
		}
		flush_stack(sL);

		for(j = W - 1; j >= 0; j--){
			while(1){
				if(element_num_stack(sR) == 0){
					R[j] = W - 1;
					break;
				}
				else if(T[i][j] > T[i][look_data_stack(sR)]){
					R[j] = look_data_stack(sR) - 1;
					break;
				}
				garbage = take_data_stack(sR);
			}
			add_data_stack(j, sR);
		}
		flush_stack(sR);

		for(j = 0; j < W; j++){
			ans = max(ans, ((T[i][j] + 1) / 2) * ((R[j] - L[j] + 2) / 2));
		}
	}
	return ans;
}

int main(){
	int H, W, i, j, count;
	scanf("%d%d", &H, &W);
	char **S = (char **)malloc(sizeof(char *) * H);
	for(i = 0; i < H; i++){
		S[i] = (char *)malloc(sizeof(char) * (W + 1));
		scanf("%s", S[i]);
	}
	int **A = (int **)malloc(sizeof(int *) * (2 * H - 1));
	for(i = 0; i < 2 * H - 1; i++){
		A[i] = (int *)malloc(sizeof(int) * (2 * W - 1));
		for(j = 0; j < 2 * W - 1; j++){
			A[i][j] = 1;
		}
	}
	for(i = 1; i < H; i++){
		for(j = 1; j < W; j++){
			count = 0;
			if(S[i][j] == '#'){
				count++;
			}
			if(S[i - 1][j] == '#'){
				count++;
			}
			if(S[i][j - 1] == '#'){
				count++;
			}
			if(S[i - 1][j - 1] == '#'){
				count++;
			}
			if(count == 1 || count == 3){
				A[2 * i - 1][2 * j - 1] = 0;
			}
		}
	}
	printf("%d\n", largest_rectangle(2 * H - 1, 2 * W - 1, A));
	return 0;
}

Measured memory_bytes: 129280
N,M,X,Y = input().split()

n = int(N)
m = int(M)
x = int(X)
y = int(Y)


x_n = []
y_m = []


x_n = input().split()
y_m = input().split()

x_int = [int(x_n[i]) for i in range(n)]
y_int = [int(y_m[i]) for i in range(m)]
x_int.append(x)
y_int.append(y)

max_x = max(x_int)
min_y = min(y_int)



if(max_x < min_y):
      if(x < y):
            print("No War")
      else:
            print("War")
else:
    print("War")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

lint N,Q;
vector<vector<lint>> edges;
lint qus[200010];
lint ans[200010];

void dfs(int cur,int prev,int sum)
{
	sum+=qus[cur];
	ans[cur]+=sum;

	for(auto&& i:edges[cur])
	{
		if(i==prev)
			continue;

		dfs(i,cur,sum);
	}
	return;
}

int main()
{
	cin >> N >> Q;
	edges.resize(N);

	for(int i=0;i<N-1;i++)
	{
		lint a,b;
		cin >> a >> b;
		a--;
		b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	for(int i=0;i<Q;i++)
	{
		lint p,x;
		cin >> p >> x;
		qus[p-1]+=x;
	}
//	cout << "asdf " << endl;
	dfs(0,-1,0);
	for(int i=0;i<N;i++)
	{
		cout << ans[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	return 0;
}



Measured memory_bytes: 25600
N = gets.to_i
H = gets.split.map(&:to_i)

ret = 0
tmp = 0
N.times do |n|
  if n == (N - 1)
    ret = tmp if ret <= tmp
    break
  end
  if H[n] >= H[n+1]
    tmp += 1
  else
    ret = tmp if ret <= tmp
    tmp = 0
  end
end

puts ret

Measured memory_bytes: 8580
swapPut :: [Int]->String
swapPut [x,y] = if x<=y
	then show x ++ " " ++ show y
	else show y ++ " " ++ show x

mapToIntList :: String->[Int]
mapToIntList = map read.words

flipIntPairList :: [[Int]]->[String]
flipIntPairList xs = case xs of
	([0,0]:_)->[]
	(x:xs)-> swapPut x : flipIntPairList xs

main=getContents>>=mapM_ putStrLn.flipIntPairList.map mapToIntList.lines

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

int n, m, X, Y;
int x[105], y[105];

int main() {
  cin >> n >> m >> X >> Y;
  for (int i = 1; i <= n; i++)
    cin >> x[i];
  for (int i = 1; i <= m; i++)
    cin >> y[i];

  bool nowar = false;
  for (int z = X + 1; z <= Y; z++) {
    int c = 0;
    for (int i = 1; i <= n; i++)
      if (x[i] < z)
        c++;
    for (int i = 1; i <= m; i++)
      if (y[i] >= z)
        c++;
    if (c == n + m)
      nowar = true;
  }

  cout << (nowar ? "No War" : "War") << endl;
}

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

int main() {
    int x[1000] = {};
    int a;
    while(cin >> a) {
        x[a]++;
    }

    int mx = -1, mx_count = 0;
    for (int i = 0; i < 101; i++) {
        if (mx_count < x[i]) {
            mx = i;
            mx_count = x[i];
        }
    }
    for (int i = 0; i < 101; i++) {
        if (mx_count == x[i])
            cout << i << endl;
    }
}



Measured memory_bytes: 3036
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
using namespace std;
int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='B'){
      //  cout<<i<<" "<<s[i]<<" "<<s<<endl;
      if(i==0){
        s.erase(i,1);
        i=-1;
       // cout<<"iam here"<<" ";
      }
        else{
            s.erase(i-1,2);
            i=-1;
           }
        }
     //  cout<<i<<" "<<s[i]<<" "<<s<<endl;
    }
    cout<<s;


}


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

int main(){
    int w, h, x, y, r;
    int lim_w, lim_h;
    cin>>w>>h>>x>>y>>r;
    lim_w = w - r;
    lim_h = h - r;
    if(x>=0 && x<=lim_w && y>=0 && y<=lim_h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

int main(void)
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 0; h < H; h++) {
			for (w = 0; w < W; w++) putchar('#');
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  string S;
  cin>>S;
  if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2]) cout<<"Yes"<<endl;
  else if(S[0]==S[2]&&S[1]==S[3]&&S[0]!=S[1]) cout<<"Yes"<<endl;
  else if(S[0]==S[3]&&S[2]==S[1]&&S[0]!=S[2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;

signed main(){

    int n, m; cin >> n >> m;
    if((int)abs(n - m) > 1LL){
        cout << 0 << endl;
        return 0;
    }else{
        int ans = 1;
        for(int i = 1; i <= n; i++){
            ans *= i;
            ans %= MOD;
        }

        for(int i = 1; i <= m; i++){
            ans *= i;
            ans %= MOD;
        }

        if(n == m){
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << endl;
    }

    return 0;
}

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

int n,cnt_max;
bool flag[1<<24];

int hantei( long long int put, long long int remove ) {
  if ( ( put ^ ( put & remove ) ) == 0 ) return 1;
  return 0;
}

int saiki( vector<int> c, vector<long long int> put, long long int remove, int cnt ) {
  if ( flag[remove] ) return 0;
  flag[remove] = true;
  for ( int i = 0; i < n-1; i++ ) {
    if ( hantei( put[i], remove ) ) {
      for ( int j = i+1; j < n; j++ ) {
	if ( hantei( put[j], remove ) && c[i] == c[j] ) {
	  put[i] += 1<<n;
	  put[j] += 1<<n;
	  saiki( c, put, remove + (1<<i) + (1<<j), cnt+2 );
	  put[i] -= 1<<n;
	  put[j] -= 1<<n;
	}
      }
    }
  }
  cnt_max = max( cnt_max, cnt );
  return 0;
}

int main() {

  while(true) {

    cin >> n;
    if ( n == 0 ) break;

    vector<int> x,y,r,c;
    vector<long long int> put;
    int input1,input2,input3,input4;
    for ( int i = 0; i < n; i++ ) {
      cin >> input1 >> input2 >> input3 >> input4;
      x.push_back(input1);
      y.push_back(input2);
      r.push_back(input3);
      c.push_back(input4);
      put.push_back(0);
      for ( int j = 0; j < i; j++ ) {
	input1 = x[i] - x[j];
	input2 = y[i] - y[j];
	input3 = r[i] + r[j];
	if ( input1*input1 + input2*input2 < input3*input3 ) put[i] += ( 1 << j );
      }
    }

    for ( int i = 0; i < (1<<24); i++ ) {
      flag[i] = false;
    }
    cnt_max = 0;
    saiki( c, put, 0, 0 );
    cout << cnt_max << endl;

  }

  return 0;

}

Measured memory_bytes: 17608
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   string s;
   cin >> s;
   int flag = 0;
   REP(i, s.length()) {
       if(i%2==0) {
           if(s[i]!='h') {
               flag = 1;
           }
       } else {
           if(s[i]=='i') {
               flag == 1;
           }
       }
   }
   if(s[s.length()-1]!='i') flag = 1;
   if(flag) cout << "No" << endl;
   else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX_V 100010

using namespace std;

typedef pair<int,int> ii;
typedef vector<ii>   vii;
typedef vector<int>   vi;
const int DFS_WHITE = -1; // unvisited
const int DFS_BLACK =  1; // visited

int V,E;
int dfsNumberCounter,rootChildren,dfsRoot;
vi dfs_num,dfs_low,dfs_parent,articulation_vertex;
vii AdjList[MAX_V];// ii(neighbor,weight)


void articulationPointAndBridge(int u)
{
  dfs_low[u] = dfs_num[u] = dfsNumberCounter++;
  for(int j=0;j<(int)AdjList[u].size();j++)
    {
      ii v = AdjList[u][j];
      if(dfs_num[v.first] == DFS_WHITE)
	{
	  dfs_parent[v.first] = u;
	  if(u == dfsRoot)rootChildren++;

	  articulationPointAndBridge(v.first);

	  if(dfs_low[v.first] >= dfs_num[u])
	    articulation_vertex[u] = true;
	  //if(dfs_low[v.first] >  dfs_num[u])
	    //printf("Edge (%d,%d) is a bridge\n",u,v.first);
	  dfs_low[u] = min(dfs_low[u],dfs_low[v.first]);

	}
      else if(v.first != dfs_parent[u])
	dfs_low[u] = min(dfs_low[u],dfs_num[v.first]);
    }
}

void compute()
{
  dfsNumberCounter = 0; dfs_num.assign(V,DFS_WHITE); dfs_low.assign(V,0);
  dfs_parent.assign(V,0); articulation_vertex.assign(V,0);
  //puts("Bridges:");
  for(int i = 0; i < V; i++)
    if(dfs_num[i] == DFS_WHITE)
      {
	dfsRoot = i; rootChildren = 0;
	articulationPointAndBridge(i);
	articulation_vertex[dfsRoot] = (rootChildren > 1);// special case
      }
  //puts("Articulation Points");
  for(int i = 0; i < V; i++)
    if(articulation_vertex[i])
      printf("%d\n",i);
      //printf("Vertex %d\n",i);
}

int main()
{
  scanf("%d%d",&V,&E);
  rep(i,V)AdjList[i].clear();
  rep(i,E)
    {
      int s,t;
      scanf("%d%d",&s,&t);
      AdjList[s].push_back(ii(t,1));
      AdjList[t].push_back(ii(s,1));
    }

  compute();

  return 0;
}

Measured memory_bytes: 5384
n = int(input())
t = list(map(int, input().split()))
m = int(input())
t_sum = sum(t)
ans = []
for i in range(m):
    t_sum = sum(t)
    p, x = map(int, input().split())
    p -= 1
    t_sum -= t[p]
    t_sum += x
    ans.append(t_sum)
    # print(t_sum)
for i in range(m):
    print(ans[i])


Measured memory_bytes: 8916
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<string, string> SS;
long long int INF = 1e18;
long long int MOD = 1000000007;

namespace std {
    template <>
    class hash<std::pair<string, string>> {
    public:
        size_t operator()(const std::pair<string, string>& x) const{
            return hash<string>()(x.first) ^ hash<string>()(x.second);
        }
    };
}

using namespace std;

int main(){
	
	int N;
	cin >> N;
	
	string str, str1, str2;
	cin >> str;
	
	str1 = str.substr(0, N);
	str2 = str.substr(N);
	
	unordered_map<SS, int> m1;
	
	for(int i = 0; i < (1 << N); i++){
		string s1 = "", s2 = "", hoge = " ";
		for(int j = 0; j < N; j++){
			hoge[0] = str1[j];
			if(i & (1 << j)){
				s1 = s1 + hoge;
			}else{
				s2 = hoge + s2;
			}
		}
		m1[SS(s1, s2)]++;
	}
	
	long long int ans = 0;
	
	for(int i = 0; i < (1 << N); i++){
		string s1 = "", s2 = "", hoge = " ";
		for(int j = 0; j < N; j++){
			hoge[0] = str2[j];
			if(i & (1 << j)){
				s1 = hoge + s1;
			}else{
				s2 = s2 + hoge;
			}
		}
		ans += m1[SS(s1, s2)];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 88564
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

map<LL,LL> m;

int main(){
    LL N,M;
    cin >> N >> M;
    LL a[N],b[N+1];
    memset(b,0,sizeof(b));
    for(int i=0;i<N;i++){
        cin >> a[i];
        a[i]%=M;
    }
    m[b[0]]++;
    for(int i=0;i<N;i++){
        b[i+1]=(b[i]+a[i])%M;
        m[b[i+1]]++;
    }
    LL ans=0;
    for(auto p:m){
        ans+=p.sc*(p.sc-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules ! vec_md { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }

fn main() {
    input! {
        n: usize,
        h: [usize; n],
        a: [u64; n]
    }

    let mut sqd = SqDecomposition::new(n+1, std::cmp::max, 0);
    for i in 0..n {
        let f = sqd.fold(h[i]+1);
        sqd.update(h[i], f + a[i]);
    }
    println!("{}", sqd.fold(n+1));
}

#[allow(dead_code)]
struct SqDecomposition {
    all: Vec<u64>,
    sq: Vec<u64>,
    d: usize,
    op: Box<Fn(u64, u64) -> u64>,
    init: u64,
}
#[allow(dead_code)]
impl SqDecomposition {
    fn new<B>(n: usize, op: B, init: u64) -> SqDecomposition
    where
        B: Fn(u64, u64) -> u64 + 'static,
    {
        let d = (n as f64).sqrt().ceil() as usize;
        SqDecomposition {
            all: vec![init; n],
            sq: vec![init; d],
            d: d,
            op: Box::new(op),
            init: init,
        }
    }
    fn update(&mut self, i: usize, a: u64) {
        self.all[i] = (self.op)(self.all[i], a);
        self.sq[i / self.d] = (self.op)(self.sq[i / self.d], a);
    }
    #[doc = " [0,n)"]
    fn fold(&self, n: usize) -> u64 {
        let mut ret = self.init;
        for i in 0..n / self.d {
            ret = (self.op)(ret, self.sq[i]);
        }
        for i in 0..n % self.d {
            ret = (self.op)(ret, self.all[n - n % self.d + i]);
        }
        ret
    }
}

Measured memory_bytes: 10492
import java.util.Scanner;

public 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 >= 10) System.out.println("error");
        else System.out.println(a + b);
    }
}

Measured memory_bytes: 35752
n = int(input())
a = list(map(int, input().split()))
ans = a[0]

if 0 in a:
    ans = 0
else:
    for i in range(1, n):
        if ans <= 10 ** 18:
            ans *= a[i]
        else:
            break

if ans <= 10 ** 18:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 21612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,result;
  cin>>N>>K;
  result=1;
  for(int i=0;i<N;i++){
  result=(result+K<result*2) ? result+K : result*2;
  }
  cout<<result<<endl;
}

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

using namespace std;

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

    int a,b;
    cin>>a>>b;

    if(a+b>=10)
        cout<<"error";
    else
        cout<<a+b;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

string format(int t) {
	string res = "";
	int h = t / 100, m = t % 100;
	res += toStr(h);
	res += ":";
	if (m < 10) {
		res += "0";
	}
	res += toStr(m);
	
	return res;
}

int main() {
	int N, h, m;
	cin >> N;
	set<int> data;
	REP(i, N) {
		cin >> h >> m;
		data.insert(100 * h + m);
	}
	cin >> N;
	REP(i, N) {
		cin >> h >> m;
		data.insert(100 * h + m);
	}

	vi times;
	for (auto it = data.begin(); it != data.end(); it++) {
		times.push_back(*it);
	}

	sort(ALL(times));
	REP(i, times.size()) {
		cout << format(times[i]);
		if (i != times.size() - 1) {
			cout << " ";
		}
	}
	cout << endl;
}

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
		cin>>a[i];
	for(int i=0; i<n; i++) {
		if(a[i] % 2 == 0) {
			if(a[i] % 3 != 0 && a[i] % 5 != 0) {
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
}


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

int n, q;

int keta(int num)
{
    int i = 1;
    while (1) {
        if (num < 10) break;
        num /= 10;
        i++;
    }
    return i;
}

int tejun2(int n, int ketasuu)
{
    int max = 0;
    int tmp = 10;
    for (int i = 1; i < ketasuu; i++) {
        int x = n / tmp;
        int y = n % tmp;
        int tmp2 = x * y;
        if (max < tmp2) max = tmp2;
        tmp *= 10;
    }
    return max;
}

int kakezan(int n)
{
    int count = 0;
    while (1) {
        int ketasuu = keta(n);
        if (ketasuu == 1) break;
        n = tejun2(n, ketasuu);
        count++;
    }
    return count;
}

int main()
{
    cin >> q;
    for (int i = 0; i < q and cin >> n; i++) {
        int ans = kakezan(n);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1164