akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
using namespace std;
int a,b,c,n,m,dis[100005];
bool vis[100005];
struct edge{
	int to,v;
	edge(int a=0,int b=0){to=a;v=b;}
};
vector<edge> path[200005];
bool spfa(int x){
	vis[x]=true;
	for(int i=0;i<path[x].size();i++){
		edge e=path[x][i];
		if(dis[e.to]<dis[x]+e.v){
			if(vis[e.to])return true;
			dis[e.to]=dis[x]+e.v;
			if(spfa(e.to))return true;
		}
	}
	vis[x]=false;
	return false;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&a,&b,&c);//b-a=c
		path[b].push_back(edge(a,c));
		path[a].push_back(edge(b,-c));
	}
	for(int i=1;i<=n;i++){
		dis[i]=-9999999;
		path[0].push_back(edge(i,0));
	}
	if(spfa(0))printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 14456
import java.io.*;
import java.util.*;
 
public class  Main{
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		char[]in1=sc.next().toCharArray();
		char[]in2=sc.next().toCharArray();
		for(int i=0;i<n;i++) {
			pw.print(in1[i]+""+in2[i]);
		}
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21332
from math import gcd
max_a = int(2e6)
factor = [0]*max_a
for p in range(2,max_a):
  if factor[p]:
    continue
  factor[p] = p
  for x in range(p+p,max_a,p):
    if factor[x]:
      continue
    factor[x] = p

def prime_fac(ai):
  while factor[ai]:
    yield factor[ai]
    x = factor[ai]
    while x == factor[ai]:
      ai = int(ai/factor[ai])

n = int(input())
a = list(map(int,input().split()))

cnt = [0]*max_a
loop_end = False
g = 0
pairwise_coprime = True
setwise_coprime = True

for ai in a:
  for p in prime_fac(ai):
    if cnt[p]:
      pairwise_coprime = False
      loop_end = True
    cnt[p] = 1
    if loop_end:
      break
  if loop_end:
    break

for ai in a:
  g = gcd(g,ai)
setwise_coprime = g==1

if pairwise_coprime:
  print('pairwise coprime')
elif setwise_coprime:
  print('setwise coprime')
else:
  print('not coprime')

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) cin >> A.at(i);
  for (int i = 0; i < M; i++) {
    N -= A.at(i);
  }
  if (N < 0) N = -1;
  cout << N << "\n";
}

Measured memory_bytes: 3640
import java.util.Scanner;

/**
 * @author yoshida3203
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		String S=sc.next();
		char[]a=S.toCharArray();

		int n=0;
		for(int i=0;i<S.length();i++){
			if(i%2==0){
				if(a[i]=='L'){
					n++;
				}
			}else{
				if(a[i]=='R'){
					n++;
				}
			}
		}
		if(n==0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}



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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s, n) s, s + n
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pii pair <int, int>
#define pll pair <ll, ll>
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
using namespace std;

int k, x;
int main () {
	IOS;

	cin >> k >> x;
	cout << (k * 500 >= x ? "Yes" : "No") << '\n';
	return 0; 
}


Measured memory_bytes: 256
// URL : https://atcoder.jp/contests/practice2/tasks/practice2_b
#include "atcoder/fenwicktree.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n)    for (ll (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    atcoder::fenwick_tree<ll> fw(N);
    REP(i, N) fw.add(i, A[i]);
    while (Q--) {
        int a, b, c;
        cin >> a >> b >> c;
        if (a == 0) {
            fw.add(b, c);
        } else {
            cout << fw.sum(b, c) << endl;
        }
    }
}


Measured memory_bytes: 10084
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int num = a * 100 + b * 10 + c;
    if(num % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<cstring>
#include <algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;


int main()
{
    int n;
    cin >> n;
    vector<int> a, b, c, d;
    for (int i = 0; i < n;i++){
        int x, y;
        cin >> x >> y;
        a.push_back(x + y);
        b.push_back(x - y);
        c.push_back(-x + y);
        d.push_back(-x - y);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());

    cout << max({a.back() - a.front(), b.back() - b.front(), c.back() - c.front(), d.back() - d.front()});


    return 0;
}


Measured memory_bytes: 6664
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,k;cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  set<int> st;
  rep(i,k) st.insert(p[i]);
  int left = 0;
  int right = k;
  int res = 1;
  while(right < n) {
    bool f = true;
    auto lit = st.find(p[left]);
    if(lit != st.begin() ) f = false;
    st.erase(p[left]);
    st.insert(p[right]);
    auto rit = st.find(p[right]);
    rit++;
    if(rit != st.end()) f = false;
    if(!f) res++;
    left++;
    right++;
  }

  int cnt = 1;
  int kk = 0;
  rep(i,n-1) {
    if(p[i] < p[i+1]) cnt++;
    else {
      if(cnt >= k) kk++;
      cnt = 1;
    }
  }
  if(cnt >= k) kk++;
  res -= max(kk - 1, 0);
  cout << res << "\n";
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& w : a) cin >> w;
  sort(begin(a), end(a));
  int x = a[n - 1];
  int i = lower_bound(begin(a), end(a), x / 2) - a.begin();
  int y;
  if (i == 0)
    y = a[0];
  else
    y = ((x / 2.0 - a[i - 1]) <= (a[i] - x / 2.0)) ? a[i - 1] : a[i];

  cout << x << " " << y << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, m;
    cin >> n >> m;
    if (n & 1) {
        REP(i, 1, m + 1) cout << i << " " << n - i << endl;
    } else {
        int x = m / 2;
        int y = m - x;
        REP(i, 1, y + 1) cout << i << " " << 2 * y + 1 - i << endl;
        REP(i, 1, x + 1) cout << i + 2 * y << " " << n - i << endl;
    }
}

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


Measured memory_bytes: 3664
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Squid struct {
  Vertex int
  Color int
  Priority int
}

func main() {
  NM := NextIntVec()
  N, M := NM[0], NM[1]
  V := make([]Squid, N)
  for i := range V {
    V[i] = Squid{i, 0, 0}
  }
  E := make([][]int, M)
  for i := range E {
    AB := NextIntVec()
    E[i] = []int{AB[0] - 1, AB[1] - 1}
  }
  SQ := make([][]Squid, 11)
  for i := range SQ {
    SQ[i] = make([]Squid, 0)
  }
  Q := NextInt()
  for i := 0; i < Q; i++ {
    VDC := NextIntVec()
    SQ[VDC[1]] = append(SQ[VDC[1]], Squid{VDC[0] - 1, VDC[2], i + 1})
  }
  for d := 10; d >= 0; d-- {
    Next := make([]Squid, N)
    for i, v := range V {
      Next[i] = v
    }
    for _, e := range E {
      if V[Next[e[0]].Vertex].Priority < V[e[1]].Priority {
        Next[e[0]].Vertex = V[e[1]].Vertex
      }
      if V[Next[e[1]].Vertex].Priority < V[e[0]].Priority {
        Next[e[1]].Vertex = V[e[0]].Vertex
      }
    }
    for i, _ := range V {
      Next[i].Color = V[Next[i].Vertex].Color
      Next[i].Priority = V[Next[i].Vertex].Priority
      Next[i].Vertex = i
    }
    for _, sq := range SQ[d] {
      if Next[sq.Vertex].Priority < sq.Priority {
        Next[sq.Vertex] = sq
      }
    }
    for i, v := range Next {
      V[i] = v
    }
  }
  A := make([]string, N)
  for i, v := range V {
    A[i] = strconv.Itoa(v.Color)
  }
  Write(strings.Join(A, "\n"))
  Output()
}

Measured memory_bytes: 30080
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <limits>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

typedef pair<ll, ll> curr;
const int MOD = 998244353;


int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main()
{
  int N,a,b,sum=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a >> b;
    sum += b-a+1;
  }
  cout << sum;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    double R,pi; cin >> R;

    printf("%.16f",R*2*M_PI);

    return 0;

}

Measured memory_bytes: 3800
/* 
 * Author: pawanmsr
 */

// #include <iostream>
// #include <iomanip>
// #include <string>
// #include <vector>
// #include <algorithm>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <iterator>
// #include <list>
// #include <stack>
// #include <map>
// #include <set>
// #include <functional>
// #include <numeric>
// #include <utility>
// #include <limits>
// #include <fstream>
// #include <cstring>

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
ll a, b, c;

// Functions //


// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> a >> b >> c;
    ll op = c - a - b;
    if (op <= 0) cout << "No" << endl;
    else if (op*op > 4*a*b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<4700) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> {
        val m = readInt; isPrime(m)
      }
    })
  }
}

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

using namespace std;

int main(){
    while(true){
        int n, m;
        cin >> n >> m;
        
        if( n == 0 && m == 0 )
            break;
        
        vector<int> a(m);
        vector<int> b(m);
        vector<int> par(n+1);
        int ans = 0;
        
        for(int i = 0; i < m; i++)
            cin >> a[i] >> b[i];
        
        for(int j = 1; j <= n; j++)
            par[j] = j;
        
        for(int i = 0; i < m; i++){
            if( a[i] == 1 ){
                par[ b[i] ] = 1;
            }
        }
        
        for(int i = 0; i < m; i++){
            if( par[ a[i] ] == 1 && par[ b[i] ] == 1 )
                continue;
            if( par[ a[i] ] == 1 )
                par[ b[i] ] = a[i];
            else if( par[ b[i] ] == 1 )
                par[ a[i] ] = b[i];
        }
        
        for(int j = 2; j <= n; j++){
            if( par[ par[j] ] == 1 )
                ans += 1;
        }
        
        cout << ans <<endl;
        
    }
}

Measured memory_bytes: 3144
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;

#define FORN(i, j, k) for(int i=j;i<k;i++)
#define FORR(i, j, k) for(int i=j;i>=k;i--)
#define REP(i, n) FORN(i, 0, n)
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

const int MODO = 1e+9 + 7;
const int MAX = 1e+5;
int n, k;
int a[MAX];

void solve(){
	int dp[n+k];
	REP(i, n+k){
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	REP(i, n){
		FORN(j, i+1, i+k+1){
			dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]));
		}
	}
	cout << dp[n-1] << endl;
	return;
}

int32_t main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin >> n >> k; 
		REP(i, n){
			cin >> a[i];
		}
		solve();
		return 0;
}



Measured memory_bytes: 5132
#coding:utf-8
import fractions
#import math
import collections
#素因数分解
def prime_factorial(num):
    fact = []
    for i in range(2, int(num**0.5)+1):
        while num % i == 0:
            fact.append(i)
            num = num // i
    if num != 1:
        fact.append(num)
    return fact

if __name__ == "__main__":
    #最大公約数を素因数分解し、その個数＋1が答え
    a, b = map(int, input().split())
    #g = math.gcd(a, b)
    g = fractions.gcd(a, b)
    #print(g)
    #print(prime_factorial(g))

    c = collections.Counter(prime_factorial(g))
    print(len(list(c.keys())) + 1)

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

typedef long long ll;
#define MOD 1000000007

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size(), m = t.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    string ans = "";
    for (int i = n, j = m; i > 0 && j > 0;) {
        if (dp[i][j] > max(dp[i - 1][j], dp[i][j - 1]))
            ans = s[i - 1] + ans, i--, j--;
        else
            (dp[i - 1][j] > dp[i][j - 1]) ? i-- : j--;
    }
    cout << ans << endl;
}

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

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

  if ((a + b) < 10) cout << a + b << endl;
  else cout << "error" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    string str;
    while(cin >> str)
    {
        string res;
        
        rep(i, str.size())
        {
            if(str[i] == '@')
            {
                rep(j, str[i+1] - '0')
                    res += str[i+2];
                i += 2;
            }
            else
                res += str[i];
        }
        
        cout << res << endl;        
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int ans = 0, length = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            length ++;
        }
        else length = 0;
        ans = max(ans,length);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
N = gets.to_i
A = gets.split.map(&:to_i).sort

while A.size > 1
  if A[0] > 0
    for i in 1...A.size
      A[i] %= A[0]
    end
    A.sort! 
  else
    A.shift
  end
end

puts A[0]

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


int main(int argc, char const *argv[])
{
	string s; cin >> s;

	stack<char> st;
	for (auto u : s) {
		if (st.empty()) {
			st.push(u);
		} else {
			int top = st.top();
			if ((top == '0' && u == '1') || (top == '1' && u == '0')) {
				st.pop();
			} else {
				st.push(u);
			}
		}
	}

	printf("%d\n", int(s.size() - st.size()));
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z =(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else {
      x=x->right;
    }
  }
  z->parent=y;
  
  if(y==NIL){
    root =z;
  } else{
    if(z->key < y->key){
      y->left =z;
    }else{
      y->right =z;
    }
  }
}

void Inorder(Node *u){
  if(u==NIL) return;
  Inorder(u->left);
  printf(" %d", u->key );
  Inorder(u->right);
}

void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d", u->key );
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n );
  for(i=0;i<n;i++){
    cin >> com;
    if(com=="insert"){
      scanf("%d",&x );
      insert(x);
    } else if (com=="print"){
      Inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 26652
#include <cstdio>
#pragma warning(disable : 4996)
const int inf = 1234567890;
int Q, x, a[2000009]; char c[15];
int main() {
	scanf("%d", &Q);
	int l = Q, r = Q;
	while (Q--) {
		scanf("%s", c);
		if (c[0] == 'i') {
			scanf("%d", &x);
			a[--l] = x;
		}
		else if (c[6] == 'F') {
			while (a[l] == inf) l++;
			a[l++] = 0;
		}
		else if (c[6] == 'L') {
			while (a[r - 1] == inf) r--;
			a[--r] = 0;
		}
		else {
			scanf("%d", &x);
			for (int i = l; i < r; i++) {
				if (a[i] == x) {
					a[i] = inf;
					break;
				}
			}
		}
	}
	for (int i = l, cnt = 0; i < r; i++) {
		if (a[i] != inf) {
			printf(cnt++ ? " %d" : "%d", a[i]);
		}
	}
	printf("\n");
	return 0;
}

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

int main() {
  int x,n;cin>>x>>n;
  vector<int> p(n),vec(102);
  rep(i,n){
    cin>>p[i];
    vec[p[i]]++;
  }
  int cnt=1e9,ans=0;
  rep(i,102){
    if(vec[i]==0&&abs(x-i)<cnt){
      cnt=abs(x-i);
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
s=input()

a=[1,0,0,0]

for i in range(len(s)):
    if s[i]=="A":
        a[1]+=a[0]
    elif s[i]=="B":
        a[2]+=a[1]
    elif s[i]=="C":
        a[3]+=a[2]
    else:
        a=[ a[0]*3 ] + [ a[j]*3+a[j-1] for j in range(1,4) ]

    a=[a[i]%1000000007 for i in range(4)]

print(a[3])

Measured memory_bytes: 3188
/*
    It is the level of one's commitment that determines the success, far more than the knowledge one possess.
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        int n = Integer.parseInt(br.readLine());

        int[][] dp = new int[n+1][3];

        for(int i=1 ; i<=n ; i++) {
            st = new StringTokenizer(br.readLine());
            for(int j=0 ; j<3 ; j++) {
                dp[i][j] = Integer.parseInt(st.nextToken());
            }
        }


        for(int i=1 ; i<=n ; i++) {
            for(int j=0 ; j<3 ; j++) {
                int max = 0;
                for(int k=1 ; k<3 ; k++) {
                    max = Math.max(max, dp[i-1][(j+k)%3]);
                }
                dp[i][j] += max;
            }
        }
        
        int ans = Math.max(dp[n][0], dp[n][1]);
        ans = Math.max(ans, dp[n][2]);

        pw.println(ans);
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 44512
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
use std::cmp;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        S: chars,
        T: chars,
    }

    let mut ok = false;
    let mut start_ind = S.len() - T.len() + 1;
    'outer: loop {
        if start_ind == 0 { break }
        start_ind -= 1;
        'inner: for ind in start_ind .. start_ind+T.len() {
            if S[ind] == '?' || S[ind] == T[ind-start_ind] { continue 'inner; }
            else { continue 'outer; }
        }
        ok = true;
        break;
    }

    if !ok {
        println!("UNRESTORABLE");
        return
    }

    let start_ind = start_ind;
    for ind in 0..S.len() {
        if start_ind <= ind && ind < start_ind + T.len() {
            S[ind] = T[ind-start_ind];
        } else if S[ind] == '?' {
            S[ind] = 'a';
        }
    }

    println!("{}", S.into_iter().collect::<String>());
}


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

int main(void) {
    long long N;
    cin >> N;
    long long ans = 0;
    for (long long A = 1; A <= N - 1; A++) {
        ans += (N - 1) / A;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3760
N, A, B = map(int,input().split(' '))
ans = 0
for i in range(N+1):
    ii = str(i)
    check = 0
    for j in range(len(ii)):
        check = check + int(ii[j])
    if check >= A and check <= B:
        ans = ans + i

print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define forN(n, N) for(int n=0; n<N; n++)
#define res_out(ans) cout << ans << "\n";
#define ll long long

ll DIV = 1e9 + 7;
int N, S[int(2e5)], memo[int(2e5)][200];

ll dfs(int mod, int n){
    if(memo[mod][n] != -1){
        //cout << "1: " << mod << " " << n << " " << S[n] << " ";
        //res_out(memo[mod][n])
        return memo[mod][n];
    }
    else if(n == 0){
        memo[mod][n] = mod % S[n];
        //cout << "2: " << mod << " " << n << " ";
        //res_out(memo[mod][n])
        return memo[mod][n];
    }
    else{
        memo[mod][n] = (dfs(mod % S[n], n - 1) + dfs(mod, n - 1) * n) % DIV;
        //cout << "3: " << mod << " " << n << " ";
        //res_out(memo[mod][n])
        return memo[mod][n];
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin >> N >> X;
    forN(n, N)cin >> S[n];
    memset(memo, -1, (X + 1) * 200 * sizeof(int));
    sort(S, S + N);
    res_out(dfs(X, N - 1))
    /*
    forN(x, X + 1){
        forN(n, N)cout << memo[x][n] << " ";
        res_out(" ")
    }
    */
    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  int k;
  cin >> k;
  ll a[100005];
  for (int i = 0; i < k; i++) {
    cin >> a[i];
  }
  ll mn = 2;
  ll mx = 2;
  for (int i = k - 1; i >= 0; i--) {
    // [L, R]のaの倍数のminは、ceil(L/a)*a
    //                  maxは、floar(R/a)*a
    ll amn = (mn + a[i] - 1) / a[i] * a[i];
    ll amx = mx / a[i] * a[i];
    if (amn > mx) {
      cout << -1 << endl;
      return 0;
    }
    mn = amn;
    mx = amx + a[i] - 1;
  }
  cout << mn << " " << mx << endl;
}


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

long long N,K;
long long P[5001];
long long C[5001];

vector<long long> ele[5001];

void visit(long long i, long long v){
    if(i==v) return;
    ele[i].push_back(v);
    visit(i,P[v]);
}

void search(){
    long long i;
    for(i=1; i<=N; i++){
        ele[i].push_back(i);
        visit(i,P[i]);
    }
}

int main(){
    cin >> N >> K;
    long long i,j,v;
    for(i=1; i<=N; i++){
        cin >> P[i];
    }
    for(i=1; i<=N; i++){
        cin >> C[i];
    }
    search();
    long long ans=-1000000000000000010;
    long long sum,subsum, subsummax, len;
    for(i=1; i<=N; i++){
        sum=0;
        len=ele[i].size();
        for(j=0; j<len; j++){
            sum+=C[ele[i][j]];
        }
        subsum=C[i];
        subsummax=C[i];
        for(j=1; j<len-1; j++){
            subsum+=C[ele[i][j]];
            subsummax=max(subsummax,subsum);
        }
        if(K<len){
            subsum=C[i];
            ans=max(ans,subsum);
            for(j=1; j<K; j++){
                subsum+=C[ele[i][j]];
                ans=max(ans,subsum);
            }
        }else{
            ans=max(ans,subsummax);
            ans=max(ans,sum);
            if(K/len!=1){
                ans=max(ans,((K/len)-1)*sum);
            }
            ans=max(ans,((K/len)-1)*sum+subsummax);
            subsum=((K/len))*sum;
            ans=max(ans,subsum);
            for(j=0; j<(K%len); j++){
                subsum+=C[ele[i][j]];
                ans=max(ans,subsum);
            }
        }
    }
        

    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 219128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;



int main(){
    int h,w;cin>>h>>w;
    vvin dp(10,vin(10));
    rep(i,10)rep(j,10){
        int c;cin>>c;
        dp[i][j]=c;
    }
    rep(k,10)rep(i,10)rep(j,10)dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    int sum=0;
    rep(i,h)rep(j,w){
        int a;cin>>a;
        if(a!=-1)sum+=dp[a][1];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
a[1<<20];
n=1<<20;
main(i,c){
	*a=a[1]=1;
	for(;++i<n;)
		if(!a[i])
			for(c=2;c*i<n;)
				a[i*c++]=1;
	for(;scanf("%d",&n),n;printf("%d\n",c)){
		c=0;
		for(i=n;++i<=2*n;)
			a[i]||c++;
	}
	i*0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    int sugoroku[n+1000];
    fill_n(sugoroku,n+1000,0);
    for(int i=0;i<n;i++)
      cin>>sugoroku[i];
    int now=1;
    int ans=-1;
    int flag=true;
    for(int i=0;i<m;i++){
      int me;cin>>me;
      if(flag)
	now=now+me+sugoroku[now+me-1];
      //cout<<now<<endl;
      if(now<0)now=0;
      if(now>=n&&flag){
	ans=i+1;
	flag=false;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int iCount = int.Parse(Console.ReadLine());
        int[] N = new int[iCount];
        string[] P = Console.ReadLine().Split(' ');
        for (int i = 0; i < P.Length; i++)
        {
            N[i] = int.Parse(P[i]);
        }

        int oCount = 0;
        for (int i = 1; i < iCount - 1; i++)
        {
            if ((N[i - 1] < N[i] && N[i] < N[i + 1]) || (N[i + 1] < N[i] && N[i] < N[i - 1])) oCount++;
        }

        Console.WriteLine(oCount);
    }
}


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

/// <summary>
/// 根付き木
/// </summary>
namespace ALDS1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            int[] vals;

            //入力
            line = Console.ReadLine().Trim();
            var nodeCount = int.Parse(line);

            var nodes = new Dictionary<int, Node>();
            for (int i = 0; i < nodeCount; i++)
            {
                line = Console.ReadLine().Trim();
                vals = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(e => int.Parse(e)).ToArray();

                Node node;
                if (!nodes.TryGetValue(vals[0], out node))
                {
                    node = new Node() { Value = vals[0] };
                    nodes.Add(vals[0], node);
                }
                for (int k = 0; k < vals[1]; k++)
                {
                    Node child;
                    if (!nodes.TryGetValue(vals[k + 2], out child))
                    {
                        child = new Node() { Value = vals[k + 2] };
                        nodes.Add(vals[k + 2], child);
                    }
                    node.AddChild(child);
                }
            }

            // 出力
            foreach (var item in nodes.OrderBy(x => x.Key).Select(x => x.Value))
            {
                Console.WriteLine(item.ToString());
            }
        }
    }


    class Node
    {
        public Node Root { get; set; } = null;
        public int Value { get; set; } = 0;
        public List<Node> Children { get; } = new List<Node>();

        public void AddChild(Node child)
        {
            child.Root = this;
            Children.Add(child);
        }
        public string NodeType()
        {
            if (Root == null)
            {
                return "root";
            }
            if (Children.Any())
            {
                return "internal node";
            }
            return "leaf";
        }
        public int Depth()
        {
            if (Root == null)
            {
                return 0;
            }
            return Root.Depth() + 1;
        }

        public override string ToString()
        {
            return $"node {Value}: parent = {(Root != null ? Root.Value : -1)}, depth = {Depth()}, {NodeType()}, [{String.Join(", ", Children.Select(x => x.Value).ToArray()) }]";
        }
    }
}



Measured memory_bytes: 56352
n = int(input())
a,b,c,d = 0,0,0,0
for i in range(n):
    tmp = input()
    if tmp == 'AC':
        a += 1
    if tmp == 'WA':
        b += 1
    if tmp == 'TLE':
        c += 1
    if tmp == 'RE':
        d += 1
print('AC x ',a)
print('WA x ',b)
print('TLE x ',c)
print('RE x ',d)

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

typedef long long int ll;
typedef long double ld;
const ll MAX=1e5+5;
const ll INF=1e15+2;

#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi pair<ll,ll>

ll dp[3001][3001];
ll a[3001];

ll calc(ll l,ll r)
{
    if(dp[l][r]!=-1)
        return dp[l][r];
        
    if(l==r)
    {
        dp[l][r]=a[l];
        return dp[l][r];
    }
    
    ll a1=a[l]-calc(l+1,r);
    ll a2=a[r]-calc(l,r-1);
    
    dp[l][r]=max(a1,a2);
    return dp[l][r];
}

int main()
{
    ll n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    
    for(int i=1;i<=n;i++)
        cin>>a[i];
        
    ll val=calc(1,n);
    
    cout<<dp[1][n];    
}

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

using ll = long long;

int a, b, c; ll k;

int main(){
    scanf("%d%d%d%lld", &a, &b, &c, &k);
    printf("%d\n", (a - b) * ((k & 1) ? -1 : 1));
}

Measured memory_bytes: 256
using System;

class B
{
	static void Main()
	{
		var a = int.Parse(Console.ReadLine());
		int c = 0, w = 0, t = 0, r = 0; 
		for (int i = 0; i < a; i++)
		{
			var b = Console.ReadLine();
			switch (b)
			{
				case "AC":
					c++;
					break;
				case "WA":
					w++;
					break;
				case "TLE":
					t++;
					break;
				case "RE":
					r++;
					break;
			}
		}
		Console.WriteLine("AC x " + c + "\n" + "WA x " + w + "\n" + "TLE x " + t + "\n" + "RE x " + r);
	}
}

Measured memory_bytes: 30708
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, k = list(map(int, input().strip().split()))
    s = input().strip()
    q = 0
    p = ''
    for c in s:
        if c != p:
            q += 1
        p = c
    # print(q)
    print(min(n-1, n - q + 2 * k))

if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include <iostream>
using namespace std;
int main() {
	char hex[2];
	cin >> hex[0] >> hex[1];
	if (hex[0] > hex[1]) {
		cout << '>' << endl;
	}
	else if (hex[0] < hex[1]) {
		cout << '<' << endl;
	}
	else {
		cout << '=' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
int m, n;


	
	while(scanf("%d %d",&n ,&m))
	{
		if(m == 0 && n == m)
		{
			break;
		}
	for(int i = 0; i < m; i++)
	{
		printf("#");
	}
	printf("\n");
		for(int i = 0; i < n - 2; i++)
		{
			printf("#");
			for(int j = 0; j < m - 2; j ++)
			{
				printf(".");
			}
			printf("#");
			printf("\n");
		}
		for(int i = 0; i < m ; i++)
		{
			printf("#");		
			
		}
		
		printf("\n");
		printf("\n");
	}

return 0;

}



Measured memory_bytes: 2560
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2018-12-2 21:01:36
# Powered by Visual Studio Code
#

s = gets.chomp
ans = 10000
for i in 0...s.size
  ans = [ans, (753 - s[i...i+3].to_i).abs].min
end
puts ans



Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
int a[400][400];
map<P,int> m;

bool search(){
  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(i==j||i==k||j==k) continue;
        if(a[i][j]>a[i][k]+a[k][j]) return true;
        if(a[i][j]==a[i][k]+a[k][j]) m[P(i,j)]++;
      }
    }
  }

  return false;
}

int main(){
  cin>>n;
  rep(i,n){
    rep(j,n){
      cin>>a[i][j];
    }
  }

  if(search()){
    cout<<-1<<endl;
    return 0;
  }

  ll ans=0;
  rep(i,n){
    FOR(j,i+1,n){
      if(m[P(i,j)]) continue;
      ans+=a[i][j];
    }
  }

  cout<<ans<<endl;


}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
int main(){
    ll n,ans=0;
    string s;cin>>s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    else if(s=="Cloudy") cout<<"Rainy"<<endl;
    else if(s=="Rainy") cout<<"Sunny"<<endl;
    
}


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

using pii = pair<int, int>;

constexpr int INF = 1e9;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    vector<int> C(N), R(N);
    for(int i = 0; i < N; ++i) {
        cin >> C[i] >> R[i];
    }
    for(int i = 0; i < M; ++i) {
        int s, t;
        cin >> s >> t;
        g[s - 1].push_back(t - 1);
        g[t - 1].push_back(s - 1);
    }
    vector<int> d(N, INF);
    d[0] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> que;
    que.emplace(0, 0);
    while(!que.empty()) {
        int c, v;
        tie(c, v) = que.top();
        que.pop();
        if(c > d[v]) {
            continue;
        }
        c += C[v];
        vector<bool> visited(N);
        queue<pii> que2;
        que2.emplace(v, R[v]);
        visited[v] = true;
        while(!que2.empty()) {
            int vv = que2.front().first;
            int r = que2.front().second;
            que2.pop();
            for(auto to : g[vv]) {
                if(visited[to]) {
                    continue;
                }
                visited[to] = true;
                if(r - 1 > 0) {
                    que2.emplace(to, r - 1);
                }
                if(d[to] > c) {
                    d[to] = c;
                    que.emplace(c, to);
                }
            }
        }
    }
    cout << d.back() << endl;
}


Measured memory_bytes: 3568
S = input()

mae = int(S[0:2])
ushiro = int(S[2:])

if mae < 13 and mae > 0:

    if ushiro < 13 and ushiro > 0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if ushiro < 13 and ushiro > 0:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int t[100][100];
int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>t[i][j];
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      ans+=min(t[i][j],t[j][i]);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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


int main(){

    int n; cin >> n;
    string s; cin >> s;

    char last_slime = s[0];
    int ans = 1;

    for(int i = 1; i < n; i++){
        if(last_slime != s[i])  ans++;
        last_slime = s[i];
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n;
ll l, a[maxn];

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

	cin >> n >> l;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int pos = -1;
	for (int i = 0; i < n - 1; i++)
		if (a[i] + a[i + 1] >= l)
			pos = i;
	if (pos == -1)
	{
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	for (int i = 0; i < pos; i++)
		cout << i + 1 << endl;
	for (int i = n - 2; i >= pos; i--)
		cout << i + 1 << endl;
}



Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int d, g, p[15], c[15];
int ans = INF;

signed main() {
	cin >> d >> g;
	for (int i = 0; i < d; i++)cin >> p[i] >> c[i];
	for (int i = 0; i < (1 << d); i++) {
		int cnt = 0, cnt2 = 0;
		vector<P> vec;
		for (int j = 0; j < d; j++) {
			if (i&(1 << j)) {
				cnt += (1 + j) * 100 * p[j] + c[j];
				cnt2 += p[j];
			}
			else vec.push_back({ (1 + j) * 100,p[j] - 1 });
		}
		sort(all(vec));
		reverse(all(vec));
		int k = 0;
		while (cnt < g&&k < (int)vec.size()) {
			cnt2 += min(vec[k].second, (g - cnt + vec[k].first - 1) / vec[k].first);
			cnt += vec[k].first * min(vec[k].second, (g - cnt + vec[k].first - 1) / vec[k].first);
			k++;
		}
		if (cnt >= g)ans = min(ans, cnt2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> val;
    int cnt=0;
    char v=S[0];
    int flg=int(v=='1');
    rep(i,N){
        if(S[i]==v)cnt++;
        else{
            val.push_back(cnt);
            cnt=1;
            v=S[i];
        }
        if(i==N-1)val.push_back(cnt);
    }
    vector<int> sum_val;
    int tmp=0;
    sum_val.push_back(0);
    for(auto x:val){
        tmp+=x;
        sum_val.push_back(tmp);
    }
    // K = min(K,int(sum_val.size()));
    // DEBUG{
    //     cout << K << endl;
    //     rep(i,sum_val.size()){
    //         cout << sum_val[i] << endl;
    //     }
    // }
    int res=0;
    rep(i,N) {
        if(flg){
            if(i+2*K>=sum_val.size())continue;
            else if(i+2*K+1>=sum_val.size()){
                res = max(res, sum_val[i+2*K]-sum_val[i]);
                continue;
            }
            res = max(res, sum_val[i+2*K+1]-sum_val[i]);
        }
        else{
            if(i+2*K>=sum_val.size())continue;
            res = max(res, sum_val[i+2*K]-sum_val[i]);
        }
        flg =1-flg;
    }
    if(res==0){
        res=sum_val[sum_val.size()-1];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1528
n, m = list(map(int, input().split()))

if n == 1 and m == 1:
    print(1)
elif n == 1 and m > 1:
    print(m - 2)
elif n > 1 and m == 1:
    print(n - 2)
else:
    print((n-2)*(m-2))

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, X: int):

    res = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if 500*a+100*b+50*c == X:
                    res += 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(A, B, C, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064