akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for _ in 0..n {
        match sc.cin::<String>().as_str() {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            _ => re += 1,
        }
    }
    println!("AC x {}\nWA x {}\nTLE x {}\nRE x {}", ac, wa, tle, re);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
  int a,b,c,d;cin>>a>>b>>c>>d;
  
  while (a>0)
  {
    c-=b;
    a-=d;
  }
  
  if (c>0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  
}

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

int main(){
  int x,n; cin>>x>>n;
  vector<int> p(n);
  for (int i=0; i<n; i++)  cin>>p[i];
  
  int dist=10e3;
  int ans=10e3;
  
  for (int i=101; i>=0; i--){
    bool check=true;
    for (auto d : p){
      if (i==d) check=false;
    }
    if (check){
      int t_dist=abs(x-i);
      if (t_dist<=dist){
        ans=i;
        dist=t_dist;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;++i){
        cin>>v[i];
    }
    sort(v.begin(), v.end());

    ld ans = v[0];
    for(ll i=1;i<n;++i){
        ans = (v[i] + ans) / 2;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  
  ll e = lcm(c,d);
  
  cout << b-a+1-b/c+(a-1)/c-b/d+(a-1)/d+b/e-(a-1)/e << endl;
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<15;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  string S; cin >> S;
  string odd = "01", even = "10";
  int ansodd = 0, anseven = 0;
  for (int i=0; i<S.size(); i++) {
    if (S[i] != odd[i%2]) ansodd++;
  }
  for (int i=0; i<S.size(); i++) {
    if (S[i] != even[i%2]) anseven++;
  }
  cout << min(anseven, ansodd) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }

    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; }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;


bool kaibun(string str){
    // print(str);
    rep(i, str.size()/2){
        int num = str.size()-i-1;
        if(str[i] != str[num]){
            return false;
        }
    }

    return true;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    string str; cin >> str;
    int N; N = str.size();

    // print(kaibun(str.substr(0, (N-1)/2)));
    // print(kaibun(str.substr((N+3)/2-1, N - (N+3)/2 + 1)));
    // print((N+3)/2);
    // print(N);


    int a = ((N-1)/2);
    int b = (N+3)/2-1;

    bool res = kaibun(str.substr(0, a));
    bool res2 = kaibun(str.substr(b, N-b));
    bool res3 = kaibun(str);

    if(res && res2 && res3){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout <<"No" << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	int m = n;
	int s = 0;
	while (m) {
		s += m % 10;
		m /= 10;
	}
	if (n % s) {
		cout << "No";
	} else {
		cout << "Yes";
	}
	cout << '\n';
}



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

int main()
{
    LL n;
    cin >> n;
    LL fib_1 = 2, fib_2 = 1, cnt = 1;
    while(fib_2 <= 1000000000000000000){
        if(cnt == n){
            cout << fib_2 << "\n";
            return 0;
        }
        cnt++;
        LL temp = fib_1;
        fib_1 = fib_2;
        fib_2 += temp;
    }
    cout << fib_1 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  while(cin >> N){
    map<string, int> m;

    REP(i,N){
      string s; cin >> s;
      m[s] += 1;
    }

    int mx = 0;
    for(auto &kv : m){
      chmax(mx, kv.snd);
    }

    vector<string> ans;

    for(auto &kv : m){
      if(kv.snd == mx){
        ans.push_back(kv.fst);
      }
    }

    
    sort(ALL(ans));

    join(cout, ALL(ans), "\n");
  }


  return 0;
}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

 const int N=100005;
 const int inf=1e18;
 const double eps=1e-9;
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int x;
    cin>>x;
    int n=100;
    int c=0;
    while(n<x){
        c++;
        n+=n/100;
    }
    cout<<c;








	
return 0;
}


Measured memory_bytes: 3588
def ins(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i -g
        while j >= 0 and a[j] >v:
            a[j+g] = a[j]
            j = j-g
            cnt += 1
            a[j+g] = v

def shell(a,n):
    global cnt
    cnt = 0 
    h = 1 
    G=[]
    while h <= n:
        G.append(h)
        h = 3*h +1
    G.reverse()
    m = len(G)
    print(m)
    print(" ".join(map(str, G)))

    for i in range(m):
        ins(a, n, G[i])

intn = int(input())
a = [int(input()) for i in range(intn)]

shell(a,intn)
print(cnt)
for w in a:
    print(w)

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

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

int main() {

    int K,X;

    cin >> K >> X;

    for(ll i=(X-K+1); i<=(X+K-1); i++){
        if(i>=-1000000 && i<=1000000){
            cout << i << ' ';
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int x,y;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>x>>y;
	for(int i=0;i<=x;i++)if(i*2+(x-i)*4==y)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3652
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[3];
            string[] s = Console.ReadLine().Split(' ');
            a[0] = int.Parse(s[0]);
            a[1] = int.Parse(s[1]);
            a[2] = int.Parse(s[2]);

            if ((a[0] < a[1]) && (a[1] < a[2])) Console.WriteLine("Yes");
            else Console.WriteLine("No");

        }
    }
}

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

int main() {

	int x, y;
	cin >> x >> y;

	if (x == 1 ||x== 3 ||x== 5 ||x== 7 ||x== 8 ||x== 10 ||x== 12) {
		if (y == 1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else if (x == 4 || x==6 || x==9||x==11) {
		if (y == 4 || y==6 || y==9 || y==11) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else if (x == 2) {
		if (y == 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int n; cin >> n;
    bool can=false;

    while(n != 0){
        int a=0;
        a = n%10;
        n /= 10;
        if(a==7) can=true;
//        cout << a;
    }
    
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int) (n); i++)
#define  itn int
using ll=int64_t;
using vi = vector<int>;
using vll = vector<ll>;



int main(){
  double h,m;
  double  a,b;
  cin>>a>>b>>h>>m;
  double co;
  co = cos(2*3.14159265358793238462643383279*fabs( (h*60+m)/720-m/60));
   cout << fixed << setprecision(10);
  cout<< sqrt(a*a+b*b-2*a*b*co);
  
  

}


Measured memory_bytes: 4160
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	k := scanInt()

	arr := []int{}
	memo := map[int]bool{}

	var dfs func(num int)
	dfs = func(num int) {
		if memo[num] {
			return
		}
		arr = append(arr, num)
		memo[num] = true

		b := num % 10
		num *= 10
		if num > 1e11 {
			return
		}
		for i := 0; i < 10; i++ {
			if abs(b-i) > 1 {
				continue
			}

			dfs(num + i)
		}
	}

	for i := 1; i < 10; i++ {
		dfs(i)
	}

	sort.Ints(arr)

	fmt.Fprintln(wr, arr[k-1])
}


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

int main(){
    string s;
    cin >> s;
    int count = 0;
    if(s[0] == '1'){count++;}
    if(s[1] == '1'){count++;}
    if(s[2] == '1'){count++;}

    cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

class Parser_ {
public:
  int operator() (std::string str_) {
    str = str_;
    i = 0;
    return calc().first;
  }
  std::pair<int, int> calc() {
    return formula(0);
  }
  std::pair<int, int> formula(int i) {
    auto v = value(i);
    if( v.second != i ) return v;
    i = v.second;
    char c1 = str[i]; i += 1;
    if( c1 == '-' ) {
      auto f1 = formula(i);
      return std::pair<int, int>(2 - f1.first, f1.second);
    }
    assert( c1 == '(' );
    auto f1 = formula(i);
    i = f1.second;
    char c2 = str[i]; i += 1;
    auto f2 = formula(i);
    i = f2.second;
    int res = 0;
    assert( c2 == '+' or c2 == '*' );
    if( c2 == '+' ) {
      res = std::max(f1.first, f2.first);
    }
    else {
      res = std::min(f1.first, f2.first);
    }
    if( str[i] != ')' ) {
      std::cerr << str[i] << std::endl;
      assert(0);
    }
    i += 1; // pass ')'
    return std::pair<int, int>(res, i);    
  }
  std::pair<int, int> value(int i) {
    if( '0' <= str[i] and str[i] <= '2' ) {
      return std::pair<int, int>(str[i]-'0', i + 1);
    }
    return std::pair<int, int>(0, i);
  }    
private:
  std::string str;
  int i;
};
Parser_ Parser;

std::string Assign(std::string str, int P, int Q, int R) {
  for(int i = 0; i < (int)str.size(); ++i) {
    if( str[i] == 'P' ) str[i] = P + '0';
    if( str[i] == 'Q' ) str[i] = Q + '0';
    if( str[i] == 'R' ) str[i] = R + '0';
  }
  return str;
}

int main() {
  for(;;) {
    std::string str;
    std::cin >> str;
    if( str == "." ) break;

    int count = 0;
    for(int i = 0; i < 3; ++i) {
      for(int j = 0; j < 3; ++j) {
        for(int k = 0; k < 3; ++k) {
          if( Parser(Assign(str, i, j, k)) == 2 ) count += 1;
        }
      }
    }
    printf("%d\n", count);
  }
  
  return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b);i++)
#define repv(vec,v) for(v=(vec).begin(); v!=(vec).end();v++)
#define sz(vec) (int)(vec).size()
#define PB push_back
#define F first()
#define S second()


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

	ll r = n/ (a+b);
	cout << r*a + min(a,n-r*(a+b));
	return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        long n = Read();
        var ga = Read();
        var sa = Read();
        var ba = Read();
        var gb = Read();
        var sb = Read();
        var bb = Read();
        n = Solve(n, new IntTuple(ga, gb), new IntTuple(sa, sb), new IntTuple(ba, bb));
        n = Solve(n, new IntTuple(gb, ga), new IntTuple(sb, sa), new IntTuple(bb, ba));
        Console.WriteLine(n);
    }

    //向こうのレートでどれくらいにできるか
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long Solve(long n, IntTuple g, IntTuple s , IntTuple b)
    {
        if (g.Item1 >= g.Item2) return Solve(n, s, b);
        if (s.Item1 >= s.Item2) return Solve(n, g, b);
        if (b.Item1 >= b.Item2) return Solve(n, g, s);
        long max = 0;
        long currentEffort = 0;
        while (n >= 0)
        {
            max = Max(max, currentEffort + Solve(n, g, s));
            n -= b.Item1;
            currentEffort += b.Item2;
        }
        return max;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long Solve(long n, IntTuple g, IntTuple s)
    {
        if (g.Item1 >= g.Item2) Solve(n, s);
        if (s.Item1 >= s.Item2) Solve(n, g);
        long max = 0;
        long currentEffort = 0;
        while (n >= 0)
        {
            max = Max(max, currentEffort + Solve(n, g));
            n -= s.Item1;
            currentEffort += s.Item2;
        }
        return max;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long Solve(long n, IntTuple g)
    {
        if (g.Item1 >= g.Item2) return n;
        return n % g.Item1 + (n / g.Item1) * g.Item2;
    }

    static readonly TextReader In = Console.In;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static int Read()
    {
        int res = 0;
        int next = In.Read();
        while (48 > next || next > 57) next = In.Read();
        while (48 <= next && next <= 57)
        {
            res = res * 10 + next - 48;
            next = In.Read();
        }
        return res;
    }
}

struct IntTuple
{
    public int Item1;
    public int Item2;
    public IntTuple (int item1, int item2)
    {
        Item1 = item1;
        Item2 = item2;
    }
}

Measured memory_bytes: 13652
n,k=map(int,input().split())
S=input()
s_dict={
  'A':'a',
  'B':'b',
  'C':'c',
}
ans=''

for i,s in enumerate(S):
  if i!=(k-1):
    ans+=s
  else:
    ans+=s_dict[s]
print(ans)


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

ll n;

int dfs(ll a){
    if(a > n){
        return 0;
    }

    int three = 0; 
    int five = 0; 
    int seven = 0; 
    bool ok = true;
    string s = to_string(a);
    for(int i = 0; i < s.size(); i++){
        switch (s[i])
        {
            case '3'/* constant-expression */:
                three++;
                break;

            case '5':
                five++;
                break;

            case '7':
                seven++;
                break;
        
            default:
                ok = false;
                break;
        }
    }

    int ret = 0;
    if(three > 0 && five > 0 && seven > 0 && ok){
        ret = 1;
    }
    ret += dfs(a*10+3);
    ret += dfs(a*10+5);
    ret += dfs(a*10+7);

    return ret;
}

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

    cin >> n;

    int ans = dfs(0);
    

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,int> P;
typedef unsigned long long int ull;
const int MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const int INF=1e9;

int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    for(int i=0;i<n;i++){
        if(i>0){
          int t=min(a[i-1],a[i]);
            ans+=t;
            a[i-1]-=t;
            a[i]-=t;
        }
        ans+=a[i]/2;
        a[i]-=(a[i]/2)*2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
//整数の割り算の切り上げ
int64_t updiv(int64_t a,int64_t b){
    return (a+(b-1))/b;
}
int main(){
    int64_t n,k;
    cin>>n>>k;
    vector<int64_t> a(n);
    int64_t amax=0;
    rep(i,n){
        cin>>a[i];
        amax = max(amax,a[i]);
    }
    int ans;
    int r = amax,l=1;
    int m;
    while(r-l>1){
        m=(r+l)/2;
        int fl=0;
        rep(i,n){
            fl += updiv(a[i],m)-1;
        }
        if(fl<=k) {//もっと切れる
            r = m;
        }
        else{//fl>k ->そんなに切れない->
            l = m;
        }
    }
    //lとrを比較
    int last=0;
    rep(i,n){
        last += updiv(a[i],l)-1;
    }
    if(last>k){
        cout<<r<<endl;
    }
    else{
        cout<<l<<endl;
    }
}

Measured memory_bytes: 4768
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class Main {

	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		while (read())
			solve();
	}
	
	static int W, H;
	static char[][] cliff = new char[60][30];
	static int ns, ng;
	static int[] sx = new int[30], gx = new int[30];
	
	static boolean read() {
		W = sc.nextInt(); H = sc.nextInt();
		if (W == 0 && H == 0) return false;
		
		ns = 0;
		for (int i = 0; i < H; i++) { 
			for (int j = 0; j < W; j++) { 
				cliff[i][j] = sc.next().charAt(0);
				if (cliff[i][j] == 'S') {
					sx[ns++] = j;
					cliff[i][j] = 'X';
				}
			}
		}
				
		return true;
	}

	static final int INF = 1 << 29;
	static void solve() {
		int ans = dijkstra();
		if (ans == INF)
			ans = -1;
		System.out.println(ans);
	}	
	
	static int[][] dx = {
		{3, 2, 2, 2, 1, 1, 1, 1, 1},
		{-3, -2, -2, -2, -1, -1, -1, -1, -1}
	};
	static int[] dy = {
		0, -1, 0, 1, -2, -1, 0, 1, 2
	};
	static int[][][] dist = new int[2][60][30]; // prev_foot, prev_y, prev_x
	static int dijkstra() {
		for (int i = 0; i < 2; i++) 
			for (int j = 0; j < 60; j++)
				fill(dist[i][j], INF);
		
		PriorityQueue<State> que = new PriorityQueue<State>();
		for (int i = 0; i < ns; i++) {
			for (int j = 0; j < 2; j++) {
				que.add(new State(0, j, sx[i], H - 1));
			}
		}		
		
		int ans = INF;
		boolean find = false;
		while (!que.isEmpty()) {
			State s = que.poll();

			int cost = s.cost, prev = s.prev, prev_y = s.foot[1], prev_x = s.foot[0];
			if (dist[prev][prev_y][prev_x] <= cost) continue;
			
			// update distination
			dist[prev][prev_y][prev_x] = cost;
			// try to next step
			for (int k = 0; k < 9; k++) {
				int nx = prev_x + dx[prev][k];
				int ny = prev_y + dy[k];
				int nprev = (prev + 1) % 2;
				int dc = getCost(nx, ny);
				if (dc == 0) {
					// find goal
					return cost;
				} else if (dc != -1) {
					int ncost = cost + dc;
					que.add(new State(ncost, nprev, nx, ny));
				}
			}
		}
		
		return INF;
	}
	
	static int getCost(int x, int y) {
		if (x < 0 || W <= x || y < 0 || H <= y || cliff[y][x] == 'X')
			return -1;
		else if (cliff[y][x] == 'T')
			return 0;
		else 
			return Integer.parseInt(Character.toString(cliff[y][x]));
	}
}


class State implements Comparable<State> {
	int cost, prev; // time, prev_foot
	int[] foot; // Lfoot
	State(int cost, int prev, int x, int y) {
		this.cost = cost;
		this.prev = prev;
		foot = new int[2];
		foot[0] = x;
		foot[1] = y;
	}
	
	public int compareTo(State s) {
		return this.cost - s.cost;
	}
}

Measured memory_bytes: 14000
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int64, n)
	sum := int64(0)
	im := make(IntMap, 1)

	var ans int64
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		sum += aa[i]
		im.increment(sum)
	}

	for key, cnt := range im {
		if key == 0 {
			ans += int64(cnt)
		}
		if cnt < 2 {
			continue
		}
		ans += int64((cnt * (cnt - 1)) >> 1)
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

// IntMap ...
type IntMap map[int64]int

func (m IntMap) get(key int64) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int64) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}


Measured memory_bytes: 13312
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(a!=0&&c!=0){
    c-=b;
    if(c<=0){break;}
    a-=d;
    if(a<=0){break;}
  }
  if(a>0){printf("Yes\n");}
  else{printf("No\n");}
  return 0;
}


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 0;
  for (int i = 0; i < 1000; i++) {
    string s;
    int x = i;
    for (int j = 0; j < 3; j++) {
      s += '0' + x % 10;
      x /= 10;
    }
    int c = 0;
    for (int j = 0; j < N; j++) {
      if (S[j] == s[c]) {
        c++;
      }
      if (c == 3) {
        cnt++;
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  ll n;cin >> n;
  ll bottom_rank = 1LL;
  ll bottom_point = 0LL;
  for(ll i=0LL; i<n;++i){
    ll a,b;cin >>a>>b;
    if(a>=bottom_rank) {
      bottom_rank = a;
      bottom_point = b;
    }
  }
  cout << bottom_rank + bottom_point << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int n,a;
    cin>>n;
    deque<int> deq;
    bool op=false;
    rep(i,n)
    {
        cin>>a;
        if(op)
        {
            deq.push_front(a);
        }
        else
        {
            deq.push_back(a);
        }
        op=!op;
    }
    if(op)
    {
        reverse(all(deq));
    }
    rep(i,n)
    {
        cout<<deq[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <bitset>

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

bool flag;

void binary_brute_force(const vector<char>& num)
{
    int n = num.size() - 1, sum;
    for(int i=0; i < (1 << n); ++i)
    {
        sum = (num[0] - '0');
        for(int j=0; j<n; ++j)
        {
            if((i >> j) & 1)
            {
                sum += (num[j+1] - '0');
            }
            else{
                sum -= (num[j+1] - '0');
            }
        }
        if(sum == 7)
        {
            cout << num[0];
            for(int j=0;j<n;++j)
            {
                if((i >> j) & 1) cout << '+';
                else             cout  << '-';
                cout << num[j+1];
            }
            cout << "=7" << endl;
            break;
        }
    }
}

void dfs(const vector<char>& num, int sum, int index, bitset<3> state)
{
    if(flag) return;
    if(index >= num.size()-1)
    {
        if(sum == 7)
        {
            cout << num[0];
            for(int i=0;i<3;++i)
            {
                if(state[i]) cout << "+";
                else         cout << "-";
                cout << num[i+1];
            }
            cout << "=7" << endl;
            flag = true;
        }
        return;
    }
    state[index] = 1;
    dfs(num, sum + (num[index+1] - '0'), index+1, state);
    state[index] = 0;
    dfs(num, sum - (num[index+1] - '0'), index+1, state);
}

int main()
{
    flag = false;
    vector<char> num(4);
    for(char& c : num){
        cin >> c;
    }
    //binary_brute_force(num);
    dfs(num, num[0] - '0', 0, bitset<3>());
}


Measured memory_bytes: 256
n = int(input())
dp = [[0 for _ in range(3)] for _ in range(n + 1)]
ans = 0
for d in range(1, n + 1):
    abc = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            dp[d][j] = max(dp[d][j], dp[d - 1][i] + abc[j])
            ans = max(ans, dp[d][j])
print(ans)

Measured memory_bytes: 87552
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();

		boolean ans = false;
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				if (i * j == N)
					ans = true;
			}
		}
		if (ans)
			System.out.println("Yes");
		else
			System.out.println("No");

	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
 
int main()
{
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
 
  int flag = 0, ans = 1;
  for (int i = 1; i < N; ++i) {
    if (flag == 0) {
      if (A[i-1] < A[i]) flag = 1;
      else if (A[i-1] > A[i]) flag = 2;
    } else if (flag == 1) {
      if (A[i-1] > A[i]) {
        flag = 0;
        ans++;
      }
    } else if (flag == 2) {
      if (A[i-1] < A[i]) {
        flag = 0;
        ans++;
      }
    }
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 1024
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	int n; scanf("%d",&n);
	vector<vector<int>> f(n),p(n);
	rep(i,0,n){
		f[i].resize(10);
		rep(j,0,10) scanf("%d",&f[i][j]);
	}
	rep(i,0,n){
		p[i].resize(11);
		rep(j,0,11) scanf("%d",&p[i][j]);
	}
	ll ans=-INF;
	rep(mask,1,1<<10){
		ll sub=0;
		rep(i,0,n){
			int k=0;
			rep(j,0,10)if((mask>>j&1)&&f[i][j]) k++;
			sub+=p[i][k];
		}
		ans=max(ans,sub);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    string s;
    int n,mx;
    cin >> n >> s;
    mx=n=0;
    rep(i,s.length()){
        if(s[i]=='I')n++;
        else n--;
        mx=max(n,mx);
    }
    cout << mx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

vector<int> G[100'010];
bool on_path[100'010];

int main(){
  
  int n,m;
  cin>>n>>m;
  int a,b;
  REP(i,m){
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bool lflag=false,rflag=false;
  deque<int> path;
  int l,r;
  l = r = 0;
  on_path[0] = true;
  path.push_front(0);
  
  int temp;
  while(!lflag || !rflag){
    if(!lflag){
      temp = l;
      for(int next_:G[l]){
        if(on_path[next_])continue;
        path.push_front(next_);
        on_path[next_] = true;
        l = next_;
        break;
      }
      if(l == temp){
        lflag = true;
      }
    }
    if(!rflag){
      temp = r;
      for(int next_:G[r]){
        if(on_path[next_])continue;
        path.push_back(next_);
        on_path[next_] = true;
        r = next_;
        break;
      }
      if(r == temp){
        rflag = true;
      }
    }
  }
  
  int len = path.size();
  cout<<len<<endl;
  for(int u:path){
    cout<<u+1<<' ';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>

int main()
{
  int n;
  while(scanf("%d",&n)!=EOF)
    {
      int a,b,c,d,count=0;
      for(a=0;a<=9;a++){
	for(b=0;b<=9;b++){
	  for(c=0;c<=9;c++){
	    for(d=0;d<=9;d++){
	      if(a+b+c+d==n) count++;
	    }
	  }
	}
      }
      printf("%d\n",count);
    }
  return 0;
}

Measured memory_bytes: 596
//https://atcoder.jp/contests/abc157/tasks/abc157_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    vector<vector<ll>> a33(3,vector<ll>(3));
    map<ll,pair<ll,ll>> tbl;
    FOR(y,0,3){
        FOR(x,0,3){
            ll a; cin>>a;
            tbl[a]={x,y};
        }
    }

    vector<vector<ll>> flag(3,vector<ll>(3,0)); 
    ll N; cin>>N;
    REP(i,N){
        ll b; cin>>b;
        auto it =tbl.find(b);
        if(it!=tbl.end()){
            auto p=it->second;
            flag.at(p.second).at(p.first)=1;
        }
    }
    //たて、よこ、ななめ
    bool ans=false;
    FOR(y,0,3){
        if (flag[y][0] && flag[y][1] && flag [y][2]){
            ans=true;
        }
        if (flag[0][y] && flag[1][y] && flag [2][y]){
            ans=true;
        }
    }
	if(flag[0][0] && flag[1][1] && flag[2][2]) {
		ans = true;
	}
	if(flag[0][2] && flag[1][1] && flag[2][0]) {
		ans = true;
	}
    cout<<(ans?"Yes":"No")<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, q;
vector<pair<LL, LL>> imo;
set<LL> s;

void solve() {
  cin >> n >> q;
  REP(_, n) {
    LL s, t, x;
    cin >> s >> t >> x;
    s -= x;
    t -= x;
    imo.push_back({s, x});
    imo.push_back({t, -x});
  }
  sort(ALL(imo));
  int i = 0;
  REP(_, q) {
    LL d;
    cin >> d;
    while(i < SZ(imo) && imo[i].first <= d) {
      if (imo[i].second > 0) {
        s.insert(imo[i].second);
      } else {
        s.erase(-imo[i].second);
      }
      i++;
    }
    if (SZ(s) > 0) {
      cout << *s.begin() << endl;
    } else {
      cout << -1 << endl;
    }
  }
}

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


Measured memory_bytes: 18408
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<iomanip>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
struct  node
{
    int add,cost,mod;
}a[25];
bool cmp(node a,node b)
{
    return a.mod>b.mod;
}
int main()
{
    ios::sync_with_stdio(false);
    // freopen("D:\\in.txt","r",stdin);
    // freopen("D:\\out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].add;
    }
    for(int i=0;i<n;i++)
    {
        cin>>a[i].cost;
    }
    for(int i=0;i<n;i++)
    {
        a[i].mod=a[i].add/a[i].cost;
    }
    sort(a,a+n,cmp);
    int i=0;
    int sum=0;
    while(a[i].mod>=1)
    {
        sum+=(a[i].add-a[i].cost);
        i++;
    }
    cout<<sum<<endl;
    return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
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>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void){
    int n;cin>>n;
    multiset<int> a;
    set<int> type;
    rep(i,n){
        int t;cin>>t;
        a.insert(t);
        type.insert(t);
    }
    int ans=0;
    rfor(x,type){
        int cnt=a.count(x);
        if(x>cnt){
            ans+=cnt;
        }else if(x<cnt){
            ans+=cnt-x;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9216
from collections import deque

def main():
    N,K=map(int,input().split())

    A=list(map(lambda x:int(x)-1,input().split()))
    FootPrintA=A[:]

    loop=[]

    slack_que=deque([])
    flag=0
    t=0
    start=0
    while flag==0:
        slack_que.append(t)
        t_ = FootPrintA[t]
        FootPrintA[t]=-1
        if t_==-1:
            start=slack_que.index(t)
            flag=1
            slack_que.pop()
        t = A[t]

    slack=list(slack_que)
    slack_num=start
    loop_num=len(slack)-slack_num

    # print(slack)
    # print(start)
    # print(slack_num)
    # print(loop_num)
    #
    loop=slack[start:]
    # print(loop)
    if (K-slack_num)<0:
        res=slack[K]+1
    else:
        tele_num=((K-slack_num)%loop_num)
        town=loop[tele_num]
        res=town+1

    print(res)

if __name__=="__main__":
    main()



Measured memory_bytes: 33924