akhauriyash/Code-Regression huggingface dataset:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    pr = S[0] # 前の色
    cnt = 0
    for i in range(1,len(S)):
        if S[i] != pr:
            pr = S[i]
        else:
            cnt += 1
            if pr == '0':
                pr = '1'
            else:
                pr = '0'
    print(cnt)
if __name__ == '__main__':
  main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;

int main() {
  string s;
  cin >> s;
  
    if(s=="SAT")co(1);
    if(s=="MON")co(6);
    if(s=="TUE")co(5);
    if(s=="WED")co(4);
    if(s=="THU")co(3);
    if(s=="FRI")co(2);
    if(s=="SUN")co(7);
  
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  bool hantei = false;
  
  for(int i=0; i<=25; i++){
    for(int j=0; j<15; j++){
      int total = 4*i + 7*j;
      if (total == n) {
        hantei = true;
        break;
      }
    }
  }
  
  if (hantei) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main (void)
{
	char s[1200];
	int i;
	
	for(i = 0 ; i < 1200 ; i++)
	{
		s[i] = '\0';
	}
	
	scanf("%[^\n]",s);
	
	i = 0;
	
	while(s[i] != '\0')
	{
		if(s[i] >= 0x41 && s[i] <= 0x5a)
		{
			s[i] = s[i] + 32;
		}
		else if(s[i] >= 0x61 && s[i] <= 0x7a)
		{
			s[i] = s[i] - 32;
		}
		i++;
	}
	
	printf("%s\n",s);
	
	return 0;
}


Measured memory_bytes: 2064
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            double d = sc.nextInt();
            double t = sc.nextInt();
            double s = sc.nextInt();
            if(s >= d/t) {
                pw.println("Yes");
            }
            else {
                pw.println("No");
            }
        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32724
text = ''
while True:
    try:
        s = input().lower()
    except EOFError:
        break
    if s == '':
        break
    text += s
for i in 'abcdefghijklmnopqrstuvwxyz':
    print(i+' : '+str(text.count(i)))
    #print("{0} : {1}".format(i, text.count(i)))

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

int main()
{
    string S;
    cin >> S;
    int res = 0;
    if (S[0] == 'R')
    {
        res++;
        if (S[1] == 'R')
        {
            res++;
            if (S[2] == 'R')
            {
                res++;
                cout << res << endl;
                return 0;
            }
        }
        cout << res << endl;
        return 0;
    }
    if (S[1] == 'R')
    {
        res++;
        if (S[2] == 'R')
        {
            res++;
            cout << res << endl;
            return 0;
        }
        cout << res << endl;
        return 0;
    }
    if (S[2] == 'R')
    {
        res++;
        cout << res << endl;
        return 0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
 int n,x,a,b,c,how=0;
 while(scanf("%d%d",&n,&x) && (n!=0 || x!=0)){
  for(a=1;a<n+1;a++){
   for(b=2;b<n+1;b++){
    for(c=3;c<n+1;c++){
     if(x == a + b + c ) {
      if(a!=b && b!=c && c!=a && a<b &&b<c) {
       how+=1;
       }
      }
     }
    }
   }
printf("%d\n",how);
how=0;
}


}


Measured memory_bytes: 2144
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

int main ()
{
	int N;
	while( cin >> N , N )
	{
		int a , b , c=0 , d=0;
		for( size_t i = 0; i < N; i++ )
		{
			cin >> a >> b;
			if( a == b )
			{
				c += a;
				d += b;
			}else a < b ? d += a + b : c += a + b;
		}
		cout << c << " " << d << endl;
	}
}

Measured memory_bytes: 1156
while(1):
    N=int(raw_input())
    if N==0:
        break
    else:
        know=[0]+[[] for i in range(N)]
        for i in range(N):
            data=[int(x) for x in raw_input().split()]
            M=data[0]
            for j in range(M):
                know[data[j+1]].append(i+1) #j info known by mr.(i+1)
        data=[int(x) for x in raw_input().split()]
        K=data[0]
        suspect=know[data[1]]
        for i in range(K-1):
            suspecttemp=[x for x in know[data[i+2]] if x in suspect]
            suspect=suspecttemp
        if len(suspect)==1:
            print suspect[0]
        else:
            print -1

Measured memory_bytes: 4324
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    long n, k, q;
    cin >> n >> k >> q;
    long p[n];
    fill(p, p+n, k - q);
    for (long i=0; i<q; i++) {
        int a; cin >> a;
        p[a-1]++;
    }
    for (auto &pi:p)
        cout << (pi > 0 ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll ans,M[100007];

ll compME(ll b, ll e, ll m){  // bのe乗のmod m を返す
    if (e == 0) return 1;
    ans = compME(b, e / 2, m);
    ans = (ans * ans) % m;
    if (e % 2 == 1) ans = (ans * b) % m;
    return ans;
}

int main(){
    ll N,M;
    cin >> N >> M;
    if(N>=M/2){
        cout << M/2 << endl;
    }
    else{
        cout << (N*2+M)/4 << endl;
    }
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
ma = max(A)

X = [0] * (ma + 1)
ans = 0
A.sort()

for a in A:
    X[a] += 1
for a in A:
    if X[a] ==1:
        ans += 1
    num = 1
    while num * a <= ma:
        X[num * a] += 2
        num += 1

print(ans)


Measured memory_bytes: 121984
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int main(){
	ll n,m;
	cin >> n >> m;
	if(n%3==0 || m%3==0) {
		puts("0");
		return 0;
	}

	ll s1,s2,s3,ans=INFLL;

	ll k = n/3;
	ll kk = (k+1)*m - k*m;
	ans = min(kk,ans);

	k = m/3;
	kk = (k+1)*n - k*n;
	ans = min(kk,ans);

	for(ll x=1; x<=(m+1)/2+1; x++){
		s1 = x*n;
		s2 = (m-x)*(n/2);
		s3 = m*n - s1 - s2;

		ll t = 0;
		ll t1 = s1>s2 ? s1-s2 : s2-s1;
		t = t1>t ? t1 : t;
		ll t2 = s1>s3 ? s1-s3 : s3-s1;
		t = t2>t ? t2 : t;
		ll t3 = s3>s2 ? s3-s2 : s2-s3;
		t = t3>t ? t3 : t;
		// if(ans > t){
		// 	cout << s1 << " " << s2 << " " << s3 << endl;
		// 	cout << x << " " << t << endl;
		// }
		ans = ans>t ? t : ans;
	}

	for(ll y=1; y<=(n+1)/2+1; y++){
		s1 = y*m;
		s2 = (n-y)*(m/2);
		s3 = m*n - s1 - s2;
		ll t = 0;
		ll t1 = s1>s2 ? s1-s2 : s2-s1;
		t = t1>t ? t1 : t;
		ll t2 = s1>s3 ? s1-s3 : s3-s1;
		t = t2>t ? t2 : t;
		ll t3 = s3>s2 ? s3-s2 : s2-s3;
		t = t3>t ? t3 : t;
		ans = ans>t ? t : ans;
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>

using namespace std;

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point {
public:
	double x, y;


	Point(double x = 0, double y = 0) :x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x, a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; };

	bool operator < (const Point& p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator ==(const Point& p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0.0);
}

bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}
struct Segment {
	Point p1, p2;
	Segment() {}
	Segment(Point p1, Point p2) :p1(p1), p2(p2) {}
};
typedef Segment  Line;

double norm(Vector a) {
	return a.x * a.x + a.y * a.y;
}
double abs(Vector a) {
	return sqrt(norm(a));
}

Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / norm(base);
	return s.p1 + base * r;
}

Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p) * 2.0;
}
double getDistance(Point a, Point b) {
	return abs(a - b);
}

double getDistanceLP(Line l, Point p) {
	return fabs(cross(l.p2 - l.p1, p - l.p1)/abs(l.p2 - l.p1));
}

double getDistanceSP(Segment s, Point p) {
	if (dot(s.p2 - s.p1, p - s.p1) < 0.0)return abs(p - s.p1);
	if (dot(s.p1 - s.p2, p - s.p2) < 0.0)return abs(p - s.p2);
	return getDistanceLP(s, p);

}

double getDistance(Segment s1, Segment s2) {
	//if (intersect(s1, s2))return 0.0;
	return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
		min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if (cross(a, b) > EPS)return COUNTER_CLOCKWISE;
	if (cross(a, b) < -EPS) return CLOCKWISE;
	if (dot(a, b) < -EPS)return ONLINE_BACK;
	if (a.norm()<b.norm()) return ONLINE_FRONT;

	return ON_SEGMENT;


}


int main() {
	double x1, y1, x2, y2, x0, y0;
	cin >> x1 >> y1 >> x2 >> y2;
	int q;
	Line s = Line(Point(x1, y1), Point(x2, y2));
	map<int, string> m;
	m[COUNTER_CLOCKWISE] = "COUNTER_CLOCKWISE";
	m[CLOCKWISE] = "CLOCKWISE";
	m[ONLINE_BACK] = "ONLINE_BACK";
	m[ONLINE_FRONT] = "ONLINE_FRONT";
	m[ON_SEGMENT] = "ON_SEGMENT";

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> x0 >> y0;
		cout <<m[ ccw(Point(x1, y1), Point(x2, y2), Point(x0, y0))] << endl;;
		//printf("%.8lf %.8lf\n", ans.x, ans.y);
	}

	return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#define llint long long
#define mod 998244353

using namespace std;

llint fact[4005], fact_inv[4005];

llint pow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (pow(a, n-1)%mod)) % mod;
	}
	else{
		return pow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 4005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 4005; i++){
		fact_inv[i] = pow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint K, N;
llint beki[4005];

llint divide(llint n, llint k)
{
	return comb(n+k-1, n);
}

llint calc(llint n, llint x, llint y)
{
	llint ret = 0;
	for(int i = 0; i <= min(x, n); i++){
		llint tmp = divide(n-i, i+y) * beki[i] % mod;
		tmp *= comb(x, i), tmp %= mod;
		ret += tmp, ret %= mod;
	}
	return ret;
}

int main(void)
{
	cin >> K >> N;
	for(llint i = 0, mul = 1; i <= 2*K; i++, mul *= 2, mul %= mod) beki[i] = mul;
	make_fact();
	
	for(int i = 2; i <= 2*K; i++){
		llint g = (i-1)/2, ans = 0;
		if(i > K+1) g = (2*K+1-i)/2;
		if(i % 2) ans += calc(N, g, K-2*g), ans %= mod;
		else{
			ans += calc(N, g, K-2*g-1), ans %= mod;
			ans += calc(N-1, g, K-2*g-1), ans %= mod;
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

const int N = 2e5 + 10; 
int n, m, a[N], cnt[N], p[N], tot;  

void add(int x) {
    int l = x - cnt[x]++; 
    if(l > 0 && ++p[l] == 1) 
        --tot; 
}
void rem(int x) {
    int l = x - --cnt[x]; 
    if(l > 0 && --p[l] == 0) 
        ++tot;
}

int main(int argc, char const *argv[]) {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        add(a[i]); 
    } tot += n;  
    while(m--) {
        int x, y; 
        scanf("%d %d", &x, &y);
        rem(a[x]); a[x] = y; add(a[x]); 
        printf("%d\n", tot); 
    }
}

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

using namespace std;

int solve(){
    int n;
    cin>>n;
    vector<int> v(n+1,0);
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j < n; j++)
        {
           for (int k = 1; k < n; k++)
           {
              int x=i*i+j*j+k*k+i*j+j*k+i*k;
              if(x>n) break;
              v[x]++;
           }
           
        }
        
    }

    for (int i = 1; i <= n; i++)
    {
        cout<<v[i]<<"\n";
    }
    
    
    return 0;
}

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


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

#define ll long long
#define value(x) cout<<#x<<" "<<x<<'\n';
#define print_vec(vec) for(auto x: vec) cout<<x<<" "; \
                        cout<<endl;

void solve()
{
	int n;
	cin >> n;
	vector<int> v(n);
	map<int, int> mp;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		mp[v[i]]++;
		sum += v[i];
	}
	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;
		int diff = c - b;
		sum += diff * (mp[b]);
		mp[c] += mp[b];
		mp[b] = 0;

		cout << sum << '\n';
	}

}

int main()
{
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
}


Measured memory_bytes: 8084
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		long N = scan.nextLong();
		long K = scan.nextLong();

		long rest = N % K;

		System.out.println(rest > K - rest ? K - rest : rest);
	}
}

Measured memory_bytes: 23636
#include <stdio.h>

int main(void)
{
        int a[3],i,j,tmp;

        for (i=0;i<3;i++){
                scanf("%d",&a[i]);
        }


        for (i=0;i<3;i++){
                for (j=i+1;j<3;j++){
                        if (a[i]>a[j]){
                                tmp=a[i];
                                a[i]=a[j];
                                a[j]=tmp; 
                        }
                }
        }
        printf("%d\n",a[2]*10+a[1]+a[0]);

        return 0;
}

Measured memory_bytes: 128
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

def kouyaku(a,b):
    aa = max(a,b)
    bb = min(a,b)
    if bb == 0:
        return aa
    else:
        return kouyaku(bb,aa%bb)

g = 1
A = [a//2 for a in A]
for i in range(N):
    g = g//kouyaku(g, A[i])*A[i]
    if g > M:
        print(0)
        exit()
Flag = False
for i in range(N):
    if (g//A[i])%2 == 0:
        Flag = True
if Flag:
    print(0)
else:
    print((M//g+1)//2)

Measured memory_bytes: 64228
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    if(2*x<=y && y <= 4*x && y%2 == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n;
    cin >> n;

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a--;

        b[a] = i;
    }

    vector<array<int, 2>> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = { i - 1, i + 1 };
    }

    int64_t r = 0;
    for (int i = n - 1; i >= 0; i--) {
        auto t = p[b[i]];
        r += (int64_t)(i + 1) * (t[1] - b[i]) * (b[i] - t[0]);
        if (t[0] >= 0) p[t[0]][1] = t[1];
        if (t[1] <  n) p[t[1]][0] = t[0];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	int R;
	scanf("%d", &R);
	
	if (R < 1200) printf("ABC\n");
	else if (R < 2800) printf("ARC\n");
	else printf("AGC\n");
	return 0;
}

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

using namespace std;

int main(){
        int i=0,len,fir=0,las=0;
        string s;
        cin >> s;
        len = s.size();
        while(s[i]!='A'){
                i++;
        }
        len-=i;
        i=s.size();
        while(s[i]!='Z'){
                i--;
                las++;
        }
        len -= las;
        len++;
        cout << len << endl;
        return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
### スペース区切りの２つの数値を入力し、小さい順に並べる。
### 数値が 二つとも0 まで、入力を繰り返す。
### 数値入力が終わったらまとめて表示する。


int_in = [1,1]
int_out = []

## 標準入力・入力内容の分割
while 1:
	str_in = raw_input()
	int_in = map(int, str_in.split())
	if int_in[0] == 0 :
		if int_in[1] == 0:
			break
	## 数値を小さい順に入れ替える。
	if int_in[0] > int_in[1]:
		swap = int_in[0]
		int_in[0] = int_in[1]
		int_in[1] = swap
	## 出力用配列へ追加する。
	int_out.extend([int_in])

##表示
for i in int_out:
		print(repr(i[0]) + ' ' + repr(i[1]))



Measured memory_bytes: 4828
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
	int A, B;
	cin >> A >> B;
	int answer;
	if (A > 12) answer = B;
	else if (A > 5) answer = B / 2;
	else answer = 0;
	cout << answer;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int K; 
int main(){
	cin>>s>>K;
	for(int i=0;i<s.size()&&K;i++){
		if(s[i]=='a')continue;
		int n='z'+1-s[i];
		if(n<=K){
			s[i]='a';
			K-=n;
		}
	}
	int d=s[s.size()-1]-'a';
	d+=K;
	d%=26;
	s[s.size()-1]='a'+d;
	cout<<s;
	return 0;
}


Measured memory_bytes: 512
n = gets.to_i
fs = Array.new(n) { gets.delete(' ').to_i(2) }
ps = Array.new(n) { gets.split.map(&:to_i) }

pmax = -Float::INFINITY

1.upto(1023) do |b|
  x = 0
  n.times do |i|
    x += ps[i][(fs[i] & b).to_s(2).count('1')]
  end
  pmax = pmax < x ? x : pmax
end

p pmax

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 2e5+10;
int n,a[maxn];
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    LL ans = 0;
    for (int i=2;i<=n;i++){
        if (a[i] < a[i-1]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }
 
ll rec(int i, ll cur, ll sum, const string &S) {
	if(i == S.size()) {
		return sum;
	}
	int d = S[i] - '0';
	ll res = 0;
	if(i + 1 != S.size())
		res += rec(i + 1, cur * 10 + d, sum, S);
	res += rec(i + 1, 0, sum + cur * 10 + d, S);
	return res;
}
 
int main() {
	string S;
	while(cin >> S) {
		ll ans = rec(0, 0, 0, S);
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char S[100001];
	scanf("%s", S);
	int i, count = 0;
	for (i = 1; S[i] != 0; i++) if (S[i] != S[i-1]) count++;
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main(){
    long long n;
    cin >> n;
    int shortest =~(1<<31);
    for(long long i= 1; i <= ceil(sqrt(n));i++){
        if(n % i != 0){
            continue;
        }
        long long buf = n / i;
        shortest = min(shortest, (int)to_string(buf).length());
    }
    cout << shortest << endl;
}


Measured memory_bytes: 256
n, k=map(int, input().split())
a=list(map(int, input().split()))
table=[0]*(n+1)

for i in range(n):
    table[a[i]]+=1

l=sorted(table, reverse=True)
get=0
for i in range(k):
    get+=l[i]

print(sum(l)-get)

Measured memory_bytes: 25876
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<random>
#include<map>
using namespace std;
#define int long long
int lg(int n) {
	int ans = 0;
	while (n) {
		n /= 10;
		ans++;
	}
	return ans;
}
signed main() {
	int n;
	cin >> n;
	if (n < 10)cout << n << endl;
	else {
		string sa = to_string(n);
		if (sa[0] == '1') {
			int ans = (sa.size() - 1) * 9;
			sort(sa.begin(), sa.end());
			if (sa[1] == '9'&&sa[sa.size() - 1] == '9')ans++;
			cout << ans << endl;
		}
		else {
			int ans = (sa.size() - 1) * 9;
			ans += (sa[0] - '0');
			ans--;
			n++;
			sa = to_string(n);
			sort(sa.begin(), sa.end());
			if (sa[0] == '0'&&sa[sa.size() - 2] == '0')ans++;
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL r;
  cin >> r;
  cout << r*r*3 << endl;
  return 0;
}


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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      vi s(200, 0);
      cin >> n >> k;
      fr(i, 0, k) {
            cin >> m;
            fr(j, 0, m) {
                  int t; cin >> t;
                  s[t]++;
            }
      }
      int a = 0;
      fr(i, 1, n+1) {
            if(s[i] == 0) a++;
      }
      cout << a << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;
#define EPS (1e-6)
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef pair<int,int> P;

int gcd( int a, int b )
{
  int c;
  while ( a != 0 ) {
    c = a; a = b%a;  b = c;
  }
  return b;
}

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);
  int INF = 1000000;

  int a,b;
  while(cin>>a>>b){
    cout << gcd(a,b) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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

  ll MOD = (ll)1e9+7;
  int N; cin>>N;
  vi A = vi(N); REP(i,N) cin>>A[i];

  ll ans = 1L;
  vi h(N+1, 0);
  // h[i] := i 個置いてある色の数はいくつか (0<= h[i] <= 3)
  h[0] = 3;

  REP(i,N) {
    int j = A[i];
    ans *= h[j];
    ans %= MOD;
    h[j] -= 1;
    h[j+1] += 1;
  }
  
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;


long long beki(long long a,int n)
{
  long long s=1LL;
  while(n){
    if(n%2)s=s*a;
    a=a*a;
    n/=2;
  }
  return s;
}

int main(void) {
  ll n,i=1;
  cin>>n;
  while(beki(3,i)<n)i++;
  cout<<i<<endl;
}

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

int main()
{
    string str;
    while(cin >> str) {
        int n1, n2;
        n1 = n2 = 0;
        for(int i = 0; i < str.size() - 2; i++) 
            if(str.substr(i, 3) == "JOI")
                n1++;

        for(int i = 0; i < str.size() - 2; i++) 
            if(str.substr(i, 3) == "IOI")
                n2++;
        
        cout << n1 << endl << n2 << endl;
        
    }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
  // フィールド宣言

  public static void main(String[] args){
    // 入力の受けつけ　3つの文字列として受け取る
    Scanner sc = new Scanner(System.in);

    while(true){
      String line = sc.nextLine();
      String[] input = line.split(" ");
      int num1 = Integer.parseInt(input[0]);
      String op = input[1];
      int num2 = Integer.parseInt(input[2]);

      // 2つ目のopの値によって場合分け
      if(num1 < 0 || num1 > 20000 || num2 < 0 || num2 > 20000){
        System.out.println("数字が範囲外です．0 <= num <= 20,000");
      }

      if(op.equals("?")){
        return;
      }else if(op.equals("+")){
        System.out.println(num1 + num2);
      }else if(op.equals("-")){
        System.out.println(num1 - num2);
      }else if(op.equals("*")){
        System.out.println(num1 * num2);
      }else if(op.equals("/")){
        System.out.println(num1 / num2);
      }else{
        System.out.println("入力が正しくありません");
      }

    }
  }
}



Measured memory_bytes: 26188
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  map<char, ll> amap;
  vector<char> arr;
  for(int i=0;i<S.size();++i){
    if(amap[S[i]]==0) arr.push_back(S[i]);
    amap[S[i]]++;
  }
  int siz = arr.size();
  int n = siz/2;
  vector<ll> arr1, arr2;
  ll tmp;
  for(int bit=0;bit<(1<<n);++bit){
    tmp = 1;
    for(int i=0;i<n;++i){
      if((bit&(1<<i))!=0) {
        tmp *= amap[arr[i]];
        tmp %= mod;
      }
    }
    arr1.push_back(tmp);
  }
  for(int bit=0;bit<(1<<(siz-n));++bit){
    ll tmp = 1;
    for(int i=0;i<siz-n;++i){
      if((bit&(1<<i))!=0){
        tmp *= amap[arr[i+n]];
        tmp %= mod;
      }
    }
    arr2.push_back(tmp);
  }
  ll ans = 0;
  for(int i=0;i<arr1.size();++i){
    for(int j=0;j<arr2.size();++j){
      ans += arr1[i]*arr2[j]%mod;
      ans %= mod;
    }
  }
  cout<<ans-1<<endl;
}


Measured memory_bytes: 640
// https://atcoder.jp/contests/abc057/tasks/abc057_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, r;

  cin >> a >> b;

  r = (a + b) % 24;

  cout << r << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

ll dp[401][401];
vector<int> a;
ll slime(int l,int r){
	ll &ans = dp[l][r];
	if(ans!=-1)
		return dp[l][r];
	if(r==l)
		return 0;
	ans = 1e15;
	ll rt = 0,lt = 0;
	for(int k=r;k>=l;--k)
		rt+=a[k];
	for(int k=l;k<r;++k){
		lt+=a[k];
		rt-=a[k];
		ans = min(slime(l,k)+slime(k+1,r)+lt+rt,ans);
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	memset(dp,-1,sizeof dp);
	a.resize(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	cout<<slime(0,n-1);
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
    
int main(){
    int ss,h,m,s;
    
    cin >> ss;
   
    if((ss>=0)&&(ss<=86400)){
   
       h = ss / 3600;
       m = (ss - h*3600)/ 60 ;
       s = ss - h*3600 - m*60;
    
       cout << h << ":" << m << ":" << s << endl;
   
    }else{
   
       cout << "error" << endl;
   
    };
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for (int i=0;i<100;i++){
		c-=b;
		a-=d;
		
		if (c<=0){
			cout<<"Yes";
			break;
		}
		
		
		if (a<=0){
			cout<<"No";
			break;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>
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; }

signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  map<int,int> plus;
  map<int,int> minus;
  rep(i,0,n){
    plus[A[i]+i]++;
    minus[i-A[i]]++;
  }
  int ans = 0;
  for(auto p:plus){
    ans += p.second*minus[p.first];
  }
  cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

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

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

int main() {
	int n, p;
	cin >> n;
	int total = 0;
	vector<int> vec(n);
	vector<int> party(3);
	for (int i = 0; i < n; i++) {
		cin >> p;
		vec.at(i) = p;
	}
	for (int j = 0; j < n - 2; j++) {
		vector<int> party(3);
		party.at(0) = vec.at(j);
		party.at(1) = vec.at(j + 1);
		party.at(2) = vec.at(j + 2);
		if (party.at(0) < party.at(1) && party.at(1) < party.at(2)) {
			total++;
		}
		else if (party.at(0) > party.at(1) && party.at(1) > party.at(2)) {
			total++;
		}
		else {
			continue;
		}
	}
	cout << total << endl;
}

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

namespace Algorithm
{
    class Program
    {
        const int Size = 2;
        private int[,] comb;
        
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            int n = line[0], m = line[1];
            var array = new int[(int) Math.Pow(2, n)][];

            var dfs = new DfsMaster(n, array);
            dfs.Execute(0);

            var list = new int[m][];
            for (var i = 0; i < m; i++)
            {
                list[i] = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            }

            var last = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();

            var count = 0;

            foreach (var p in dfs.map)
            {
                var isTrue = true;

                for (var i = 0; i < m; i++)
                {
                    var total = 0;
                    for (var j = 1; j < list[i].Length; j++)
                    {
                        total += p[list[i][j]-1];
                    }
                    if (total % 2 != last[i])
                    {
                        isTrue = false;
                        break;
                    }
                }
                if (isTrue) count++;
            }

            Console.WriteLine(count);
        }
    }

    public class DfsMaster
    {
        public int n { get; set; }
        public int y { get; set; }
        public int[] xmap { get; set; }
        public int[][] map { get; set; }

        public DfsMaster(int n, int[][] map)
        {
            this.n = n;
            this.map = map;
            xmap = new int[n];
        }

        public void Execute(int x)
        {
            if (x == n)
            {
                map[y] = xmap.Clone() as int[];
                y++;
                return;
            }

            xmap[x] = 1;
            Execute(x + 1);

            xmap[x] = 0;
            Execute(x + 1);
        }
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		char c[] = s.toCharArray();
		int count =0;
		int start =0;
		int last = N-1;
		int minlast=-1;
		int maxstart=N;
		while (start<last) {
			while (start<maxstart&&c[start]=='R') {
				start++;
			}
			while (last>minlast&&c[last]=='W') {
				last--;
			}
			if (start<last) {
				c[start]= 'R';
				c[last] = 'W';
				count ++;
				maxstart = last;
				minlast = start;
			} else {
				break;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 41144
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  string s,t;
  cin>>s>>t;
  bool f=false;
  int c=0,ans=0,b;
  if(s.size()<t.size()){
    co("UNRESTORABLE");
    return 0;
  }
  rep(i,0,s.size()-t.size()+1){
    rep(j,0,t.size()){
      if(s[i+j]=='?' || s[i+j]==t[j]) c++;
    }
    if(c==t.size()){
      b=i;
      f=true;
    }
    c=0;
  }
  if(f==false){
    co("UNRESTORABLE");
    return 0;
  }
  else{
    rep(i,0,t.size()) s[b+i]=t[i];
    rep(i,0,s.size()) if(s[i]=='?') s[i]='a';
  }
  co(s);
      
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#define REP(i, START, n, STEP) for(int i = START; i < (n); i += (STEP))
#define rep(i, n) REP(i, 0, n, 1)
using namespace std;

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

int main() {
	int n, m;
	cin >> n >> m;
	int size = 1 << n;
	vector<P> key(m);
	rep(i, m) 
	{
		int b, c;
		key[i].first = 0;
		cin >> key[i].second;
		cin >> b;
		rep(j, b) 
		{
			cin >> c;
			key[i].first += 1 << c - 1;
		}
	}
	vector<int> cost(size, -1);
	cost[0] = 0;
	rep(i, size - 1)
	{
		if (cost[i] == -1) continue;
		rep(j, m)
		{
			int next = i | key[j].first;
			int next_cost = cost[i] + key[j].second;
			if (cost[next] == -1)			 cost[next] = next_cost;
			else if (next_cost < cost[next]) cost[next] = next_cost;
		}
	}
	if (cost[size -1] == -1) cout << -1;
	else cout << cost[size - 1];

	return 0;


}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN = 100000;
const int BLOCK = 320;
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[MAXN];
void addedge(int u, int v, int c, int d) {
	g[u].push_back(node(v,c,d));
	g[v].push_back(node(u,c,d));
}
int clr[MAXN + 5], dis[MAXN + 5];
int fa[MAXN + 5][20], dep[MAXN + 5];
int dfn[2*MAXN + 5], fir[MAXN + 5], bac[MAXN + 5], dcnt = 0;
void dfs(int x, int pre) {
	dfn[++dcnt] = x, fir[x] = dcnt;
	fa[x][0] = pre, dep[x] = dep[pre] + 1;
	for(int i=1;i<20;i++)
		fa[x][i] = fa[fa[x][i-1]][i-1];
	for(int i=0;i<g[x].size();i++)
	{
		int v=g[x][i].to;
		if( v != pre ) {
			dfs(v, x);
			clr[v] = g[x][i].co, dis[v] = g[x][i].ct;
		}
	}
	dfn[++dcnt] = x, bac[x] = dcnt;
}
int lca(int u, int v) {
	if( dep[u] < dep[v] ) swap(u, v);
	for(int i=19;i>=0;i--)
		if( dep[fa[u][i]] >= dep[v] )
			u = fa[u][i];
	if( u == v ) return u;
	for(int i=19;i>=0;i--)
		if( fa[u][i] != fa[v][i] )
			u = fa[u][i], v = fa[v][i];
	return fa[u][0];
}
struct query{
	int le, ri, num;
	int x, y;
}qry[MAXN + 5];
bool operator < (query a, query b) {
	return (a.le/BLOCK == b.le/BLOCK) ? a.ri < b.ri : a.le < b.le;
}
int nwres, cnt[MAXN + 5], tag[MAXN + 5];
int sum[MAXN + 5], ans[MAXN + 5];
void update(int x) {
	int y = dfn[x];
	if( tag[y] )
		cnt[clr[y]]--, sum[clr[y]] -= dis[y], nwres -= dis[y];
	else cnt[clr[y]]++, sum[clr[y]] += dis[y], nwres += dis[y];
	tag[y] ^= 1;
}
int main() {
	int N, Q; scanf("%d%d", &N, &Q);
	for(int i=1;i<N;i++) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		addedge(a, b, c, d);
	}
	dfs(1, 0);
	for(int i=1;i<=Q;i++) {
		int x, y, u, v; scanf("%d%d%d%d", &x, &y, &u, &v);
		int l = lca(u, v);
		if( l == u || l == v ) {
			if( l == v ) swap(u, v);
			qry[i].le = fir[u] + 1, qry[i].ri = fir[v];
		}
		else {
			if( fir[u] > fir[v] ) swap(u, v);
			qry[i].le = bac[u], qry[i].ri = fir[v];
		}
		qry[i].num = i, qry[i].x = x, qry[i].y = y;
	}
	sort(qry + 1, qry + Q + 1);
	int l = 1, r = 0;
	for(int i=1;i<=Q;i++) {
		while( l > qry[i].le ) update(--l);
		while( r < qry[i].ri ) update(++r);
		while( l < qry[i].le ) update(l++);
		while( r > qry[i].ri ) update(r--);
		ans[qry[i].num] = nwres - sum[qry[i].x] + cnt[qry[i].x]*qry[i].y;
	}
	for(int i=1;i<=Q;i++)
		printf("%d\n", ans[i]);
}


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

using namespace std;
#define int long long
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e5 + 5;
int sz[N], c, n, ans;
vector <pii> g[N];

int dfs(int v, int par = 0, int W = 0) {
    sz[v] = 1;
    for (pii p : g[v]) if (p.F != par) sz[v] += dfs(p.F, v, p.S);
    ans += W*sz[v]*2;
    return sz[v];
}
int centr(int v, int par = 0) {
    for (pii p : g[v]) if (p.F != par && 2 * sz[p.F] > n) return centr(p.F, v);
    return v;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v, w; cin >> u >> v >> w;
        g[u].push_back({v, w}), g[v].push_back({u, w});
    }
    dfs(1), c = centr(1), ans = 0, dfs(c);
    int mn = 1e9;
    pii big {0, 0};
    for (pii p : g[c]) {
        mn = min(mn, p.S);
        if (sz[p.F] > sz[big.F]) big = p;
    }
    if (2 * sz[big.F] == n) ans -= big.S;
    else ans -= mn;
    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 17312