akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;

int a[3010],b[3010],dp[2][3010],mm1[3010],mm2[3010];
int main(){
	int N,T,S,I,O,hog,hma,res;
	cin>>N>>T>>S;
	for(int i=1;i<=N;i++){
		cin>>a[i]>>b[i];
	}
	memset(dp[0],-1,sizeof(dp[0]));
	I=0;O=1;
	dp[0][0]=0;
	for(int i=1;i<=N;i++){
		memset(dp[O],-1,sizeof(dp[O]));
		hma=-1;
		for(int j=0;j<=S;j++){
			hog=dp[I][j];
			if(j>=b[i]&&dp[I][j-b[i]]!=-1)hog=max(hog,dp[I][j-b[i]]+a[i]);
			dp[O][j]=hog;
			hma=max(hma,hog);
		}
		mm1[i]=hma;
		swap(I,O);
	}
	memset(dp[I],-1,sizeof(dp[I]));
	dp[I][0]=0;
	for(int i=N;i>=1;i--){
		memset(dp[O],-1,sizeof(dp[O]));
		hma=-1;
		for(int j=0;j<=T-S;j++){
			hog=dp[I][j];
			if(j>=b[i]&&dp[I][j-b[i]]!=-1)hog=max(hog,dp[I][j-b[i]]+a[i]);
			dp[O][j]=hog;
			hma=max(hma,hog);
		}
		mm2[i]=hma;
		swap(I,O);
	}
	res=0;
	mm1[0]=mm2[N+1]=0;
	for(int i=0;i<=N;i++){
		//cout<<i<<" "<<j<<" "<<mm1[i][j]<<" "<<mm2[i+1][j]<<endl;
		res=max(mm1[i]+mm2[i+1],res);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1240
n, m, c=map(int, input().split())
b=list(map(int, input().split()))
x=0
for _ in range(n):
	s=list(map(int, input().split()))
	z=c
	for i in range(m):
		z+=(s[i]*b[i])
	if z>0:
			x+=1
print(x)

Measured memory_bytes: 3060
#include<iostream>
#include<string>

using namespace std;

struct Dice{
	int P[6];
	void Roll(char a){
		
	int top;
	
	switch(a) {
		
		case 'E':
		top = P[0];
		P[0] = P[3];
		P[3] = P[5];
		P[5] = P[2];
		P[2] = top;
		break;
		
		case 'W':
		top = P[0];
		P[0] = P[2];
		P[2] = P[5];
		P[5] = P[3];
		P[3] = top;
		break;
		
		case 'S':
		top = P[0];
		P[0] = P[4];
		P[4] = P[5];
		P[5] = P[1];
		P[1] = top;
		break;
		
		default :
		top = P[0];
		P[0] = P[1];
		P[1] = P[5];
		P[5] = P[4];
		P[4] = top;
		break;	
	}
	
}
};

int main() {
	
	int n = 6;
	Dice S;
	
	while( cin >> S.P[0] ) {
		
		for(int i=1;i<n;i++)
		cin >> S.P[i];
		
		string Action;
		cin >> Action;
		
		for(int i=0;i<Action.length();i++)
		S.Roll(Action[i]);
		
		cout << S.P[0] << "\n";
		
	}
	
	return 0;
}



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

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

    int n;
    while(cin >> n){
        if(n == 0) return 0;
        vector<bool> F(n + 1, true);
        for(int i = 2; i <= (int)sqrt(n); i++){
            if(F[i]){
                for(int j = i + i; j <= n; j += i){
                    F[j] = false;
                }
            }
        }

        int ans = 0;
        for(int i = 2; i <= n / 2; i++){
            if(F[i] and F[n - i]) ans++;
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3036
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	ans := 1
	cnt := 0
	for i := 1; i < n+1; i++ {
		j := i
		t := 0
		for j > 0 {
			if j%2 != 0 {
				break
			}
			j /= 2
			t++
		}
		if t > cnt {
			cnt = t
			ans = i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
    int a,b;
    cin >> a >> b;
    if(a+b==15){
        cout << "+";
    }else if(a*b==15){
        cout << "*";
    }else{
        cout << "x";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  if(b == 1){
    cout << 0 << endl;
    return 0;
  }

  if( a >= b ){
    cout << 1 << endl;
    return 0;
  }

  int ans = 1;
  int nownum = a-1;
  while(nownum<b){
    if( nownum + a >= b ){
      ans += 1;
      nownum += a;
    }else{
      ans += 1;
      nownum += a - 1;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
vi ea(100000,0),eb(100000,0),ec(100000,0);
ll x,y,a,b,c;
int main( ){
    cin>>x>>y>>a>>b>>c;
    rep(i,0,a)cin>>ea[i];
    rep(i,0,b)cin>>eb[i];
    rep(i,0,c)cin>>ec[i];
    sort(ea.begin(),ea.end(),greater<int>());
    sort(eb.begin(),eb.end(),greater<int>());
    sort(ec.begin(),ec.end(),greater<int>());
    vll res;
    rep(i,0,x)res.push_back(ea[i]);
    rep(i,0,y)res.push_back(eb[i]);
    rep(i,0,c)res.push_back(ec[i]);
    sort(res.begin(),res.end(),greater<int>());
    ll ans=0;
    rep(i,0,x+y){
      ans+=res[i];
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 7664
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void){
  int i;
  char str[201];

  fgets(str, 201, stdin);
  str[strlen(str)-1] = '\0';
  for(i = 0; str[i] != '\0'; i++){
    str[i] = toupper((int)str[i]);
  }
  puts(str);
  return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    rep(i, N) {
        string S;
        cin >> S;
        mp[S]++;
    }
    int ma = -1;
    for (auto p : mp) {
        ma = max(p.second, ma);
    }

    vector<string> X(0);
    for (auto p : mp) {
        if (p.second == ma) X.push_back(p.first);
    }
    sort(all(X));
    for (int i = 0; i < X.size(); i++) {
        cout << X[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 26992
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  int N;
  cin >> N;
  int t = numeric_limits<int>::max(), answer = 0;
  for (int i = 1; i < N; i++) {
    int B;
    cin >> B;
    answer += min(t, B);
    t = B;
  }
  answer += t;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3640
while True:
	try:
		A=[int(i) for i in input().split()]
		B=[int(i) for i in input().split()]
		#Hit
		hit=0
		for i in range(len(A)):
			if A[i]==B[i]:
				hit+=1
		#Blow
		blow=0
		for i in range(len(A)):
			for j in range(len(A)):
				if i!=j:
					if A[i]==B[j]:
						blow+=1

		print(hit,blow)



	except EOFError:
		break

Measured memory_bytes: 7752
N, M, S = map(int,input().split())
ubab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

from heapq import heappush, heappop

routes = [[] for _ in range(N)]
max_money = 0
for u, v, a, b in ubab:
    routes[u-1].append([b, -a, v-1]) #★注意★[コスト、お金、要素]
    routes[v-1].append([b, -a, u-1])
    if a > max_money:
        max_money = a

for i, (c, d) in enumerate(cd):
    routes[i].append([d,+c,i])

max_pocessing = max_money * (N-1)

minimum = [[10e+1000 for _ in range(max_pocessing+1)] for _ in range(N)] 
if S>max_pocessing:
    S = max_pocessing
minimum[0][S] = 0
last_num = 0
last_money = S # [地点番号、所持金]
hp = []


while True:
    for cost, money, num in routes[last_num]:
        if last_money+money >= max_pocessing:
            money = max_pocessing - last_money
        if minimum[num][last_money+money] == 10e+1000:
            heappush(hp, (minimum[last_num][last_money]+cost, last_money+money, num))    
    while len(hp)>0:
        candidate_cost, candidate_money, candidate_num = heappop(hp)
        if minimum[candidate_num][candidate_money] == 10e+1000 and candidate_money >= 0:
            break
    else:
        break
    last_num = candidate_num
    last_money = candidate_money
    minimum[candidate_num][candidate_money] = candidate_cost

for each_minimum in minimum[1:]:
    print(min(each_minimum))


Measured memory_bytes: 123200
n = int(input())
a = list(map(int,input().split()))
sum = 0
c_1 = 0
c_2 = 0
for i in range(n):
    sum += a[i]

for i in range(n):
    c_1 += a[i]
    if c_1 * 2 >= sum:
        break
for i in range(n):
    c_2 += a[n - i - 1]
    if c_2 * 2 >= sum:
        break
    
if c_1 * 2 - sum >= c_2 * 2 - sum:
    print(c_2 * 2 - sum)
else:
    print(c_1 * 2 - sum)

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

int main(){
	int n,t;
	cin>>n>>t;
	vector<int> a(n);
	for(int i = 0;i<n;i++){
		cin>>a[i];
	}
	
	int ans = 0;
	
	for(int i = 0;i<n-1;i++){
		if(a[i+1]-a[i]<t){
			ans+=(a[i+1]-a[i]);
		}else{
			ans+=t;
		}
	}
	ans+=t;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

vector<int> to[100005];

int main(){
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
 
  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v]+1;
      pre[u] = v;
      q.push(u);
    }
  }
 
  cout << "Yes" << endl;
  rep(i,n) {
    if (i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}

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

typedef long long int ll;
using namespace std;
int main(){
	int H;
	cin>>H;
	int a,b,c,d;
	a=H/1000;
	b=(H-a*1000)/100;
	c=(H-a*1000-b*100)/10;
	d=H-a*1000-b*100-c*10;
	if(a==b||b==c||c==d){
		cout<<"Bad"<<endl;
	}else{
		cout<<"Good"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
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();
        double H = sc.nextDouble();
        double M = sc.nextDouble();
        sc.close();

        double Hx = A * Math.sin(Math.toRadians(360 * (H + M / 60) / 12));
        double Hy = A * Math.cos(Math.toRadians(360 * (H + M / 60) / 12));

        double Mx = B * Math.sin(Math.toRadians(360 * M / 60));
        double My = B * Math.cos(Math.toRadians(360 * M / 60));

        double x = (Hx - Mx);
        double y = (Hy - My);

        System.out.println(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
    }
}

Measured memory_bytes: 37448
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    bool x=true,y=true;
    for(int i=0;i<s.length();i++){
        if(i%2==1){
            if(s[i]-'R'==0) x=false;
        }
        else{
            if(s[i]-'L'==0) y=false;
        }
    }
    if(x&&y) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

int main()
{
  FAST();
  int n;
  int a[300];
  cin >> n;
  int ans = 0;
  bool f = true;
  rep(i,n){
    cin >> a[i];
    if(a[i] & 1)f = false;
  }

  while(f){
    ++ans;
    rep(i,n){
      a[i] /= 2;
      if(a[i] &1){
        f = false;
        break;
      }
    }
  }
  outl(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	int m=max(a,max(b,c));
	if((m*3-(a+b+c))%2==0)cout<<(m*3-(a+b+c))/2;
	else cout<<(m*3-(a+b+c))/2+2;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
  int i, j = 0, d = 0;
  int ATC_COUNT[10] = {0,0,0,0,0,0,0,0,0,0};
  char STRING[10];
  scanf("%s", STRING);
  for(i=0; i<=10; i++){
    if(STRING[i] == 'A' || STRING[i] == 'G' || STRING[i] == 'C' || STRING[i] == 'T') {
      ATC_COUNT[i] = 1;
    }
  }
  for(i=0; i<=10; i++) {
  	if(ATC_COUNT[i] == 1){
  		j++;
  	}
  	if(j >= d){
  		d = j;
  	}
  	if(ATC_COUNT[i] == 0){
  		j = 0;
  	}
  }
	printf("%d",d);
  return 0;
}


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

int n, p[int(1e5+1)];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	int cnt = 0;
	for(int i = 1; i <= n; i++) if(i == p[i]) {
		if(i > 1 && p[i-1] == i-1) swap(p[i], p[i-1]);
		else swap(p[i], p[i+1]);
		++cnt;
	}
	cout << cnt;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 1;
        String last = s.substring(0, 1);
        int index = 1;
        int length = 1;

        while (index + length <= s.length()) {
            String v = s.substring(index, index + length);
            if (last.equals(v)) {
                length++;
            } else {
                last = v;
                index += length;
                length = 1;
                ans++;
            }
        }

        System.out.println(ans);
    }
}

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

int main() {
	string x;
	int tmp, sum;

	while(1){
		cin >> x;
		if (x == "0") break;

		sum = 0;
		
		for (int i = 0; i < x.size(); i++){
			sum += x[i] - '0';
		}

		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3184
# 早い方が価値は元帥。小さい順に投入する。

import sys
n = sys.stdin.readline()
v = sys.stdin.readline()
n = int(n)
v = v.split()
v = sorted([int(x) for x in v], reverse=True)
ans = sum([(v[i] * (1 / 2 ** (i+1))) for i in range(0,n)]) + v[(n-1)] * (1 / 2 ** (n))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ABC048-C, 1128, 
	int n, x; cin >> n >> x;
	vector<ll> v(n), s(n - 1);
	rep(i, n) {
		cin >> v[i];
		if (i != 0) s[i - 1] = v[i - 1] + v[i];
	}
	ll ans = 0;
	if (v[0] > x) {
		ans += v[0] - x;
		s[0] -= v[0] - x;
	}
	rep(i, n - 1) {
		if (s[i] > x) {
			ans += ll(s[i] - x);
			if (i != n - 2) {
				s[i + 1] -= s[i] - x;
			}
		}
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll h;
    cin>>h;
    ll ans = 0;
    ll m = 1;
    while(h>0)
    {
        h/=2;
        ans+=(m);
        m*=2;
    }
    cout<<ans;
}

Measured memory_bytes: 256
import sys

(h, w, k) = map(int, sys.stdin.readline().strip().split())

list_matrix = [sys.stdin.readline()[:-1] for _ in range(h)]

ans = 0
for check_row in range(1 << h):  # 左ビットシフトした値で上限を規定
    for check_column in range(1 << w):
        num_black = 0
        for i in range(h):
            for j in range(w):
                if (check_row >> i) & 1 == 0 and (check_column >> j) & 1 == 0 and list_matrix[i][j] == '#':
                    num_black += 1
        if num_black == k:
            ans += 1

print(ans)

Measured memory_bytes: 73560
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,l,r) for(int i=(l);i<(r);i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// g++ -std=c++11 prac.cpp 
int main(){
    ll a,b,x=0,y=0,z=0,n,m=0,k,ans=0,h,w,sum=0,Max=-1e9-1,cnt=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n >> s;
    rep(i,n-2){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
            ans++;
    }
    cout << ans << endl;
    return 0;
}


 

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

using namespace std;

int main()
{
  int N, K; cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; ++i) {
    cin >> l[i];
  }

  sort(l.begin(), l.end(), greater<int>());

  int ans = 0;
  for (int i = 0; i < K; ++i) {
    ans += l[i];
  }

  cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int N, u[1000001], v[1000001], L, O, q[1000001];
char a[1000001], b[1000001];
int main()
{
	scanf("%d%s%s", &N, a + 1, b + 1);
	if (std::equal(a + 1, a + N + 1, b + 1, b + N + 1))
	{
		puts("0");
		return 0;
	}
	for (int i = N, last = N + 1; i; i--)
		if (b[i - 1] != b[i])
		{
			do last--; while (last && (last > i || a[last] != b[i]));
			if (!last)
			{
				puts("-1");
				return 0;
			}
			u[++L] = last;
			v[L] = i;
		}
	int H = 1, T = 0;
	for (int i = 1; i <= L; i++)
	{
		q[++T] = u[i] + i;
		while (H <= T && q[H] - i >= v[i])
			H++;
		O = std::max(O, T - H + 2);
	}
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
 
#define sd(mark) scanf("%d",&mark)
#define ss(mark) scanf("%s",mark)
#define sl(mark) scanf("%lld",&mark)
#define debug(mark) printf("check%d\n",mark)
#define clr(mark) memset(mark,0,sizeof(mark))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define N 100010
string s;

int pre[N],post[N];

int main()
{
	clr(pre);clr(post);
	cin>>s;
	int i,j,n=s.length();
	for(i=2;i<n;i++)
	{
		pre[i]=pre[i-2];
		if(s[i]!=s[i-2])
			pre[i]=1;
	}
	for(i=n-3;i>=0;--i)
	{
		post[i]=post[i+2];
		if(s[i]!=s[i+2])
			post[i]=1;
	}
	if(pre[n-1]==0)
		return 0*printf("Second\n");
	bool f=0;
	for(i=1;i<n-1;i++)
	{
		if(s[i-1]==s[i+1])	continue;
		if(pre[i-1] || post[i+1])	continue;
		if(i>=2)
			if(s[i-2]!=s[i+1])	continue;
		if(i+2<n)
			if(s[i-1]!=s[i+2])	continue;
		f=1;
	}
	if(f)
		return 0*printf("First\n");
	if(s[0]==s[n-1])
		--n;
	if(n%2)
		printf("First\n");
	else
		printf("Second\n");
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
ll a, b;
int k;

int main() {
	while(~scanf("%lld %lld %d", &a, &b, &k) && a && b) {
		bool flg = 0;
		while(k--) {
			if(!flg) {
				if(a & 1) a--;
				b += a / 2;
				a /= 2;
			}
			else {
				if(b & 1) b--;
				a += b / 2;
				b /= 2;
			}
			flg ^= 1;
		}
		printf("%lld %lld\n", a, b);
	}
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int N = (int)1e5+77;
const int inf = (int) 1e9+77;
const ll mod = (ll) 998244353;
const ld pi = acos(-1);

int main() {
    fast;
    int n, a[3];
    vector<int> dp(3, 0);
    cin >> n;
    forn(i, n) {
        forn(j, 3) {
            cin >> a[j];
        }
        vector<int> new_dp(3, 0);
        forn(j, 3) {
            forn(k, 3) {
                if (j == k) continue;
                new_dp[k] = max(new_dp[k], dp[j] + a[k]);
            }
        }
        dp = new_dp;
    }
    int ans = 0;
    forn(i, 3) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N, T, E, x;
	int i, j;
	
	scanf("%d %d %d", &N, &T, &E);
	for (i = 0; i < N; i++){
		scanf("%d", &x);
		for (j = T - E; j <= T + E; j++){
			if (j % x == 0){
				printf("%d\n", i + 1);
				
				return (0);
			}
		}
	}
	printf("-1\n");
	
	return (0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

ll N;
ll ans = 0;
ll inf = string::npos;

void dfs(string n){
    if(stoll(n) > N) return;
    if(n.find('3') != inf && n.find('5') != inf && n.find('7') != inf) ans += 1;
    dfs(n + '3');
    dfs(n + '5');
    dfs(n + '7');
}

void solve(){

	cin >> N;
	dfs("3");
	dfs("5");
	dfs("7");
	print(ans);
	
}	

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
    
	return 0;
	
}


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

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

  if (n == 1) {
    cout << "Hello World" << endl;
  }
  else {
    int a,b;
    cin >> a >> b;
    
    a += b;

    cout << a << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class IDONTKNOWCSHARP
{
    public static void Main()
    {
        int num = int.Parse(Console.ReadLine());
        long[] values = Convert(Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
        int count = 0;
        List<(long, long, long)> list = new List<(long, long, long)>();

        Array.Sort(values);
        for (int i1 = 0; i1 < num-2; i1++)
        {
            for (int i2 = i1 + 1; i2 < num-1; i2++)
            {
                for (int i3 = i2 + 1; i3 < num; i3++)
                {
                    //    Console.WriteLine($"{values[i1] },{values[i2]},{values[i3]}");
                    if (values[i1] + values[i2] > values[i3] && values[i1] != values[i2] && values[i2] != values[i3])
                    {

                        //  if (!list.Any(x => x == (values[i1], values[i2], (values[i3]))))
                        //     {
                        list.Add((values[i1], values[i2], values[i3]));
                        count++;
                        //    }
                    }
                }
            }
        }


        Console.WriteLine(count);
      //  Console.ReadKey();
    }

    static long[] Convert(string[] str)
    {
        long[] temp = new long[str.Length];
        for (int i = 0; i < temp.Length; i++)
        {
            temp[i] = long.Parse(str[i]);
        }
        return temp;
    }
}

Measured memory_bytes: 37668
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, X, Y;
    cin >> N >> X >> Y;

    vi ans(N-1, 0);
    FOR(i, 1, N+1) FOR(j, 1, N+1) {
        if (i>=j) continue;
        int min_d = min(abs(j-i), min(abs(X-i) + 1 + abs(j-Y), abs(Y-i) + 1 + abs(j-X)));
        assert(INRANGE(min_d, 0, N-1));
        ans[min_d-1]++;
    }

    for (int a : ans) cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int main(){
  long long n,i,j,k,NN=1e6+10,M=1e9+7,pr[1010],r=0,a[100010],b[1010],x,ans=0;
  char p[1000010]={1,1};
  scanf("%lld",&n);
  for(i=2;i*i<NN;i++){
    if(p[i])continue;
    for(j=i*i;j<NN;j+=i)p[j]=1;
  }
  for(i=0;i*i<NN;i++){
    if(p[i])continue;
    pr[r++]=i;
  }
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
    x=a[i];
    for(j=0;j<r;j++){
      for(k=0;x%pr[j]==0;k++)x/=pr[j];
      if(b[j]<k)b[j]=k;
    }
    hin(x);
  }
  x=k=N[hout()];
  for(i=1;i<n;i++){
    j=N[hout()];
    if(x==j)continue;
    k=(k*j)%M;
    x=j;
  }
  for(i=0;i<r;i++){
    for(j=0;j<b[i];j++)k=(k*pr[i])%M;
  }
  //printf("%lld\n",k);
  //for(i=0;i<n;i++)printf("%lld\n",k*inv(a[i],M));
  for(i=0;i<n;i++)ans=(ans+(k*inv(a[i],M)%M))%M;
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);


int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

int lcm(int u,int v){
    int r = gcd(u,v);
    r = (u / r)*v;
    return r;
}
signed main(){
    int n;
    cin >> n;
    int ans = 1;
    REP(i,n){
        int t;
        cin >> t;
        ans = lcm(ans,t);
    }
    cout << ans << endl;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, d);
    int x = 0;
    if(a == 3) x += 100000;
    if(a == 2) x += 200000;
    if(a == 1) x += 300000;
    if(b == 3) x += 100000;
    if(b == 2) x += 200000;
    if(b == 1) x += 300000;
    if(a == 1 && b == 1) x += 400000;
    Cout(x);
}









Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

int a,b;

int main(){
    cin>>a>>b;
    for(int i=0;i<max(a,b);++i)cout<<min(a,b);
    cout<<endl;
}


Measured memory_bytes: 256
def main():
    X, Y = map(int, input().split())
    flag = False
    for i in range(0, X+1):
        for j in range(0, X+1):
            if i + j == X and i*2 + j*4 == Y:
                flag = True
    
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

const ll MOD = 1000000000 + 7;
int N, C;
int A[410], B[410];
ll table[410][410], dp[410][410];

ll rec(int idx, int rest){
    if(idx == N){
        return rest == 0 ? 1 : 0;
    }

    if(dp[idx][rest] != -1ll){
        return dp[idx][rest];
    }

    ll res = 0ll;
    for(int i=0;i<=rest;++i){
        res = (res + (table[B[idx]][i] - table[A[idx]-1][i] + MOD) * rec(idx + 1, rest - i) % MOD) % MOD;
    }

    return dp[idx][rest] = res;
}

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

    for(int i=1;i<=400;++i){
        ll x = 1;
        
        for(int j=0;j<=400;++j){
            table[i][j] = (table[i - 1][j] + x) % MOD;
            x = x * i % MOD;
        }
    }
    
    std::cin >> N >> C;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    for(int i=0;i<N;++i){
        std::cin >> B[i];
    }

    memset(dp, -1ll, sizeof(dp));
    ll res = rec(0, C);
    std::cout << res << std::endl;
}


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

int main(void) {
	string com, str;
	int n;
	set<string> s;
	cin >> n;
	while (n--) {
		cin >> com >> str;
		if (com == "insert") 
			s.insert(str);
		else if (com == "find") {
			if (s.find(str) != s.end())
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
	}
}


Measured memory_bytes: 32560
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

    int val = 0;
    if(k < a){
        val = k;
    } else {
        if(k < a + b){
            val = a;
        } else {
            int mC = k - (a + b);
            val = a - mC;
        }
    }

    cout << val << "\n";

    return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int dp[1010][1010];

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> d(n), c(m);
    rep(i, 0, n) cin >> d[i];
    rep(i, 0, m) cin >> c[i];

    rep(i, 0, n){
        rep(j, 0, m){
            if(j != 0){
                dp[i + 1][j] = min(dp[i + 1][j - 1], dp[i][j - 1] + d[i]*c[j]);
            }else{
                if(i == 0) dp[1][0] = d[0]*c[0];
                else dp[i + 1][0] = 1e9;
            }
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }
    cout << dp[n][m - 1] << endl;
}

Measured memory_bytes: 7616
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt(), W = sc.nextInt();
    String[][] S = new String[H][W];
    int ansH = -1,ansW = -1;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        S[i][j] = sc.next();
        if(S[i][j].equals("snuke")){
          ansH = i;
          ansW = j;
        }
      }
    }
    System.out.println((char)('A'+ansW)+""+(ansH+1));
  }
}

Measured memory_bytes: 23252
#include<iostream>
#include<memory>
#include<cstdio>

using namespace std;

int rest;
int leak;

struct M{
  int size;
  M(int c):size(c){
    rest-=c;
  }
  ~M(){
    leak+=size;
  }
};

typedef shared_ptr<M> P;


P ptr[128];
char line[301];
char *p;

P expr(){
  if(*p=='('){
    p++;
    P r=expr();
    p++;
    return r;
  }else if(*p=='m'){
    p+=7;
    int r,n;
    sscanf(p,"%d%n",&r,&n);
    p+=n+1;
    if(r>rest){
      return nullptr;
    }else{
      return P(new M(r));
    }
  }else if(*p=='c'){
    p+=6;
    P r=expr();
    p++;
    if(r){
      if(r->size==0)throw 0;
      if(rest<r->size){
	return nullptr;
      }else{
	return P(new M(r->size));
      }
    }else{
      return nullptr;
    }
  }else if(p[1]=='U'){
    p+=4;
    return nullptr;
  }else{
    char c=*p;
    p++;
    if(*p!='='){
      return ptr[c];
    }else{
      p++;
      return ptr[c]=expr();
    }
  }
}

void l(){
  if(*p=='f'){
    p+=5;
    P r=expr();
    p++;
    if(r){
      if(r->size==0)throw 0;
      rest+=r->size;
      r->size=0;
    }
  }else{
    expr();
  }
}

int main(){
  cin>>rest;
  for(auto &e:ptr){
    e=P(new M(0));
  }
  try{
    while(cin>>line){
      p=line;
      l();
    }
    cout<<leak<<endl;
  }catch(...){
    cout<<"Error"<<endl;
  }
}

Measured memory_bytes: 1320
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N = I()
dist = [[100]*(N+1) for _ in range(N+1)]  # 2点間の最短距離
edges = {}

for i in range(N-1):
    a,b = MI()
    dist[a][b] = 1
    dist[b][a] = 1
    edges[(a,b)] = i
    edges[(b,a)] = i

for i in range(1,N+1):
    dist[i][i] = 0

for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])

M = I()
A = []  # uとvを結ぶ経路上にある辺の集合
for _ in range(M):
    u,v = MI()
    B = set()
    while True:
        if dist[u][v] == 1:
            B.add(edges[(u,v)])
            break
        else:
            for i in range(1,N+1):
                if dist[u][i] == dist[u][v]-1 and dist[i][v] == 1:
                    B.add(edges[(i,v)])
                    v = i
                    break
    A.append(B)

# 包除原理

ans = 0
for i in range(2**M):
    C = set()
    a = 0
    for j in range(M):
        if (i >> j) & 1:
            C |= A[j]
            a += 1
    l = len(C)
    a %= 2
    ans += (-1)**a * 2**(N-1-l)

print(ans)


Measured memory_bytes: 74076
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main() { 
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, A;
	cin >> N >> A;
	ll x[60];
	REP(i, 0, N) cin >> x[i];
	ll dp[60][60][3000];
	REP(i, 0, 60) REP(j, 0, 60) REP(k, 0, 3000) dp[i][j][k] = 0;
	dp[0][0][0] = 1;
	REP(i, 0, N) {
		REP(j, 0, N) {
			REP(k, 0, 3000) {
				if (dp[i][j][k] == 0) continue;
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
			}
		}
	}
	ll ans = 0;
	REP(i, 1, N + 1) {
		ans += dp[N][i][i*A];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 84608
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
//#include <cmath>
//#include <cstdlib>
using namespace std;


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

	/*calc*/
    for(int i = 1; i <= k; i++){
    	if(i % 2 != 0){
    		if(a % 2 != 0){
    			a -= 1;
    			b += a/2;
    			a /= 2;
    		}
    		else{
    			b += a/2;
    			a /= 2;
    		}
    	}
    	else{
    		if(b % 2 != 0){
    			b -= 1;
    			a += b/2;
    			b /= 2;
    		}
    		else{
    			a += b/2;
    			b /= 2;
    		}
    	}
    }

    /*output*/
	cout<< a <<" "<< b <<endl;
    return 0;
}


Measured memory_bytes: 256
#[test]
fn test_solve() {
   assert_eq!(solve("1\n3 7\n"), "2\n");
   assert_eq!(solve("4\n13 13\n7 11\n7 11\n2017 2017\n"), "1\n0\n0\n1\n");
   assert_eq!(solve("6\n1 53\n13 91\n37 55\n19 51\n73 91\n13 49\n"), "4\n4\n1\n1\n1\n2\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    const MAX:usize = 50_000;

    let ipm = is_prime_table(2*MAX);
    let mut sum = vec![0; MAX+1];
    for i in 0..MAX {
        sum[i+1] = sum[i];
        if ipm[2*i+1] && ipm[i+1] {
            sum[i+1] += 1;
        } 
    }
    
    let mut ret = String::new();
    use std::fmt::Write;
    
    let q: usize = sc.read();
    for _ in 0..q {
        let l: usize = sc.read();
        let r: usize = sc.read();
        let (l, r) = (l >> 1, r >> 1);
        writeln!(&mut ret, "{}", sum[r+1] - sum[l]).unwrap();
    }
    
    ret
}
fn is_prime_table(n: usize) -> Vec<bool> {
    let mut ipm = vec![true; n + 1];
    ipm[0] = false;
    ipm[1] = false;
    let nsr = (n as f64).sqrt() as usize;
    for p in 2..nsr + 1 {
        if ipm[p] {
            let mut mpp = 2 * p;
            while mpp <= n {
                ipm[mpp] = false;
                mpp += p;
            }
        }
    }
    ipm
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

Measured memory_bytes: 6780
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[A];
        int[] b = new int[B];
        int[][] c = new int[M][3];
        int mina = Integer.MAX_VALUE;
        int minb = Integer.MAX_VALUE;
        for (int i = 0; i < A; i++) {
            a[i] = sc.nextInt();
            if(a[i] < mina) mina = a[i];
        }
        for (int i = 0; i < B; i++) {
            b[i] = sc.nextInt();
            if(b[i] < minb) minb = b[i];
        }
        for (int i = 0; i < M; i++) {
            c[i][0] = sc.nextInt()-1;
            c[i][1] = sc.nextInt()-1;
            c[i][2] = sc.nextInt();
        }
        int ans = mina + minb;
        for (int i = 0; i < M; i++) {
            int t = a[c[i][0]] + b[c[i][1]] - c[i][2];
            if(t < ans) ans = t;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 161872
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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


#define MAX_N 200000

ll bit[MAX_N+1];

void init(int n){
    for(int i = 0; i < n; i++){
        bit[i] = 0;
    }
}

// indexが0~iまでの和を求める。
ll sum(int i){
    ll s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & (-i);
    }
    return s;
}

// iがindex, xが加える値, nが全体の配列の大きさ
void add(int i, ll x, int n){
    while(i <= n){
        bit[i] += x;
        i += i & (-i);
    }
}



int main(){
    string s;
    cin >> s;
    int n = s.length();

    int count[26], lcount[26];
    fill(count, count+26, 0);
    fill(lcount, lcount+26, 0);

    for(int i = 0; i < n; i++){
        count[s[i] - 'a']++;
    }

    int odd_count = 0;
    for(int i = 0; i < 26; i++){
        if(count[i] % 2 == 1){
            odd_count++;
        }
    }

    if(n % 2 == 0 && odd_count > 0){
        cout << -1 << endl;
        return 0;
    }
    else if(n % 2 == 1 && odd_count > 1){
        cout << -1 << endl;
        return 0;
    }

    ll res = 0, tmp = 0;
    vector<int> l_list, r_list;

    map<P, ll> m;
    for(int i = 0; i < n; i++){
        int c = s[i] - 'a';
        if(lcount[c] < count[c] / 2){
            lcount[c]++;
            res += tmp;
            l_list.push_back(c);
            m[P(c, lcount[c])] = i - tmp;
        }
        else if(count[c] % 2 == 1 && lcount[c] == (count[c] - 1) / 2){
            res += tmp;
            lcount[c]++;
            tmp++;
        }
        else{
            tmp++;
            r_list.push_back(c);
        }
    }
    reverse(r_list.begin(), r_list.end());

    int rcount[26];
    fill(rcount, rcount+26, 0);

    vector<int> v;
    for(int i = 0; i < r_list.size(); i++){
        int c = r_list[i];
        rcount[c]++;
        v.push_back(m[P(c, rcount[c])]);
    }

    init(n / 2);
    for(int i = 0; i < v.size(); i++){
        res += i - sum(v[i]+1);
        add(v[i]+1, 1, n / 2);
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 8848
#include <iostream>
#include <cstdio>
using namespace std;
const int nmax = 200100;
int N, R, A[nmax];
unsigned long long ans;
int main()
{
   cin >> N;
   for (int i =0 ; i < N; ++i)
   {
        cin >> A[i];
   }
   A[N] = 2<<20-1;
   int xorsum = 0;
   for(int i = 0; i < N; ++i)
   {
    if(i == R) xorsum = 0;
    while(R < N && (xorsum & A[R]) == 0)
       xorsum^=A[R], R++;
    ans+=(R-i);
    //cout << i << ' ' << R << ' ' << ans << ' ' << xorsum << endl;
    //cout << xorsum << ' ' << A[R] << ' ' << (xorsum & A[R] ) << endl;
    xorsum^=A[i];
   }
   cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>

typedef long long int ll;


using namespace std;

double weight,tall;


int main(){
	int n;
	while(scanf("%d,%lf,%lf",&n,&weight,&tall)!=EOF){
		if(weight>=25.0*tall*tall)cout<<n<<endl;
	}
}

Measured memory_bytes: 1232
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	vector<int> num(3);
	rep(i, 3) {
		cin >> num[i];
	}
	sort(num.begin(), num.end());
	int ans = 0;
	if ((num[1] - num[0]) % 2 != 0) {
		num[0]++;
		num[2]++;
		ans++;
	}
	ans += (num[1] - num[0]) / 2;
	ans += num[2] - num[1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

int main(){

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

    if(a < b){
        for(int i = 0; i < b; i++){
            cout << a ;
        }
        cout << endl;
    }
    else{
        swap(a, b);
        for(int i = 0; i < b; i++){
            cout << a ;
        }
        cout << endl;

    }

}

Measured memory_bytes: 256