akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	m := eGetInt(scanner)

	h := &IntHeap{}
	heap.Init(h)

	for i := 0; i < n; i++ {
		heap.Push(h, eGetInt(scanner))
	}

	for i := 0; i < m; i++ {
		max := heap.Pop(h).(int)
		max /= 2
		heap.Push(h, max)
	}
	sum := 0
	for i := 0; i < len(*h); i++ {
		sum += (*h)[i]
	}
	fmt.Println(sum)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 6656
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<string> v;
vector<string> vec[51];
map<string, int> mp;

int NUM;
void rec(int now) {
  FOR(it, vec[now]) {
    string s = *it;
    if (s[0] == '[') {
      v.push_back(s.substr(1,s.size()-2));
      if (v.size() > NUM) throw 0;
    } else {
      rec(mp[s]);
    }
  }
}

ll dp[52][52][52][52];

int main() {
  int Na, Nt, Ng, Nc;
  while(cin>>Na>>Nt>>Ng>>Nc) {
    NUM = Na+Nt+Ng+Nc;
    int m;
    cin >> m;
    string line;
    getline(cin,line);
    REP(i,m) vec[i].clear();
    mp.clear();
    REP(i,m) {
      getline(cin,line);
      stringstream ss(line);
      string name;
      ss >> name;
      name = name.substr(0,name.size()-1);
      mp[name] = i;
      string s;
      while(ss>>s) {
        vec[i].push_back(s);
      }
    }
    v.clear();
    try {
      rec(0);
    } catch(int a) {
      cout << 0 << endl;
      continue;
    }

    // FOR(it, v) {
    //   cout << *it << " ";
    // }
    // cout << endl;
    if (v.size() != Na+Nt+Ng+Nc) {
      puts("0");
      continue;
    }

    const int mod = 1e9+7;
    memset(dp,0,sizeof(dp));
    dp[0][0][0][0] = 1;
    REP(i,Na+1) {
      REP(j,Nt+1) {
        REP(k,Ng+1) {
          REP(l,Nc+1) {
            int now=i+j+k+l;
            if (now >= v.size()) continue;
            FOR(it, v[now]) {
              int ii = i+(*it=='A');
              int jj = j+(*it=='T');
              int kk = k+(*it=='G');
              int ll = l+(*it=='C');
              (dp[ii][jj][kk][ll] += dp[i][j][k][l]) %= mod;
            }
          }
        }
      }
    }
    cout << dp[Na][Nt][Ng][Nc] << endl;
  }
}

Measured memory_bytes: 58388
IDENTIFICATION                    DIVISION.
PROGRAM-ID.                       PROGRAM_ID.
DATA                              DIVISION.
WORKING-STORAGE                   SECTION.
01 LN           PIC X(8).
01 N            PIC 9(3).
01 R            PIC 9(4).
01 ans          PIC Z(3)9.

PROCEDURE                         DIVISION.
    ACCEPT LN.
    UNSTRING LN DELIMITED BY SPACE INTO N R.
    IF 10 <= N
        MOVE R TO ans
    ELSE
        COMPUTE ans = R + 100 * (10 - N)
    END-IF.
    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 636
#!/bin/bash
':' /*
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro node:5.2-slim \
  /bin/bash -c "node /vo/$(basename $0) < /vo/g.inp"; exit $?
exit 0
*/

"use strict";

const main = (input) => {
  let mask = 0;
  for(let x of Array.from(input.split("\n"), x=> Number(x)-1)){
    mask += Math.pow(2,x);
  }
  return Math.log2(0b111 ^ mask) + 1;
};
console.log(main(require("fs").readFileSync("/dev/stdin", "utf-8").trim()));


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

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

int main() {
	map<pair<int,int>,bool> mp;
	unsigned long long h,w,n; cin >> h >> w >> n;
	vector<pair<int,int> > ab(n);
	for(int i=0;i<n;++i) {
		cin >> ab[i].first >> ab[i].second;
		mp[ab[i]]=true;
	}
	sort(ab.begin(),ab.end());
	unsigned long long ans[10]={};
	ans[0]=(h-2)*(w-2);
	for(int i=0;i<n;++i) {
		int a=ab[i].first,b=ab[i].second;
		for(int c=0;c<9;++c) {
			int d,cnt=0;
			for(d=0;d<9;++d) {
				auto tmp=make_pair(a+dx[c]+dx[d],b+dy[c]+dy[d]);
				if(tmp.first < 1 || tmp.second < 1 ||
				   tmp.first > h || tmp.second > w) break;
				if(mp[tmp]) {
					if(tmp<ab[i]) break;
					cnt++;
				}
			}
			if(d!=9) continue;
			ans[cnt]++;
			ans[0]--;
		}
	}
	for(int i=0;i<10;++i) cout << ans[i] << endl;
	
	return 0;
}


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

using namespace std;


int main()
{
	double kitaichi[1001];
	kitaichi[1] = 1.0;

	for (int i = 2; i <= 1000; i++)
	{
		kitaichi[i] = (kitaichi[i - 1] * ((double)i - 1.0) + (double)i) / (double)i;
	}

	int N, K;
	cin >> N >> K;
	vector<double> p;

	for (int i = 0; i < N; i++)
	{
		int num;
		cin >> num;
		p.push_back(kitaichi[num]);
	}

	double max_kitai = 0;
	double now_kitai = 0;
	
	for (int i = 0; i < K; i++)
	{
		now_kitai += p[i];
		max_kitai = now_kitai;
	}

	for (int i = K; i < N; i++)
	{
		now_kitai = now_kitai + p[i] - p[i - K];
		max_kitai = max(max_kitai, now_kitai);
	}
	
	cout << fixed << setprecision(15) << max_kitai << endl;
}

Measured memory_bytes: 2420
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        out.println((in.nextInt() * in.nextInt()) % 2 == 0 ? "Even" : "Odd");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 22996
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

using namespace std;
typedef long long ll;

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


    vector<ll> a(n);

    rep(i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll ans = a[0];
    ll preAns = ans;
    for (int i = 1; i < n; i++) {
        if (ans == 0) {
            break;
        }
        ans *= a[i];

        if (ans > 1000000000000000000 || ans < preAns) {
            ans = -1;
            break;
        }
        preAns = ans;
    }


    // cin >> ans;

    // bool overs = false;

    // rep(i, n-1) {
    //     ll a;
    //     cin >> a;

    //     if (!overs) {
    //         ans *= a;

    //         if (ans > 1000000000000000000) {
    //             ans = -1;
    //             overs = true;
    //         }
    //     } else {
    //         if (a == 0) {
    //             ans *= a;
    //             overs = false;
    //         }
    //     }
    // }

    cout << fixed << ans;

    return 0;
}


Measured memory_bytes: 3552
import java.util.*;
 
class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		double a = scan.nextDouble();
		double b = scan.nextDouble();
		double c = scan.nextDouble();

		double s = a * b * Math.sin(Math.toRadians(c)) / 2;
		double l = a + b + Math.sqrt((a * a) + (b * b) - 2 * a * b * Math.cos(Math.toRadians(c)));
		double h = b * Math.sin(Math.toRadians(c));

		System.out.println(s);
		System.out.println(l);
		System.out.println(h);
    }
}

Measured memory_bytes: 28100
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX = 410;

int dp[MAX][MAX];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    rep(i, MAX) rep(j, MAX) dp[i][j] = INF;
    dp[0][0] = 0;

    rep(i, n) {
        REPR(j, MAX, a[i]) REPR(k, MAX, b[i]) {
            dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]] + c[i]);
        }
    }
    int ans = INF;
    REP(k, 1, 40) {
        ans = min(ans, dp[k*ma][k*mb]);
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
l, r = list(map(int, input().split()))
MOD = 2019
diff = r - l
ans = 0
if diff < 2019:
    l = l%MOD
    r = l + diff
    ans = 2018
    for i in range(l,r):
        for j in range(i+1, r+1):
            ans = min(ans, (i%MOD*j%MOD)%MOD )
      
print(ans)

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

using namespace std;

int main()
{
    int n,i,c,a[100002],x;
    scanf("%d",&n);
    int mx=0;
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(i=1;i<100000;i++)
    {
        c=a[i]+a[i-1]+a[i+1];
        if(c>mx)
        {
            mx=c;
        }
    }
    printf("%d",mx);
    return 0;
}


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

int main(){
    int N; cin>>N;
    vector<int> A(N+1);
    rep(i,N){
        cin>>A.at(i+1);
    }

    vector<int> visited(N+1,0);
    int pos=1;
    int flag = 0;
    int counter=0;
    while(true){
        visited.at(pos) = 1;

        if(pos==2){
            flag=1;
            break;
        }else{
            counter++;
            pos  = A.at(pos);
            if(visited.at(pos)==1){//行ったことがあるところに帰ってきたからもうダメ
                break;
            }
        }
    }
    if(flag==1){
        cout<<counter<<endl;
    }else{
        cout<<-1<<endl;
    }





}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int a[n];
        for(int &it : a){
            cin >> it;
        }
        int p = 1;
        for(int &it : a){
            double r = (double)INF / it;
            //cout << p << ' ' << r << '\n';
            if(p > r){
                p = -1;
                break;
            }
            p *= it;
        }
        if(p > INF){
            p = -1;
        }
        for(auto &it : a){
            if(it == 0){
                p = 0;
                break;
            }
        }
        cout << p << '\n';
    }
}

Measured memory_bytes: 35136
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" <<endl;
  
  return 0;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b && b != c) || (b == c && c != a) || (c == a && a != b))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int 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 N=1005;
//Code begin...

int main ()
{
    int n, a, b;
    scanf("%d%d%d",&n,&a,&b);
    LL ans=(LL)(n-2)*(b-a);
    if ((n==1&&a!=b)||a>b) puts("0");
    else printf("%lld\n",ans+1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
using namespace std;
using ll=long long;
using ld=long double;
#define ssort(n) sort((n).begin(),(n).end())
typedef pair<int,int> P;

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N)cin >> a[i];
    map<ll,ll> b;
    stack<ll> stack_b;
    rep(i,N){
        if(!b.count(a[i])){
            b[a[i]]=1;
            stack_b.push(a[i]);
        }else{
            b[a[i]]++;
        }
    }
    ll val;
    ll count=0;
    while(!stack_b.empty()){
        val=stack_b.top();
        stack_b.pop();
        
        if(b[val]>=val){
            count+=b[val]-val;
        }

        else{
            count+=b[val];
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vi;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

int const N = 10000000;
bool isp[N];
int ps[N / 2];
int c = 0;
void eratos(){
    rep(i, N) isp[i] = true;
    isp[0] = isp[1] = false;
    for (int i = 2; i < N; i++){
        if (!isp[i]) continue;
        ps[c++] = i;
        for (int j = i + i; j < N; j += i){
            isp[j] = false;
        }
    }
}

int solve(int n, int p){
    auto it = upper_bound(ps, ps + c, n);
    vi v(p*p, 1 << 30);
    rep(i, p)loop(j, i, p){
        v[i * p + j] = *(it + i) + *(it + j);
    }
    sort(all(v));
    return v[p - 1];
}

int main(){
    eratos();
    int n, p;
    while (cin >> n >> p && n!=-1 && p!=-1){
        cout << solve(n, p) << endl;
    }
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  vector<ll> d(n);
  rep(i, n) {
    cin >> d[i];
  }

  sort(all(d));

  cout << (d[n / 2] - d[n / 2 - 1]) << endl;

  return 0;
}


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

#define X first
#define Y second
#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int main()
{
	int n;
	scanf("%d",&n);
	int last=0;
	LL ans=0;
	for (int j=1;j<=n;++j)
	{
		int x;
		scanf("%d",&x);
		last+=x;
		ans+=last/2;
		last%=2;
		if (x==0) last=0;
	}
	cout<<ans<<endl;
	return 0;
}


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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }
	do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
	return x * f;
}

int main() {
	int k = read();
	int a = read(), b = read();
	for(int i = a;i <= b;i++)
		if(!(i % k)) return std::puts("OK"), 0;
	std::puts("NG");
	return 0;
}


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

using namespace std;

#define endl '\n'
#define MAX 20

typedef long long ll;
typedef pair<ll,ll> pii;

const ll oo = 0x3f3f3f3f;

vector<pii> g[MAX];

vector<int> odds;

ll dist[MAX][MAX], dp[1 << 18];

int N,M;

ll Solve(){

	ll ans = 0;

	for(int I = 0;I < N;++I){

		for(auto it : g[I])
			ans += it.second;

		if(g[I].size() & 1)
			odds.push_back(I);
	}

	ans /= 2;

	for(auto u : odds){

		priority_queue<pii> Q;

		vector<int> d(MAX, oo);

		vector<bool> flag(MAX, false);

		int s = u;

		d[u] = 0;

		Q.push(pii(0,s));

		while(!Q.empty()){

			ll curr = Q.top().second; Q.pop();

			if(flag[curr])
				continue;
			flag[curr] = 1;

			for(auto edge : g[curr]){

				ll next = edge.first;

				ll peso = edge.second;

				if(!flag[next]){

					if(d[next] > d[curr] + peso){
						d[next] = d[curr] + peso;
						Q.push(pii(-d[next], next));
					}
				}
			}
		}

		for(auto v : odds){
			dist[u][v] = d[v];
		}
	}

	int N = (int)odds.size();

	for(int I = 0;I < (1 << N);++I)
		dp[I] = oo;

	dp[0] = 0;

	for(int mask = 0;mask < (1 << N);++mask){

		for(int I = 0;I < N;++I){

			if(!(mask & (1 << I))){

				for(int K = I + 1;K < N;++K){

					if(!(mask & (1 << K))){

						dp[mask | 1 << I | 1 << K] = min(dp[mask | 1 << I | 1 << K], dp[mask] + dist[odds[I]][odds[K]]);
					}
				}
			}
		}
	}

	ans += dp[(1 << N) - 1];

	return ans;
}

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

    cin >> N >> M;

    ll a,b,c;

    while(M--){
    	cin >> a >> b >> c;
    	g[a].push_back(pii(b,c));
    	g[b].push_back(pii(a,c));
    }

    cout << Solve() << endl;
}



Measured memory_bytes: 3264
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int c; cin>>c;
    string hoge;
    rep(i,c){
        cin>>hoge;
        sort(all(hoge));
        int p=stoi(hoge);
        sort(all(hoge),greater<char>());int q=stoi(hoge); cout<<q-p<<endl;
    }
    
}

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

using namespace std;

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

bool calc(vector<string> grid,int n)
{
	int h=grid.size(),w=grid[0].size();
	for(;;){
		rep(j,w) for(int i=h,k=h;i--;)
			if(grid[i][j]!='.')
				swap(grid[i][j],grid[--k][j]);
		
		bool update=false;
		vector<vector<int>> flg(h,vector<int>(w));
		rep(i,h) rep(j,w){
			if(grid[i][j]=='.') continue;
			bool f1=i+n<=h,f2=j+n<=w;
			rep(k,n) if(f1) f1&=grid[i+k][j]==grid[i][j];
			rep(k,n) if(f2) f2&=grid[i][j+k]==grid[i][j];
			update|=f1||f2;
			rep(k,n) if(f1) flg[i+k][j]=1;
			rep(k,n) if(f2) flg[i][j+k]=1;
		}
		rep(i,h) rep(j,w) if(flg[i][j]) grid[i][j]='.';
		if(!update) break;
	}
	return count(begin(grid),end(grid),string(w,'.'))==h;
}

int main()
{
	for(int h,w,n;cin>>h>>w>>n;){
		vector<string> grid(h);
		rep(i,h) cin>>grid[i];
		
		bool res=false;
		rep(i,h) rep(j,w-1){
			swap(grid[i][j],grid[i][j+1]);
			res|=calc(grid,n);
			swap(grid[i][j],grid[i][j+1]);
		}
		cout<<(res?"YES":"NO")<<endl;
	}
}

Measured memory_bytes: 1244
N,K,Q = map(int,input().split())
A = []
B = []
for j in range(N):
    B.append(K-Q)
for i in range(Q):
    A.append(int(input()))
    B[A[i]-1] += 1
for j in range(N):
    if B[j] >= 1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 16856
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int X=1e9;
LL s;
int main(){
	cin>>s;
	printf("0 0\n");
	printf("1 %d\n",X);
	int x=(s-1)/X;
	int y=(s-1)%X+1;
	printf("%d %d\n",x+1,X-y);
	return 0;
}

Measured memory_bytes: 256
#coding:utf-8
n=[int(i) for i in input().split()]
m1=[1,3,5,7,8,10,12]
m2=[4,6,9,11]
if(n[0]==n[1]==2):
  print("Yes")
elif(n[0] in m1 and n[1] in m1):
  print("Yes")
elif(n[0] in m2 and n[1] in m2):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 1e10;
using P = pair<int, int>;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<P> cd(m);
  for (auto&& u : a) cin >> u;
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    cd[i] = make_pair(c, b);
  }
  sort(begin(cd), end(cd));
  sort(begin(a), end(a));
  // cerr << endl;
  // for (auto&& u : cd) cerr << u.first << " " << u.second << endl;
  int sum = 0;
  int i = n - 1;
  int j = m - 1;
  int cnt = n;
  while (cnt > 0) {
    //  cerr << sum << " " << i << " " << j << endl;
    if (j < 0 || a[i] >= cd[j].first) {
      sum += a[i];
      i--;
      cnt--;
    } else {
      int r = min(cnt, cd[j].second);
      sum += r * cd[j].first;
      j--;
      cnt -= r;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 2560
#include <cstdio>
using namespace std;
long long a,b,c,sum;
int main()
{
	scanf("%lld%lld",&a,&b);
	for(long long i=1;i<=b;i++)
	{
		scanf("%lld",&c);
		sum+=c;
	}
	if(sum>=a)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ers erase
#define ins insert
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cout << #x << "= " << x << '\n';
#define kill(x) return cout << x, 0;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 1e5 + 10;
const ll INF = 1e18;
const ll LOG = 25;

ll Sum_Max[3 * N], Sum_Min[3 * N], n, a[3 * N];
multiset<pll> Max_set;
multiset<pll> Min_set;
ll Sum;
int main(){
	cin >> n;
	for (int i = 1; i <= 3 * n; i++) cin >> a[i];
	for (int i = 1; i <= 3 * n; i++){
		Max_set.ins({a[i], i});
		Sum += a[i];
		if (Max_set.size() > n){
			pll av = *(Max_set.begin());
			Sum -= av.F;
			Max_set.ers(av);
		}
		Sum_Max[i] = Sum;	
	}
	Sum = 0;
	for (int i = 3 * n; i >= 1; i--){
		Sum += a[i];
		Min_set.ins({a[i], i});
		if (Min_set.size() > n){
			pll tah = *(Min_set.rbegin());
			Sum -= tah.F;
			Min_set.ers(tah);
		}
		Sum_Min[i] = Sum;
	}
	ll ans = -INF;
	for (int i = n; i <= 2 * n; i++){
		//cout << i << ' ' << Sum_Max[i] << '\n';
		ans = max(ans, Sum_Max[i] - Sum_Min[i + 1]);
	}	
	cout << ans;

	return 0;

}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	ll k, rem = 0;
	cin >> k;

	for(ll i = 1; i <= 3 * k; i++){
		rem = (rem * 10 + 7) % k;
		if(rem == 0){
			cout << i << endl;
			return 0;
		}
	}


	cout << -1 << endl;
	
	
	return 0;
}


Measured memory_bytes: 3608
using System;

namespace A___Libra
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var l = int.Parse(input[0]) + int.Parse(input[1]);
            var r = int.Parse(input[2]) + int.Parse(input[3]);
            if (l > r)
            {
                Console.WriteLine("Left");
            }
            else if (l == r)
            {
                Console.WriteLine("Balanced");
            }
            else
            {
                Console.WriteLine("Right");
            }
        }
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		if(sc.nextInt() * 500 >= sc.nextInt()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 23252
N, C, K = list(map(int, input().split()))
T = []
for i in range(N):
  T.append(int(input()))

bus = []
departure=0

T.sort()

for passenger in T:
  if bus == []:
    bus.append(passenger)
    
  elif passenger <= bus[0]+K and len(bus)<=(C-1):
    bus.append(passenger)
  
  else:
    bus.clear()
    departure+=1
    bus.append(passenger)
    
if bus != []:
  print(departure + 1)
else:
  print(departure)

Measured memory_bytes: 13304
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int fs[N];
  for (int i = 0; i <= N; i++) {
    fs[i] = 0;
  }
  for (int x = 1; x <= 110; x++) {
    for (int y = 1; y <= 110; y++) {
      for (int z = 1; z <= 110; z++) {
        int n = x * x + y * y + z * z + x * y + y * z + z * x;
        if (n <= N) {
          fs[n]++;
        }
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << fs[i] << endl;
  }
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
		if(x+r<=W && y+r<=H && x-r>=0 && y-r>=0){
			printf("Yes\n");
	}
    	else {
		printf("No\n");
	}


	return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    int result[N];
    int AC = 0, WA = 0;
    for(int i = 0; i < N; i++) result[i] = 0;
    for(int i = 0; i < M; i++) {
        int p;
        string S;
        cin >> p >> S;
        p--;
        if(result[p] == 1)
            continue;
        else {
            if(S.compare("AC") == 0) {
                AC++;
                WA -= result[p];
                result[p] = 1;
            } else
                result[p]--;
        }
    }
    cout << AC << " " << WA << "\n";
    return 0;
}

Measured memory_bytes: 640
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
ll bsearch(vector<ll>&v,ll s,ll e,ll a,ll b)
{
    ll ans=-1;
    while(s<=e)
    {
        ll mid=(s+e)/2;
        if(v[mid]<=a)
        {
            s=mid+1;
        }else if(v[mid]>=b)
        {
            e=mid-1;
        }else{
            ans=v[mid];
            return ans;
        }
    }
    return ans;
}
int main()
{
fast;
ll n;
cin>>n;
string s;
cin>>s;
map<ll,vector<ll> >m;
for(ll i=0;i<n;i++)
{
    ll x=s[i]-48;
    m[x].pb(i);
}
ll ans=0;
for(ll i=0;i<=9;i++)
{
    for(ll j=0;j<=9;j++)
    {
        for(ll k=0;k<=9;k++)
        {
            if(m[i].size()==0||m[j].size()==0||m[k].size()==0)
            {
                continue;
            }
            ll x=m[i][0];
            ll hh=m[k].size();
            ll z=m[k][hh-1];
            if(x>=z)
            {
                continue;
            }
            ll sz=m[j].size();
            ll ans1=bsearch(m[j],0,sz-1,x,z);

            if(ans1==-1)
            {
                continue;
            }
            if(ans1>x&&ans1<z)
            {
                //cout<<i<<" "<<j<<" "<<k<<endl;
                ans++;
            }
        }
    }
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 768
import java.util.*;

public class Main {
    static double[][][] dp; 
    static int N;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        // int[] a = new int[N];
        int x=0;
        int y=0;
        int z=0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a == 1) {
                x++;
            } else if(a == 2) {
                y++;
            } else if(a == 3) {
                z++;
            }
        }
        dp = new double[N+6][N+6][N+6];
        System.out.println(rec(x,y,z));
   }
   public static double rec(int x, int y, int z) {
       if (x == 0 && y == 0 && z == 0) {
           return 0;
       }
       if (dp[x][y][z] > 0.1) return dp[x][y][z];
       int s = x + y + z;
       if (x>0) {
           dp[x][y][z] += (rec(x-1,y,z) * ((double) x)) / s;
       }
       if (y>0) {
           dp[x][y][z] += (rec(x+1,y-1,z) * ((double) y)) / s;
       }
       if (z>0) {
           dp[x][y][z] += (rec(x,y+1,z-1) * ((double) z)) / s;
       }
       dp[x][y][z] += ((double) N)/s;
       return dp[x][y][z];
   }
}

Measured memory_bytes: 308116
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s, t, u;
    ll a, b;
    cin >> s >> t >> a >> b >> u;

    ll x = a, y = b;
    if(u == s) {
        x--;
    }
    else {
        y--;
    }
    
    cout << x << " " << y << endl;
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int W,H,x,y;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> W >> H >> x >> y;
  cout << W*H/2.0 << " " << (x*2 == W && y*2 == H) << endl;

  return 0;
}

Measured memory_bytes: 256
//http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm　参照
#include<cstdio>

using namespace std;

int main(void){
	float xa,ya,xb,yb,xc,yc,xd,yd;
	float ta,tb,tc,td;

	while((scanf("%f,%f,%f,%f,%f,%f,%f,%f",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd))!=EOF){
		ta=(xb-xd)*(ya-yb)+(yb-yd)*(xb-xa);
		tb=(xa-xc)*(yb-ya)+(ya-yc)*(xa-xb);
		tc=(xb-xd)*(yc-yb)+(yb-yd)*(xb-xc);
		td=(xa-xc)*(yd-ya)+(ya-yc)*(xa-xd);
		if(ta*tc<0 && tb*td<0)	printf("YES\n");
		else	printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define ld long double
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
 /*struct cmp{ bool operator() ( const, const )const{}};
  use as set<ll> ,cmp> a*/
int main()
{
  ios::sync_with_stdio(false);cin.tie(0);
  //freopen("input.txt" , "r" , stdin );
  ll n,m,x;
  cin>>n>>m>>x;
  vector<vector<ll>> a(m+1,vector<ll> (n));
  for(ll i = 0 ; i<n ; i++)
  {
      for(ll j = 0 ; j<m+1 ; j++)
      {
          cin>>a[j][i];
      }
  }
  vector<pair<ll,bool>> b(10000);
  for(ll i = 0 ; i<10000 ; i++)
  {
      b[i] = make_pair(0,1);
  }
  for(ll i = 1 ; i<m+1 ; i++)
  {
      for( ll j = 1 ; j<(1<<n) ; j++ )
      {
          ll sum = 0 ;
          ll csum = 0 ;
          for( ll k = 0 ; k<n ; k++)
          {

              if( j&(1<<k) )
              {
                  sum += a[i][k] ;
                  csum += a[0][k];
              }
          }

              b[j].first = csum ;
              if(sum>=x && b[j].second==1 )
                b[j].second = 1;
              else
                b[j].second = 0;



      }
  }
  ll mi = 10000000;
  for(ll i = 0 ; i<10000 ; i++)
  {

      if(b[i].second==1 && b[i].first>0)
        mi = min(mi,b[i].first);
  }
  if(mi==10000000)
    cout<<-1;
  else
    cout<<mi;
  return 0;

}



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

using namespace std;

int main ()
{
	
	double n, sum = 0;
	cin >> n;
	for (int i=1; i<=n; i++){
		if (i % 2 == 1){
			sum++;
		}
	}
	cout << fixed << setprecision(10) << sum/n << endl;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn print_v<T: std::fmt::Debug>(v: &Vec<Vec<T>>){
    for row in v{
        println!("{:?}", row);
    }
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, m)  = (line[0], line[1]);
    let num_patterns = 1 << n;

    let mut a = vec![];
    let mut c: Vec<usize> = vec![];

    //let dummy = std::u64::MAX;
    let dummy = -1;

    for _ in 0..m{
        let line = read_as_vec::<_>();
        a.push(line[0]);

        let c_vec = read_as_vec::<usize>();
        let mut c_bit = 0;

        for treasure in c_vec{
            c_bit |= 1 << (treasure -1);
        }

        c.push(c_bit);
    }

    let mut dp: Vec<Vec<_>> = vec![vec![dummy;num_patterns];m];
    dp[0][0] = 0;
    dp[0][c[0]] = a[0];
    for i in 1..m{
        for j in 0..num_patterns{
            if dp[i-1][j] != dummy{
                //do not use key i
                //overwrite
                if dp[i][j] == dummy || dp[i-1][j] < dp[i][j]{
                    dp[i][j] = dp[i-1][j];
                }

                //use key i
                let new_pattern = c[i] | j;
                if dp[i][new_pattern] == dummy || dp[i][new_pattern] > dp[i-1][j]+a[i]{
                    dp[i][new_pattern] = dp[i-1][j]+a[i];
                }

            }
        }
    }

    //print_v(&dp);

    println!("{}",dp[m-1][num_patterns-1]);
}


Measured memory_bytes: 24828
from collections import deque

s = input()
cnt = 0
i = 0
n = len(s)
stack = deque()
updated = True
while updated:
    updated = False
    while i < n and len(stack) > 0 and stack[-1] != s[i]:
        updated = True
        stack.pop()
        i += 1
        cnt += 2
    if i < n:
        updated = True
        stack.append(s[i])
    i += 1
# print(stack)
print(cnt)



Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int, int> mii;

int getId(vi &v, int e, bool is) {
    int i;
    for (i = 0; i < v.size(); i++) {
        if (e == v[i])
            break;
    }
    return (is ? (i + 1) % 4 : (i - 1 + 4) % 4);
}

int main() {FIN
    
    int i, j, q, a, b;
    vi dd(6);
    vvi ps = {{1,2,4,3}, {0,3,5,2}, {0,1,5,4}};
    mii idd;
    for (i = 0; i < 6; i++) {
        cin >> dd[i];
        idd[dd[i]] = i;
    }
    cin >> q;
    while (q--) {
        cin >> a >> b;
        i = idd[a], j = idd[b];
        if (i == 0 or i == 5) {
            i = getId(ps[0], j, i == 0);
            cout << dd[ps[0][i]] << "\n";
        } else if (i == 1 or i == 4) {
            i = getId(ps[1], j, i == 1);
            cout << dd[ps[1][i]] << "\n";
        } else {
            i = getId(ps[2], j, i == 2);
            cout << dd[ps[2][i]] << "\n";
        }
    }
    return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std ;
int main () {
  char a ;
  int nul[26] = {} ;
  while(cin>>a){
    if(isupper(a)) a = tolower(a) ;
    nul[(int)a-'a'] ++ ;
  }
  for(int i = 0 ; i < 26 ; i++ ) {
    cout << char(i+'a') << " : " << nul[i] << endl ;
  }
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <queue>

int main (void){
  int R, C; std::cin >> R >> C;
  std::pair<int,int> start = {1-1,1-1};
  std::pair<int,int> goal  = {R-1,C-1};

  int mass_w = 0;
  std::vector<std::vector<int>> meiro;
  meiro.resize(R); for(int i=0; i<R; i++) meiro[i].resize(C);
  for(int i=0; i<R; i++) {
    for(int j=0; j<C; j++) {
      char c; std::cin >> c;
      if ( c == '#' ) meiro[i][j] = 1;
      if ( c == '.' ) {
        meiro[i][j] = 0;
        mass_w++;
      }
    }
  }

  std::pair<int,int> dirs[4] = { {-1,0 }, {1, 0}, {0,-1}, {0,1} };


  {
    std::vector<std::vector<int>> memo;
    memo.resize(R); for(int i=0; i<R; i++) memo[i].resize(C, 0);

    std::queue<std::pair<int,int>> q;
    q.push(start);
    memo[start.first][start.second] = 1;
    while(!q.empty()){
      std::pair<int,int> cur = q.front(); q.pop();
      if ( cur == goal ) {
        std::cout << mass_w - memo[goal.first][goal.second] << std::endl;
        return 0;
      }
      for(std::pair<int,int> dir : dirs) {
        std::pair<int, int> next = { cur.first + dir.first, cur.second + dir.second };
        if ( next.first >= 0 && next.first < R && next.second >= 0 && next.second < C
           && meiro[next.first][next.second] == 0 && memo[next.first][next.second] == 0 ){
          memo[next.first][next.second] = memo[cur.first][cur.second]+1;
          q.push(next);
        }
      }
    }
  }
  std::cout << -1 << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int x,y,z;
    cin>>x>>y>>z;
    cout << z << " " << x << " " << y << "\n";
}

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<vector<long long>> dp(c+1, vector<long long>(d+1,0));
    dp[a][b] = 1;
    for (int x = a; x < c + 1; x++)
    {
        for (int y = b; y < d + 1; y++)
        {
            if (x != a or y != b)
            {
                dp[x][y] = dp[x - 1][y] * y + dp[x][y - 1] * x - dp[x - 1][y - 1] * (x - 1) * (y - 1);
                dp[x][y] += 2*998244353;
                dp[x][y] %= 998244353;
            }
        }
    }

    cout << (dp[c][d]+2*998244353) % 998244353 << endl;
    return 0;
}


Measured memory_bytes: 73744
N = int(input())
Stone = list(input())
Black_count = 0
White_count = 0
Cost = []

#全体の白石の数をかぞえる
for i in range(N):
  if Stone[i] == '.':
    White_count += 1

#"黒い石のすぐ右に白い石があるような箇所がない"状態 = j番目の点より右側は黒、左側は白になる。(j番目の点の色はどっちでもいい)
#つまり、j番目(0 ≦ j ≦ N-1)の石を境目にする時のコストをCostに記入していき最小のものを取れば良い。

for j in range(N):
  #j番目の石が白のとき
  if Stone[j] == '.':
    White_count -= 1
    Cost.append(White_count + Black_count)
  #j番目の石が黒のとき
  else:
    Cost.append(White_count + Black_count)
    Black_count += 1

print(min(Cost))


Measured memory_bytes: 12836
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	long long ans=0,r=0,s=0;
	for(int i=0;i<n;i++)
	{
		while(r<n&& (s^a[r])==(s+a[r]))
		{
			s+=a[r];
			++r;
		}
		ans+=r-i;
		s-=a[i];
	}
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 4412
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
struct Node{
  int no;
  int par;
  int dist;
  vector<pair<int,int>> edge;
  void build(int i){
    no=i;par=0;dist=0;
  }
};
signed main(){
  int n;cin>>n;
  vector<Node> node(n+1);
  rep(i,n-1){
    int u,v,w;cin>>u>>v>>w;
    node[u].edge.emplace_back(v,w);
    node[v].edge.emplace_back(u,w);
  }
  rep1(i,n){
    node[i].build(i);
  }
  queue<Node> que;
  que.push(node[1]);
  while(!que.empty()){
    Node buf=que.front();que.pop();
    int num=buf.edge.size();
    rep(i,num){
      if(node[buf.edge[i].first].no!=buf.par){
        node[buf.edge[i].first].par=buf.no;
        node[buf.edge[i].first].dist=buf.dist+buf.edge[i].second;
        que.push(node[buf.edge[i].first]);
      }
    }
  }

  rep1(i,n){
    if(node[i].dist%2==0){
      cout<<1<<"\n";
    }
    else{
      cout<<0<<"\n";
    }
  }
  return 0;
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s, p;
  cin >> s >> p;
  s += s;

  for (int i = 0; i < s.size() - p.size(); ++i)
    if (s.substr(i, p.size()) == p)
    {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 3208
class BitMatrix
	def initialize(m, n)
		@rows = [0] * m
		@cols = [0] * n
	end

	def [](i,j)
		@rows[i][j]
	end

	def []=(i,j,x)
		raise "set non-binary value to BitMatrix" if x != 0 && x != 1
		@rows[i] |= (x << j)
		@cols[j] |= (x << i)
	end

	def row(i)
		@rows[i]
	end

	def col(i)
		@cols[i]
	end

	def row_size
		@rows.size
	end

	def col_size
		@cols.size
	end

	def *(other)
		return self.dup if other == 1

		prod = self.class.new(self.row_size, other.col_size)
		(0..prod.row_size-1).each{|i|
			(0..prod.col_size-1).each{|j|
				prod[i, j] = self.row(i) & other.col(j) > 0 ? 1 : 0
			}
		}
		prod
	end

	def to_s
		@rows.map{|b|
			s = b.to_s(2)
			s.reverse + "0" * (@rows.size - s.size)
		}.join("\n")
	end
		
end

def exp(n, k, mod = nil)
	x = 1
	r = n
	while k > 0
		x = r * x if k & 1 == 1
		r *= r		
		if mod
			x %= mod
			r %= mod
		end
		k >>= 1
	end
	x
end

loop {
	n, m, z = gets.split.map &:to_i
	break if n == 0

	edges = (1..m).map {
		e = gets.split.map &:to_i
		[e, e.reverse]
	}.flatten(1)

	mat = BitMatrix.new(2*m, 2*m)
	(0..2*m-1).each{|i|
		(0..2*m-1).each{|j|
			mat[i, j] = 1 if edges[i][1] == edges[j][0] && edges[i][0] != edges[j][1]
		}
	}
	u = BitMatrix.new(1, 2*m)
	(0..2*m-1).each{|i|
		u[0, i] = 1 if edges[i][0] == 1 
	}
	v = BitMatrix.new(2*m, 1)
	(0..2*m-1).each{|i|
		v[i, 0] = 1 if edges[i][1] == n
	}
	puts (u * exp(mat, z-1) * v)[0, 0] > 0 ? 'yes' : 'no'
}

Measured memory_bytes: 6096