akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second

typedef long long ll;

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

using Graph = vector<vector<int>>;
int N,Q;
ll dp[200005];
ll query_matome[200005];
// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v,int pre) {
    seen[v] = true; // v を訪問済にする
    if(pre>=0){
        dp[v] = query_matome[v] + dp[pre];
    }
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v,v); // 再帰的に探索
    }
}

int main() {
	//頂点数, Query数

	cin>>N>>Q;
	//グラフ（隣接リスト表現）
	Graph G(N);
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		//無向グラフの場合は以下を追加
		G[b].push_back(a);
	}
    rep(i,Q){
        int p,x;
        cin>>p>>x;
        p--;
        query_matome[p] += x;
    }
    
	// 頂点 0 をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dp[0] = query_matome[0];
    dfs(G, 0, -1);
    for(int i = 0; i < N; ++i){
        if(i == N){
            cout<<dp[i]<<endl;
        }
        else cout<<dp[i]<<" ";
    }
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n+10);
    for(int i=1;i<=n;++i) a[i] = 100000000;
    a[1] = 1;
    a[2] = 2;
    a[3] = 3;
    a[4] = 4;
    a[5] = 5;
    a[6] = 1;
    a[7] = 2;
    a[8] = 3;
    a[9] = 1;
    for(int i=10;i<=n;++i){
        int now = i, j=1;
        while(now >= 0){
            a[i] = min(a[i], a[now]+1);
            now = i - pow(6, j);
            ++j;
        }
        now = i; j=1;
        while(now >= 0){
            a[i] = min(a[i], a[now]+1);
            now = i - pow(9, j);
            ++j;
        }
    }
    cout << a[n] << endl;
}


Measured memory_bytes: 640
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * --------------------------------------------------
 * Main Class
 * --------------------------------------------------
 */
public class Main {

	public void exec() throws IOException {
		Scanner input = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = input.nextInt();
		int K = input.nextInt();
		int[] l = new int[N];
		int ans = 0;
		for(int i=0; i<l.length; i++){
			l[i] =input.nextInt();
		}
		Arrays.sort(l);
		for(int i=0; i<K; i++) {
			ans+=l[N-1-i];
		}
		out.println(ans);
		out.flush();
		input.close();
	}

	public static void main(String[] args) throws IOException {
//		long time = System.currentTimeMillis();
		new Main().exec();
//		System.out.println(System.currentTimeMillis() - time);
	}
}


Measured memory_bytes: 22996
package main

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

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

var reader *bufio.Reader

func readLine() string {
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

func readFields() []string {
	return strings.Fields(readLine())
}

func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func sum(a []int) int {
	total := 0
	for _, x := range a {
		total += x
	}
	return total
}

var CYCLE int64 = 1000000007
var N int
var M int
var left [200001]int
var right [200001]int
var score [200001]int64
var confirmedIntervals [200001][]int

// Segment Tree begin

type T int64

type SegmentTree struct {
	size        int
	depth       int
	data        [][]T
	delayedData [][]T
	dirty       [][]bool
}

var INVALID T = 0

func (t SegmentTree) reduce(a, b T) T {
	if a > b {
		return a
	} else {
		return b
	}
}

func (t SegmentTree) _query(s, e, d, i int) T {
	if t.delayedData[d][i] != 0 {
		dd := t.delayedData[d][i]
		t.delayedData[d][i] = 0
		t.data[d][i] += dd
		if d > 0 {
			t.delayedData[d-1][i<<1] += dd
			t.delayedData[d-1][(i<<1)+1] += dd
		}
	}

	step := 1 << uint(d)
	ss := i * step
	ee := ss + step
	if ee <= s || e <= ss {
		return INVALID
	} else if ss < s || e < ee || t.dirty[d][i] {
		t.data[d][i] = t.reduce(t._query(s, e, d-1, i<<1), t._query(s, e, d-1, (i<<1)+1))
		t.dirty[d][i] = false
	}
	return t.data[d][i]
}

func (t SegmentTree) query(s, e int) T {
	return t._query(s, e, t.depth-1, 0)
}

func (t SegmentTree) _addRange(s, e, d, i int, value T) {
	step := 1 << uint(d)
	ss := i * step
	ee := ss + step
	if ee <= s || e <= ss {
		// Nothing to do
	} else if s <= ss && ee <= e {
		t.delayedData[d][i] += value
	} else {
		t._addRange(s, e, d-1, i<<1, value)
		t._addRange(s, e, d-1, (i<<1)+1, value)
		t.dirty[d][i] = true
	}
}

func (t SegmentTree) addRange(s, e int, value T) {
	t._addRange(s, e, t.depth-1, 0, value)
}

func newSegmentTree(size int) SegmentTree {
	var t SegmentTree
	t.size = size

	t.depth = 1
	for k := size - 1; k > 0; k >>= 1 {
		t.depth++
	}

	t.data = make([][]T, t.depth)
	t.delayedData = make([][]T, t.depth)
	t.dirty = make([][]bool, t.depth)
	for d := t.depth; d > 0; d-- {
		w := 1 << uint(t.depth-d)
		t.data[d-1] = make([]T, w)
		t.delayedData[d-1] = make([]T, w)
		t.dirty[d-1] = make([]bool, w)
	}

	return t
}

// Segment Tree end

func main() {
	fmt.Scan(&N, &M)
	for i := 0; i < M; i++ {
		f := readFields()
		left[i] = parseInt(f[0])
		right[i] = parseInt(f[1])
		score[i] = parseInt64(f[2])
		confirmedIntervals[right[i]] = append(confirmedIntervals[right[i]], i)
	}

	t := newSegmentTree(N + 1)

	var maxScore T
	for i := 1; i <= N; i++ {
		t.addRange(i, i+1, maxScore)

		for _, k := range confirmedIntervals[i] {
			t.addRange(left[k], right[k]+1, T(score[k]))
		}

		maxScore = t.query(0, i+1)
	}

	fmt.Println(maxScore)
}


Measured memory_bytes: 24192
#include <bits/stdc++.h>
int main(void)
{
  char str[27] = {};
  std::cin >> str;
  int used[26] = {};
  int l = std::strlen(str);
  for(int i = 0; i != l; i++) used[str[i] - 'a'] = i + 1;
  if(l < 26){ 
    std::cout << str;
    int j = 0;
    while(used[j] != 0) j++;
    std::cout << (char)(j + 'a') << std::endl;
  }else{
    bool solved = false;
    for(int i = 25; i >= 0; i--){
      for(auto j = (char)(str[i] + 1); j <= 'z'; j++){
        if(!solved){
          if(used[j - 'a'] > i + 1){
            for(int k = 0; k != i; k++)
              std::cout << str[k];
            std::cout << j << std::endl;
            solved = true;
          }
        }
      }
    }
    if(!solved) std::cout << -1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int n,q; cin >> n >> q;
    stack<int> st[n];
    for(int i = 0; i < q; i++){
        int num; cin >> num;
        if (num == 0){
            int t,x; cin >> t >> x;
            st[t].push(x);
        } else if (num == 1){
            int t; cin >> t;
            if (st[t].size()){
                cout << st[t].top() << endl;
            }
        } else if (num == 2){
            int t; cin >> t;
            if (st[t].size()){
                st[t].pop();
            }
        }
    }
}
  




Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[100005];
int main()
{
    ll n,k,q,t;
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++)
        a[i]=k-q;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&t);
        a[t]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=0)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 1024
import math


def solution(K, A, B):
    if A >= B - 2:
        return K + 1
    iterTmp = K - (A - 1)
    return math.floor(iterTmp / 2) * (B - A) + A + iterTmp % 2


if __name__ == "__main__":
    K, A, B = [int(s) for s in input().split(' ')]
    print(solution(K, A, B))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    VI pri(n + 1, 0);
    eFOR(i, 2, n) {
        int a = i;
        eFOR(j, 2, n) {
            while (a % j == 0) {
                a /= j;
                pri[j]++;
            }
        }
    }

    int ans = 0;
    FOR(i, 0, n)FOR(j, 0, n)FOR(k, 0, n) {
        if (i == j || j == k || k == i)continue;
        ans += (pri[i] >= 4 && pri[j] >= 4 && pri[k] >= 2);
    }
    ans /= 2;
    FOR(i, 0, n)FOR(j, 0, n) {
        if (i == j)continue;
        ans += (pri[i] >= 24 && pri[j] >= 2);
        ans += (pri[i] >= 4 && pri[j] >= 14);
    }
    FOR(i, 0, n) {
        ans += (pri[i] >= 74);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int b[8],day1=0,day2=0,i,k=0;
while(1){
for(i=0;i<6;i++){
scanf("%d",&b[i]);
}
for(i=0;i<6;i++){
if(b[i]==-1){
k++;
break;
}
}
if(k==1){
break;
}
if((b[0]%4==0 && b[0]%100!=0  && b[1]>2) || (b[0]%400==0 && b[1]>2)){
day1++;
}
if((b[3]%4==0 && b[3]%100!=0  && b[4]>2) || (b[3]%400==0 && b[4]>2)){
day2++;
}
for(i=1;i<b[1];i++){
day1=day1+a[i];
}
day1=day1+b[2];
for(i=1;i<b[4];i++){
day2=day2+a[i];
}
day2=day2+b[5];
for(i=1;i<b[0];i++){
if((i%4==0 && i%100!=0) || (i%400==0)){
day1=day1+366;
}
else{
day1=day1+365;
}
}
for(i=1;i<b[3];i++){
if((i%4==0 && i%100!=0) || (i%400==0)){
day2=day2+366;
}
else{
day2=day2+365;
}
}
printf("%d\n",day2-day1);
day1=0,day2=0;
}
return 0;
}


Measured memory_bytes: 2100
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#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 <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

int main() {

    int N;
    cin >> N;

    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    vector<int> b(N + 1, 0);

    vector<int> ans(N, 0);

    for (int i = N - 1; i >= 0; i--) {
        int d = i + 1;
        int sum = 0;
        for (int j = d; j <= N; j += d) {
            sum += b[j];
        }
        if ((sum + a[i]) % 2 == 1) {
            b[d]++;
            ans[i]++;
        }
    }

    int s = accumulate(ans.begin(), ans.end(), 0);

    cout << s << endl;

    for (int i = 0; i < N; i++) {
        if(ans[i] == 1){
            cout << i + 1 << " ";
        }
    }

}

































Measured memory_bytes: 3200
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

sougaku = 0
for i in range(n + 1):
	sougaku += abs(a[i] - a[i + 1])

for i in range(1, n + 1):
	print(sougaku - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]))

Measured memory_bytes: 14168
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,w; cin >> h >> w;
  vector<string> a(h); rep(i,h) cin >> a[i];
  int ans = 0;
  queue<pair<int,int>> q1,q2;
  rep(i,h) rep(j,w) if(a[i][j] == '#') q2.push({i,j});
  while(!q2.empty()){
    ans++;
    while(!q2.empty()){
      q1.push(q2.front());
      q2.pop();
    }
    while(!q1.empty()){
      auto now = q1.front(); q1.pop();
      int y = now.first, x = now.second;
      rep(i,4){
        if(x+dx[i]<0 || w<=x+dx[i] || y+dy[i]<0 || h<=y+dy[i]) continue;
        if(a[y+dy[i]][x+dx[i]] == '.'){
          a[y+dy[i]][x+dx[i]] = '#';
          q2.push({y+dy[i],x+dx[i]});
        }
      }
    }
  }
  cout << ans-1;
  cout << "\n";
  return 0;
}


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

using namespace std;

const int N = 2e5+10;
const string s = "AABBAABB";

vector<int> adj[N];
string label;
int reach[N][4];

void go(int u, int k) {
  if(reach[u][k] == 1) {
    cout << "Yes" << endl;
    exit(0);
  }
  if(reach[u][k] == 2) return;
  reach[u][k] = 1;
  for(int v : adj[u])
    if(s[k+1] == label[v])
      go(v, (k+1)%4);
  reach[u][k] = 2;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;

  cin >> label;

  for(int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  for(int i = 0; i < n; i++)
    if(!reach[i][0])
      go(i, 0);

  cout << "No" << endl;
}



Measured memory_bytes: 26576
#include<stdio.h>
#include<math.h>
#define N 100000

int main(){
  int A[N];
  int i,n,j;
  int cnt=0,flag;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    
    flag=0;
    
    for(j=2;j<=sqrt(A[i]);j++){
      if(A[i]%j==0){
	flag=1;
	break;
      }
    }
    
    if(flag==0)
     cnt++;
   
  }
  printf("%d\n",cnt);

  return 0;
}

  

Measured memory_bytes: 636
#include <iostream>
using namespace std;
const int maxn = 100011;

int a[maxn], b[maxn], n;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        b[a[i]] = i;
    }
    for (int i = 1; i <= n; i++)
        cout << b[i] << " ";
    
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(){
	int n, p;
	while(cin >> n >> p, n){
		int num = p, pos = 0;
		int s[50] = {};
		while(true){
			pos %= n;
			if(num==0) swap(num, s[pos]);
			else       num--, s[pos]++;
			if(s[pos]==p){
				cout << pos << endl;
				break;
			}
			pos++;
		}
	}
}

Measured memory_bytes: 868
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 400005;
const int mod = 1e9+7;

int fac[maxn],inc[maxn],h,w,a,b,ans;
int fpm(LL p,int k) {
	LL res=1ll;
	while (k) {
		if (k&1) (res*=p)%=mod;
		(p*=p)%=mod;k>>=1;
	}
	return res;
}
LL comb(int n,int m) {
	return (LL)fac[n]*inc[m]%mod*(LL)inc[n-m]%mod;
}
int main()
{
	#ifdef Amberframe
		freopen("arc058d.in","r",stdin);
		freopen("arc058d.out","w",stdout);
	#endif
	scanf("%d %d %d %d",&h,&w,&a,&b);
	fac[0]=inc[0]=1;int n=max(h,w)*2;
	for (int i=1;i<=n;i++) fac[i]=(LL)fac[i-1]*i%mod;
	inc[n]=fpm(fac[n],mod-2);
	for (int i=n;i>=2;i--) inc[i-1]=(LL)inc[i]*i%mod;
	
	for (int i=1;i<=h-a;i++) //(1,1)->(i,b)->(i,b+1)->(h,w)
		ans=(ans+comb(i+b-2,i-1)*comb(h-i+w-b-1,h-i))%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    int N,cnt =0,i=0,a;
    cin >> N;
    vector<int> vec(N);
    REP(i,N) cin >> vec[i];

    bool fl = true;

    while (cnt!=N){
        cnt++;
        a = vec[i];
        i = a-1;
        if(a==2){
            cout << cnt << endl;
            fl = false;
            break;
        } 
        
    }
    if(fl) cout << -1 << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

S = input()

after_map = [0]*len(S)

repeat_pos = None

for i in range(len(S)):
    if not repeat_pos:
        for j in range(i+1, len(S)):
            if S[j - 1] == 'R' and S[j] == 'L':
                repeat_pos = (j-1, j)
                break

    diff = repeat_pos[0] - i
    if diff % 2 == 0:
        after_map[repeat_pos[0]] += 1
    else:
        after_map[repeat_pos[0] + 1] += 1

    if i < len(S)-1 and S[i] == 'L' and S[i + 1] == 'R':
        repeat_pos = None

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


Measured memory_bytes: 10484
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
        int n,m;
        cin>>n>>m;
        cout<<(n<m?0:10)<<endl;

        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;


int cntAB(string s,int l,int r){ // [l,r]
int res = 0;
for(int i=l;i<r;i++){
  if(s[i] == 'A' and s[i+1] == 'B') {res++;i++;continue;}
}
//cout<<res<<endl;
return res;

}

int main(){
  int N; cin>>N;
  int XA=0,BY = 0,BA = 0;
  int ans = 0;
  int midAB  = 0;
  int leftB = 0;
  int rightA = 0;
  vector <string> S;S.resize(N);
  for(int i=0;i<N;i++){
    cin>>S[i];}
  for(int i=0;i<N;i++){
    string now = S[i];
    int l = 0,r = now.size() - 1;
    if(now[0] == 'B' and now[r] == 'A') BA++;
    else if(now[0] == 'B') BY++;
    else if(now[r] == 'A') XA++;
    if(now[0] == 'B'){leftB++;l++;}
    if(now[r] == 'A'){rightA++;r--;}
    
    ans += cntAB(now,l,r);
  }
  if(XA >=1 and BY >= 1){ans += BA+1;ans += min(XA-1,BY-1);}
  else if(XA >=1 or BY >=1)ans += BA ;
  else if(BA>0)ans += BA-1;
  cout<<ans<<endl;
  /*
  cout<<XA<<endl;
  cout<<BY<<endl;
  cout<<BA<<endl;
*/


  return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
using namespace std;
int main() {
	int s;
	cin >> s;
	if (s / 100 >= 1 && s / 100 <= 12 && s % 100 >= 1 && s % 100 <= 12) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (s / 100 >= 1 && s / 100 <= 12) {
		cout << "MMYY" << endl;
	}
	else if (s % 100 >= 1 && s % 100 <= 12) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 1000000007
struct segtree{
  ll M=1, INIT;
  vector<ll> dat;
  segtree(ll N, ll num){
    INIT = num;
    while(M<N) M*=2;
    for(int i=0;i<M*2-1;i++)  dat.push_back(num);
  }
  void update(ll x, ll k, ll l=0, int r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] += x;
    while(k>0) k = (k-1)/2, dat[k] = dat[k*2+1] + dat[k*2+2];
  }
  ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INIT;
    if(a<=l && r<=b) return dat[k];
    ll A = query(a, b, k*2+1, l, (l+r)/2);
    ll B = query(a, b, k*2+2, (l+r)/2, r);
    return A + B;
  }
};

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  vvl dp = VV(n+1, n+1, 0, ll);
  string s;std::cin >> s;
  segtree b(n+1, 0);
  for(int i=0;i<n;i++) b.update((s[i]=='1'), i);
  dp[0][0] = 1;
  vvl d;
  ll r = -1;

  for(int i=0;i<m;i++){
    ll x, y;std::cin >> x >> y;
    x--, y--;
    if(r >= y) continue;
    r = y;
    if(d.size()&&d[d.size()-1][0]==x){
      d[d.size()-1][1] = r;
    }else{
      d.push_back(vll{x, y});
    }
  }

  for(int i=0;i<n;i++){
    auto itr = upper_bound(all(d), vll{i, -1});
    ll r;
    if(itr==d.begin()) r = i-1;
    else {
      r = (*--itr)[1];
      if(r < i) r = i-1;
    }

    ll sa = r - i + 1;
    itr = upper_bound(all(d), vll{i, 100000});
    ll ad = 0;
    if(itr!=d.begin()){
      itr--;
      if((*itr)[0]==i){
        ad = b.query(r+1, (*itr)[1]+1);
        sa = (*itr)[1] - i + 1;
      }
    }
    if(sa==0){
      dp[i+1] = dp[i];
    }else{
      for(int j=0;j<=n;j++){
        ll one = j + ad;
        if(one>n || sa < one) continue;
        ll zero = sa - one;
        if(one) dp[i+1][one-1] = (dp[i+1][one-1] + dp[i][j])%P;
        if(zero) dp[i+1][one] = (dp[i+1][one] + dp[i][j])%P;
      }
    }
  }
  std::cout << dp[n][0] << '\n';
  return 0;
}


Measured memory_bytes: 73736
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> sum(n + 1);
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        sum[i] = sum[i - 1] + x + 1;
    }
    int ans = 0;
    for (int i = k; i <= n; i++)
        ans = max(ans,sum[i] - sum[i - k]);
    
    cout << prec(10) << ans/(db)2;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N;
cin >> N;
vector<long> a(N+1);
erep(i, N) cin >> a[i];
long s = 1, t = 0;
long tmp = 0; long ans = 0;
while(t+1 <= N){
  if((tmp ^ a[t+1]) == (tmp + a[t+1])){
    t++;
    ans = ans + t - s + 1;
// cout << t << t-s+1 << endl;
    tmp = tmp + a[t];
  }
  else{
    tmp = tmp - a[s];
    s++;
  }
  }
show(ans);

return 0;
}

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

typedef long long ll;

int ans[100][100];

int main(){
  int h, w;
  cin>>h>>w;
  vector<string>s(h);
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#') {
	if(i-1>=0) ans[i-1][j]++;
	if(i+1<h) ans[i+1][j]++;
	if(j-1>=0) ans[i][j-1]++;
	if(j+1<w) ans[i][j+1]++;
	if(i-1>=0&&j-1>=0) ans[i-1][j-1]++;
	if(i-1>=0&&j+1<w) ans[i-1][j+1]++;
	if(i+1<h&&j-1>=0) ans[i+1][j-1]++;
	if(i+1<h&&j+1<w) ans[i+1][j+1]++;
      } 
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
	cout<<'#';
      }else{
       cout<<ans[i][j];
      }
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
x,y = map(int,input().split())
li = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
for i, l in enumerate(li):
    if x in l and y in l:
        print("Yes")
        break
    if i == len(li) - 1:
        print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll x,y;
    cin >> x >> y;
    cout << x+(y/2) << endl;
    return 0;
}


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

typedef vector<pair<int64_t, int64_t>> factors;

factors p_fac(int64_t n)
{
    factors res;
    for (int64_t p = 2; p * p <= n; p++)
    {
        if (n % p == 0)
        {
            int64_t e = 0;
            while (n % p == 0)
            {
                n /= p;
                e += 1;
            }
            res.push_back(make_pair(p, e));
        }
    }
    if (n != 1)
    {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

void solve(int N, vector<int> A)
{
    vector<factors> A_fac(N);
    for (int i = 0; i < N; i++)
    {
        A_fac.at(i) = p_fac(A.at(i));
    }

    set<int64_t> fac_union;
    for (auto &&f : A_fac.at(0))
    {
        fac_union.insert(f.first);
    }
    int64_t g = A.at(0);

    bool is_pairwise = true;
    for (int i = 1; i < N; i++)
    {
        if (is_pairwise)
        {
            for (auto &&f : A_fac.at(i))
            {
                if (fac_union.count(f.first) > 0)
                {
                    is_pairwise = false;
                    break;
                }
                fac_union.insert(f.first);
            }
        }
        g = gcd(g, A.at(i));
    }

    if (is_pairwise)
        cout << "pairwise coprime" << endl;
    else if (g == 1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 164564
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n):
    if l[i]%2==0:
        if l[i]%3!=0 and l[i]%5!=0:
            print("DENIED")
            c=1
            break
if c!=1:
    print("APPROVED")

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader in = new FastReader();
        FastWriter out = new FastWriter();
        int a, b;
        a = in.nextInt();
        b = in.nextInt();
        out.pl(a<=9&&b<=9 ? a*b : "-1");
        out.close();
    }

}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32880
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
X=input()
XX=int(X,2)
m=X.count('1')
if m-1>0:
    l=[XX%(m+1),(XX%(m-1))]
else:
    l=[XX%(m+1),0]
for i in range(N):
    if X[i]=='0':
        n=l[0]+pow(2,(N-1)-i,m+1)
        n%=m+1
    else:
        if m-1==0:
            print(0)
            continue
        n=l[1]-pow(2,(N-1)-i,m-1)
        n%=m-1
    ans=1
    while n>0:
        n%=bin(n).count('1')
        ans+=1
    print(ans)

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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i=0;i<n;i++){
		cin >> d[i];
	}
	sort(d.begin(),d.end());
	int ans = 1, now = d[0];
	for(int i=0;i<n;i++){
		if(now < d[i]){
			ans++;
			now = d[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  string s[N];
  map <char,int> ma;
  for (int i=0;i<N;i++){
    cin>>s[i];
    ma[s[i].at(0)]++;
  }
  long long D[5];
  D[0]=ma['M'];
  D[1]=ma['A'];
  D[2]=ma['R'];
  D[3]=ma['C'];
  D[4]=ma['H'];

  int P[10]={0,0,0,0,0,0,1,1,1,2}; 
  int Q[10]={1,1,1,2,2,3,2,2,3,3}; 
  int R[10]={2,3,4,3,4,4,3,4,4,4};
  
  long long res=0;
  
  for(int d=0;d<10;d++){
    res+=D[P[d]]*D[Q[d]]*D[R[d]]; 
  }
  cout<<setprecision(18)<<res<<endl;
  return 0;
}




  

Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = 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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e17;
constexpr const ll MOD = 1000000007;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll k = 100,c = 0;
    while(k < x){
        k += k/100;
        c++;
    }
    PRINT(c);
}


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

bool Check(string s,int W){
    
    int count = 0;
    for(int i=0;i<W;i++){
        if(s[i] == '.') count++;
    }
    
    if(count == W) return false;
    else return true;
}
int main(){

    int H,W;
    cin >> H >> W;
    vector<string> S;
    string key;
    
    for(int i=0;i<H;i++){
        cin >> key;
        if(Check(key,W)) S.push_back(key);
    }
    int show_data[W];
    for(int i=0;i<W;i++) show_data[i] = 1;
    
    for(int i=0;i<W;i++){
        int count =0;
        for(int j=0;j<S.size();j++){
            if(S[j][i] == '.') count++;
        }
        if(count == S.size()) show_data[i] = 0;
    }
  
    for(int i=0;i<S.size();i++){
        for(int j=0;j<W;j++){
            if(show_data[j] == 1) cout << S[i][j]; 
        }
        cout << endl;
    }
}

Measured memory_bytes: 3608
import Control.Monad
import Data.List
main = do
 n<-readLn
 i<-replicateM n getLine
 putStr$concat[(show (snd x))++"\n"|x<-(sort (zip(zip[(words x)!!0|x<-i][100-read((words x)!!1)|x<-i])[1..n]))]

Measured memory_bytes: 1020
#include<stdio.h>
#include<cctype>
#include<algorithm>
using namespace std;
#define Maxn 3009
int read() {
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) {
		x=x*10+ch-48;
		ch=getchar();
	}
	return x;
}
int n,m,p,ans,f[Maxn][Maxn][2];
int main(){
	n=read();m=read();p=(int)(1e9+7);
	f[0][0][1]=1;
	for(int i=1;i<=n;++i) f[0][i][0]=1;
	for(int i=0;i<m;++i)
		for(int j=0;j<=n;++j)
			for(int k=0;k<=1;++k) {
				if(j) {
					(f[i+1][j-1][k|(j==1)]+=f[i][j][k])%=p;
					(f[i+1][j][k|(j==1)]+=f[i][j][k])%=p;
				}
				if(n-j) {
					(f[i+1][j][k]+=f[i][j][k])%=p;
					(f[i+1][j+1][k]+=f[i][j][k])%=p;
				}
			}
	int ans=0;
	for(int i=0;i<=n;++i) 
		(ans+=f[m][i][1])%=p;
	printf("%d\n",ans);
	return 0;
}

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


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

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

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/


int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
       int n;
       cin>>n;
       vi v(n);
       for(int i=0;i<n;i++)cin>>v[i];
        int ans=0;
       for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(v[i]!=v[j] && v[j]!=v[k] && v[k]!=v[i]){
                    if(v[i]+v[j]>v[k] && v[i]+v[k]>v[j] && v[j]+v[k]>v[i]){
                        ans++;
                    }
                }
            }
        }
       }
       cout<<ans<<endl;

    }
}















Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string S;
    cin >> S;
    map<char, int> m;
    for(int i = 0; i < S.length(); i++) {
        m[S[i]]++;
    }
    for(auto u : m) {
        if(u.second >= 2) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
ss = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1]
gets.to_i.times do
  a, b = gets.split.map(&:to_i)
  rs = []
  ss.each_with_index do |s, i|
    next unless s == a
    rs << []
    j = i
    loop do
      rs.last << ss[j]
      break if ss[j] == b
      j += 1
      j %= ss.size
    end
  end
  puts rs.min_by(&:size).join ' '
end

Measured memory_bytes: 8596
using System;

using System.Linq;

using System.Collections.Generic;



namespace hello_cs

{

    class Program

    {

        static void Main(string[] args)

        {

            var blank = "";

            var ipt = Console.ReadLine().Split(blank.ToCharArray()).Select(x => long.Parse(x));

            var k = ipt.Last();

            var n = ipt.First();

            var i = n / k > 0 ? n % k : n;



            var num = new List<long>();

            while (true)

            {

                num.Add(i);

                i = Math.Abs(i - k);

                if(num.Contains(i)){

                    break;

                }

            }

            

            num.Sort();

            System.Console.WriteLine(num.First());

        }

    }

}



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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

vll binary_convert(ll n){
    vll s;
    ll size = 0;

    while(n / (ll)(pow(2,size)) > 0)size++;
    rep(i,size + 1){
        s.pb(n / (ll)(pow(2,i)));
        n %= (ll)(pow(2,i));
    }

    return s;
}

ll fib(ll n){
    vll a(n+1);
    a[0] = 1;
    a[1]  = 1;

    REP(i,2,n+1){
        a[i] = a[i-1] + a[i-2];
        a[i] %= mod;
    }

    return a[n-1];
}

int main()
{
    ll n,x,sum = 0;
    cin >> n >> x;

    vll l(n);
    ll ans = 1;
    rep(i,n){
        cin >> l[i];
        sum += l[i];
        if(sum <= x)ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length) sort(array, array + length, greater<>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    int n;
    cin >> n;

    set<long> s;
    for (int i = 0; i < n; i++)
    {
        int val;
        cin >> val;
        s.insert(val);
    }

    if (n != s.size())
    {
        NO
    }
    YES
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll umax(ll a ,ll b)
{
	if(a>b)return a;return b;
}
int main()
{
	ll n;cin >> n;
	ll a[n][3];
	for(ll i=0;i<n;i++)
	{
		ll a1,b,c;cin >> a1 >> b >> c;
		if(i==0)
		{
			a[0][0]=a1;
			a[0][1]=b;
			a[0][2]=c;
		}
		else
		{
			a[i][0]=umax(a1+a[i-1][1],a1+a[i-1][2]);
			a[i][1]=umax(b+a[i-1][0],b+a[i-1][2]);
			a[i][2]=umax(c+a[i-1][0],c+a[i-1][1]);
		}
	}
	cout << umax(a[n-1][0],umax(a[n-1][1],a[n-1][2]));
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main(void){
	int x, i=1;
	while(1){
		scanf("%d", &x);
		if(x == 0){
			break;	
		}
		printf("Case %d: %d\n", i, x);
		i = i + 1;
	}
	return 0;
}

Measured memory_bytes: 2552
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ACircle {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int r;
        in>>r;
        out<<r*r<<'\n';
    }
};


int main() {
	ACircle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define sl(i,m) for(auto i=m.begin();i!=m.end();++i)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define tc int t;in(t);while(t--)
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    SYNC 
    int d,t,s;
    in(d)>>t>>s;
    double ti=d*1.0/s;
    if(ti<=t)
    o("Yes");
    else
    o("No");
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> V(N);
    rep(i,0,N)cin >> V[i];
    ll ans = 0;

    rep(i,0,N){
        if(i != 0){
            ans += min(V[i-1], V[i]);
            V[i] -= min(V[i-1], V[i]);
        }
        ans += V[i] / 2;
        V[i] %= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>


int main(){

 long long int K;
  scanf("%lld",&K);
  char A[100];
  scanf("%s",A);


  
int i;
  /*
  long long int A[N+1];
  long long int i;
  for(i=1;i<=N;i++){
   scanf("%lld",&A[i]);
   }
  */
  int a;
  a=strlen(A);
  if(a<=K){
    printf("%s",A);
  }
  else{
    for(i=0;i<K;i++){
      printf("%c",A[i]);
    }
      printf("...");
  }







 return(0);
 }


Measured memory_bytes: 1732