akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF ((int)(1e9))
#define INF2 ((ll)(1e18))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_V = 202;

int d[MAX_V][MAX_V];	// d[u][v] は辺 e = (u,v) のコスト（存在しない場合は INF, ただし d[i][i] = 0 とする）

void warshall_floyd(int V){
	for (int k = 0; k < V; ++k){
		for (int i = 0; i < V; ++i){
			for (int j = 0;j < V; ++j){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			} // end for
		} // end for
	} // end for
}
int main()
{
	memset(d, 0, sizeof(d));
	rep (i, MAX_V){
		rep (j, MAX_V){
			if (i != j){
				d[i][j] = INF;
			} // end if
		} // end rep
	} // end rep

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M, R; cin >> N >> M >> R;
	vector<int> r(R, 0);
	rep (i, R){
		cin >> r[i];
		--r[i];
	} // end rep
	rep (i,M){
		int a, b, c; cin >> a >> b >> c;
		--a, --b;
		d[a][b] = c;
		d[b][a] = c;
	} // end rep

	warshall_floyd(N);

	ll res = INF2;
	sort(ALL(r));
	do{
		ll curr = 0LL;
		for (int i = 1; i < (int)r.size(); ++i){
			curr += (ll)d[r[i-1]][r[i]];
		} // end for
		res = min(res, curr);
	}while(next_permutation(ALL(r)));

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N, K;
  cin>>N>>K;
  string s;
  cin>>s;
  for (int i = 0; i < N; i++) {
    if (i == K-1) {
      if (s[i]=='A') {
        cout<<'a';
      } else if (s[i]=='B') {
        cout<<'b';
      } else {
        cout<<'c';
      }
    } else {
      cout<<s[i];
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long ans = x / 11;
		x -= ans * (long)11;
		ans = ans << 1;
		if(x > 6) ans += 2;
		else if(x >= 1) ans++;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

if c2[0]-c1[0] == c2[1]-c1[1] == c2[2]-c1[2] \
   and c3[0]-c2[0] == c3[1]-c2[1] == c3[2]-c2[2] \
   and c1[1]-c1[0] == c2[1]-c2[0] == c3[1]-c3[0] \
   and c1[2]-c1[1] == c2[2]-c2[1] == c3[2]-c3[1] :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef queue<ll> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,ll> mpci;
typedef map<ll,ll> mpii;
typedef map<string,ll> mpsi;
typedef set<ll> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<n;i++)
#define ford(i,p,n) for(int i=n-1;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))

/*=====================================================================*/
inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
/*======================================================================*/
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int ans;
/*======================================================================*/
int main()
{
  /*
	ios_base::sync_with_stdio(0);
	cin(tie);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int n=read(),k=read();
  string s;
  cin>>s;
  rep(i,n)
  {
  	if(s[i]==s[i+1])
  	  ans++;
  }
  ll cnt=min(ans+2*k,n-1);
  cout<<cnt;
  return 0;
}


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

using namespace std;

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

	int ans = S.length();

	for (int i = 0; i < N - 1; i++)
	{
		char first_slim = S[i];
		char second_slim = S[i+1];
		if (first_slim == second_slim)
		{
			ans -= 1;
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 512
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll A[3],ans;

int main() {
	cin >> A[0] >> A[1] >> A[2];
	sort(A,A+3);
	ans += 2 * A[2] - A[1] - A[0];
	
	if ((A[0] + A[1]) % 2 == 1)ans++;
	ans /= 2;
	if ((A[0] + A[1]) % 2 == 1)ans++;
	

	ct(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=100000+10;
const int maxq=50000+10;
int n,q;
int a[maxn],b[maxq];
bool binary_search(int a[],int left,int right,int key)
{
    while(left<right)
    {
        int mid=(left+right)/2;
        if(a[mid]==key) return true;
        else if(a[mid]>key) right=mid;
        else left=mid+1;
    }
    return false;
}
void solve()
{
    int sum=0;
    for(int i=0;i<q;i++)
    {
        if(binary_search(a,0,n,b[i])) sum++;
    }
    printf("%d\n",sum);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    scanf("%d",&q);
    for(int i=0;i<q;i++) scanf("%d",&b[i]);

    sort(a,a+n);
    solve();

    return 0;
}

Measured memory_bytes: 3800
import java.util.*;

public class Main {
	long N;
	String S;

	Main() {
		Scanner in = new Scanner(System.in);
		S = in.nextLine();
		N = Long.parseLong(S);
		in.close();
	}

	void calc() {
		List<String> valueStrs = new ArrayList<>();
		for (int i = 2; i < S.length(); ++i) {
			valueStrs.addAll(getSubValues(i));
		}

		List<Long> values = new ArrayList<>();
		for (String valStr : valueStrs) {

			if (check(valStr)) {
				long v = Long.parseLong(valStr);
				if (v <= N) {
					values.add(v);
				}
			}
		}

		System.out.println(values.size());
	}

	boolean check(String s) {
		boolean three = false, five = false, seven = false;
		for (int i = 0; i < s.length(); ++i) {
			char c = s.charAt(i);
			if (c == '3') {
				three = true;
			} else if (c == '5') {
				five = true;
			} else if (c == '7') {
				seven = true;
			}
		}
		return three && five && seven;
	}

	List<String> getSubValues(int remain) {
		if (remain == 0) {
			List<String> result = new ArrayList<>();
			result.add("3");
			result.add("5");
			result.add("7");
			return result;
		} else {
			List<String> result = new ArrayList<>();
			List<String> subs = getSubValues(remain - 1);
			String[] chars = { "3", "5", "7" };
			for (String c : chars) {
				for (String sub : subs) {
					result.add(c + sub);
				}
			}
			return result;
		}
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calc();
	}

}

Measured memory_bytes: 32084
def main():
    n = int(input())
    A = input_list()
    B = input_list()
    C = [A[i] - B[i] for i in range(n)]
    s = sum(C)
    if s < 0:
        print(-1)
        exit()
    C.sort()
    ans = 0
    for i in range(n):
        if C[i] < 0:
            continue
        elif C[i] <= s:
            ans += 1
            s -= C[i]
        else:
            break
    print(n-ans)
    

def input_list():
    return list(map(int, input().split()))

if __name__ == "__main__":
    main()

Measured memory_bytes: 97680
#include <stdio.h>
int main()
{
	int s[111] = { 0 };
	s[2] = 1;
	int n, a,m = -1;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		if (!(i % 2)) s[i] = s[i / 2] + 1;
		if (m < s[i])
		{
			a = i; m = s[i];
		}
	}
	printf("%d\n", a);
}

Measured memory_bytes: 128
#include <cstdio>
#include <array>
using namespace std;

bool graph[8][8];

void dfs(int n, int root, int &result, array<bool, 8> visited)
{
	visited[root] = true;
	bool allVisited = true;
	for (int i = 0; i < n; ++i)
	{
		if (!visited[i])
		{
			allVisited = false;
		}
	}
	if (allVisited)
	{
		++result;
		return;
	}
	for (int i = 0; i < n; ++i)
	{
		if (!visited[i] && graph[root][i])
		{
			dfs(n, i, result, visited);
		}
	}
}

int main()
{
	for (int i = 0; i < 8; ++i)
	{
		for (int j = 0; j < 8; ++j)
		{
			graph[i][j] = false;
		}
	}
	int n, m;
	scanf("%d %d", &n, &m);
	array<bool, 8> visited;
	visited.fill(false);
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		graph[a - 1][b - 1] = true;
		graph[b - 1][a - 1] = true;
	}
	int result = 0;
	dfs(n, 0, result, visited);
	printf("%d", result);
	
	return 0;
}

Measured memory_bytes: 1680
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    string number;
    cin >> number;
    int answer = 0;
    int number_size = number.size();
    for (int i=0; i < number_size; i++) {
        int counter = 0;
        char key = number[i];
        for(int j=0; j < number_size; j++){
            if(j !=0) {if(number[j] != key){break;}}
            if(number[j] == key) {counter += 1;}
        }
        if(counter >= 3){answer = 1; break;}
    }
    if(answer == 0){cout << "No" << endl;}
    else{cout << "Yes" << endl;}
    return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
h = [int(i) for i in input().split()]
h.append(99999999999999)
dp = np.array([999999999999999]*(n+1))
dp[0] =0
for j in range(n-1):
  dp[j+1] = min(dp[j]+abs(h[j]-h[j+1]),dp[j+1])
  dp[j+2] = min(dp[j]+abs(h[j]-h[j+2]),dp[j+2])
print(dp[n-1])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	ll x[114514];
	cin>>n>>k;
	int z=n;
	bool f=false;
	REP(i, n){
		cin>>x[i];
		if(x[i]>=0 && !f){
			z=i;
			f=true;
		}
	}
	ll ans=1e18;
	if(n-z>=k){
		ans=min(ans, x[z+k-1]);
	}
	if(z>=k){
		ans=min(ans, -x[z-k]);
	}
	FOR(i, z, n){
		if(z>=k-i+z-1){
			ans=min(ans, 2*x[i]-x[i-k+1]);
		}
	}
	REP(i, z){
		if(n-z>=k-z+i){
			ans=min(ans, -2*x[i]+x[k+i-1]);
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1024
import string
li = list(string.ascii_lowercase)
s = list(input())
if s[0] == "A" and s[2:-1].count("C") == 1:
    s.remove("C")
    s.remove("A")
else:
    print("WA")
    exit()
if all([s[i] in li for i in range(len(s))]):
    print("AC")
    exit()
else:
    print("WA")

Measured memory_bytes: 3772
import sys
stdin = sys.stdin
mod = 10**9 + 7

import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = na()
b = na()
c = na()
ans = sum(b)
d = np.array(a[:-1]) - np.array(a[1:])
for di, num in enumerate(d):
        if num == -1:
                ans += c[a[di]-1]
print(ans)


Measured memory_bytes: 21280
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:i64,
    }
    let mut md = ModComb::new(MX, MOD);
    if n < 2 {
        println!("{}", 0);
        return;
    }
    if n == 2 {
        println!("{}", 2);
        return;
    }
    let mut ans = 1i64;
    ans = mod_pow(10, n, MOD) - 2 * mod_pow(9, n, MOD) + mod_pow(8, n, MOD);
    ans = (ans + MOD + MOD) % MOD;
    println!("{}", ans);
}
const MX: usize = 1010101;
/// x ^ n % m
pub fn mod_pow(x: i64, n: i64, m: i64) -> i64 {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}
struct ModComb {
    fact: Vec<i64>,
    fact_inv: Vec<i64>,
    n: usize,
    p: i64,
}
impl ModComb {
    fn initialize(&mut self) {
        let n = self.n;
        self.fact[0] = 1;
        for i in 1..n {
            self.fact[i] = (self.fact[i - 1] * i as i64) % self.p;
        }
        self.fact_inv[n - 1] = mod_pow(self.fact[n - 1], self.p - 2, self.p);
        for i in (0..n - 1).rev() {
            self.fact_inv[i] = (self.fact_inv[i + 1] * (i + 1) as i64) % self.p;
        }
    }
    fn new(max_n: usize, p: i64) -> ModComb {
        let mut ft = ModComb {
            fact: vec![0; max_n + 1],
            fact_inv: vec![0; max_n + 1],
            n: max_n + 1,
            p: p,
        };
        ModComb::initialize(&mut ft);
        ft
    }
    fn fact(&self, n: usize) -> i64 {
        self.fact[n]
    }
    fn comb(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        (self.perm(n, k) * self.fact_inv[k as usize]) % self.p
    }
    fn perm(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        self.fact[n as usize] * self.fact_inv[(n - k) as usize] % self.p
    }
    fn nsk(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        let mut res = 0;
        for i in 0..k + 1 {
            let v = self.comb(k, i) * mod_pow(i, n, self.p) % self.p;
            if (k - i) % 2 == 1 {
                res = (res + self.p - v) % self.p;
            } else {
                res = (res + v) % self.p;
            }
        }
        return res * self.fact_inv[k as usize] % self.p;
    }
}
const MOD: i64 = 1000000007;


Measured memory_bytes: 17864
#include<iostream>
#include<deque>

using namespace std;

int main(){
   int n, a;

   cin >> n;
   deque<int> li;

   for(int i = 0; i < n; i++){
      cin >> a;
      if(i % 2 == 0){
         li.push_front(a);
      }else{
         li.push_back(a);
      }
   }
   if(n % 2 == 0){
      for(auto i = li.rbegin(); i != li.rend(); i++){
         cout << *i << ' ';
      }
   }else{
      for(auto i = li.begin(); i != li.end(); i++){
         cout << *i << ' ';
      }
   }
}

Measured memory_bytes: 4468
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

int		main(void)
{
	int		a, b, c;

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);

	if(( a < b ) && ( b < c))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<class Tuple, unsigned Index>
void print_tuple(ostream& os, const Tuple& t) {}

template<class Tuple, unsigned Index, class Type, class... Types>
void print_tuple(ostream& os, const Tuple& t) {
	if(Index > 0) os << ", ";
	os << get<Index>(t);
	print_tuple<Tuple, Index + 1, Types...>(os, t);
}

template<class... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t) {
	os << '(';
	print_tuple<tuple<Types...>, 0, Types...>(os, t);
	return os << ')';
}

template<class Iterator>
ostream& dump_range(ostream&, Iterator, const Iterator&);

template<typename T>
ostream& operator<<(ostream& os, vector<T> c) {
	return dump_range(os, c.cbegin(), c.cend());
}

template<class Iterator>
ostream& dump_range(ostream& os, Iterator first, const Iterator& last) {
	os << '[';
	for(int i = 0; first != last; ++i, ++first) {
		if(i) os << ", ";
		os << *first;
	}
	return os << ']';
}

constexpr long long INF = 0xffffffffffff;

class union_find {
private:
	vector<int> uf;
	vector<long long> pd;

public:
	union_find(int n):uf(n, -1), pd(n, 0) {}
	
	inline int find(int x) {
		if(uf[x] < 0)
			return x;

		const int tmp = uf[x];
		uf[x] = find(uf[x]);
		pd[x] += pd[tmp];
		return uf[x];
	}

	inline int dist_root(int x) {
		find(x);
		return pd[x];
	}
	
	inline void unite(int xx, int yy, int d) {
		int x = find(xx), y = find(yy);
		if(x == y)
			return;
		
		d += pd[yy] - pd[xx];
		if(uf[x] < uf[y]) {
			swap(x, y);
			d = -d;
		}

		else if(uf[x] == uf[y])
			--uf[y];
		
		uf[x] = y;
		pd[x] = d;
	}
	
	inline bool same(int x, int y) {
		return find(x) == find(y);
	}

	inline long long get_dist(int x, int y) {
		return !same(x, y) ? INF : dist_root(x) - dist_root(y);
	}
};


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

	for(int n, m; cin >> n >> m && n;) {
		union_find uf(n);
		for(int i = 0; i < m; ++i) {
			char q;
			int a, b;
			cin >> q >> a >> b;

			--a;
			--b;

			if(q == '!') {
				int d;
				cin >> d;
				uf.unite(a, b, d);
			}
			else {
				const long long ans = uf.get_dist(a, b);
				if(ans == INF)
					cout << "UNKNOWN" << endl;
				else
					cout << ans << endl;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2380
def chmin(dp, i, *x):
  dp[i] = min(dp[i], *x)
INF = float("inf")

# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
  a, b = map(int, input().split())
  for j in range(h + 1):
    chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h])

Measured memory_bytes: 74408
#include<cstdio>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef long long weight;
weight const infty = 0x3fffffffffffff;
typedef pair<weight,int> edge;
class Graph{
private:
    int numVertex;
    vector<edge> *adj;
public:
    Graph(int v){
        this->numVertex=v;
        this->adj=new vector<edge>[v];
    }
    ~Graph(){ delete[] adj; }
    void addEdge(int u,int v,weight w=1,bool isDirected=false){
        adj[u].push_back({w,v});
        if(!isDirected)adj[v].push_back({w,u});
    }
    void dijkstra(weight l[],int s){
        for(int i=0;i<numVertex;i++)l[i]=infty;
        l[s]=0;
        priority_queue<edge,vector<edge>,greater<edge>> pq;
        pq.push({0,s});
        while(!pq.empty()){
            int u=pq.top().second;
            pq.pop();
            for(auto i=adj[u].begin();i!=adj[u].end();i++){
                int v=(*i).second;
                weight w=(*i).first;
                if(l[v]>l[u]+w){
                    l[v]=l[u]+w;
                    pq.push({l[v],v});
                }
            }
        }
    }
};
weight d[100001];
int main(){
    int n,a;
    scanf("%d",&n);
    Graph g(n+1);
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        g.addEdge(i,a,1,true);
    }
    g.dijkstra(d,1);
    printf("%lld",(d[2]==infty)?-1:d[2]);
    return 0;
}

Measured memory_bytes: 6528
//Δ_A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int main()
{
	int n,k;
	cin>>n>>k;
	cout<<n-k+1;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
tmp = 0
nmax = 0
for i in range(n):
    a, b = map(int,input().split())
    if a==b:
        tmp+=1
        nmax=max(nmax,tmp)
    else:
        tmp=0
if nmax>=3:
    print("Yes")
else:
    print("No")

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ll a,b,c;cin >> a >> b >> c;
    cout << min(a+b+1,c)+b << endl;
    return 0;
}

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

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

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

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

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

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        N: usize,
        A: usize,
        B: usize,
        v: [usize; N],
    }
    v.sort_by(|a, b| b.cmp(a));
    println!("{:?}", (v.iter().take(A).sum::<usize>() as f64)/(A as f64));
    let min = v[A-1];
    let countA = v.iter().take(A).filter(|&&a| a == min).count();
    let countV = v.iter().filter(|&&a| a == min).count();
    let mut ans = 0;
    if countA == A {
        for c in countA .. cmp::min(countV, B)+1 {
            ans += bin_coef(c, countV);
        }
    } else {
        ans = bin_coef(countA, countV);
    }
    println!("{}", ans);
}

fn bin_coef(k:usize, n:usize) -> usize {
    if k > n/2 {
        bin_coef(n-k, n)
    } else {
        (0..k).fold(1, |acc, x| (acc*(n-x))/(x+1))
    }
}

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

int main() {
  int n;
  cin >> n;
  int arr[n];

  for (int i=0; i<n; i++) {
    cin >> arr[i];
  }

  int cnt=0, p=1;
  while (p) {
    for (int i=0; i<n; i++) {
      if (arr[i]%2!=0) {
        p=0;
      } else {
        arr[i]/=2;
      }
    }
    if (p) cnt++;
  }

  cout << cnt << endl;
}

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

struct Graph {
  int n;
  struct edge { int src, dst, rev; };
  vector<vector<edge>> adj;
  Graph() : n(0) {}

  void addEdge(int src, int dst) {
    n = max(n, max(src, dst)+1);
    if (adj.size() < n) adj.resize(n);
    adj[src].push_back({src, dst, (int)adj[dst].size()});
    adj[dst].push_back({dst, src, (int)adj[src].size()-1});
  }

  bool eulerianPath() {
    int m = 0, s = -1;
    if (adj[0].size() % 2 == 0 || adj[1].size() % 2 == 0) return false;
    for (int u = 2; u < n; ++u) {
      if (adj[u].size() % 2 == 1) return false;;
    }
    return true;
  }
};

int main() {
  int a, b;
  while (cin >> a >> b) {
    Graph g;
    while (1) {
      g.addEdge(a-1, b-1);
      if (cin >> a >> b, a) continue;
      break;
    }
    cout << ( (g.eulerianPath()) ? "OK" : "NG" ) << endl;
  }
  return 0;
}



Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define per(i,a,b) for(ll i=(a)-1; i>=(b); i--)
const ll mod=1e9+7, maxn=2e5+5;
ll n,a,b,f[maxn], sz[maxn], w[maxn], ans[maxn];
vector<ll> ady[maxn];
ll bin_pow(ll a, ll x) {
    ll ans=1;
    for(ll p=a;x;x/=2,p=p*p%mod) if(x&1) ans=ans*p%mod;
    return ans;
}
ll inv(ll a) {
    return bin_pow(a, mod-2);
}
void calc_fact() {
    f[0]=1;
    rep(i,1,maxn) f[i]=i*f[i-1]%mod;
}
ll choose(ll n, ll r) {
    return f[n]*inv(f[r])%mod*inv(f[n-r])%mod;
}
void dfs(ll x, ll p) {
    w[x]=sz[x]=1;
    for(ll to:ady[x]) if(to!=p) {
        dfs(to, x);
        sz[x]+=sz[to];
        w[x]=w[x]*choose(sz[x]-1,sz[to])%mod*w[to]%mod;
    }
}
void dfs2(ll x, ll p) {
    ans[x]=w[x];
    for(ll to: ady[x]) if(to!=p) {
        w[x]=w[x]*inv(choose(sz[x]-1, sz[to]))%mod*inv(w[to])%mod;
        sz[x]-=sz[to];
        sz[to]+=sz[x];
        w[to]=w[to]*choose(sz[to]-1,sz[x])%mod*w[x]%mod;
        dfs2(to,x);
        w[to]=w[to]*inv(choose(sz[to]-1, sz[x]))%mod*inv(w[x])%mod;
        sz[to]-=sz[x];
        sz[x]+=sz[to];
        w[x]=w[x]*choose(sz[x]-1,sz[to])%mod*w[to]%mod;
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    calc_fact();
    cin>>n;
    rep(i,1,n) cin>>a>>b, ady[a].push_back(b), ady[b].push_back(a);
    dfs(1,0);
    dfs2(1,0);
    rep(i,1,n+1) cout<<ans[i]<<"\n";
}


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

signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    int k,x;
    cin>>k>>x;
    for(int i=x-k+1;i<=x+k-1;i++){
        cout<<i<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 256
from collections import Counter

N, K = map(int, input().split())

c = Counter(map(int, input().split()))

def it():
    for k, v in sorted(c.items(), key=lambda kv: kv[1]):
        if len(c) <= K:
            break
        else:
            yield v
            del c[k]

print(sum(it()))


Measured memory_bytes: 41492
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    ll x;
    cin >> x;
    ll b = 100LL;
    int ans = 0;
    while(b<x){
        
        b*=1.01;
        ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3592
using System;
public class Aprob {
    public static void Main() {
        string[] read = new string[3];
        read = Console.ReadLine().Split(' ');
        /*int A = int.Parse(read[0]);
        int B = int.Parse(read[1]);
        int C = int.Parse(read[2]);*/
        Console.WriteLine("A"+read[1].Substring(0,1)+"C");

    }
}

Measured memory_bytes: 2648
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def bfs(start):
    que=deque([start])
    D=[-1]*(h*w)
    D[start]=0
    while que:
        x=que.popleft()
        for next_x in (x+1,x-1,x+w,x-w):
            if maze[next_x]=='.' and D[next_x]==-1:
                D[next_x]=D[x]+1
                que.append(next_x)
    return max(D)

def main():
    global h,w,maze
    h,w=map(int,input().split())
    h+=2
    w+=2
    maze="#"*w
    for _ in range(h-2):
        maze+="#"+input()+"#"
    maze+="#"*w 
    print(max(bfs(i) for i,c in enumerate(maze) if c=='.'))


if __name__=='__main__':
    main()




Measured memory_bytes: 41708
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var K = nextInt();
  var queue = [1,2,3,4,5,6,7,8,9];
  var last = 0;
  for(var i = 0; i < K; i++){
    var tmp = queue[i];
    last = tmp;
    switch(last % 10){
      case 0:
        queue.push(last * 10);
        queue.push(last * 10 + 1);
        break;
      case 9:
        queue.push(last * 10 + 8);
        queue.push(last * 10 + 9);
        break;
      default:
        queue.push(last * 10 + last % 10 - 1);
        queue.push(last * 10 + last % 10);
        queue.push(last * 10 + last % 10 + 1);
        break;
                    }
    
  }
  //myerr(queue);
  myout(queue[K - 1]);
}

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

int main(){
  int n;
  cin >> n;
  int l,r;
  int res=0;
  
  rep(i,n){
    cin >> l >> r;
    res+=r-l+1;
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll s = 0;
    rep(i,n) s += a[i];
    
    vector<ll> ans(n);
    ll sum = 0;
    for(int i = 1; i < n-1; i += 2) sum += a[i];
    ans[0] = s - (2*sum);
    for(int i = 1; i < n; i++){
        ans[i] = (2 * a[i-1]) - ans[i-1];
    }
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    int count = 0;

    for(int i=n; i <= m; i++) {
        if(i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define rep_one(i, n) for(int i=1; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int n; cin >> n;
    ll ans = 0;
    rep_one(k, n+1){
        ll tmp = n/k;
        ans += k*tmp*(1+tmp)/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    960 Hours of Solitude
    Quarantine_Day : 40
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<ll>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 200005

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

    int n, m;
    cin>>n;
    map<string, int>mb, mr;
    REP(i, n){
        string s; cin>>s;
        mb[s]++;
    }
    cin>>m;
    REP(i, m){
        string s; cin>>s;
        mr[s]++;
    }
    int ans = 0;
    for(auto i : mb){
        ans = max(ans, mb[i.first] - mr[i.first]);
        //db(ans);
    }
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
UV = [[int(x) for x in readline().split()] for _ in range(M)]
S, T = map(int, readline().split())

PATH = [[] for _ in range(N + 1)]

for u, v in UV:
    PATH[u].append(v)

dist = [[-1] * 3 for _ in range(N+1)]

q = deque()
q.append((S, 0))
dist[S][0] = 0

while q:
    u, mod = q.popleft()
    d = dist[u][mod]

    nmod = (mod + 1) % 3
    for v in PATH[u]:
        if dist[v][nmod] != -1:
            continue
        dist[v][nmod] = d + 1
        q.append((v, nmod))


if dist[T][0] == -1:
    ans = -1
else:
    ans = dist[T][0] // 3

print(ans)


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

int N, A[1 << 18];
int X[1 << 18], Y[1 << 18], Answer[1 << 18];
vector<int> G[1 << 18];

// LIS Array
int SZ;
int B[1 << 18];
pair<int, int> V[1 << 18];

void dfs(int pos, int dep, int pre) {
	int pos1 = lower_bound(B, B + SZ, A[pos]) - B;
	V[dep] = make_pair(pos1, B[pos1]);
	B[pos1] = A[pos];
	if (pos1 == SZ) SZ++;
	Answer[pos] = SZ;

	for (int i : G[pos]) {
		if (i == pre) continue;
		dfs(i, dep + 1, pos);
	}

	if (V[dep].second == 0) SZ--;
	B[V[dep].first] = V[dep].second;
	V[dep] = make_pair(0, 0);
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N - 1; i++) {
		cin >> X[i] >> Y[i];
		G[X[i]].push_back(Y[i]);
		G[Y[i]].push_back(X[i]);
	}
	dfs(1, 0, -1);

	for (int i = 1; i <= N; i++) cout << Answer[i] << endl;
	return 0;
}

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

int main() {
  string S,T;
  cin>>S>>T;
  int a=0;
  int b=S.size();
  for(int i=0;i<b;i++){
  if(S.at(i)!=T.at(i)){
  a++;
  }
  }
  
  cout<< a<<endl;
}

Measured memory_bytes: 3916
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

bool compare(const int &lhs, const int &rhs)
{
    return lhs > rhs;
}

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::vector< std::vector<int> > vec(100010);
    int x, y;
    for (int i = 0; i < n; ++i)
    {
        std::cin >> x >> y;
        vec[x].push_back(y);
    }

    std::multiset<int> taken;

    for (int i = m; i > 0; --i)
    {
        std::sort(vec[i].begin(), vec[i].end(), compare);

        int maxSize = m - i + 1;
        for (int j = 0; j < vec[i].size(); ++j)
        {
            if (taken.size() < maxSize)
                taken.insert(vec[i][j]);
            else
            {
                if (*(taken.begin()) < vec[i][j])
                {
                    taken.erase(taken.begin());
                    taken.insert(vec[i][j]);
                }
            }
        }
    }

    int ans = 0;
    for (auto it : taken)
    {
        ans += it;
    }

    std::cout << ans;
}


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

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

  int N; cin >> N;
  int D; cin >> D;
  int X; cin >> X;
  int ans = X;
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    ans += 1 + (D - 1) / A;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=4e5+5;
typedef long long ll;
int n,k;
char s[N];
int num[N];
int st;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
        num[i]=s[i]-'A';
    st=num[1];
    int p=1;
    int cnt=0;
    while(k--){
        if(st==0){
            st^=1;
            num[p]^=1;
        }
        else{
            p++;
            cnt++;
            st=num[p];
            st^=(cnt&1);
        }
        if(p>n)
            break;
    }
    if(p<=n){
        for(int i=p;i<=n;i++)
            putchar('A'+(num[i]^(cnt&1)));
        int t=p-1,c=(cnt-1)&1;
        while(t--){
            putchar('A'+c);
            c^=1;
        }
    }
    else{
        if((cnt-1)&1)
            for(int i=1;i<=n;i++)
                putchar('A'+(i&1));
        else{
            putchar('A'+(k&1));
            for(int i=1;i<n;i++)
                putchar('A'+(i&1));
        }
    }
}

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

#define repeat(i, x) for (int64_t i = 0; (i) < (int64_t)(x); (i)++)

const int64_t inf = (1LL << 40);

struct Network {
    using Flow = int64_t;
    using Cost = int;

    struct Arc {
        int to;
        Flow cap;
        Cost cost;
        int rev;

        Arc() {}
        Arc(int to, Flow cap, Cost cost, int rev) :
            to(to), cap(cap), cost(cost), rev(rev) {}
    };

    int n;
    vector<vector<Arc>> graph;

    Network(int n = 0) : n(n), graph(n) {}

    void addArc(int from, int to, Flow cap) {
        graph[from].emplace_back(to, cap, 0, graph[to].size());
        graph[to].emplace_back(from, 0, 0, graph[from].size() - 1);
    }

    Flow findMaximumFlow(int s, int t) {
        vector<pair<int, int>> hist(n, {-1, -1});
        Flow sumFlow = 0, flow;

        while (flow = findBlockingFlow(hist, s, t), flow > 0) {
            int u = t;
            while (hist[u].first >= 0) {
                Arc& arc = graph[hist[u].first][hist[u].second];

                arc.cap -= flow;
                graph[arc.to][arc.rev].cap += flow;
                u = hist[u].first;
            }
            sumFlow += flow;
        }
        return sumFlow;
    }

    Flow findMinimumCut(int s, int t) {
        return findMaximumFlow(s, t);
    }

private:
    Flow findBlockingFlow(vector<pair<int, int>>& hist, int s, int t) {
        vector<int> dist(n, -1);
        vector<Flow> limit(n, inf);
        fill(hist.begin(), hist.end(), make_pair(-1, -1));

        queue<int> que;
        dist[s] = 0;
        que.push(s);

        bool flag = false;

        while (!que.empty() and !flag) {
            int u = que.front(); que.pop();

            for (int i = 0; i < graph[u].size(); i++) {
                const Arc& arc = graph[u][i];

                if (dist[arc.to] < 0 and arc.cap > 0) {
                    dist[arc.to] = dist[u] + 1;
                    hist[arc.to] = {u, i};
                    limit[arc.to] = min(limit[u], arc.cap);
                    que.push(arc.to);

                    if (arc.to == t) {
                        flag = true;
                        break;
                    }
                }
            }
        }
        return flag ? limit[t] : 0;
    }
};

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

    int n;
    cin >> n;

    vector<int64_t> a(n);

    repeat (i, n) {
        cin >> a[i];
    }

    // 2n個の頂点+s+t
    Network network(n + 3);
    int s = n + 1,  // 破壊されない
        t = n + 2;  // 破壊される

    int64_t ans = 0;
    for (int u = 1; u <= n; u++) {
        if (a[u - 1] > 0) {
            ans += a[u - 1];
            network.addArc(u, t, a[u - 1]);
        } else {
            network.addArc(s, u, -a[u - 1]);
        }

        for (int v = 2 * u; v <= n; v += u) {
            network.addArc(u, v, inf);
        }
    }

    ans -= network.findMinimumCut(s, t);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void){
    int A,B,i,j,k,count = 0;
    scanf("%d%d",&A,&B);
    
    for(i = 1;i < 10;i++){
        for(j = 0;j < 10;j++){
            for(k = 0;k < 10;k++){
                int val;
                val = i*10000 + j*1000 + k*100 + j*10 + i*1;
                // printf("%d\n",val);
                if(A <= val && B >= val) count++;
            }
        }
    }

    printf("%d",count);

}

Measured memory_bytes: 128
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    // テストコードをここにコピペする
r"5
" => r"YES",

r"6
" => r"NO"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: i32,
    }
    match x {
        3 => return "YES".to_string(),
        5 => return "YES".to_string(),
        7 => return "YES".to_string(),
        _ => return "NO".to_string(),
    }
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

A, B, C, D, E, F, = map(int, input().split())

A = A * 100
B = B * 100

ans = 0
m = (0, 0)
for i in range(int(F / A) + 1):
    for j in range(int(F / B) + 1):
        for k in range(80):
            for l in range(80):
                wa = (A * i) + (B * j)
                su = (C * k) + (D * l)

                if wa + su > F:
                    continue

                if (wa // 100 * E) < su:
                    continue

                if wa == 0:
                    continue

                t = (su * 100) / (wa + su)
                if ans <= t:
                    ans = t
                    m = (wa, su)

print(sum(m), m[1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007 //(10^9 +7)
#define INF 1000000000000000000 //(10^18)
using namespace std;
typedef long long  ll;
typedef long double ld;
const ll N=100005;
const ll inf=1e18;
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}
int main(){
    fastIO;
    ll n;
    cin>>n;
    vector<ll> vect(n,0);
    ll i=0,j=0;
    for(i=0;i<n;i++){
        cin>>vect[i];
    }
    vector<ll> dp(n,INF);
    dp[0]=0;
    dp[1]=abs(vect[1]-vect[0]);
    for(i=0;i<n-1;i++){
        //dp[i]=min(dp[i-1]+abs(vect[i]-vect[i-1]),dp[i-2]+abs(vect[i]-vect[i-2]));
        dp[i+1]=min(dp[i+1],dp[i]+abs(vect[i+1]-vect[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(vect[i+2]-vect[i]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string[] hd = Console.ReadLine().Split(' ');
        string ret;
        if (hd[0] == "H") {
            ret = hd[1];
        } else {
            if (hd[1] =="H") ret = "D";
            else ret = "H";
        }
        Console.WriteLine(ret);
    }
}


Measured memory_bytes: 13140