akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;
typedef long long ll;

ll gcd(ll x, ll y){
  if(y==0) return x;
  return gcd(y, x % y);
}


int main()
{
  ll a, b;
  ll c, d;
  ll res=0;
  cin >> a >> b >> c >> d;
  
  ll lcm = c*d/gcd(c,d);

#if 0
  cout << gcd(c,d)<<endl;
  cout << lcm << endl;
  cout << b/c-(a-1)/c << endl;
  cout << b/d-(a-1)/d << endl;
  cout << b/lcm-(a-1)/lcm << endl;
#endif
  
  res = (b - a + 1) - ((b/c-(a-1)/c) + (b/d-(a-1)/d) - (b/lcm - (a-1)/lcm));
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=924844033;
vector<VVI> wy[2];
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,k;
  cin>>n>>k;
  forn(z,2)
    wy[z].resize(2,VVI(2,VI(n+3,0)));
  in sw=1;
  in nw=0;
  wy[nw][0][0][0]=1;
  in hl,hr;
  in mm=0;
  forn(s,k){
    for(in i=s;i<n;i+=k){
      swap(sw,nw);
      forn(a,2){
	forn(b,2){
	  forn(i,n+3){
	    wy[nw][a][b][i]=0;
	    wy[sw][a][b][i]%=mdl;
	  }
	}
      }
      ++mm;
      hl=(i>s);
      hr=(i+k<n);
      forn(wd,hl+1){
	forn(wu,hl+1){
	  forn(td,2){
	    forn(tu,2){
	      forn(mtg,2){
		if(mtg==1 && (td||tu))
		  continue;
		forn(ob,max(mm,n-mm)+3){
		  if(ob==0 && (td+tu>0))
		    continue;
		  if(hr){
		    wy[nw][-mtg+!td][-mtg+!tu][ob+1-td-tu-mtg]+=wy[sw][wd][wu][ob]*(tu?(ob-wd):1)*(td?(ob-wu):1)%mdl;
		  }
		  else{
		    wy[nw][0][0][ob+1-td-tu-mtg]+=wy[sw][wd][wu][ob]*(tu?(ob-wd):1)*(td?(ob-wu):1)%mdl;
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
  cout<<wy[nw][0][0][0]%mdl<<endl;
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
using pair = Pair<long, long>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;

        int left = 0;
        int right = N - 1;

        WriteLine(0);
        var L = ReadLine();
        if (L == "Vacant") return;
        WriteLine(N - 1);
        var R = ReadLine();
        if (R == "Vacant") return;
        while (true)
        {
            int mid = (left + right) / 2;
            WriteLine(mid);
            var M = ReadLine();
            if (M == "Vacant") return;
            bool flag = true;
            if (L == M)
            {
                if ((mid - left - 1) % 2 == 1) flag = false;
            }
            else
            {
                if ((mid - left - 1) % 2 == 0) flag = false;
            }
            if (flag)
            {
                right = mid;
                R = M;
            }
            else
            {
                left = mid;
                L = M;
            }
        }

    }


}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f;
    public U s;
    public Pair(T f, U s)
    {
        this.f = f;
        this.s = s;
    }
    public int CompareTo(Pair<T, U> a)
    {
        return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    }
    public override string ToString()
    {
        return f + " " + s;
    }
}
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13512
#include <stdio.h>
#define MAX_N 100001

int a[MAX_N];

void swap(int &a, int &b)
{
    int t = a;
    a = b;
    b = t;
}

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == i) {
            cnt++;
            swap(a[i], a[i + 1]);
        }
    }
    if (a[n] == n) {
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
signed main(){
  cin.tie(0);
  int n,q;
  cin>>n>>q;
  vector<int> s(n);
  for(int i=0;i<n;i++) cin>>s[i];
  string query[q];
  int a[q];
  for(int i=0;i<q;i++) cin>>query[i]>>a[i];
  
  vector<int> v=s;
  sort(v.begin(),v.end());
  map<int,int> m;
  for(int i=0;i<n;i++) m[v[i]]=i;
  
  set<int> si;
  for(int i=0;i<q;i++){
    if(query[i]=="ADD"){
      si.insert(a[i]-1);
      continue;
    }
    if(query[i]=="REMOVE"){
      si.erase(a[i]-1);
      continue;
    }
    if(a[i]==n){
      cout<<0<<endl;
      continue;
    }
    vector<int> u;
    for(int j: si) u.push_back(m[s[j]]);
    sort(u.begin(),u.end());
    u.erase(unique(u.begin(),u.end()),u.end());
    int sz=u.size();
    //for(int j=0;j<sz;j++) cout<<u[j]<<"-";cout<<endl;
    
    if(!sz || u[sz-1]+1<n-a[i]){
      cout<<"NA"<<endl;
      continue;
    }
    int l=-1,r=(1e9)+7;
    while(l+1<r){
      int x=(l+r)/2;
      int tmp=-1,cnt=0;
      for(int j=0;j<sz;j++){
	int pos=lower_bound(v.begin(),v.end(),v[u[j]]-x)-v.begin();
	if(pos<tmp) pos=tmp;
	cnt+=u[j]+1-pos;
	tmp=u[j]+1;
      }
      //cout<<x<<":"<<cnt<<"-"<<n-a[i]<<endl;
      if(cnt<n-a[i]) l=x;
      else r=x;
    }
    cout<<r<<endl;
  }
  return 0;
}

Measured memory_bytes: 57520
N, K = map(int,input().split())
S = input()

lex_min = "z"
for char in S:
  lex_min = min(char, lex_min)

U = S + S[::-1]

L = 0
L_max = 0
for i in range(N << 1):
  if U[i] == lex_min:
    L_max += 1
  else:
    L = max(L, L_max)
    L_max = 0
L = max(L, L_max)

if (1 << (K - 1)) * L >= N:
  print(lex_min * N)
else:
  candidates = []
  n = (1 << (K - 1)) * L
  for i in range(N, N << 1):
    if U[i-L+1:i+1] == L * lex_min:
      cand = n * lex_min + U[i-N+n-L+1:i-L+1][::-1]
      candidates.append(cand)
      
  print(min(candidates))

Measured memory_bytes: 263540
# switchが10個以下


N,M = map(int,input().split())

sw = [[] for _ in range(M)]
for i in range(M):
  sw[i] = list(map(int,input().split()[1:]))
  

p = [int(x) for x in input().split()] # 不要

import itertools


answer = 0
for tpl in itertools.product([0,1],repeat=N):
  bl = True
  for i in range(M):
    # 電球iを計算
    s = sum([tpl[s-1] for s in sw[i]])
    if (s-p[i])%2 != 0:
      bl = False
      break
  if bl:
    answer += 1
print(answer)

Measured memory_bytes: 3188
#include <iostream>
#include <array>
#include <algorithm>

int min = 99999;
int time_[5];

int check_(std::array<int, 5> flag ){
  int rtn = 0;
  for(int i=0; i<5; i++){
    if ( flag[i] == 1 ) rtn++;
  }
  return rtn;
}

void dfs (std::array<int, 5> flag, int sum, std::string str) {
  if ( check_(flag) == 5 ) {
    min = std::min(min, sum);
    return;
  }
  if ( check_(flag) == 4 ) {
    for(int i=0; i<5; i++){
      if ( flag[i] == 0 ){
        std::array<int,5> flag_ = flag; flag_[i] = 1;
        std::string str_ = str + (" " + std::to_string(i));
        dfs( flag_, sum+time_[i], str_);
      }
    }
    return;
  }
  if ( check_(flag) < 4 ){
    for(int i=0; i<5; i++){
      if ( flag[i] == 0 ){
        std::array<int,5> flag_ = flag; flag_[i] = 1;
        std::string str_ = str + (" " + std::to_string(i));
        if ( (sum+time_[i])% 10 == 0 ) dfs( flag_, sum+time_[i], str_);
        else dfs( flag_, 10*(((sum+time_[i])/10)+1), str_);
      }
    }
    return;
  }
}

int main (void){

  for(int i=0; i<5; i++){
    std::cin >> time_[i];
  }
  std::array<int, 5> flag = {0};
  dfs(flag, 0, "");

  std::cout << min << std::endl;
  return 0;
}


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

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int x, n;
	cin >> x >> n;
	int ans = 0;
	vector<int> p(n);
	vector<bool> found(101);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		found[p[i]] = true;
	}
	for (int i = 0; i <= 101; i++) {
		if (i <= 100 && found[i])
			continue;
		if (abs(x - i) < abs(x - ans)) {
			ans = i;
		} else if (abs(x - i) == abs(x - ans) && i < ans) {
			ans = i;
		}
	}
	cout << ans << '\n';
}



Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
using namespace std;

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

const ll MAX_N = 2e5 + 5;
ll n, m, v, p, ans;
ll Arr[MAX_N];
ll Brr[MAX_N];

bool can(ll d) {
    ll ind = n - p + 1;
    if (d < Arr[ind - 1])
        return false;

    ll nv = v - (p - 1);
    if (nv <= 0)
        return true;

    for (int i = 0; i < ind; i++)    
        Brr[i] = d - Arr[i];

    ll s = 0;
    while (s < ind && Brr[s] >= m && nv) {
        nv--;
        s++;
    }

    if (nv <= 0)
        return true;

    ll sum = 0;
    for (int i = s; i < ind; i++)
        sum += Brr[i];

    return sum >= nv * m;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m >> v >> p;
    for (int i = 0; i < n; i++)
        cin >> Arr[i];
    sort(Arr, Arr + n);
    ll s = 0, e = 2e9;
    while (e - s > 1) {
        ll mid = e + s >> 1;
        if (can(mid))
            e = mid;
        else
            s = mid;
    }

    for (int i = 0; i < n; i++)
        if (Arr[i] + m >= e)
            ans++;

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
l_d = []
l_A = []
for i in range(K):
  di = int(input())
  Ai = list(map(int, input().split()))
  l_d.append(di)
  l_A.append(Ai)

l = [0]*N
for i in range(len(l_A)):
  for j in l_A[i]:
    l[j-1] = 1

print(l.count(0))

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a ;
  int m = a / 100;
  int n = a / 10 - m * 10;
  int b = m % 2 + n % 2 + a % 2;
  cout << b  << endl;
}

Measured memory_bytes: 384
use strict;
use warnings;

chomp (my $n = <>);
my @w = split /\s/, <>;

my @l;
my @r;

my $sum = 0;
my $cnt = 0;
foreach my $i (@w) {
	$sum += $i;
	$l[$cnt] = $sum;
	$cnt++;
}

$sum = 0;
$cnt = @w - 1;
foreach my $i (reverse @w) {
	$sum += $i;
	$r[$cnt] = $sum;
	$cnt--;
}

my $min = 99999999;

for (my $i = 0; $i < @w - 1; $i++) {
	my $diff = abs($l[$i] - $r[$i + 1]);
	if ($min > $diff) {
		$min = $diff;
	}
}

print $min, "\n";



Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
template<typename T> inline void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> inline void chmax(T& a, T b) { if (a < b) a = b; }
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 19;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[4];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), M = getint(), L = getint();
	int C[300][300];
	rep(j, N) rep(i, j) C[i][j] = 1e9 + 1;
	rep(i, M) {
		int a = getint(), b = getint(), c = getint();
		C[--a][--b] = c;
		C[b][a] = c;
	}

	rep(k, N) {
		auto Ck = C[k];
		rep(i, k) {
			auto Ci = C[i];
			auto Cik = Ci[k];
			for (int j = i + 1; j < k; j++) {
				chmin(Ci[j], Cik + C[j][k]);
			}
			for (int j = k + 1; j < N; j++) {
				chmin(Ci[j], Cik + Ck[j]);
			}
		}
		for (int i = k + 1; i < N; i++) {
			auto Ci = C[i];
			auto Cki = Ck[i];
			for (int j = i + 1; j < N; j++) {
				chmin(Ci[j], Cki + Ck[j]);
			}
		}
	}

	rep(j, N) rep(i, j) {
		C[i][j] = (C[i][j] <= L) ? 1 : 1e9;
	}

	rep(k, N) {
		auto Ck = C[k];
		rep(i, k) {
			auto Ci = C[i];
			auto Cik = Ci[k];
			for (int j = i + 1; j < k; j++) {
				chmin(Ci[j], Cik + C[j][k]);
			}
			for (int j = k + 1; j < N; j++) {
				chmin(Ci[j], Cik + Ck[j]);
			}
		}
		for (int i = k + 1; i < N; i++) {
			auto Ci = C[i];
			auto Cki = Ck[i];
			for (int j = i + 1; j < N; j++) {
				chmin(Ci[j], Cki + Ck[j]);
			}
		}
	}

	int Q = getint();
	rep(i, Q) {
		int s = getint(), t = getint();
		if (--s > --t) swap(s, t);
		if (C[s][t] == 1) {
			*di++ = '0';
			*di++ = '\n';
		}
		else if (C[s][t] < 1e9) putint(C[s][t] - 1);
		else {
			*di++ = '-';
			*di++ = '1';
			*di++ = '\n';
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1152
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

L, R = map(int, readline().split())

t1 = L - (L // 2019) * 2019
t2 = R - (L // 2019) * 2019
temp = 0
min_temp = 2019

if R - L >= 2019:
    print("0")
else:
    for i in range(t1, t2):
        for j in range(i + 1, t2 + 1):
            temp = (i * j) % 2019
            if temp < min_temp:
                min_temp = temp

    print(min_temp)


Measured memory_bytes: 3064
### subroutines

def parse_tree(ts)
  if ts[$pos] =~ /[0-9]/
    c = ts[$pos]
    $pos += 1
    return $rs[c.to_i - 1]
  end

  tr = [$nct]
  $nct += 1

  $pos += 1
  tr << parse_tree(ts)
  $pos += 1
  tr << parse_tree(ts)
  $pos += 1

  tr
end

def calc_tree(tr, ops)
  return tr if tr.class != Array

  sl = calc_tree(tr[1], ops)
  sr = calc_tree(tr[2], ops)

  case ops[tr[0]]
  when 0
    sl &= sr
  when 1
    sl |= sr
  when 2
    sl ^= sr
  end

  sl
end

### main

max_bits = 15

loop do
  treestr = gets.strip
  break if treestr == 'END'

  $n = gets.to_i
  $rs = []

  $n.times do
    $rs << gets.split.join.to_i(2)
  end

  $pos = 0
  $nct = 0

  tr = parse_tree(treestr)
  #p tr

  ops = $nct.times.map{0}
  count = 0

  loop do
    sbits = calc_tree(tr, ops)
    count += 1 if sbits == max_bits

    i = 0
    while i < $nct
      ops[i] += 1
      break if ops[i] <= 2
      ops[i] = 0
      i += 1
    end

    break if i >= $nct
  end

  puts count
end

Measured memory_bytes: 6128
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define ll long long

ll H;

void input() {
  cin >> H;
}

ll dfs(ll h) {
  if (h == 1) return 1;
  ll half = floor(h / 2);
  return 1 + 2 * dfs(half);
}

void solve() {
  cout << dfs(H) << endl;
}

int main() {
  input();solve();return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,k;
	long long ans=0,res=0;
	cin>>n>>k;
	res=n/k;
	ans+=res*res*res;
	if(k%2);else res=(n+(k/2))/k,ans+=res*res*res;
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
using System;
class Program{
  static void Main(string[] args){
    var input = Console.ReadLine().Split(' ');
    var n = int.Parse(input[0]);
    var r = int.Parse(input[1]);
    if(n<10){
      Console.WriteLine(r+(10-n)*100);
    }else{
      Console.WriteLine(r);
    }
  }
}

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

void cha(vector<int>&P,string s){
    for(int i=0;i<s.size();i++){
        int t; 
        if(s[i]=='N') t=P[2],P[2]=P[1],P[1]=P[3],P[3]=P[0],P[0]=t;
        if(s[i]=='S')for(int i=0;i<3;i++) t=P[2],P[2]=P[1],P[1]=P[3],P[3]=P[0],P[0]=t;
        if(s[i]=='E') t=P[4],P[4]=P[1],P[1]=P[5],P[5]=P[0],P[0]=t;
        if(s[i]=='W')for(int i=0;i<3;i++) t=P[4],P[4]=P[1],P[1]=P[5],P[5]=P[0],P[0]=t;
    }
}
int main(){
    int A[6];
    for(int i=0;i<6;i++) cin >>A[i];
    vector<int>D(6);
    D[0]=1;
    D[1]=6;
    D[2]=2;
    D[3]=5;
    D[4]=4;
    D[5]=3;
    string  s;
    cin >>s;
    cha(D,s);
    cout << A[D[0]-1] << endl;
    
}


Measured memory_bytes: 3204
n = int(input())
a = [int(num) for num in input().split()]
dp = [[0,0,0] for _ in range(n//2+1)]

#dp[0] = [a[0],a[1],a[2]]

for i in range(n//2):
    dp[i+1][0] = dp[i][0] + a[i*2]
    dp[i+1][1] = max(dp[i][1],dp[i][0]) + a[i*2+1]
    if n % 2 == 1:
        dp[i+1][2] = max(dp[i][2],dp[i][1],dp[i][0]) + a[i*2+2]
#print(dp)
if n% 2 == 1:
    print(max(dp[-1]))
else:
    print(max(dp[-1][:2]))

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

using namespace std;

int main() {
	string s;
	ios::sync_with_stdio(0);
	cin >> s;
	int ans = 0;
	for(int i = 0 ; i < s.length() ; i++) {
		ans = (s[i] - '0'+ ans ) % 9; 
	}
	if(!ans)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

string S;
ll K;

int main()
{
   cout << fixed << setprecision(10);
   cin >> S >> K;
   
   ll ans = 0;
   ll prev = -1;
   ll cnt = 0;
   ll init = -1;
   ll initNum = -1;
   ll cur;
   REP(i, SZ(S)) {
      cur = S[i] - 'a';
      if (init < 0) {
         init = cur;
      }
      if (cur == prev) {
         cnt++;
      } else {
         if (!i) {
            prev = cur;
            continue;
         }
         if (initNum < 0) {
            initNum = cnt;
         } else {
            ans += (cnt + 1) / 2;
         }
         cnt = 0;
      }
      prev = cur;
   }
   ll finalAns;
   if (cur == init) {
      finalAns = ans * K;
      finalAns += (initNum + cnt + 2) / 2 * (K - 1);
      finalAns += (initNum + 1) / 2;
      finalAns += (cnt + 1) / 2;
   } else {
      ans += (initNum + 1) / 2;
      ans += (cnt + 1) / 2;
      finalAns = ans * K;
   }
   if (initNum < 0) {
      finalAns = (cnt + 1) * K / 2;
   }
   cout << finalAns << endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main () 
{
    long long int n,p=1;cin>>n;
    long long int a[n];
    for (long long int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for (long long int i=1;i<n;i++) {
        if (a[i]==a[i-1]) {p=0;break;}
    }
    if (p==0) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    
    
    
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x,k,d,ans,i;
    cin>>x>>k>>d;
    x=abs(x);
    d=abs(d);
    if(x/d<k){
        i=k-x/d;
        if(i%2==0){
            ans=x%d;
        }
        else{
            ans=abs(x%d-d);
        }
    }
    else{
        ans=x-d*k;
    }
    cout<<ans<<endl;
    return 0;
}



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

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


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll N;cin>>N;
    ll ans=1e12;
    rep(i,1,sqrt(N)+2){
        if(N%i==0){
            ans=min(ans,N/i+i-2);
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    long long ans = 0;
    long long m = 0, a = 0, r = 0, c = 0, h = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s[0] == 'M')
            m++;
        if (s[0] == 'A')
            a++;
        if (s[0] == 'R')
            r++;
        if (s[0] == 'C')
            c++;
        if (s[0] == 'H')
            h++;
    }
    ans += m * a * r;
    ans += m * a * c;
    ans += m * a * h;
    ans += m * r * c;
    ans += m * r * h;
    ans += m * c * h;
    ans += a * r * c;
    ans += a * r * h;
    ans += a * c * h;
    ans += r * c * h;

    cout << ans << endl;

    return 0;
}

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 main(){
    let n: i32 = read_as_vec::<i32>()[0];

    for a in 1..10{
        if n%a != 0{
            continue;
        }

        let b = n/a;

        if b < 10{
            println!("Yes");
            return;
        }
    }

    println!("No");
 }


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int N;
    cin >> N;
    
    vi s(N);
    in(N,s);
    
    sort(all(s));
    int ans = 0;
    rep(i,N) ans+=s[i];
    if(ans%10!=0){
        cout << ans << endl;
        return 0;
    }else{
        rep(i,N){
            if(s[i]%10!=0){
                ans-=s[i];
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<n; ++i)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define F first
#define S second
#define PB push_back
#define MP make_pair 
using namespace std;
typedef unsigned long ul;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int, int> pi;
const int INF = 100100100;
const unsigned int MOD = 1000000007;

bool is_prime(int n) { for (int i = 2; i*i <= n; ++i) { if (n % i == 0) return false; } return true; }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }

ll dp[25][51000];
int value[25];
int n, m;


int main() {
    cin >> n >> m;
    for(int i = 0; i < m; ++i) cin >> value[i];
    REP(i, 51000) dp[1][i] = i;
    
    for(int i = 2; i <= m; ++i) {
        for(int j = 0; j <= n; ++j) {
            
            if(j - value[i - 1] >= 0) {
                dp[i][j] = dp[i][j - value[i - 1]] + 1;
                chmin(dp[i][j], dp[i - 1][j]);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            } 
        }
    }
    
    cout << dp[m][n] << endl;
}



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

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

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

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

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

//////////////////////////////////////////////////////////////


string abacus[10] = {
  "* = ****",
  "* =* ***",
  "* =** **",
  "* =*** *",
  "* =**** ",
  " *= ****",
  " *=* ***",
  " *=** **",
  " *=*** *",
  " *=**** ",
};

int main() {
  
  string input;
  bool bl = 0;
  char output[20][20];
  while(cin >> input) {
    if(bl) cout << endl;
    bl = 1;
    memset(output, 0, sizeof(output));
    rep(i,5) rep(j,8) output[j][i] = abacus[0][j];
    
    int const N = input.size();
    int const OFFSET = 5-N;
    rep(i, N) {
      int idx = (int)(input[i]-'0');
      rep(j, 8)
	output[j][i+OFFSET] = abacus[idx][j];
    }
    
    rep(i, 8) cout << output[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)

using ll = long long;  // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
using mlv = map<long long, vector<long long>>;

int main() {
	ll const mod = 1e9 + 7;
	ll n, k;
	cin >> n >> k;
	vll a(n);
	rep(i, n) cin >> a[i];
	vvll dp(n + 1, vll(k + 1, 0));
	// dp[i][j]はi-1番目の子供までにj個配る場合の数
	// dp[n][k]が答え
	dp[0][0] = 1;
	rep(i, n) {
		vll sum(k + 1, 0);
		sum[0] = dp[i][0];
		rep(j, k) sum[j + 1] = (sum[j] + dp[i][j + 1]) % mod;

		rep(j, k + 1) {
			ll l = j - a[i] - 1;
			dp[i + 1][j] = sum[j];
			if(l > -1) dp[i + 1][j] -= sum[l];
		}
	}
	cout << (dp[n][k] % mod + mod) % mod << endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) cout << "Yes" << endl; else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,x;
    cin>>n>>x;
    vector<ll> l(n);
    ll c=0,an=1;
    for(auto& i:l){
        cin>>i;
        c+=i;
        if(c<=x) ++an;
    }
    cout<<an<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	auto sum = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		sum += A[i] / 2;
		if (A[i] % 2 > 0
			&& i < N - 1
			&& A[i + 1] > 0)
		{
			++sum;
			--A[i + 1];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1152
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn solve() {
    let (n, m) = get!(usize, usize);
    let mut ab = get!(usize, usize; n);
    ab.sort_by(|&(a1,b1), &(a2,b2)| a2.cmp(&a1));

    let mut res = 0usize;
    let mut heap = BinaryHeap::new();
    for i in 1..m+1 {
        while let Some((a,b)) = ab.pop() {
            if a <= i {
                heap.push((b,a));
            } else {
                ab.push((a,b));
                break;
            }
        }
        if let Some((b,a)) = heap.pop() {
            res += b;
        }
    }
    println!("{}", res);
}


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

int A[210000];

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

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

    std::sort(A,A+N);

    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;

}

Measured memory_bytes: 1024
package main

import "fmt"

func main(){
	var n,max_num,ans int
	fmt.Scan(&n)
	a := make([]int,n+1)
	for i:=1 ; i<=n ; i++ {
		fmt.Scan(&a[i])
		if max_num < i-a[i] {
			max_num = i-a[i]
		}
	}
	minus_temp := make([]int,max_num+1)
	plus_temp := make([]int,max_num+1)
	for i:=1;i<=n;i++{
		if i-a[i] >= 0 {
			minus_temp[i-a[i]]++
		}
		if i+a[i] <= max_num{
			plus_temp[i+a[i]]++
		}
	}
	for i:=0 ; i<=max_num ; i++{
		if minus_temp[i] + plus_temp[i] >= 2 {
			ans += minus_temp[i] * plus_temp[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 9696
n = int(input())
al = list(map(int,input().split()))
bl = []
count = 0
#print(al)

for i in range(len(al)):
    if al[i] %2 == 0:
        bl.append(al[i])

#print(bl)

for j in range(len(bl)):
    
    if bl[j] %3 == 0 or bl[j] %5 == 0:
        count += 1
    else:
        pass
    
print(['DENIED','APPROVED'][count == len(bl)])

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> F[101];
    vector<int> P[101];
    ll ans = -100000000000;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            int x;
            cin >> x;
            F[i].push_back(x);
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 10; j++) {
            int x;
            cin >> x;
            P[i].push_back(x);
        }
    }

    for (int bits = 0; bits < (1<<10); bits++) {
        vector<int>v;
        for (int i = 0; i < 10; i++) {
            if (bits&(1<<i)) {
                v.push_back(i);
            }
        }
        if (v.size() == 0) {
            continue;
        }
        ll profit = 0;
        for (int i = 0; i < N; i++) {
            int cnt = 0;
            for (int j = 0; j < v.size(); j++) {
                if (F[i][v[j]] == 1) {
                    cnt++;
                }
            }
            profit += P[i][cnt];
        }
        if (profit > ans) {
            ans = profit;
        } 
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func Count(a []int, k int) (count int) {
	for _, v := range a {
		if v == k {
			count++
		}
	}
	return
}

func NextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, _ := NextInt(sc)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = NextInt(sc)
	}

	q, _ := NextInt(sc)
	for i := 0; i < q; i++ {
		b, _ := NextInt(sc)
		e, _ := NextInt(sc)
		k, _ := NextInt(sc)
		fmt.Println(Count(a[b:e], k))
	}
}



Measured memory_bytes: 1132
S = input()
T = input()
d = {}

for s, t in zip(S, T):
  if s in d:
    if d[s] != t:
      print("No")
      exit()
  else:
    d[s] = t

if len(d) != len(set(d.values())):
  print("No")
else:
  print("Yes")



Measured memory_bytes: 3632
function Main(input) {
var nagasa = input.length;
var loop = 0;
var flag = "Yes";
while(loop != nagasa){
if(loop%2 == 0){
  if(input[loop] == "L"){
    flag = "No";
  }
  //奇数の処理
}else{
  if(input[loop] == "R"){
    flag = "No";
  } 
  //偶数の処理
}
  loop ++;
}
console.log(flag);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
/*...Part - 01...*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/

const int max_n = 1e5 + 5, mod = 1e9 + 7 ;

int dp[2][max_n] ;
vector < vector < int > > g ;

inline int mul(int a, int b){
	return (ll)a * b % mod ;
}

inline int add(int a, int b){
	a += b ;
	if(a >= mod)a -= mod ;
	return a ;
}

void dfs(int s, int p = 0){
	int sum1 = 1, sum2 = 1 ;
	for(int i : g[s]){
		if(i == p)continue ;
		dfs(i, s) ;
		sum1 = mul(sum1, add(dp[0][i], dp[1][i])) ;
		sum2 = mul(sum2, dp[0][i]) ;
	}
	dp[0][s] = sum1 ;
	dp[1][s] = sum2 ;
}

int main(){
    int test = 1 , tc = 0 ;
    while(test--){
        int n = Int ;
        g.resize(n + 1) ;
        for(int i = 1 ; i < n ;++i){
        	int x = Int, y = Int ;
        	g[x].pb(y) ;
        	g[y].pb(x) ;
        }
        dfs(1) ;
        cout << add(dp[0][1], dp[1][1]) << '\n' ;
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/




Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main() {
    int n,flg = 0;
    cin >> n;
    vector<string> w(n);
    set<string> se;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < n-1; ++i) {
        if(w[i][w[i].size()-1] != w[i+1][0]) flg = 1;
    }
    for (int i = 0; i < n; ++i) {
        if(se.count(w[i])) flg = 1;
        se.insert(w[i]);
    }
    if(flg) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void)
{
	int money1,money2,amari1,amari2;
	
	scanf("%d",&money1);
	
	amari1=money1%500;
	
	money1=1000*((money1-amari1)/500);
	
	amari2=amari1%5;
	
	money2=5*((amari1-amari2)/5);
	
	printf("%d",money1+money2);
	
	return 0;
}

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

using namespace std;

int main()
{
    char f;
    cin>>f;
    if(f=='A')
    {
        cout<<'T'<<endl;
    }
    else if(f=='T')
    {
        cout<<'A'<<endl;
    }
    else if(f=='G')
    {
        cout<<'C'<<endl;
    }
    else if(f=='C')
    {
        cout<<'G'<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> f = vector<int>(n, 0);
    vector<int> s = vector<int>(n, 0);
    
    int sumtmp = 0;
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        cin >> tmp;
        sumtmp += tmp;
        f[i] = sumtmp;
    }
    sumtmp = 0;
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        cin >> tmp;
        sumtmp += tmp;
        s[i] = sumtmp;
    }
    
    int ret = f[0] + s[n - 1];
    for (int i = 1; i < n; ++i)
    {
        ret = max(ret, f[i] + s[n - 1] - s[i - 1]);
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    char c;
    cin >> c;

    string ans = "ATACGC";
    REP(i, 6)
    {
        if(ans[i] == c)
        {
            cout << ans[i+1] << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll n;
        cin >> n;
        vll a(n+1);

        rep(i, 1, n+1) cin >> a[i-1] >> a[i];

        //print1d(a);

        vllvll dp(110, vll(110, inf));
        rep(i, 0, 110) dp[i][i] = 0;
        
        rep(width, 2, n+1) {
            rep(left, 1, n-width+2) {
                ll right = left + width - 1;
                rep(div, left, right) {
                    chmin(dp[left][right], dp[left][div] + dp[div+1][right] + a[left-1] * a[div] * a[right]);
                }
            }
        }

        cout << dp[1][n] << endl;
}






Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    char b;
    cin >> b;
    if (b == 'A') {
        dump('T');
    }
    else if (b == 'C') {
        dump('G');
    }
    else if (b == 'G') {
        dump('C');
    }
    else if (b == 'T') {
        dump('A');
    }
    return 0;
} 

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

int main(){
  int a1, a2, a3;
  int b1, b2, b3;
  int c11, c12, c13;
  int c21, c22, c23;
  int c31, c32, c33;

  cin >> c11 >> c12 >> c13;
  cin >> c21 >> c22 >> c23;
  cin >> c31 >> c32 >> c33;

  for( a1=0; a1<=c11; a1++ ){
    b1 = c11 - a1;
    for( a2=0; a2<=c22; a2++ ){
      b2 = c22 - a2; 
      for( a3=0; a3<=c33; a3++ ){
        b3 = c33 - a3;
        if( c12==a1+b2 && c13==a1+b3 && c21==a2+b1 && c23==a2+b3 && c31==a3+b1 && c32==a3+b2 ){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

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

using namespace std;

const int INF=1<<29;

int n;
int song[50][3];

int dp[50][51][51];
int dfs(int t,int i,int j){
	if(t==n) return 0;

	if(dp[t][i][j]!=-INF) return dp[t][i][j];

	int ans=-INF;
	rep(k,i+1){ // 新たに k 本のサイリウムを折る
		int val=song[t][2];
		rep(a,min(k,8)+1) rep(b,min(j,8-a)+1) if(a+b>0) val=max(val,a*song[t][0]+b*song[t][1]);
		ans=max(ans,val+dfs(t+1,i-k,k));
	}
	return dp[t][i][j]=ans;
}

int main(){
	int m; scanf("%d%d",&n,&m);
	rep(i,n) rep(j,3) scanf("%d",song[i]+j);

	rep(t,n) rep(i,m+1) rep(j,m+1) dp[t][i][j]=-INF;
	printf("%d\n",dfs(0,m,0));

	return 0;
}

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

#define fi first
#define se second

const int N = 200200;

using namespace std;

int G = 200000;
long long inf = 1e18;

struct seg
{
        long long t[4 * N];
        seg()
        {
                for(int i = 0; i < 4 * N; i++) t[i] = inf;
        }

        void upd(int x, int l, int r, int g, long long y)
        {
                if(l == r){
                        t[x] = min(t[x], y);
                        return;
                }
                int m = (l + r) / 2;
                if(g <= m){
                        upd(x * 2, l, m, g, y);
                } else{
                        upd(x * 2 + 1, m + 1, r, g, y);
                }
                t[x] = min(t[x * 2], t[x * 2 + 1]);
        }
        long long get(int x, int l, int r, int tl, int tr)
        {
                if(tl > tr){
                        return inf;
                } else if(l == tl && r == tr){
                        return t[x];
                }
                int m = (l + r) / 2;
                return min(get(x * 2, l, m, tl, min(m, tr)), get(x * 2 + 1, m + 1, r, max(m + 1, tl), tr));
        }
};

int n, q, A, B;
seg t1, t2;
int a[N];
long long s[N];
long long d[N];

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> q >> A >> B;
        a[0] = A;
        for(int i = 1; i <= q; i++){
                cin >> a[i];
                s[i] = s[i - 1] + abs(a[i] - a[i - 1]);
        }

        long long res = inf;


        for(int i = 0; i < q; i++){
                d[i] = s[i] + abs(B - a[i + 1]);
                if(i > 0){
                        d[i] = min(d[i], t1.get(1, 1, G, a[i + 1], G) + s[i] - a[i + 1]);
                        d[i] = min(d[i], t2.get(1, 1, G, 1, a[i + 1]) + s[i] + a[i + 1]);
                }

                t1.upd(1, 1, G, a[i], d[i] - s[i + 1] + a[i]);
                t2.upd(1, 1, G, a[i], d[i] - s[i + 1] - a[i]);

                res = min(res, d[i] + s[q] - s[i + 1]);
        }

        cout << res << "\n";
}


Measured memory_bytes: 16640