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

void Slimes()
{
  int n;
  string s;
  cin >> n >> s;
  int res = n;
  for (int i = 0; i < n-1; i++)
  {
    if (s[i] == s[i+1]) res -= 1;
  }

  cout << res << endl;
}

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

Measured memory_bytes: 512
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto x = RD;
	long ans = x / 11 * 2;
	if (x % 11 != 0)
		ans += x % 11 <= 6 ? 1 : 2;

	writeln(ans);
	stdout.flush();
	//readln();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    map<ll, ll> mp1, mp2;
    rep(i, N){
        mp1[A[i]+i]++;
        mp2[i-A[i]]++;
    }
    ll ans = 0;
    for(auto &e: mp1){
        ans += e.second*(mp2[e.first]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 39528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> switches(n); //n番目のスイッチとmbit目の豆電球が繋がっている
    rep(i,m){
        int k;
        cin >> k; //何個のスイッチに繋がっているか取得
        rep(j,k){ //繋がっているスイッチの番号を取得
            int s;
            cin >> s;
            s--; // 0 index
            switches[s] |= 1 << i; //i=2 s=1の場合、switches[1] = 000ならswitches[1] = 100になる
        }
    }

    int p=0;

    rep(i,m){//ibit目の電球のスイッチのあまり
        int x;
        cin >> x;
        p |= x << i;
    }

    int ans=0;
    
    for(int s=0;s<(1<<n); s++){//n=3なら(1<<n)==1000なので、000~111まで回せる スイッチの押し方を全探索
        int t=0;//押してるスイッチの数(bit毎に電球に対応したスイッチが押された数を表している)
        rep(i,n){
            if(s >> i & 1){ //s=110でi=2ならs>>iは1、&1は最下位ビットが立っているかどうか判定
                t ^= switches[i];
            }
        }
        if(t==p){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::map;
using std::set;
const int mod = 1e9 + 7, N = 1e5 + 1;
int n;
vector < int > v;
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> n;
 int a;
 For( i, 1, n )
  cin >> a,
  v.push_back( a );
 std::sort( v.begin( ), v.end( ), std::less < int > ( ) );
 int cnt = std::unique( v.begin( ), v.end( ) ) - v.begin( );
 cout << ( ( ( n - cnt ) & 1 ) ? cnt - 1 : cnt ); 
 return 0;
}

Measured memory_bytes: 3932
from math import sqrt

N, P = map(int, input().split())
primes = []
for i in range(2, 1+int(sqrt(P))):
    count = 0
    while P % i == 0:
        P //= i
        count += 1
    primes.append((i, count))
if P > 1:
    primes.append((P, 1))

ans = 1
for p, k in primes:
    ans *= p ** (k // N)
print(ans)


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

using namespace std;

int ans, n, m, k[40], a[30][30];
int vote[30];
bool b, bb;

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		cin >> k[i];
		for(int j = 0; j < k[i]; ++j){
			cin >> a[i][j];
			vote[a[i][j] - 1]++;
		}
	}
	for(int f = 0; f < m; ++f){
		b = true;
		for(int i = 0; i < n; ++i){
			bb = false;
			for(int j = 0; j < k[i]; ++j){
				if(a[i][j] == f + 1){
					bb = true;
					break;
				}
			}
			if(!bb){
				b = false;
				break;
			}
		}
		if(b) ans++;
	}
	cout << ans << endl;
}

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();
        int c = sc.nextInt();
        double S = (double)a * b * Math.sin(Math.toRadians((double)c)) / 2;
        double _c = Math.sqrt(a * a + b * b - 2 * (double)a * b * Math.cos(Math.toRadians((double)c)));
        double L = a + b + _c;
        double h = (double)b * Math.sin(Math.toRadians((double)c));
        System.out.println(S);
        System.out.println(L);
        System.out.println(h);
    }
}


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


int main() {
  vector<int> a(5);
  rep(i, 5) cin >> a[i];
  
  int m = 1000000;
  for(int k : a) {
    if(k%10 != 0) m = min(k%10, m);
  }
  
  rep(i, 5) {
  	if(a[i]%10 != 0) a[i] = (int(a[i]/10)+1)*10;
  }
  
  int ans = 0;
  for(int k :a) ans += k;
  ans -= (10 - m);
  if(ans > 10000) ans += (10 - m);
  
  cout << ans <<endl;
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<vector>
using namespace std;

int min(const int& a, const int& b){
    return a < b? a: b;
}
int getMinUtil(vector<int>& tree, const int& L, const int& R, const int& i, const int& l, const int& r){
    if(i >= tree.size() || l > r){
        return INT_MAX;
    }
    if(r < L || l > R){
        return INT_MAX;
    }
    if(l >= L && r <= R){
        return tree[i];
    }
    int m = l + (r - l)/2;
    return  min(getMinUtil(tree, L, R, 2*i+1, l, m), getMinUtil(tree, L, R, 2*i+2, m+1, r));
}

int getMin(vector<int>& tree, const int& n, const int& L, const int& R){
    return getMinUtil(tree, L, R, 0, 0, n-1);
}

vector<int> buildTree(vector<int>& A, const int& max_size, const int& n){
    vector<int> tree (max_size, INT_MAX);
    for(int i = 0; i < A.size(); i++){
        tree[i+n-1] = A[i];
    }
    for(int i = n-2; i >= 0; i--){
        tree[i] = min(tree[2*i+1], tree[2*i+2]);
    }
    return tree;
}

int main(){
    int n, l;
    scanf("%d %d", &n, &l);
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    int h = ceil(log2(n)) + 1;
    int max_size = pow(2, h) - 1;
    vector<int> tree = buildTree(A, max_size, pow(2, h-1));
    vector<int> res;
    for(int i = 0; i < n-l+1; i++){
        res.push_back(getMin(tree, pow(2, h-1), i, i+l-1));
    }
    for(int i = 0; i < res.size()-1; i++){
        printf("%d ", res[i]);
    }
    printf("%d\n", res[res.size()-1]);
}



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

long long dp[110][100010];

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

    int n,w;
    cin>>n>>w;


    for(int i=0;i<101;i++)
        for(int j=0;j<100001;j++)
            dp[i][j]=LONG_MAX;


    int val[n],weight[n];

    for(int i=0;i<n;i++)
        cin>>weight[i]>>val[i];

    dp[0][0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=100000;j++)
        {
            if(dp[i][j]==LONG_MAX)
                continue;
            else
            {
                dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
                dp[i+1][j+val[i]]=min(dp[i+1][j+val[i]],dp[i][j]+weight[i]);
            }
        }
    }


    for(int i=100000;i>=0;i--)
    {
        if(dp[n][i]<=w)
        {
           cout<<i<<'\n';
            return 0;
        }
    }

    cout<<0<<'\n';

    return 0;

}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a; cin >> a;
	int arr[a + 50], n = 0, m = 0, now = 999999999;
	for(int i=0; i<a; i++)
	{
		cin >> arr[i];
		n = max(n, arr[i]);
	}
	for(int i=0; i<a; i++)
	{
		if(arr[i] == n) continue;
		int tmp = abs(arr[i] - n / 2);
		if(m % 2) tmp = min(abs(arr[i] - n / 2), abs(arr[i] - (n + 1) / 2));
		if(tmp < now)
		{
			now = tmp;
			m = arr[i];
		}
	}
	cout << n << ' ' << m << '\n';
	return 0;
}

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

typedef long long ll;

int main(void){
    ll N;
    cin >> N;
    vector<ll> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    
    int cnt = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                
                if(L[i] < L[j] && L[j] < L[k]){
                    if(L[i] != L[j] && L[j] != L[k]){
                        ll m = max({L[i],L[j],L[k]});
                        ll tmp = L[i] + L[j] + L[k] - m;
                        
                        if(tmp > m) cnt++;
                    }
                }
            }
        }
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20180305_AOJ
{
    class ALDS1_3D
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int[] levels = new int[line.Length + 1];
                for (int i = 1; i < levels.Length; i++)
                {
                    switch (line[i - 1])
                    {
                        case '\\':
                            levels[i] = levels[i - 1] - 1;
                            break;
                        case '_':
                            levels[i] = levels[i - 1];
                            break;
                        case '/':
                            levels[i] = levels[i - 1] + 1;
                            break;
                    }
                }

                List<int> lakes = new List<int>();
                for (int i = 0; i < levels.Length - 1; i++)
                {
                    if (levels[i] > levels[i + 1])
                    {
                        bool isLake = false;
                        int j = i + 1;
                        for (; j < levels.Length; j++)
                        {
                            if (levels[j] == levels[i])
                            {
                                isLake = true;
                                break;
                            }
                        }

                        if (isLake)
                        {
                            int d = 0;
                            int s = 0;
                            for (int k = i; k < j; k++)
                            {
                                switch (levels[k + 1] - levels[k])
                                {
                                    case -1:
                                        d++;
                                        break;
                                    case 1:
                                        d--;
                                        break;
                                }
                                s += d;
                            }
                            lakes.Add(s);
                            i = j - 1;
                        }
                    }
                }

                int total = lakes.Sum();
                Console.WriteLine(total);
                Console.Write(lakes.Count);
                for (int i = 0; i < lakes.Count; i++)
                {
                    Console.Write(string.Format(" {0}", lakes[i]));
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 9912
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

const int maxn = 100*1000+5;

int n;
ll l, a[maxn];

int main() {
    scanf("%d%lld", &n, &l);
    for (int i = 0; i < n; i++) scanf("%lld", a+i);
    for (int i = 0; i < n-1; i++) {
        if (a[i] + a[i+1] >= l) {
            printf("Possible\n");
            for (int j = 0; j < i; j++) printf("%d\n", j+1);
            for (int j = n-2; j > i; j--) printf("%d\n", j+1);
            printf("%d\n", i+1);
            return 0;
        }
    }
    printf("Impossible\n");
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin>>S;
 int a=0; 
  for (int i = 0; i <S.size()-2; i++) {
    
       if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
         a++;
       }
 
     
      
   }
   
    cout <<a<< endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args)
    {
        //変数
        int count=0;
        boolean sw=false;
        int max=Integer.MIN_VALUE;
        //int min=Integer.MAX_VALUE;
        long mmin=0;
        long answer=0;
        int tmp=0;
        List<Long> a=new ArrayList<>();

        long b=0;
        long c=0;
        //入力
        Scanner sc=new Scanner(System.in);
        long N=sc.nextLong();
        long A=sc.nextLong();
        long B=sc.nextLong();
        long C=sc.nextLong();
        long D=sc.nextLong();
        long E=sc.nextLong();
        //処理
        a.add(A);
        a.add(B);
        a.add(C);
        a.add(D);
        a.add(E);
        Collections.sort(a);
        mmin=a.get(0);
        if(N<A && N<B && N<C && N<D && N<E)
        {
            answer=5;
        }else
        {
            b=N/mmin;
            if(N%mmin!=0)
            {
               c=1;
            }
            answer=b+c+4;
        }
        //System.out.println(b);
        //System.out.println(c);
        /*
        Collections.sort(a);
        System.out.println(Arrays.toString(a.toArray()));
        */
        System.out.println(answer);
    }
}

Measured memory_bytes: 23764
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

	int n;
	cin >> n;
	vector<pair<int,int>> a(n);

	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		a[i] = mp(i+1, c);
	}

	sort(ALL(a), [](const pair<int, int>& x, const pair<int, int>& y) { return x.second < y.second; });

	for (int i = 0; i < n; i++) {
		cout << a[i].first << " ";
	}
	cout << endl;

    return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int n, m;

int main(){
	cin >> n;
	bool flag = false;
	for(int i=0;;i++){
		if(n>=10){
			if(n%10!=9)flag=true;
			m += 9;
			n /= 10;
		}else{
			m += n-1;
			break;
		}
	}
	if(flag==false){
		m++;
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b) = (v[0], v[1]);
    println!("{}", (a + b) % 24);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    // 7 6 5 4 3 2 1
    // 4 7 2 5 3 6
    //7+6+6+5+5+4
    int ans = 0;
    for(int i = 0; i < N-1; i++) {
        ans+=A[(i+1)/2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4836
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  ll ans = 0;
  cin >> n;
  string str;
  cin >> str;
  ll countR,countG,countB;
  countR=0;
  countG=0;
  countB=0;
  for (int i = 0; i < n; i++)
  {
    if(str[i]=='R'){
      countR+=1;
    }
    else if(str[i]=='G'){
      countG+=1;
    }
    else{
      countB+=1;
    }
  }
  ans = countR*countG*countB ;
  ll temp= n/3;
  ll count =0;
  for (int i = 1; i <= 2*temp; i++)
  {
    ll l=3+(2*(i-1));
    for (int x = 0; x < (n-l+1); x++)
    {
      if((str[x]!=str[x+(i)])&&(str[x]!=str[x+(2*i)])&&(str[x+(i)]!=str[x+(2*i)])){
        count+=1;
      }
    }
  }
  cout << ans-count;
}

Measured memory_bytes: 3196
#132b
N = int(input())
p_list = list(map(int, input().split()))

#pi−1, pi, pi+1の 3 つの数の中で、pi が 2 番目に小さい。
#pi (1<i<n) がいくつあるかを出力してください。
ans = 0

for i in range(1,N-1):
    #print(p_list[i-1],p_list[i],p_list[i+1])
    if (p_list[i-1] < p_list[i] and p_list[i] < p_list[i+1]) or (p_list[i-1] > p_list[i] and p_list[i] > p_list[i+1]):
        ans+=1

print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

const int N = 100010;

int n, i, x, y, z, mx, my, mz, ax, ay, az;

inline int maxim(int x, int y) {
    return (x > y ? x : y);
}

int main(){
    cin >> n;
    for (i = 1; i <= n; ++i) {
        cin >> x >> y >> z;
        ax = maxim(x + my, x + mz);
        ay = maxim(y + mx, y + mz);
        az = maxim(z + mx, z + my);
        mx = ax;
        my = ay;
        mz = az;
    }
    cout << maxim(maxim(mx, my), mz) << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 1e6 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int LN = 22;

long long n, m, u, v, k, t, q, x, d, p, a, b, c, s;


int arr[N];
int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
      cin >> arr[i];
      if (i > 0 and arr[i] == arr[i - 1]) continue;
      else {
         arr[i]--;
      }
   }
   
   for (int i = 1; i <= n - 1; ++i) {
      if (arr[i] > arr[i + 1]) {
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    long long ans = 0;
    for(int i = 0; i < K; i++) {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
vector<vector<ll> > G;
vector<bool> seen;
vector<ll> d;
vector<ll> f;
ll cnt=1;

void dfs(ll v){
    seen[v] = 1;

    rep(i,G[v].size()){
        if(seen[G[v][i]] == 0){
            dfs(G[v][i]);
        }
    }
    cnt++;
}

int main() {
    ll N,M;
    cin >>N>>M;
    G.resize(N);
    seen.resize(N);
    rep(i,M){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll ans=0;
    rep(i,N){
        if(seen[i]==0){
            cnt=0;
            dfs(i);
            chmax(ans,cnt);
        }
            
    }
    cout << ans << endl;


    return 0;
    

}

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

using namespace std;



int main() {
    int n;
    cin >> n;
    vector<string> input = {"AC", "WA", "TLE", "RE"};
    unordered_map<string, int> um;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        um[str]++;
    }
    for (auto ele : input) {
        cout << ele <<  " x " << um[ele] << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
#include<map>
#include<string>
#include<cstdio>

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

using namespace std;

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

int main(){
	for(int h,w;scanf("%d%d",&h,&w),h;){
		char D[10][21];
		rep(i,h) scanf("%s",D[i]);

		map<string,int> f;
		rep(i,h) rep(j,w) rep(k,8) { // ツスツタツーツトツ暗環置ツづ陛サツ古シ
			int y=i,x=j;
			string s;
			do{
				s+=D[y][x];
				if(s.length()>=2) ++f[s];
				y=(y+dy[k]+h)%h;
				x=(x+dx[k]+w)%w;
			}while(y!=i||x!=j);
		}

		string s_ans;
		map<string,int>::iterator it;
		for(it=f.begin();it!=f.end();++it) if(it->second>=2) {
			if(s_ans.length()<it->first.length()
			|| s_ans.length()==it->first.length() && s_ans>it->first) s_ans=it->first;
		}
		puts(s_ans==""?"0":s_ans.c_str());
	}

	return 0;
}

Measured memory_bytes: 27000
#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
 
#define repss(name, start, stop, step) for (int name = start; name < stop; name += step)
#define reps(name, start, stop) repss(name, start, stop, 1)
#define rep(name, stop) reps(name, 0, stop)
#define foreach(name, iterable) for (auto name = iterable.begin(); name != iterable.end(); name++)

using namespace std;
 
int main() {
  int N;
  cin >> N;

  int t;
  vector<int> A, B, C;
  rep(i, N) { cin >> t; A.push_back(t); }
  rep(i, N) { cin >> t; B.push_back(t); }
  rep(i, N) { cin >> t; C.push_back(t); }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  long long ans = 0;
  for (auto Bi = B.begin(); Bi != B.end(); Bi++) {
      auto Ae = lower_bound(A.begin(), A.end(), *Bi);
      auto Cs = lower_bound(C.begin(), C.end(), *Bi + 1);
      ans += (Ae - A.begin()) * (C.end() - Cs);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1784
import heapq

xs,ys,xt,yt = map(int,input().split())

N = int(input())

xyr = []
xyr.append([xs,ys,0])

#0からN+1までの距離

for i in range(N):

    x,y,r = map(int,input().split())
    xyr.append([x,y,r])

xyr.append([xt,yt,0])

d = [[float("inf")] * (N+2) for i in range(N+2) ]

for i in range(N+2):

    for j in range(N+2):

        nowd = ((xyr[i][0] - xyr[j][0]) ** 2 + (xyr[i][1] - xyr[j][1]) ** 2) ** 0.5
        nowd = max ( 0 , nowd - xyr[i][2] - xyr[j][2] )

        d[i][j] = nowd
        d[j][i] = nowd

ans = [float("inf")] * (N+2)
ans[0] = 0
used = [False] * (N+2)

while True:

    v = -1

    #未到達の点に関して最も数値の小さい点を選ぶ
    for i in range(N+2):
        if not used[i] and (v == -1 or ans[v] > ans[i]):
            v = i
    
    if v == -1:
        break
    
    used[v] = True
    for i in range(N+2):
        ans[i] = min(ans[i] , ans[v] + d[v][i])

#print (used,ans)
print (ans[-1])
    


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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
str S, T, U; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> a >> b >> c;

	cout << c <<" "<< a <<" "<< b << endl;



	return 0;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())
flg = True
for i in range(2 * max(A, C) + 1):
    if i % 2 == 0:
        C -= B
        if C <= 0:
            flg = False
            print('Yes')
    else:
        A -= D
        if A <= 0:
            flg = False
            print('No')
    if not flg:
        break


Measured memory_bytes: 9124
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a!=b&&a!=c&&b!=c) cout<<3;
  else if(a==b&&a==c) cout<<1;
  else cout<<2;
  cout<<endl;
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::vector<uint32_t> ref(N), P(N), Q(N);
  for (size_t i = 0; i < N; i++) std::cin >> P[i];
  for (size_t i = 0; i < N; i++) std::cin >> Q[i];
  for (size_t i = 0; i < N; i++) ref[i] = i + 1;

  uint32_t i = 1, a = 0, b = 0;
  do {
    if (ref == P) a = i;
    if (ref == Q) b = i;
    i++;
  } while (a * b == 0 && std::next_permutation(ref.begin(), ref.end()));

  std::cout << (b > a ? b - a : a - b) << std::endl;
  return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    rep(i, n) {
        if (a[i] == b[i] && a[i] == c[i]) {
            // 何もしない
        } else if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) {
            cnt += 2;
        } else {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC_147 solver = new TaskC_147();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC_147 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[][] x = new int[n][n - 1];
            int[][] y = new int[n][n - 1];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                for (int j = 0; j < a[i]; j++) {
                    x[i][j] = in.nextInt() - 1;
                    y[i][j] = in.nextInt();
                }
            }

            int options = (int) Math.pow(2, n);
            int nbHonests = 0;
            int maxHonests = 0;
            for (int option = 0; option < options; option++) {
                nbHonests = 0;
                outer:
                for (int i = 0; i < n; i++) {
                    boolean isHonest = (option & (1 << i)) != 0;
                    //System.err.println("[" + i + "] isHonest = " + isHonest + "; option = " + option + " (1<<i)" + (1<<i));
                    if (!isHonest)
                        continue;
                    nbHonests++;
                    for (int j = 0; j < a[i]; j++) {
                        boolean shouldBeHonest = (option & (1 << x[i][j])) != 0;
                        //System.err.println("[" + i + ", " + x[i][j] + "] shouldBeHonest = " + shouldBeHonest + " ; option = " + option + "x[i][j] = " + x[i][j]);
                        if (shouldBeHonest != (y[i][j] == 1)) {
                            nbHonests = 0;
                            break outer;
                        }
                    }
                }
                maxHonests = Math.max(maxHonests, nbHonests);
            }
            out.println(maxHonests);
        }

    }
}



Measured memory_bytes: 23764
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin.bytes().map(|c| c.expect("faild") as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();
    token.parse().ok().expect("faild parse")
}
fn main(){
    let n: u32 = read();
    let (mut min, mut max) = (1000000,-1000000);
    let mut sum: i64 = 0;
    for _ in 0..n{
        let input: i32 = read();
        min = if input < min { input }else { min };
        max = if input > max { input }else { max };
        sum += input as i64;
    }
    println!("{} {} {}",min,max,sum);
}


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

public class Main {

    public static void main(String[] args) {
        // AGC027A - Candy Distribution Again

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); // 2 <= n <= 10^5
        Integer[] a = new Integer[n * 3]; // 1 <= a <= 10^9

        for (int i = 0; i < n * 3; i++) {
            a[i] = sc.nextInt();
        }

        //Arrays.sort(a, Collections.reverseOrder());
        Arrays.sort(a);

        long sum = 0;
        for (int j = n; j < n * 3; j += 2) {
            sum += a[j];
        }

        System.out.println(sum);
    }

}

Measured memory_bytes: 100052
#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()
typedef long long ll;

int main() {
 int n; cin >> n;
 map<ll,int> mp;
 rep(i,n){
   int a; cin >> a;
   a--;mp[a]++;
 }
 int ans=0;
 for(auto c:mp){
   if(c.second%2!=0)ans++;
 }

 cout << ans << endl;
}


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

int main()
{
	int n;
	const int max = 100;
	int num[max];
	int a[max];
	cin >> n;
	for(int i = 1; i < max; i++){
		num[i] = 0; a[i] = 0;
	}
	num[1] = 1;
	a[1] = 1;
	for(int i = 1; i <= n; i++){
		int digit = max - 1;
		for(;num[digit] == 0;digit--);
		for(int j = digit; j >= 1; j--){
			num[j + 2] += (a[j] * i) / 100;
			num[j + 1] += ((a[j] * i) % 100) / 10;
			num[j] = ((a[j] * i) % 100) % 10;
		}
		for(int t = 1; (t <= digit + 2) && (t < max); t++){
			num[t + 1] += num[t] / 10;
			num[t] = num[t] % 10;
		}
		for(int m = 1; m <= digit + 2; m++)
			a[m] = num[m];
	}
	int digit = max - 1;
	for(;num[digit] == 0;digit--);
	for(int k = digit; digit >= 1; digit--)
		cout << num[digit];
	cout << endl;
	return 0;
}

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

int main(void) {
	std::string line;
   std::cin >> line;

	const char* str = line.data();
	int res = 0;
	for (int i = 0; i < 4; i++) {
		if (str[i] == '+')
			res++;
		else
			res--;
	}
	std::cout << res;
	return 0;
}

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

set<string> s;

int main(){
  int n;
  string str,str1,str2;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    for(int j=1;j<=str.size();j++){
      str1=str.substr(0,j);
      str2=str.substr(j);
    for(int k=0;k<2;k++){
    reverse(str1.begin(),str1.end());
    s.insert(str1+str2);
    s.insert(str2+str1);
    reverse(str2.begin(),str2.end());
    s.insert(str1+str2);
    s.insert(str2+str1);
    }
    }
  cout<<s.size()<<endl;
  s.clear();
  }
  return 0;
}

Measured memory_bytes: 1288
L, R = map(int, input().split())

minValue = 2018
rR = R if R < L + 2019 else L + 2019
for i in range(L, rR):
    temp = 0
    for j in range(i+1, rR):
        temp = i*j % 2019
        if(temp < minValue):
            minValue = temp
    temp = i*rR % 2019
    if(temp < minValue):
        minValue = temp
print(minValue)


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main (void)
{
 int ZZZ,l,a,b,c,d,P,Q;
 cin >> l >> a >> b >> c >> d;

 if (a % c != 0)
 {
   P = (a / c) + 1;
 }
 else if (a % c == 0)
 {
	 P = a / c;
 }
 if (b % d != 0)
 {
   Q = (b / d) + 1;
 }
 else if (b % d == 0)
 {
	 Q = b / d;
 }

 if (P <= Q)
 {
	 ZZZ = Q;
 }
 else if (P > Q)
 {
	 ZZZ = P;
 }

 cout << l - ZZZ << endl;
}

Measured memory_bytes: 3084
#include <stdio.h>

int main(){
	
	int c,k;
	
	// input misal masukkan angka 1 2 3 4 5
	//					   	idx c 0 1 2 3 4
	scanf("%d%d",&c,&k); // c = 5 , k = 3
	int score[c];  
	
	for ( int i=0 ; i<c ; i++){ // akan looping dari 0-4 sebanyak 5x sampai kondisi false
		scanf("%d",&score[i]); // i dari 0-4?
	}
	
	for ( int j=0 ; j<c-k; j++){
		if (score[j]<score[j+k]){
		printf("Yes\n");
	}	else {
		printf("No\n");
	}	
}
	return 0;

}

Measured memory_bytes: 2824
#include <bits/stdc++.h>
        #define ll long long  int
        #define N 1001
        #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
        #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
        #define po pop_back
        #define pb push_back
        #define pp pair<ll,ll>
        #define lb lower_bound
        #define fi first
        #define se second
        #define debug(x) cout << #x << " = " << x << endl
        #define ub upper_bound
        #define ibs ios_base::sync_with_stdio(false)
        #define cti cin.tie(0)
        #define all(x) x.begin(),x.end()
        #define PI 3.14159265
        #define cot cout.tie(0)
        using namespace std;
         /**
          * @author :: Sawlani
          *
          *
          **/
          int main()
          {

               ll a1,a2,a3;
               cin >> a1 >> a2 >> a3;

               if(a1+a2+a3>=22)
                cout << "bust";
               else
                cout << "win";
          }


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

using namespace std;

const ll N = 100100;

char buf[N];
string Read(){
    scanf("%s", buf);
    return buf;
}

string s[N];
map < vector <ll> , ll> mp;

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

    for(ll i = 0; i < n; i++)
    {
        s[i] = Read();

        vector <ll> Cnt(26,0);

        for(char c : s[i])  Cnt[c - 'a']++;

        mp[Cnt]++;
    }

    ll Ans = 0;

    for(auto p : mp)    Ans += p.second * (p.second - 1) / 2;

    cout << Ans;
}


Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
	vector<ll> p(A); for (int i = 0; i < A; i++) cin >> p[i];
	vector<ll> q(B); for (int i = 0; i < B; i++) cin >> q[i];
	vector<ll> r(C); for (int i = 0; i < C; i++) cin >> r[i];
	sort(p.rbegin(), p.rend()); while (p.size() > X) p.pop_back();
	sort(q.rbegin(), q.rend()); while (q.size() > Y) q.pop_back();
	vector<ll> v; v.reserve(p.size() + q.size() + C);
	for (auto e : p) v.emplace_back(e);
	for (auto e : q) v.emplace_back(e);
	for (auto e : r) v.emplace_back(e);
	sort(v.rbegin(), v.rend());
	cout << accumulate(v.begin(), v.begin() + X + Y, 0LL) << endl;
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
 
 
void solve(){
    string a,b;
    cin>>a>>b;
    int an=a.size(),bn=b.size();

    vector<vector<int>> dp(an+1,vector<int>(bn+1));
    for(int i=1;i<=an;i++){
        for(int j=1;j<=bn;j++){
            if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            dp[i][j]=max(dp[i][j],dp[i][j-1]);
        }
    }

    // for(auto x: dp){
    //     for(auto y: x)cout<<y<<' ';
    //     cout<<endl;
    // }


    int i=an,j=bn;
    string ans="";
    while(i>0 && j>0){
        if(dp[i][j]==dp[i-1][j])i=i-1;
        else if(dp[i][j]==dp[i][j-1])j=j-1;
        else {
            ans=a[i-1]+ans;
            i--;
            j--;
        }
    }
    cout<<ans<<endl;
}



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

    // while(n--)
    solve();

    return 0;
}

Measured memory_bytes: 35584
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main() {
  string s;
  cin >>s;
  int count0=0;
  int count1=0;
  int n=s.length();
  for(int i=0;i<n;i++){
    if(s[i]=='0') count0++;
    if(s[i]=='1') count1++;
  }

  cout << min(count0,count1)*2 << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, m, A[100005];
int dp[100005];
const int mod = 1e9+7;

signed main(){
  
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    A[a] = 1;
  }
  
  dp[0] = 1;
  
  for(int i=0;i<n;i++){
    if( !A[i+1] ){
      dp[i+1] += dp[i];
      dp[i+1] %= mod;
    }
    if( !A[i+2]){
      dp[i+2] += dp[i];
      dp[i+2] %= mod;
    }
  }

  cout<<dp[n]<<endl;
  
  return 0;
}


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

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<vector>
#include<string>
#include<iterator>
#include<algorithm>

#define ll long long
#define pi (2*acos(0.0))
#define ft first
#define sd second
#define pb push_back
#define sz size()
#define MAX 1000000000

using namespace std;

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

    cout<<N*(N-1)/2+M*(M-1)/2<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);


int main(){
	ll n,m;
	IOS
	cin>>n>>m;
	ll tmp=pow(2,n);
	ll dp[m][tmp];
	fo(i,m){
		fo(j,tmp){
			dp[i][j]=100000000;
		}
	}
	
    ll k;
    ll tmpp;
    ll our=0;
    ll a;
    cin>>a>>k;
    fo(p,k) {
    cin>>tmpp;
    our=our|(1<<(tmpp-1));

    }
    //dbg(our);
    dp[0][0]=0;
    fo(i,tmp) {
    	if(i==0) dp[0][i]=0;
    	else if(((our&i)^i)==0) {dp[0][i]=a; }
    	
    }
    //dbg(dp[0][1]);

	FOR(i,1,m-1){
        cin>>a;
		cin>>k;
		our=0;
		fo(p,k) {
			cin>>tmpp;
			our=our|(1<<(tmpp-1));



		}
		//dbg(our);
		fo(j,tmp){
			if(j==0) dp[i][j]=0;
			else {
				if(j&our) dp[i][j]=min(dp[i-1][j],dp[i-1][((our^j)&j)]+a);
				dp[i][j]=min(dp[i-1][j],dp[i][j]);
			}
			
		}
		//dbg(dp[i][1]);


	}
	if(dp[m-1][tmp-1]>=100000000) cout<<-1<<endl;
	else cout<<dp[m-1][tmp-1]<<endl;


}



Measured memory_bytes: 32256
def main2():
    input()
    s = input()
    pair = [-1] * 2
    ans = s
    idx = 0
    for idx in range(0, len(s)):
        for i in range(idx, len(s)):
            if s[i] == '(':
                pair[0] = i if pair[0] == -1 else pair[0]
            elif s[i] == ')':
                pair[1] = i
                break
        if pair[0] != -1 and pair[1] != -1:
            s = s[:pair[0]] + ' ' + s[pair[0]+1:pair[1]] + ' ' + s[pair[1]+1:]
        elif pair[0] != -1 and pair[1] == -1:
            s = s[:pair[0]] + ' ' + s[pair[0]+1:]
            ans = ans + ')'
        elif pair[0] == -1 and pair[1] != -1:
            s = s[:pair[1]] + ' ' + s[pair[1]+1:]
            ans = '(' + ans
        pair = [-1] * 2
    print(ans)


if __name__ == '__main__':
    main2()

Measured memory_bytes: 9172
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        int input =int.Parse(Console.ReadLine());
        Console.WriteLine(800*input-(input/15)*200);


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 13140
//
//  main.cpp
//  A
//
//  Created by Knight_F on 2019/8/10.
//  Copyright © 2019年 Knight_F. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#define LL long long
using namespace std;
int main(){
    int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){

int n,i,q,key,mid,right,left,sum=0;
 
scanf("%d \n",&n);
 
int A[n];
 
for(i=0;i<n;i++){
scanf("%d ",&A[i]);
}

scanf("%d \n",&q);
 
for(i=0;i<q;i++){
scanf("%d ",&key);
left = 0;
right = n;
mid = (left+right)/2;
 
while(left<right){
   if(key == A[mid]){
   sum++;
   break;
   }
   else if(key<A[mid]){
    right = mid;
    mid = (left+right)/2;
    }
   else if(key>A[mid]){
    left = mid+1;
    mid = (left+right)/2;
    }
   }
}
 
printf("%d\n",sum);
 
return 0;
}
 





Measured memory_bytes: 2076
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/16 16:47:05
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 3000 + 5, MOD = 998244353;

int n, s;
int a[N];
int dp[N][N], sum[N];

void run() {
    cin >> n >> s;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        dp[i][a[i]] = i;
        for (int j = a[i]; j <= s; j++) {
            dp[i][j] += sum[j - a[i]];
            if (dp[i][j] >= MOD) dp[i][j] -= MOD;
        }
        for (int j = 0; j <= s; j++) {
            sum[j] += dp[i][j];
            if (sum[j] >= MOD) sum[j] -= MOD;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += 1ll * dp[i][s] * (n - i + 1) % MOD;
        ans %= MOD;
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 35456
s = input()
ans = 0
for i in range(len(s) - 1):
    if s[i] == 'B' and s[i + 1] == 'W':
        ans += 1
    elif s[i] == 'W' and s[i + 1] == 'B':
        ans += 1
        
print(ans)

Measured memory_bytes: 3316