akhauriyash/Code-Regression huggingface dataset:
fn main(){
    let input_str: String = read();
    let num = search_next_sunday(&input_str);

    println!("{}", num);

}

fn search_next_sunday(s: &str) -> usize{
    let mut day_of_week = vec!["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    // 何番目の文字かを取得
    let mut index: usize = 0;
    for i in 0..day_of_week.len(){
        if s == day_of_week[i]{
            index = i;
        }
    }

    let mut count = 0;
    loop {
        if index >= day_of_week.len(){
            index = 0;
        }
        if day_of_week[index] == "SUN" && count != 0{
            return count;
        }
        index += 1;
        count += 1;
    }
}
/// 標準入力を指定の型で返す
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, L = 0;
  int neut_max = 0;
  vector<pair<int, int>> positive;  // 余った'('のほうが多い文字列たち
  vector<pair<int, int>> negative;  // 余った')'のほうが多い文字列たち
  //同数のやつは後ろに影響しないのでLが最大の場所(positiveとnegativeの間）におく
  cin >> N;
  REP(i, N) {
    string S;
    int l = 0, r = 0;  // r = 余った')'　 l =　余った '('
    cin >> S;
    for (auto s : S) {
      if (s == ')' && l == 0)  // '('が残ってなければ')'は必ず余る
        r++;
      else if (s == ')' && l != 0)  //'('が残ってたら相殺する
        l--;
      else if (s == '(')
        l++;
    }
    if (r < 1)  //余った')'がないやつは最初に並べるのがベスト
      L += l;
    else if (r - l < 0)
      positive.push_back(
          make_pair(r, r - l));  // rが常にLより小さくなるように...
    else if (r - l > 0)
      negative.push_back(make_pair(
          l, r));  // l == 0の文字列が最後に来ないと破滅、それ以外は自由
    else if (r - l == 0 &&
             r > neut_max)  //こいつはpositiveとnegativeの間におく,
                            // rが最大のやつ以外は空気
      neut_max = r;
  }
  sort(positive.begin(), positive.end());
  sort(negative.begin(), negative.end(), greater<pair<int, int>>());
  for (auto a : positive) {
    if (a.first > L) {
      cout << "No" << endl;  //余った')'が多すぎて誰も相殺できない
      return 0;
    }
    L -= a.second;
  }

  if (neut_max > L) {
    cout << "No" << endl;  //左右同数だけど')'が多すぎて相殺できない
    return 0;
  }

  for (auto n : negative) {
    if (n.second > L) {
      cout << "No" << endl;  //余った')'が残りの'('の数を上回った
      return 0;
    }
    L -= n.second;
    L += n.first;
  }

  if (L == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  //'('が余っちゃった
}

Measured memory_bytes: 7408
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	int a = 0, b = 0;
	forn(i, 2 * s.size()){
		if(i % 2)cout << t[a++];
		else cout << s[b++];
	}
	return 0;
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, K = inpl()
S = input()

x = S[0]
A = []
B = []
tmp = 0
for s in S:
    if s == x:
        tmp += 1
    else:
        if x == "0":
            A.append(tmp)
        else:
            B.append(tmp)
        x = s
        tmp = 1

if tmp > 0:
    if s == "0":
        A.append(tmp)
    else:
        B.append(tmp)

ans = 0
if S[0] == "1":
    T = sum(A[:K]) + sum(B[:K+1])
    ans = max(ans, T)
    for i in range(len(A) - K):
        T += -A[i] + A[i+K] - B[i]
        if len(B) > i + K + 1:
            T += B[i+K+1]
        ans = max(ans, T)
    print(ans)
else:
    T = sum(A[:K]) + sum(B[:K])
    ans = max(ans, T)
    for i in range(len(A) - K):
        T += -A[i] + A[i+K] - (B[i-1] * (i!=0))
        if len(B) > i + K:
            T += B[i+K]
        ans = max(ans, T)
    print(ans)

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

int p[maxn], c[maxn];
vector<int> g[maxn];

void dfs(int u, int pp = -1) {
    p[u] = pp;
    for (auto x : g[u])
        if (x != pp)
            dfs(x, u);
}

int visited[maxn];

void dfs2(int u) {
    visited[u] = true;
    for (auto x : g[u]) {
        if (!visited[x] and (c[x] == c[u] or c[x] == 0)) {
            c[x] = c[u];
            dfs2(x);
        }
    }
}

void solve() {
    int n;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1);

    vector<int> path;
    int cur = n;
    while (cur != -1) {
        path.push_back(cur);
        cur = p[cur];
    }
    reverse(path.begin(), path.end());
    for (int i = 0, j = (int) path.size() - 1; i < j;) {
        c[path[i]] = 1;
        i++;
        c[path[j]] = 2;
        j--;
        if (i == j) {
            c[path[i]] = 1;
            break;
        }
    }
    for (auto x: path)
        if (!visited[x])
            dfs2(x);
    int b = 0, w = 0;
    for (int i = 1; i <= n; i++)
        b += (c[i] == 1), w += (c[i] == 2);

//    cout << b << " " << w << endl;
    if (b > w)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}



Measured memory_bytes: 16604
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		List<Integer> list = new ArrayList<>();

		int n = sc.nextInt();
		String str = sc.next();
		int k = sc.nextInt();
		String sTarget = str.substring(k-1,k);

		for (int i = 0; i < n; i++) {
			String s = str.substring(i,i+1);
			if(sTarget.equals(s)){
				System.out.print(s);
			}else{
				System.out.print("*");
			}
		}
	}
}

Measured memory_bytes: 22868
n, k, q = gets.chomp.split.map{|a| a.to_i}

scores = Array.new(n, 0)

q.times do
  i = gets.chomp.to_i - 1
  scores[i] += 1
end

scores.each do |score|
  point = k - q + score
  if point > 0
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();

        int[] a = new int[n];

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

        int ans = a[0];

        for (int i = 1; i < n; i++) {
            ans = gcd(ans, a[i]);
        }

        sc.close();

        System.out.println(ans);
    }

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

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

using namespace std;

typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    int32_t len = (int)s.size();
    P cnt[26];
    for (auto &p:cnt) p = {len, 0};
    for (int b = 0; b < len; b++) {
        int i = s[(size_t)b] - 'a', a = cnt[i].first, same = cnt[i].second;
        if (b > a && (b-a+1) / 2 < same + 1) {
            cout << a + 1 << ' ' << b + 1 << '\n';
            return 0;
        } else 
            cnt[i] = {b, 1};
    }
    cout << -1 << ' ' << -1 << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
int main(int argc,char const* argv[])
{
  string c1('?',2),c2('?',2);
  cin >> c1;
  cin >> c2;
  bool ok=true;
  if(c1[1] != c2[1]) ok=false;
  else if(c1[0] != c2[2] || c1[2] != c2[0]) ok=false;
  
  if (ok==true) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int n,m;
int dp[100010];
vector<int>G[100010];
int ord[100010],len;
bool vis[100010];
void dfs(int x){
	// cout<<x<<endl;
	for(auto to:G[x])if(!vis[to]){
		vis[to]=1;
		dfs(to);
	}
	ord[++len]=x;
}
int main(){
	cin>>n>>m;
	for(int i=1,x,y;i<=m;i++){
		cin>>x>>y;
		G[x].pb(y);
	}
	for(int i=1;i<=n;i++)if(!vis[i])vis[i]=1,dfs(i);
	// for(int i=1;i<=n;i++)cout<<ord[i]<<' ';
	// puts("");
	for(int i=1;i<=n;i++){
		int x=ord[i];
	}
	for(int i=1;i<=n;i++){
		int x=ord[i];
		for(auto y:G[x]){
			dp[x]=max(dp[x],dp[y]+1);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7936
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	for (int ii = 1; ii < 10; ++ii){
		int tmp = N / ii;
		if (tmp < 10){
			if (ii * tmp == N){
				cout << "Yes" << "\n";
				return 0;
			}
		}
	}

	cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 256
def listing(char, str):
	l, i = [], 0
	while True:
		tmp = str.find(char, i)
		if tmp==-1:
			break
		else:
			l.append(tmp)
			i = tmp+1
	return l


def signboard(s, t):
	res = False
	if t.find(s)!=-1: return True  # 文字がふくまれていればtrue
	#まずは最初の2文字の位置のリストを作る
	A, B = listing(s[0], t), listing(s[1], t)
	if len(A)==0 or len(B)==0:
		return False

	for a in range(len(A)):
		for b in range(len(B)):
			if A[a]>=B[b]: continue
			c = B[b]-A[a]
			res = True
			for S in range(2, len(s)):
				if A[a]+S*c+1>len(t):
					res = False
					continue
				if s[S]!=t[A[a]+S*c]:
					res = False
					break
			if res==True: return res

	return res


n = int(input())
a = input().strip()
S = [input().strip() for _ in range(n)]
cnt = 0
for b in S:
	if signboard(a, b): cnt += 1
print(cnt)



Measured memory_bytes: 5620
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)

#include <algorithm>
using namespace std;
#include <cmath>
#include <string>
#include<vector>
#define elif else if
typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 200005
int N;

int main(){
    cin>>N;
    ll a[TENFIVE];
    rep(i,N)cin>>a[i];
    ll count =0;
    rep(i,N){
        while(a[i]%2==0){
            a[i]/=2;
            count++;
        }
    }
    cout<<count<<'\n';
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

type luggage struct {
	weight int
	value int
}

func main(){

	var N,W int
	var luggge_list []luggage
	var DP [][]int

	fmt.Scanf("%d %d",&N,&W)
	for i:=0;i<N;i++{
		l := luggage{}
		fmt.Scanf("%d %d",&l.weight,&l.value)
		luggge_list = append(luggge_list,l)
	}

	for i:=0;i<N+1;i++{
		var DP_inside []int
		DP_inside  = append(DP_inside,0)
		for j:=0;j<100*1000+6-1;j++{
			DP_inside  = append(DP_inside,int(math.Pow10(9)+1))
		}
		DP = append(DP,DP_inside[:])
	}

	for i:=1;i<N+1;i++{
		for j:=1;j<100*1000+6;j++ {
			if j >= luggge_list[i-1].value {
				DP[i][j] = min(DP[i-1][j],DP[i-1][j-luggge_list[i-1].value]+luggge_list[i-1].weight)
			}else{
				DP[i][j] = DP[i-1][j]
			}
		}
	}

	for j:=100*1000+5;j>1;j-- {
		if DP[N][j] <= W{
			fmt.Println(j)
			break
		}
	}

	}

Measured memory_bytes: 158848
import sys
input=sys.stdin.readline
def main():
    n,q=map(int,input().split())
    tree=[[]*n for i in range(n)]
    score=[0]*n
    
    for i in range(n-1):
        x,y=map(int,input().split())
        tree[x-1].append(y-1)
        tree[y-1].append(x-1)
        
    for i in range(q):
        x,y=map(int,input().split())
        score[x-1]+=y
    
    from collections import deque
    option=deque()
    option.append(0)
    completed=[None]*n
    
    while option:
        before=option.pop()
        completed[before]=True
        for i in tree[before]:
            if completed[i]==None:
                score[i]+=score[before]
                option.append(i)
    print(*score)
if __name__=="__main__":
    main()

Measured memory_bytes: 56168
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <cstdint>
#include <bits/stdc++.h>
#include <queue>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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;
}

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;

int qp(int a, ll b)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mod;
    a = 1ll * a * a % mod;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}

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

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);

int main(void)
{
  ll n;
  string s;
  cin >> n;
  cin >> s;

  map<char, ll> m1;
  map<string, ll> m2;
  map<string, ll> m3;

  for (ll i = n - 1; i >= 0; i--)
  {
    auto c = s[i];
    for (auto p : m2)
    {
      string tmp = "";
      tmp = tmp + c + p.first;
      m3[tmp] = 1;
    }
    for (auto p : m1)
    {
      string tmp = "";
      tmp = tmp + c + p.first;
      m2[tmp] = 1;
    }
    m1[c] = 1;
  }

  cout << m3.size() << endl;

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return t * t % mod;
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = t * t % mod;
    return k * x % mod;
  }
}
ll mod_add(ll a, ll b)
{
  return (a + b) % mod;
}

ll mod_mul(ll a, ll b)
{
  return (a * b) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

Measured memory_bytes: 512
use std::cmp::min;

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

fn main() {
    let n = scan!(i64);
    let vs = scan!(i64;;);
    let s: i64 = vs.iter().sum();

    let ave = s / n;
    let mut total0 = 0;
    for v in vs.iter() {
        let d = v - ave;
        total0 += d * d;
    }

    let ave = (s + n - 1) / n;
    let mut total = 0;
    for v in vs {
        let d = v - ave;
        total += d * d;
    }
    println!("{}", min(total0, total))
}


Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Long> c = new ArrayList<Long>();
		long mini = 1000000000;
		
		long a = sc.nextInt();
		int b = sc.nextInt();
		for(int i = 0; i < a; i++){
			long d = sc.nextInt();
			c.add(d);
		}
		Collections.sort(c);
		for(int i = 0; i < a; i++){
			if(i > a-b){
				break;
			}
			long f = c.get(i+b-1)-c.get(i);
			if(mini>f){
				mini = f;
			}
		}
		System.out.println(mini);
	}
}

Measured memory_bytes: 61124
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


s = S()
if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;


int main(){
    ll n;
    ll k;
    cin>>n>>k;
    ll a[200000]={};
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }

    vector<int> c(n+1,-1);
    ll b[200000]={};
    ll i=0;
    ll v=1;
    while(c[v]==-1){
        c[v]=i;
        b[i]=v;
        v=a[v-1];
        i++;
    }
    ll m=i-c[v];
    ll l=c[v];
    ll ans;
    if(k<l){
        ans=b[k];
    }else{
        ans=b[l+((k-l)%m)];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7220
#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
 
void solve() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    vector<ll> accR(N + 1, 0);
    vector<ll> accG(N + 1, 0);
    vector<ll> accB(N + 1, 0);
    
    for(int i = N; i >= 1; i--) {
        accR[i - 1] = accR[i] + (S[i - 1] == 'R');
        accG[i - 1] = accG[i] + (S[i - 1] == 'G');
        accB[i - 1] = accB[i] + (S[i - 1] == 'B');
    }
    
    ll ans = 0;
    for(ll j = 0; j < N; j++) {
        for(ll i = 0; i < j; i++) {
            if (S[i] == S[j]) continue;
            bool r = false, g = false, b = false;
            if (S[i] == 'R') r = true;
            if (S[i] == 'G') g = true;
            if (S[i] == 'B') b = true;
            if (S[j] == 'R') r = true;
            if (S[j] == 'G') g = true;
            if (S[j] == 'B') b = true;
            if (!r) {
                ans += accR[j + 1];
            } else if (!g) {
                ans += accG[j + 1];
            } else {
                ans += accB[j + 1];
            }
            ll k = 2 * j - i;
            if (k < N && S[i] != S[k] && S[j] != S[k]) ans--;
        }
    }
    cout << ans << endl;
}
 
int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 3708
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val cities = (0 until m).map { i ->
        val (p, y) = readLine()!!.split(' ').map { it.toInt() }
        Triple(i, p, y)
    }

    val prefectures = IntArray(n + 1) { 0 }
    val cityIds = Array(m) { "" }

    cities.sortedBy { it.third }.forEach {
        prefectures[it.second]++
        val id1 = it.second.toString().padStart(6, '0')
        val id2 = prefectures[it.second].toString().padStart(6, '0')
        cityIds[it.first] = id1 + id2
    }

    cityIds.forEach { println(it) }
}


Measured memory_bytes: 94080
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
template<class T>bool chmax(T &a, const T &b)
{ return (a<b ? (a=b)||1 : 0); }

int main(){
	int n; cin >>n;
	int r; cin >>r;
	int abs0{1<<31}, min0{r};
	for(int i=0; i<n-1; i++){
		int r; cin >> r;
		chmax(abs0, r-min0);
		min0 = min(min0, r);
	}
	cout << abs0 << endl;
}


Measured memory_bytes: 3116
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i, j, n, q, C=0, *S, *T;
  
  scanf("%d", &n);
  S = malloc( n * sizeof(int));
  for(i=0;i<n;i++){
      scanf("%d",&S[i]);
  }
    
  scanf("%d", &q);
    
  T=malloc(q*sizeof(int));

  for(i=0;i<q;i++){
      
      scanf("%d", &T[i]);
      
      for(j=0;j<n;j++){
	  if(T[i]==S[j]){
	      C++;
	      break;
	    }
      }
  }
    
  printf("%d\n",C);
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m; cin >> n >> m;
	vector<vi> dist(n, vi(n, INF));
	vector<tuple<int, int, int>> v;
	REP(i, m)
	{
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		dist[a][b] = dist[b][a] = c;
		v.emplace_back(a, b, c);
	}
	REP(i, n) dist[i][i] = 0;
	REP(k, n)REP(i, n)REP(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
	int ans = 0;
	for (auto t : v)
	{
		int a, b, c;
		tie(a, b, c) = t;
		if (dist[a][b] != c) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(void) {

  char s[101];
  scanf("%s", s);
  int length = strlen(s);
  int alp[26];
  for (int i = 0; i < 26; i++) {
    alp[i] = 0;
  }
  int flag = 1;
  for (int i = 0; i < length; i++) {
    if (i != 0 && s[i] != s[i-1]) {
      flag = 0;
    }
    alp[s[i]-'a']++;
  }
  if (flag == 1) {
    printf("0\n");
    return 0;
  }
  char generate[length];
  int operation;
  int min = 100;
  for (int i = 0; i < 26; i++) {
    if (alp[i] == 0) {
      continue;
    }
    flag = 1;
    for (int j = 0; j < length; j++) {
      generate[j] = s[j];
    }
    operation = 0;
    while (1) {
      operation++;
      flag = 1;
      for (int j = 0; j < length-operation; j++) {
        if (generate[j] != i+'a' && generate[j+1] != i+'a') {
          flag = 0;
        } else {
          generate[j] = i+'a';
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (operation < min) {
      min = operation;
    }
  }
  printf("%d\n", min);

  return 0;
}

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

using namespace std;

int main()
{
    int no_of_elements;
    scanf("%d", &no_of_elements);

    vector <int> A(no_of_elements + 1);
    for(int i = 1; i <= no_of_elements; i++)
        scanf("%d", &A[i]);

    int i = no_of_elements, front = 1, back = no_of_elements;
    vector <int> final_A(no_of_elements + 1);
    while(i >= 1)
    {
        if(front == back)
            final_A[front] = A[i--];
        else
            final_A[front++] = A[i--], final_A[back--] = A[i--];
    }

    for(int i = 1; i <= no_of_elements; i++)
        printf("%d ", final_A[i]);

    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<iomanip>

// saw editional

class DP{
public:
    int N;
    std::vector<long double>dp;
    std::vector<bool>flags;
    DP(int N){
        this->N=N;
        dp=std::vector<long double>((N+1)*(N+1)*(N+1),1);
        dp.shrink_to_fit();
        flags=std::vector<bool>((N+1)*(N+1)*(N+1),0);
        flags.shrink_to_fit();
    }
    long double f(int c1,int c2,int c3){
        if(flags[c1*(N+1)*(N+1)+c2*(N+1)+c3]){
            return dp[c1*(N+1)*(N+1)+c2*(N+1)+c3];
        }
        long double ans=0;
        long double buf=1-(N-c1-c2-c3)/(double)N;
        if(0!=c1+c2+c3){
            ans+=1/buf;
        }
        if(c1>0){
            ans+=f(c1-1,c2,c3)*c1/(double)N/buf;
        }
        if(c2>0){
            ans+=f(c1+1,c2-1,c3)*c2/(double)N/buf;
        }
        if(c3>0){
            ans+=f(c1,c2+1,c3-1)*c3/(double)N/buf;
        }
        dp[c1*(N+1)*(N+1)+c2*(N+1)+c3]=ans;
        flags[c1*(N+1)*(N+1)+c2*(N+1)+c3]=1;
        return ans;
    }
};
int main(){
    int N;
    std::cin>>N;
    int cnt[3]={0,0,0};
    for(int i=0;i<N;++i){
        int buf;
        std::cin>>buf;
        cnt[buf-1]++;
    }
    DP dp(N);
    std::cout << std::fixed << std::setprecision(12);
    std::cout<<dp.f(cnt[0],cnt[1],cnt[2])<<std::endl;
}

Measured memory_bytes: 432764
import sys

file_input = sys.stdin

NM = file_input.readline()

import itertools, bisect

while NM != '0 0\n':
    N, M = map(int, NM.split())
    P = [int(file_input.readline()) for i in range(N)]
    P.append(0)
    scores = map(sum, itertools.combinations_with_replacement(P, 2))
    scores = filter(lambda x: x <= M, scores)
    scores = list(set(scores))
    scores.sort()
    print(max(s + scores[bisect.bisect_right(scores, M - s) - 1] for s in scores))
    NM = file_input.readline()

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

int main(void)
{
	int N,K,X,Y;
	
	cin >> N >> K >> X >> Y;
	//N泊、Ｋ泊までＸ、Ｋ＋１までＹ
	if (N <= K) {
		cout << N * X << endl;
	}
	else if (N > K) {
		cout << K * X + (N - K)*Y << endl;
	}
}

Measured memory_bytes: 256
//Don't despair and never lose hope ^_^
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<functional>
#include <bitset>
#include<algorithm>
#include<fstream>
#include<string>
#include<stdio.h>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);

	string x, y;
	ll n, m;
		cin >> x >> y;
		x += y;
		stringstream sx;
		sx << x;
		sx >> m;
		n = sqrt(m);
		//cout << m << endl;
		cout << (n*n == m ? "Yes" : "No") << endl;
		
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val S = in(0)
  
  private def func():String ={
  if(S.size % 2 != 0) return "No"
  (0 until S.size).foreach{ i=>
    if((i%2 == 0 && S(i) != 'h') || (i%2 == 1 && S(i) != 'i' ) ) return "No"
  }
  return "Yes"
  }
  println(func())
}


Measured memory_bytes: 25416
#include<iostream>
#include<algorithm>
#include<string>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int N;
    int i,j;
    ULL temp;
    ULL count=0;
    string *s;
    
    cin >> N;
    s = new string[N];
    for(i=0;i<N;i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s,s+N);
    temp = 1;
    for(i=1;i<N;i++){
        if(s[i] == s[i-1]){
            temp++;
        }else{
            count += ( temp * (temp - 1)) / 2;
            temp = 1;
        }
    }
    count += ( temp * (temp - 1)) / 2;

    cout << count << endl;;
}


Measured memory_bytes: 7296
import java.util.*;

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = Integer.parseInt(sc.next())
    val y = Integer.parseInt(sc.next())
    val a = Integer.parseInt(sc.next())
    val b = Integer.parseInt(sc.next())
    val c = Integer.parseInt(sc.next())
    val p = LongArray(a)
    val q = LongArray(b)
    val r = LongArray(c)
    repeat(a){p[it] = sc.nextLong()}
    repeat(b){q[it] = sc.nextLong()}
    repeat(c){r[it] = sc.nextLong()}
    val aa = p.sortedBy{it*-1}.take(x).toLongArray()
    val bb = q.sortedBy{it*-1}.take(y).toLongArray()
    val apple = ( aa + bb + r).sortedBy{it*-1}.take(x+y)
    var ans = 0L
    repeat(x+y){ans += apple[it]}
    println(ans)
}


Measured memory_bytes: 135424
n = int(input())
a = list(map(int,input().split()))
a.sort()
p = [True for i in range(a[-1])]
ans = n
for k in range(n-1):
    if p[a[k]-1]:
        if a[k] != a[k+1]:
            for i in range(1,a[-1]+1):
                if a[k]*i <= a[-1]:
                    p[a[k]*i-1] = False
                else:
                    break
        else:
            ans -= 1
            for i in range(1,a[-1]+1):
                if a[k]*i <= a[-1]:
                    p[a[k]*i-1] = False
                else:
                    break  
    else:
        ans -= 1    
k = n-1
if p[a[k]-1]:
    for i in range(1,a[-1]+1):
        if a[k]*i <= a[-1]:
            p[a[k]*i-1] = False
        else:
            break
else:
        ans -= 1   
print(ans)

Measured memory_bytes: 165152
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1145141919
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    long long q,h,s,d,n;
    scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
    if(q*8<d){d=q*8;}
    if(h*4<d){d=h*4;}
    if(s*2<d){d=s*2;}
    if(q*4<s){s=q*4;}
    if(h*2<s){s=h*2;}
    printf("%lld\n",d*(n/2)+s*(n%2));
    return 0;
}

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

typedef struct{
  char name[10];
  int time;
}P;

void enque(P);
P deque(void);

int head=0,tail=0,n;
P Q[N];

int main(){

  int p,i,cnt=0;
  P S[N],T;

  scanf("%d %d",&n,&p);

  for(i=0;i<n;i++){
    scanf("%s",S[i].name);
    scanf("%d",&S[i].time);
    enque(S[i]);
  }

  while(1){
    T=deque();
    T.time-=p;
    if(T.time>0){
      cnt+=p;
      enque(T);
    }else if(T.time<=0){
      cnt+=T.time+p;
      printf("%s %d\n",T.name,cnt);
      if (head == tail) break;
    }
  }

  return 0;
}

void enque(P x){
  tail = (tail+1)%N;
  Q[tail]=x;
}

P deque(){
  P x;

  head = (head+1)%N;
  x=Q[head];
  
  return x;
}



Measured memory_bytes: 4060
#include<iostream>
#include<cstring>
using namespace std;
int a,b,k;
int main()
{
    scanf("%d%d%d",&a,&b,&k);
    if(b-a+1<=2*k)
    {for(int i=a;i<=b;i++)printf("%d\n",i);}
    else
    {
        for(int i=a;i<=a+k-1;i++)printf("%d\n",i);
        for(int i=b-k+1;i<=b;i++)printf("%d\n",i);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 111116
typedef pair<int,int> edge;

int n,f[N];
multiset<int> s[N];
map<edge,int> h;
queue<edge> q;

edge make(int x,int y){
	if (x>y) swap(x,y);
	return edge(x,y);
}

int find(int x){
	if (f[x]==x) return x;
	return f[x]=find(f[x]);
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=2*n-2;i++){
		int x=read(),y=read();edge e=make(x,y);
		s[x].insert(y);s[y].insert(x);
		if (++h[e]==2) q.push(e);
	}
	for (int i=1;i<=n;i++) f[i]=i;
	for (int i=1;i<=n-1;i++){
		int x=0,y=0;
		while (x==y){
			if (q.empty()) {printf("NO\n");return 0;};
			x=find(q.front().first);y=find(q.front().second);q.pop();
		}
		if (s[x].size()>s[y].size()) swap(x,y);f[x]=y;
		for (set<int>::iterator i=s[x].begin();i!=s[x].end();i++){
			int z=find(*i);edge e=make(y,z);
			if (y==z) continue;
			s[y].insert(z);s[z].insert(y);
			if (++h[e]==2) q.push(e);
			s[z].erase(s[z].find(x));
		}
		s[y].erase(s[y].find(x));s[x].clear();
	}
	printf("YES\n");return 0;
}

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

typedef long long ll;

 
int main(){
  int h, w;
  cin >> h >> w;
  int nh=0, nw=0;
  int m[h][w]={};
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    while(a>0){
      if(nh%2==0){
        a--;
        m[nh][nw] = i+1;
        if(nw+1>=w) nh++;
        else nw++;
      }else{
        a--;
        m[nh][nw] = i+1;
        if(nw-1<0) nh++;
        else nw--;
      }
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cout << m[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,n,i,d=0,e;
    cin>>a>>b>>c;
    cin>>n;
    for(i=1;i<=n;i++){
        if(b>a){
            d=1;
        }
        if(d==0 && b<=a){
            b*=2;
        }
        if(d==1 && c<=b){
            c*=2;
        }
    }
    if(c>b && b>a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3672
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;
using namespace atcoder;

int main(){
    ll n,m;
    cin >> n >> m;
    scc_graph graph(n);
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        graph.add_edge(a,b);
    }
    vector<vector<int>> ans=graph.scc();
    int k=ans.size();
    cout << k << endl;
    rep(i,k){
        int l=ans[i].size();
        cout << l;
        rep(j,l){
            cout << " " << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 40096
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        int c = Integer.parseInt(a.substring(0, 2));
        int d = Integer.parseInt(a.substring(2, 4));

        if (c >= 1 && c <= 12 && d >= 1 && d <= 12) {
            System.out.println("AMBIGUOUS");
        } else if (c >= 1 && c <= 12) {
            System.out.println("MMYY");
        } else if (d >= 1 && d <= 12) {
            System.out.println("YYMM");
        } else {
            System.out.println("NA");
        }
    }
}


Measured memory_bytes: 23764
n=int(input())
a=[int(x) for x in input().split()]
ans=0
mod=10**9+7
for i in range(64):
    num_1=0
    num_0=0
    for ai in a:
        if (ai >> i) & 1:
            num_1+=1
        else:
            num_0+=1
    ans+=num_0*num_1*(1 << i)
print(ans%mod)

Measured memory_bytes: 122808
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e3 + 10, M = 2 * N, mod = 998244353;

bool seen[N][N];
ll choose[M][M], str[N][N];

ll solve(int a, int b, int n);
ll dp(int i, int j);
ll dp2(int i, int j);

int main() {
	fast_cin();
	int k, n;
	cin >> k >> n;
	for (int i = 0; i < M; ++i) {
		choose[i][0] = choose[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			choose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % mod;
		}
	}
	for (int m = 2; m <= 2 * k; ++m) {
		int l = 0;
		for (int i = 1; i <= k; ++i) {
			int j = m - i;
			if (j <= k and j > i) {
				++l;
			}
		}
		ll ans = 0;
		if (m & 1 or m / 2 > k) {
			ans = solve(k - 2 * l, l, n);
		} else {
			ans = solve(k - 2 * l - 1, l, n) + solve(k - 2 * l - 1, l, n - 1);	
		}
		cout << ans % mod << '\n';
	}
}

ll solve(int a, int b, int n) {
	ll ans = 0;
	for (int j = 0; j <= n; ++j) {
		ans += dp(a, j) * dp2(b, n - j);
		ans %= mod;
	}
	return ans;
}

ll dp(int i, int j) {
	if (i == 0) {
		return (j == 0);
	} else {
		return choose[j + i - 1][i - 1];
	}
}

ll dp2(int i, int j) {
	if (j == 0) {
		return 1;
	} else if (i == 0) {
		return 0;
	} else if (seen[i][j]) {
		return str[i][j];
	} else {
		seen[i][j] = true;
		str[i][j] = (dp2(i - 1, j) + dp2(i - 1, j - 1) + dp2(i, j - 1)) % mod;
		return str[i][j];
	}
}

Measured memory_bytes: 145792
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int ans = 0;
long long N;

void cand(long long num,int three,int five,int seven) {
  if(num > N) return;

  if(three && five && seven) ans++;

  cand(10 * num + 3,1,five,seven);
  cand(10 * num + 5,three,1,seven);
  cand(10 * num + 7,three,five,1);
}

int main() {

 
  cin >> N;

  cand(3,1,0,0);
  cand(5,0,1,0);
  cand(7,0,0,1);

  cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    int N,M;cin >> N >> M;
    int k;
    vector<int> p(M);
    vector<vector<int>> v(M,vector<int>(N));
    rep(i,M){
        cin >> k;
        rep(j,k){
            cin >> v[i][j] ;
        }
    }
    rep(k,M){
        cin >> p[k];
    }

    int co;

    int sum = 0;

    vector<int> bit_flag(11);
    rep(i,N){
        bit_flag[i] = (1 << i);
    }
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<N); ++bit){ // bit全探索

        bool res = true;
        rep(j,M){ // スイッチのパターン一つを一周
            co = 0;
            
            rep(i,N){               // 一つの電球を探索 
                if(v[j][i] == 0)break;      // 0はすなわちスイッチがないことに等しい
                int tmp = v[j][i] - 1;      // スイッチの番号取得
                if(bit & bit_flag[tmp]){     // スイッチがONだとco++
                    co++;
                }
            }

            if(co % 2 != p[j]){     // ONスイッチの数の偶奇チェック
                res = false;
                break;
            }
        }

        if(res)sum++;       // 探索一回終了

    }

    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
 
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int z = scan.nextInt();
		int n = 0;
		do{
			n++;
		}while(x >= (n*y + n*z + z));
		System.out.println(n - 1);
		scan.close();
	}
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {

    //dp[i] = max(dp[i-1],dp[i-wi]+vi);
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] array = new int[N];
        for (int i = 0; i< array.length; i++) {
            array[i] = sc.nextInt();
        }

        int cnt = 0;
        for(int i = 0 ; i < array.length; i++) {
//            System.out.println((i+1) + "," + array[i]);
            if (i + 1 == array[i]) {
                cnt++;
                if (i < array.length -1 && array[i+1] == i + 2) {
                    i++;
                }
            }

        }

        System.out.println(cnt);

        sc.close();

    }

}


Measured memory_bytes: 51004
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200100;
int a[maxn];
int main(){
  int n;
  scanf("%d", &n);
  for(int e = 0; e < n; e++) scanf("%d", a + e);
  sort(a, a + n);
  set<pair<int, int> > b;
  for(int e = 0; e < n; e++) b.insert({a[e], e});
  int ans = 0;
  for(int e = n - 1; e >= 0; e--){
    set<pair<int,int> >::iterator me = b.lower_bound({a[e], e});
    if(me != b.end() && me->first == a[e] && me->second == e){
      long long lg = 1;
      while(a[e] >= lg) lg *= 2;
      int diff = (int)(lg - a[e]);
      auto nme = b.lower_bound({diff, -1});
      if(nme != b.end() && nme->first == diff && nme->second != e){
        b.erase(b.lower_bound({a[e], e}));
        b.erase(b.lower_bound({diff, -1}));
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){ ; 
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    if (s[k-1] == 'A'){
        s[k-1] = 'a';
    }
    if (s[k-1] == 'B'){
        s[k-1] = 'b';
    }
    if (s[k-1] == 'C'){
        s[k-1] = 'c';
    }
    cout << s << endl;
}   

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

using namespace std;

int n,i,j,mat[1100][1100];

int main()
{
    cin >> n;

    if(n<=2)
    {
        cout<<-1;
        return 0;
    }
   ///noooooooooooooooo
    for(i=1;i<n;i++)
        mat[1][i]=i+1;
    for(i=n;i>2;i--)
        for(j=1;j<=i;j++)
            mat[i][j]=j;
    for(i=3;i<n;i++)
        mat[i][i]=n;
    mat[2][1]=n;
    mat[2][2]=1;
    for(i=1;i<=n;i++)
        for(j=1;j<n;j++)
            if(mat[i][j]==0)
                mat[i][j]=j;
    for(i=2;i<n;i++)
        mat[n][i]=i+1;
    mat[n][n-1]=2;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<n;j++)
            cout<<mat[i][j]<<" ";
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 640
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ViewPatterns #-}
import qualified Data.List             as List
import qualified Data.Maybe            as Maybe
import qualified Data.ByteString.Char8 as BSC8


readInts :: IO [Int]
readInts = map (fst . Maybe.fromJust . BSC8.readInt) . BSC8.words <$> BSC8.getLine

main :: IO ()
main = do
  n  <- readLn :: IO Int
  xs <- readInts
  print $ solve n xs

solve :: Int -> [Int] -> Int
solve n (List.reverse . List.sort -> xs) = snd . List.foldl' step (1, List.head xs) $ List.tail xs
  where
    step (p, q) x
      | p == n - 1 = (p, q)
      | p == n - 2 = (p + 1, q + x)
      | otherwise  = (p + 2, q + 2 * x)

Measured memory_bytes: 35272