akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e2 + 5;
const int INF = 1e9 + 7;

int a, b, c, k;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c >> k;
	if (a >= k)
		cout << k;
	else if ((a + b) >= k)
		cout << a;
	else
		cout << a - (k - (a + b));
	return 0;
}
//11-09-2020 10:07:44

Measured memory_bytes: 3584
def main():
    n = int(input())

    r = input()
    s = set()
    s.add(r)
    r = r[-1]
    for i in range(n - 1):
        w = input()
        if w in s or r != w[0]:
            print('No')
            return
        s.add(w)
        r = w[-1]
    print('Yes')

main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int keypress = (B < D ? B : D) - (A > C ? A : C);
		System.out.println(keypress > 0 ? keypress : 0);
		sc.close();
	}
}


Measured memory_bytes: 22740
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
ls=[0 for i in range(100000)]#O(100000)
S=sum(A)
for i in range(N):#O(100000)
  ls[A[i]-1]+=1
for i in range(Q):#O(100000)
  B,C=map(int,input().split())
  ls[C-1]+=ls[B-1]
  S+=(C-B)*ls[B-1]
  ls[B-1]=0
  print(S)

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int m, nmin, nmax;
    while(cin>>m>>nmin>>nmax&&m){
        vector<int> line(m);
        foreach(i, line)cin>>i;
        int ans = nmin;
        for(int i=nmin-1;i<nmax;++i){
            if(line[i]==line[i+1])continue;
            if(line[ans]-line[ans+1]<=line[i]-line[i+1])ans=i;
        }
        cout << ans+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>
#include <tuple>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}

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

	cout << (a - 1) * (b - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dump(a) cout << #a << " " << a << endl
#define MAX_SIZE 1000
using namespace std;

string X,Y;
int dp[MAX_SIZE+1][MAX_SIZE+1];

int dfs(int xi, int yi) {
	if (dp[xi][yi] != -1) { return dp[xi][yi]; }

	if (xi==X.size() || yi==Y.size()) { return 0; }
	else if (X[xi] == Y[yi]) {
		dp[xi][yi] = dfs(xi+1,yi+1) + 1;
	}
	else {
		dp[xi][yi] = max(dfs(xi,yi+1),dfs(xi+1,yi));
	}
	return dp[xi][yi];
}

int main() {
	int N;

	cin >> N;

	for(int i=0; i<N; i++) {
		cin >> X >> Y;
		memset(dp,-1,sizeof(dp)); //-1??§?????????
		cout << dfs(0,0) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5216
#include <iostream>
using namespace std;
#define int long long
int qp(int a,int b,int m){
    int res=1;
    while(b){
        if(b&1) res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
string s;
int calc(int x){
    int cnt=1;
    while(x){
        int t=__builtin_popcount(x);
        cnt++;
        x%=t;
    }
    return cnt;
}
signed main(){
    int n,cnt=0;
    cin>>n;cin>>s;
    for(auto t : s) if(t=='1') cnt++;
    if(cnt>1){
        int sum1=0,sum2=0;
        for(int i=0;i<n;++i) {
            if (s[i] == '1') {
                sum1 = (sum1 + qp(2, n - i - 1, cnt - 1)) % (cnt - 1);
                sum2 = (sum2 + qp(2, n - i - 1, cnt + 1)) % (cnt + 1);
            }
        }
        for(int i=0;i<n;++i){
            if(s[i]=='0'){
                int t=(sum2+qp(2,n-i-1,cnt+1))%(cnt+1);
                cout<<calc(t)<<endl;
            }
            else {
                int t=(sum1-qp(2,n-i-1,cnt-1)+cnt-1)%(cnt-1);
                cout<<calc(t)<<endl;
            }
        }
    }else if(cnt==1){
        int sum=0;
        for(int i=0;i<n;++i) {
            if (s[i] == '1') {
                sum = (sum + qp(2, n - i - 1, 2)) % 2;
            }
        }
        for(int i=0;i<n;++i){
            if(s[i]=='0') {
                int t=(sum+qp(2,n-i-1,2))%2;
                cout<<calc(t)<<endl;
            }
            else cout<<0<<endl;
        }
    }else {
        for(int i=0;i<n;++i){
            cout<<1<<endl;
        }
    }


    return 0;
}

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

int const maxN = 1e5 + 10;

int N, ut, va;
vector<int> E[maxN];

int main()
{
  scanf("%d%d%d", &N, &ut, &va);
  for(int i = 0; i < N-1; i++) {
    int A, B;
    scanf("%d%d", &A, &B);
    E[A].push_back(B);
    E[B].push_back(A);
  }

  if(ut == va) { puts("0"); return 0; }


  int aoki[maxN];
  vector<bool> vis(N+1, false);
  queue<pair<int, int>> q;
  vis[va] = true;
  q.push({va, 0});

  while(q.size()) {
    //auto [u, t] = q.front(); q.pop();
    int u, t;
    tie(u, t) = q.front(); q.pop();
    aoki[u] = t;
    for(int v: E[u])
      if(!vis[v]) q.push({v, t+1}), vis[v] = true;
  }

  int taka[maxN];
  queue<tuple<int, int, int>> q2;
  memset(taka, -1, sizeof taka);
  //vis.assign(N+1, false);
  //vis[ut] = true;
  q2.push(make_tuple(ut, ut, 0));

  while(q2.size()) {
    //auto [u, t] = q2.front(); q2.pop();
    int p, u, t;
    tie(p, u, t) = q2.front(); q2.pop();
    taka[u] = t;
    for(int v: E[u])
      if(v != p && t+1 <= aoki[v]) q2.push(make_tuple(u, v, t+1)), vis[v] = true;
  }


  int ans = aoki[ut]-1;
  for(int i = 1; i <= N; i++)
    if(taka[i] != -1 && taka[i] != 0) ans = max(ans, aoki[i]-1);

  //for(int i = 1; i <= N; i++) printf("%d ", taka[i]);

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 7032
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let n:u64 = r.readl();

    let mut res = 0;

    for i in 1..(n + 1) {
        if(i % 3 == 0) || (i % 5 == 0){

        }else{
            res += i;
        }
    }

    println!("{}", res);

}

Measured memory_bytes: 2172
#include <iostream>
#include <string>
using namespace std;
int main()
{
    long long int a,n;
    a=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0) 
            continue;
        a+=i;
        

    }
    cout<<a<<endl;
}


Measured memory_bytes: 3188
count = 0

def merge_sort(n, nums):
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    global count
    count += idx
    return sorted_list


def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    sorted_list = merge_sort(n, nums)
    print(" ".join(map(str, sorted_list)))
    print(count)


if __name__ == "__main__":
    main()



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

public class ABC0124_A1 {
    public static readonly int NumOfTimesToPush = 2;

    private static void Main(string[] args) {
        string input = Console.ReadLine().Trim();
        ConvertInput(input);
    }

    private static void ConvertInput(string input) {
        var inputs = input.Split(' ').ToList();
        var numbers = ConvertListToInt(inputs);
        Solve(numbers);
    }
  
    private static void Solve(List<int> numbers) {
        var numOfCoins = 0;

        for (int i = 0; i < NumOfTimesToPush; i++) {
            numbers = numbers
                .OrderByDescending(n => n)
                .ToList();

            numOfCoins += numbers[0];
            numbers[0]--;
        }

        OutputAnswer(numOfCoins.ToString());
    }

    private static List<int> ConvertListToInt(List<string> texts) => texts.Select(x => int.Parse(x)).ToList();
    private static void OutputAnswer(string text) => Console.WriteLine(text);
}

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

int main() {
  while (true) {
    int D, E;
    cin >> D >> E;

    if (D == 0) {
      break;
    }
    
    double minerr = abs(D - E);
    for (int x = 0; x <= D / 2; x++) {
      int y = D - x;
      double err = abs(sqrt(x * x + y * y) - E);

      if (err < minerr) {
	minerr = err;
      }
    }

    cout << minerr << endl;
  }

  return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
 
int main(){
	int x,y;
	cin>>x>>y;
	int gx=1,gy=1;
	if(x==4||x==6||x==9||x==11)gx=2;
	if(x==2) gx=3;
	if(y==4||y==6||y==9||y==11)gy=2;
	if(y==2) gy=3;
	if(gx==gy)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll a, b, c, d; cin >> a >> b >> c >> d;
    print(max(max(a * c, a * d), max(b * c, b * d)))
    
    return 0;
}

Measured memory_bytes: 3648
import numpy as np
import math
import scipy
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    tar, ans = 1, 0
    bit = 0
    for i in range(n):
        if a[i] == tar:
            bit = 1
            tar += 1
        else:
            ans += 1
    if bit == 0:
        print(-1)
    else:
        print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 34180
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();

		long pattern = 1;
		Set<Character> set = new HashSet<>();
		for (int i = 0; i < A.length; i++) {
			if (set.contains(A[i])) {
				continue;
			}
			set.add(A[i]);

			long sum = 0;
			for (int j = A.length - 1; j > i; j--) {
				if (A[i] != A[j]) {
					sum++;
				} else {
					pattern += sum;
				}
			}
			pattern += sum;
		}

		System.out.println(pattern);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b, int[] c) throws IOException {
			if (a.length != b.length || b.length != c.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
				c[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 24392
/*
ID: jerrywcy
TASK: AtCoder ABC 103 Problem C
LINK: https://abc103.contest.atcoder.jp/tasks/abc103_c
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n,a;
int ans;

int main()
{
	cin>>n;
	int i,j;
	for (i=1;i<=n;i++){
		cin>>a;
		ans+=a-1;
	}
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    
    int d[50];
    for(int i=0;i<N;i++){
        cin >> d[i];
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        for(int j=1;j<N-i;j++){
            ans += d[i]*d[i+j];
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int a,b,c,d,e=0,f;
        cin>>a>>b>>c>>d;
        f = min(d,a);
        e += f;
        d -= f;
        f = min(d,b);
        e += 0;
        d -= f;
        f = min(d,c);
        e -= f;
        d -= f;
        cout<<e<<endl;
    }
    return 0;
}


Measured memory_bytes: 3608
// D - Lunlun Number
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int K; cin>>K; //候補の個数

	vector<ll> candidate; //候補

	queue<ll> q;
	rp(i, 1, 10) q.push(i); //最上位桁かつ候補の初期値

	while(q.size()){
		ll n = q.front(); q.pop(); //候補を取り出す

		candidate.push_back(n); //候補を登録
		if(candidate.size() >= K) break; //候補が充足したら終了

		int n1 = n%10; //nの第一位
		rp(i, -1, 2){ //{-1,0,+1}: n1 より +-1 の範囲が次の第一位
			int m = n1 + i; //次の第一位
			if(m < 0 || 9 < m) continue; //[0,9] の範囲外は下位桁として不適
			q.push(n*10+m); //候補を末尾に追加
		}

	}

	cout<< candidate[K-1] <<endl; //昇順で登録してあるので最終候補が解
}

Measured memory_bytes: 2548
#include <iostream>

using namespace std;

int a[10];

bool dfs(int d, int left, int right) {
    if (d == 10) {
        return true;
    }
    if (a[d] > left) {
        return dfs(d + 1, a[d], right);
    }
    if (a[d] > right) {
        return dfs(d + 1, left, a[d]);
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) {
            cin >> a[i];
        }
        if (dfs(0, 0, 0) == true) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1152
S = list(input())

#最終的にRLのところで往復することになる
#最初のLと最後のRはそこに集約される

N = len(S)

ans = list()

#最初のLの連続を集約
i = 0

if S[0] == "L":
    ans.append(0)
    while i < N:
        if S[i] == "L":
            ans[0] += 1
            if i != 0:
                ans.append(0)
        else:
            break
        i+= 1

#あとは最後まで行く
R_cnt = 0
L_cnt = 0
while i < N:
    #Rを集約
    if S[i] == "R":
        R_cnt += 1
        i += 1
    else:
        #Lを集約
        while i < N:
            if S[i] == "L":
                L_cnt += 1
                i += 1
            else:
                #RL境界の手前まで埋める
                ans += [0 for _ in range(R_cnt - 1)]
                
                #RLの値を埋める。
                #10**100移動する
                #最終移動後には、集約したRの個数のうち、R_cnt//2はLのマスへ、残りがRのマスにいる
                #最終移動後には、集約したLの個数のうち、L_cnt//2はRのマスへ、残りがLのマスにいる
                ans.append(R_cnt - (R_cnt//2) + L_cnt//2)
                ans.append(L_cnt - (L_cnt//2) + R_cnt//2)

                #RL境界以後のところをRまで埋める
                ans += [0 for _ in range(L_cnt - 1)]

                R_cnt = 0
                L_cnt = 0
                break

if R_cnt!=0:
    if L_cnt != 0:
        #...RRRLLLのような終わり方
                ans += [0 for _ in range(R_cnt - 1)]
                ans.append(R_cnt - (R_cnt//2) + L_cnt//2)
                ans.append(L_cnt - (L_cnt//2) + R_cnt//2)
                ans += [0 for _ in range(L_cnt - 1)]
    else:
        #...RRRRRRのような終わり方
        ans += [0 for _ in range(R_cnt - 1)]
        ans.append(R_cnt)

print(' '.join(map(str, ans)))

Measured memory_bytes: 17792
#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() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    int t, f;
    char c;
    int front = 1, back = 2;
    int cnt = 0;
    string add;
    rep(i,q) {
        cin >> t;
        if (t == 1) {
            cnt += 1;
            swap(front, back);
        } else {
            cin >> f >> c;
            if (f == front) add.push_back(c);
            else s.push_back(c);
        }
    }
    if (cnt%2 == 1) {
        reverse(s.begin(), s.end());
        s += add;
    } else {
        reverse(add.begin(), add.end());
        s = add + s;
    }
    cout << s << endl;
    return 0;
}

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

const int MAX = 200005;
long long A[MAX], B[MAX];

int N;
long long BIT[MAX];
void add(int a, long long w) {
    for (int x = a; x <= N+1; x += x & -x) BIT[x] += w;
}
long long sum(int a) {
    long long ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += BIT[x];
    return ret;
}

int main() {
    int K;
    long long a;
    scanf("%d %d", &N, &K);
    A[0] = B[0] = 0;
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &a);
        A[i] = A[i-1] + a - K;
        B[i] = A[i]; 
    }
    sort(B, B+N+1);
    long long ans = 0;
    for (int i = 0; i <= N; i++) {
        int p = distance(B, lower_bound(B, B+N+1, A[i]));
        ans += sum(p+1);
        add(p+1, 1ll);
    }
    printf("%lld\n", ans);
    return 0;
}

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

typedef long long ll;

int n,m;
string s1,s2;

int main(){
    cin >> n >> m;
    cin >> s1 >> s2;
    int g = __gcd(n, m);
    int n1 = n / g, m1 = m / g;
    //cout << g << endl;
    for(int i = 0; i < g; i++){
        if(s1[i * n1] != s2[i * m1]) return !printf("-1");
    }
    cout << 1LL * n1 * m1 * g << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		for (int i = A; i <= B; i++) {
			if (B-A-1>=K &&(i >= A && A + K > i) || (B >= i && i > B - K)) {
				System.out.println(i);
			}else if(K>B-A-1) {
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  int ans = 0;
  int v = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] >= H[i + 1]) v++;
    else v = 0;
    ans = max(ans, v);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3996
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]

ab.sort()
cd.sort()

pair = []
for i in range(N):
    max_y = -1
    pair_id = -1
    for j in range(N):
        if j not in pair and cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
            if max_y < ab[j][1]:
                max_y = ab[j][1]
                pair_id = j
    if pair_id != -1:
        pair.append(pair_id)

print(len(pair))




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

int main() {
  string s,ss = "CODEFESTIVAL2016";
  cin >> s;
  int ans = 0;
  rep(i,0,s.size()) if(s[i] != ss[i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N, K;
string s; 

int dfs(int i, int use, int less){
  if(use == K) return 1;
  if(i == N)   return 0;

  int ret = 0;
  if(less){
    ret += dfs(i+1, use, less);
    ret += dfs(i+1, use+1, less)*9;
  }else{
    int d = s[i]-'0';
    if(d == 0) return dfs(i+1, use, less);

    ret += dfs(i+1, use, true);
    ret += dfs(i+1, use+1, true)*(d-1);
    ret += dfs(i+1, use+1, less);
  }

  return ret;
}

signed main() {
  cin >> s >> K;

  N = s.size();

  cout << dfs(0, 0, false) << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<31; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll X;
	cin >> X;
	ll ans = 0;
	ll sum = 0;
	for(int i = 1; i <= X; i++)
	{
		sum += i;
		if(sum >= X)
		{
			cout << ans + 1 << endl;
			return 0;
		}
		ans++;
	}
	return 0;
}



Measured memory_bytes: 256
from math import sin, cos, radians

depth = int(input())


def kock(n: int, p1x: float, p1y: float, p2x: float, p2y: float)-> None:
    if n == 0:
        return

    #  p1, p2 から s, t, u を計算
    sx = (2 * p1x + 1 * p2x) / 3
    sy = (2 * p1y + 1 * p2y) / 3
    tx = (1 * p1x + 2 * p2x) / 3
    ty = (1 * p1y + 2 * p2y) / 3
    ux = (tx - sx) * cos(radians(60)) - (ty - sy) * sin(radians(60)) + sx
    uy = (tx - sx) * sin(radians(60)) + (ty - sy) * cos(radians(60)) + sy
    kock(n - 1, p1x, p1y, sx, sy)
    print(f'%10.7f %10.7f' % (sx, sy))
    kock(n - 1, sx, sy, ux, uy)
    print(f'%10.7f %10.7f' % (ux, uy))
    kock(n - 1, ux, uy, tx, ty)
    print(f'%10.7f %10.7f' % (tx, ty))
    kock(n - 1, tx, ty, p2x, p2y)


print(f'%1.7f %1.7f' % (0.0, 0.0))
kock(depth, 0.0, 0.0, 100.0, 0.0)
print(f'%10.7f %10.7f' % (100.0, 0.0))


Measured memory_bytes: 5768
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

class KMP {
    string pattern;
    vector <int> fail;

    void initKMP(const string &p) {
        pattern = p;
        int m = pattern.size();
        fail.assign(m + 1, -1);
        for (int i = 0, j = -1; i < m; i++) {
            while (j >= 0 && pattern[i] != pattern[j]) j = fail[j];
            j++;
            if (pattern[i + 1] == pattern[j]) fail[i + 1] = fail[j];
            else fail[i + 1] = j;
        }
    }

public:
    KMP(const string &p) { initKMP(p); }

    int period(int i) { return i - fail[i]; }

    vector <int> match(const string &s) {
        int n = s.size();
        int m = pattern.size();
        vector <int> res;
        for (int i = 0, k = 0; i < n; i++) {
            while (k >= 0 && s[i] != pattern[k]) k = fail[k];
            k++;
            if (k == m) res.push_back(i - m + 1);
        }
        return res;
    }
};

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

    string S, T;
    cin >> S >> T;

    int origin = S.size();
    int sn = S.size();
    int tn = T.size();

    while (sn < tn) {
        S += S;
        sn *= 2;
    }

    S += S;
    S += S;
    sn *= 4;

    KMP kmp(T);
    vector <int> vec = kmp.match(S);

    if (vec.size() == 0) {
        cout << 0 << "\n";
        return 0;
    }

    int mx = 0;
    vector <int> dp(10000000, 0);
    for (int i = 0; i < vec.size(); i++) {
        dp[vec[i] + tn] = max(dp[vec[i] + tn], dp[vec[i]] + tn);
        mx = max(mx, dp[vec[i] + tn]);
    }

    if (mx < origin * 2) {
        cout << mx / tn << "\n";
    } else {
        cout << -1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 66352
n,k = map(int,input().split())
a = list(map(int,input().split()))
rui = [0]*(n+1)
wa = 0
for i in range(n):
  rui[i+1] = rui[i] + a[i]
pura = 0
for i in range(n-k):
  if a[i] >0:
    pura += a[i]
for i in range(n-k,-1,-1):
  wa = max(pura+rui[i+k]-rui[i],pura,wa)
  if a[i-1] >0:
    pura -= a[i-1]
  if a[i+k-1]>0:
    pura += a[i+k-1]
print(wa)

Measured memory_bytes: 66848
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] p = new int[n];
    for(int i=0;i<n;i++)p[i]=sc.nextInt();
    int ans = 1;
    TreeSet<Integer> ts = new TreeSet<>();
    for(int i=0;i<n;i++){
      ts.add(p[i]);
      if(i>=k){
        if(ts.first()!=p[i-k]||ts.last()!=p[i])ans++;
        ts.remove(p[i-k]);
      }
    }
    int not = 0;
    int cnt = 1;
    for(int i=1;i<n;i++){
      if(p[i-1]<p[i]){
        cnt++;
        if(cnt==k){
          not++;
        }
      }else cnt=1;
    }
    if(not>=2)System.out.println(ans-(not-1));
    else System.out.println(ans);
  }
}

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

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

  ll N;
  ll ans = 0;
  ll mod = 1e9 + 7;
  cin >> N;

  vector<ll> A(N);
  vector<ll> S(N + 1);

  for (ll i = 0; i < N;++i)
    cin >> A[i];

  S[0] = 0;

  for (ll i = 0; i <N;++i){

    S[i + 1] = (S[i] + A[i]);

  }

  for (ll i = 0; i < N;++i){
    ll tmp = (S[N] - S[i + 1]) % mod;
    ans += tmp*A[i];
    ans %= mod;
  }

  cout << ans << endl;

  return 0;

}   


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

int main(){
	int a,b;cin >> a >> b;
  	for(int i=12;i<=1000;i++){
    	if(floor(i*0.08)==a && floor(i*0.1)==b){
        	cout << i;
          	return 0;
        }
    }
  	cout << -1;
  	return 0;
}


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

int main(void)
{
  int N,A,B,total,sum;
  cin >> N >> A >> B;
  total = sum = 0;

  for(int i=1; i<=N; i++){
    sum = (i%100000)/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10;
    if(A <= sum && sum <= B)
        total += i;
  }

  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
using namespace std;

typedef long long LL;

const LL mod = 1000000007LL;

struct state{
	int stnum;
	LL tr, fl;
	state(int s = 0, LL t = 0, LL f = 0)
	: stnum(s), tr(t % mod), fl(f % mod) {}
};

int main(){
	string ex_;
	cin >> ex_;
	size_t pos = 0;
	const char *ex = ex_.c_str();

	state rval;
	stack<state> stk;
	stk.push(state(1));
	while(!stk.empty()){
		state &tp = stk.top();
		int &num = tp.stnum;
		char c = ex[pos];
		
		if(num == 1 || num == 11){
			int next = num + 10;
			++num;
			stk.push(state(next));
		}
		else if(num == 2 || num == 12){
			stk.top() = state(num + 1, rval.tr, rval.fl);
		}
		else if(num == 3){
			if(c == '|'){
				++pos;
				++num;
				stk.push(state(11));
			}
			else{
				rval = tp;
				stk.pop();
			}
		}
		else if(num == 13){
			if(c == '&'){
				++pos;
				++num;
				stk.push(state(21));
			}
			else{
				rval = tp;
				stk.pop();
			}
		}
		else if(num == 4){
			LL nt = tp.tr * (rval.tr + rval.fl) + tp.fl * rval.tr;
			LL nf = tp.fl * rval.fl;
			tp = state(3, nt, nf);
		}
		else if(num == 14){
			LL nt = tp.tr * rval.tr;
			LL nf = tp.fl * (rval.tr + rval.fl) + tp.tr * rval.fl;
			tp = state(13, nt, nf);
		}
		else if(num == 21){
			if(c == '~'){
				++pos;
				++num;
				stk.push(state(21));
			}
			else{
				num = 31;
			}
		}
		else if(num == 22){
			swap(rval.tr, rval.fl);
			stk.pop();
		}
		else if(num == 31){
			if(c == 'x'){
				while(isdigit(ex[++pos]));
				rval = state(0, 1, 1);
				stk.pop();
			}
			else{
				++pos;
				num = 32;
				stk.push(state(1));
			}
		}
		else if(num == 32){
			++pos;
			stk.pop();
		}
	}
	
	cout << rval.tr << endl;
}

Measured memory_bytes: 38328
#include <iostream>
using namespace std;
int main()
{
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0) cout << "1";
  else if (b == 0) cout << "2";
  else if (c == 0) cout << "3";
  else if (d == 0) cout << "4";
  else if (e == 0) cout << "5";
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int N;
char A[101];
char B[101];
char C[101];

int main() {
    scanf("%d %s %s %s", &N, A, B, C);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == B[i] && B[i] == C[i]) {
            ans += 0;
        } else if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) {
            ans += 1;
        } else {
            ans += 2;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		List<String> route = new ArrayList<String>();

		boolean success = true;
		String s0 = sc.next();
		for (int i = 0; i < n; i++) {
			String s1 = "";
			if (i < n - 1) {
				s1 = sc.next();
			}
			if (s0.equals("AB")) {
				if (a == b) {
					if (s1.equals("AC") && c == 0) {
						a++;
						b--;
						route.add("A");
					} else if (s1.equals("BC") && c == 0) {
						a--;
						b++;
						route.add("B");
					} else {
						a++;
						b--;
						route.add("A");
					}
				} else if (a > b) {
					a--;
					b++;
					route.add("B");
				} else {
					a++;
					b--;
					route.add("A");
				}
			} else if (s0.equals("AC")) {
				if (a == c) {
					if (s1.equals("AB") && b == 0) {
						a++;
						c--;
						route.add("A");
					} else if (s1.equals("BC") && b == 0) {
						a--;
						c++;
						route.add("C");
					} else {
						a++;
						c--;
						route.add("A");
					}
				} else if (a > c) {
					a--;
					c++;
					route.add("C");
				} else {
					a++;
					c--;
					route.add("A");
				}
			} else if (s0.equals("BC")) {
				if (b == c) {
					if (s1.equals("AB") && a == 0) {
						b++;
						c--;
						route.add("B");
					} else if (s1.equals("AC") && a == 0) {
						b--;
						c++;
						route.add("C");
					} else {
						b++;
						c--;
						route.add("B");
					}
				} else if (b > c) {
					b--;
					c++;
					route.add("C");
				} else {
					b++;
					c--;
					route.add("B");
				}
			}

			if (a < 0 || b < 0 || c < 0) {
				success = false;;
				break;
			}
			s0 = s1;
		}

		// 出力
		if (!success) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
			route.forEach( s -> {
				System.out.println(s);
			});
		}
		sc.close();
	}
}


Measured memory_bytes: 59884
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<bitset>

using namespace std;

/************************************************/

int main(void) {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= b; i++){
		if (i - a < k) {
			cout << i << endl;
		}
		else if (b - i < k) {
			cout << i << endl;
		}
	}
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  string s;
  int K; 
  cin >> s >> K;

  int N = s.size();
  if(K <= N){
    REP(i, K){
      if(s[i] != '1'){
        cout << s[i] << "\n";
        return 0;
      }
    }
    cout << 1 << "\n";
    return 0;
  }

  REP(i, N){
    if(s[i] != '1'){
      cout << s[i] << "\n";
      return 0;
    }
  }

  return 0;
}

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

using namespace std;

template <class T>inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>inline T updmin(T &a, T b) { return a = min(a, b); }

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> a(n, 0);
	for(int i=0; i<n; i++)scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	if(n % 3 == 0){
		for(int i=0; i < 3; i++){
			if(a[i*(n/3)] != a[i*(n/3) + n/3 - 1]){
				printf("No\n");
				return 0;
			}
		}
		if((a[0] ^ a[n/3]) == a[(n*2)/3])printf("Yes\n");
		else printf("No\n");
		return 0;
	}else{
		if(a[0] != a[n-1])printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  vi h(n);
  REP(i, 0, n)  cin >> h[i];
  int cnt = 0;
  int ans = 0;

  REP(i, 1, n){
      if (h[i - 1] >= h[i])
        cnt++;
      else
        cnt = 0;
      ans = max(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    long long n,uf=1000000000;
    scanf("%lld",&n);
    long long ul=ceil(1.0*n/uf);
    pr1(0),pr1(0),pr1(uf),pr1(1),pr1(uf*ul-n),pr1(ul);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

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


int main(){
  int x;
  cin >> x;
  int tmp = 1000000;
  vector<bool> v(tmp, false);
  v[0] = true;
  v[1] = true;
  repd(i, 2, x){
    if(!v[i]){
      int res = i;
      while(res <= tmp){
        v[res] = true;
        res += i;
      }
    }
  }
  repd(i, x, tmp){
    if(!v[i]){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 384
s=int(input())
a=[s]

if s%2==0:
  a.append(int(s/2))
else:
  a.append(3*s+1)

for i in range(1000000):
  if a[i+1]%2==0:
    b=int(a[i+1]/2)
    a.append(b)
    if a.count(b)==2:
      break
  else:
    b=3*a[i+1]+1
    a.append(b)
    if a.count(b)==2:
      break

print(len(a))

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


int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  

  int tmp;
  int ans = 0;

  for (int i=0; i <= A; i++){//
    for (int j=0; j <= B; j++){
      for(int k=0; k <= C; k++){

        tmp = 500 * i + 100 * j + 50 * k; 
        if (tmp == X) ans ++;
         
      }
    }
  }
cout << ans << endl;

}


Measured memory_bytes: 256
import collections

N = int(input())
V = [int(x) for x in input().split()]

Va, Vb = [], []
for i in range(N):
    if i % 2 == 0:
        Va.append(V[i])
    else:
        Vb.append(V[i])

Va_most = collections.Counter(Va).most_common()
Vb_most = collections.Counter(Vb).most_common()

if N == collections.Counter(V).most_common()[0][1]:
    print(N//2)
    exit()

if Va_most[0][0] == Vb_most[0][0]:
    typea = 10 ** 10
    if len(Vb_most) >= 2:
        typea = (len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[1][1])
    typeb = 10 ** 10
    if len(Va_most) >= 2:
        typeb = (len(Va) - Va_most[1][1]) + (len(Vb) - Vb_most[0][1])
    print(min(typea, typeb))
    exit()

print((len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1]))

Measured memory_bytes: 34012
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	
	string s;
	cin>>s;
	int n=s.length();
	int ans=0;
	int a,g,c,t,len;
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			len=j-i+1;
			a=count(s.begin()+i,s.begin()+j+1,'A');
			g=count(s.begin()+i,s.begin()+j+1,'G');
			c=count(s.begin()+i,s.begin()+j+1,'C');
			t=count(s.begin()+i,s.begin()+j+1,'T');
			
			if((a+g+c+t)==len)ans=max(ans,len);
			
			
			
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[100005];
int main()
{
    long long int i,j,k,z,t,x,y,n;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    z=0;
    for(i=1;i<n;i++)
    {
        if(a[i]+a[i+1]>=k)
        {
            z=i;
            break;
        }
    }
    if(z==0)
        cout<<"Impossible"<<endl;
    else
    {
        cout<<"Possible"<<endl;
        for(i=1;i<z;i++)
        {
            cout<<i<<endl;
        }
        for(i=n-1;i>=z;i--)
            cout<<i<<endl;
    }
}

Measured memory_bytes: 4024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n,ma,mb;
    cin >> n >> ma >> mb;
    VI a(n),b(n),c(n);
    REP(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }

    int suma=accumulate(ALL(a),0);
    int sumb = accumulate(ALL(b),0);
    vector<VVI> DP(n,VVI(suma+1,VI(sumb+1,INT_MAX)));
    DP[0][0][0] = 0;
    REP(i,n){
        REP(j,suma+1){
            REP(k,sumb+1){
                if(i>0){
                    DP[i][j][k] = DP[i-1][j][k];
                }
                if(j==a[i]&&k==b[i]){
                    DP[i][j][k] = min(DP[i][j][k],c[i]);
                }
                if(i>0&&j>=a[i]&&k>=b[i]){
                    if(DP[i-1][j-a[i]][k-b[i]]!=INT_MAX){
                        DP[i][j][k] = min(DP[i][j][k],DP[i-1][j-a[i]][k-b[i]]+c[i]);
                    }
                }
            }
        }
    }

    int ans = INT_MAX;
    for (int i = 1; ; ++i) {
        int tma = ma*i,tmb = mb*i;
        if(tma>suma || tmb>sumb){
            break;
        }
        ans = min(ans,DP[n-1][tma][tmb]);
    }
    if(ans == INT_MAX){
        ans = -1;
    }

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


Measured memory_bytes: 18944