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

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let W: usize = sc.get();
    let mut val = Vec::new();
    let mut wei = Vec::new();
    for _ in 0..N {
        let vi: usize = sc.get();
        let wi: usize = sc.get();
        val.push(vi);
        wei.push(wi);
    }
    let mut dp = vec![vec![0; W+1]; N+1];
    for i in 0..N {
        for w in 0..W+1 {
            if w >= wei[i] {
                dp[i+1][w] = max(dp[i][w], dp[i][w - wei[i]] + val[i]);
            } else {
                dp[i+1][w] = dp[i][w];
            }
        }
    }
    let mut ans = 0;
    for w in 0..W+1 {
        ans = max(ans, dp[N][w]);
    }
    println!("{}", ans);
}



Measured memory_bytes: 13112
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n, x, m;
  cin >> n >> x >> m;
  vector<ll> roop(m);
  ll ans = 0;
  vector<ll> a(100000);
  bool bo = true;
  rep(i,n) {
    if (roop[x] > 0 && bo) {
      ll sy = a[i]-a[roop[x]-1];
      ans += sy * ((n-i)/(i-(roop[x]-1)));
      i += ((n-i)/(i-(roop[x]-1))) * (i-(roop[x]-1));
      i--;
      bo = false;
    }
    else {
      ans += x;
      if (bo) {
        a[i+1] = a[i] + x;
        roop[x] = i+1;
      }
      x = x*x%m;
    }
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;
using namespace std;

ll paths = 0;

void dfs(vector<vector<int>> &graph, vector<bool> &visited, int current) {
  bool ok = true;
  for (ll i = 0; i < visited.size(); i++) {
    if (visited[i] == false) {
      ok = false;
      break;
    }
  }

  if (ok) {
    paths++;
    return;
  }

  visited[current] = true;
  for (ll i = 0; i < graph[0].size(); i++) {
    if (graph[current][i] == 1 && visited[i] == false) {
      visited[i] = true;
      dfs(graph, visited, i);
      visited[i] = false;
    }
  }
}

int main() {
  ll N, M;
  cin >> N >> M;

  vector<vector<int>> graph(N, vector<int>(N, 0));
  for (ll i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    graph[a - 1][b - 1] = 1;
    graph[b - 1][a - 1] = 1;
  }

  vector<bool> visited(N, false);

  dfs(graph, visited, 0);

  cout << paths << endl;
}

Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
long long fac[1000005],inv[1000005];
const long long mod=998244353;
long long C(int n,int m)
{
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
    int  n,sum,i,j;
    long long k,t,x,y;
    scanf("%d%lld%lld%lld",&n,&x,&y,&k);
    fac[0]=1;
    for(i=1; i<=n; i++)
    {
        fac[i]=fac[i-1]*i%mod;

    }
    inv[1]=1;
    inv[0]=1;
    for(i=2; i<=n; i++)
    {
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    for(i=2;i<=n;i++)
    {
        inv[i]=inv[i-1]*inv[i]%mod;
    }
    //  printf("%lld\n",C(5,5));
    long long ans=0;
    for(i=0; i<=n; i++)
    {
        if(k-i*x>=0&&(k-i*x)%y==0)
        {
            t=(k-i*x)/y;
            if(t<=n)
                ans+=C(n,i)*C(n,t)%mod;
        }
    }
    printf("%lld\n",ans%mod);
    return 0;
}


Measured memory_bytes: 8320
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;typedef pair<int,int > P;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
void inp(){
	int n;scanf("%d",&n);
	printf("%s", n>=1000?"ABD":"ABC");
}
//a.cc by xsthunder at Fri Jul 27 23:09:59 2018


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

void make_set(const std::vector<long long int>& weights, const int current_pos, const long long int current, std::vector<long long int> &result) {
	if (current_pos == weights.size()) {
		result.push_back(current);
	}
	else {
		make_set(weights, current_pos + 1, current - weights[current_pos], result);
		make_set(weights, current_pos + 1, current + weights[current_pos], result);
		make_set(weights, current_pos + 1, current, result);
	}
}
int main() {
	while (true) {
		int n, m; std::cin >> n >> m;
		if (n == 0) break;
		std::vector<int>targets(n); for (auto& t : targets) std::cin >> t;
		std::vector<long long int> weights(m); for (auto& w : weights) std::cin >> w;
		std::vector<long long int> can_make; make_set(weights, 0, 0, can_make);
		std::sort(can_make.begin(), can_make.end());
		std::set<long long int> suspect; 
		for (auto i = 0; i < n; ++i) {
			if (!std::binary_search(can_make.begin(), can_make.end(), targets[i])) {
				for (const auto c : can_make) {
					suspect.insert(std::abs(c + targets[i]));
				}
				break;
			}
		}
		auto make_count = 0;
		for (auto i = 0; i < n; ++i) {
			std::set<long long int> s;
			if (std::binary_search(can_make.begin(), can_make.end(), targets[i])) {
				make_count++;
			}else{
				for (const auto c : can_make) {
					if (suspect.find(std::abs(c + targets[i])) != suspect.end()) {
						s.insert(std::abs(c + targets[i]));
					}
				}
				suspect = std::move(s);
			}
		}
		if (make_count == n) {
			std::cout << 0 << std::endl;
		}else if (suspect.empty()) {
			std::cout << -1 << std::endl;
		}
		else  {
			std::cout << *suspect.begin() << std::endl;
		}
	}
}


Measured memory_bytes: 8880
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
typedef long long ll;
ll a[N];
int k;
map<ll,int> m;
int n;
int main(){
    scanf("%d %d", &n, &k);
    for(int i=1;i<=n;i++){
        scanf("%lld", &a[i]);
        if(i>1) a[i]+=a[i-1];
    }
    ll ans=0;
    //if()
    for(int i=2;i<=n;i++){
        if(i>k){
            int x=i-k;
            m[(a[x]-x)%k]--;
        }
        int x=i-1;
        m[(a[x]-x)%k]++;
        ans+=m[(a[i]-i)%k];
        if((a[i]%k)==i) ans++;
    }
    if(a[1]%k==1) ans++;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }
const int INF = 1000000000;

int w[10][10];
int ans[10];

int main(){
    int H,W; cin>>H>>W;
    rep(i,0,10) rep(j,0,10) cin>>w[i][j];
    rep(i,0,H) rep(i,0,W){
        int a; cin>>a;
        if(a!=-1) ans[a]++;
    }
    rep(k,0,10) rep(i,0,10) rep(j,0,10){
        w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
    }
    int res=0;
    rep(i,0,10){
        res+=ans[i]*w[i][1];
    }
    cout<<res<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  string taken = "";
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (T[i] == 'r') {
      if (i >= K && taken[i - K] == 'p') {
        if (i + K < N)
          taken += T[i + K];
        else
          taken += "r";
      } else {
        taken += "p";
        ans += P;
      }
    } else if (T[i] == 's') {
      if (i >= K && taken[i - K] == 'r') {
        if (i + K < N)
          taken += T[i + K];
        else
          taken += "s";
      } else {
        taken += "r";
        ans += R;
      }
    } else {
      if (i >= K && taken[i - K] == 's') {
        if (i + K < N)
          taken += T[i + K];
        else
          taken += "p";
      } else {
        taken += "s";
        ans += S;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(b <=a){
    cout << "delicious" << endl;
  }
  else if(a < b && b <= x+a){
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2*60 + m2 - h1*60 - m1 -k << '\n';

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
const int mod = 1e9+9;
/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
*void exEuclid(int a, int b){
	if(b==0){x = 1; y=0; d=a; return ;}
	exEuclid(b, a%b);
	int x1=y;
	int y1=x-(a/b)*y;
	x=x1;
	y=y1;
} 
* */
//===========================================================//
const int nax = 1e5+3;
int n;
int dp[nax];
int a[nax];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+f(i+1);
	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));
	return dp[i]=ans;
}
int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  int a, b;
  cin >> a >> b;

  cout << min(a*N, b) << endl;
  
  return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int d[200000];
vector <int> v[200000];

int main() {
    int n, x = 0, i;
    queue <int> q;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        a--;
        b--;
        
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    for (i = 0; i < n; i++) d[i] = 1e9;
    d[x] = 0;
    q.push(x);
    
    while (!q.empty()) {
        int x = q.front();
        
        q.pop();
        
        for (i = 0; i < v[x].size(); i++) {
            int y = v[x][i];
            
            if (d[y] > d[x] + 1) {
                d[y] = d[x] + 1;
                q.push(y);
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        if (d[i] > d[x]) x = i;
    }
    
    for (i = 0; i < n; i++) d[i] = 1e9;
    d[x] = 0;
    q.push(x);
    
    while (!q.empty()) {
        int x = q.front();
        
        q.pop();
        
        for (i = 0; i < v[x].size(); i++) {
            int y = v[x][i];
            
            if (d[y] > d[x] + 1) {
                d[y] = d[x] + 1;
                q.push(y);
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        if (d[i] > d[x]) x = i;
    }
    
    if (d[x] % 3 == 1) {
        puts("Second");
    } else {
        puts("First");
    }
    
    return 0;
}


Measured memory_bytes: 13556
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()
    val M = scn.nextInt()
    var A = IntArray(N+1)

    if(M==0 && N==1) {
        println(0)
        return
    }

    for(i in 1..N){
        A[i] = -1
    }

    for(i in 1..M){
        var s = scn.nextInt()
        var c = scn.nextInt()
        if(A[s] != -1 && A[s] != c) {
            println(-1)
            return
        }

        A[s] = c
    }

    var result = ""
    if(A[1]==-1) A[1]=1

    for(i in 1..N){
        if(A[i]==-1) A[i] = 0
        result += A[i].toString()
    }

    if(result.toInt().toString().length == N) {
        println(result)
    }else{
        println(-1)
    }

}


Measured memory_bytes: 31392
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

ll n;
int res(ll y, ll tmp, ll tmp2) { return y * y * n - 2 * tmp * y + tmp2; }
int main() {
  cin >> n;
  ll tmp = 0, tmp2 = 0, y, z, ans;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    tmp += x;
    tmp2 += x * x;
  }
  y = tmp / n;
  z = y + 1;
  ans = min(res(y, tmp, tmp2), res(z, tmp, tmp2));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
ll H,W,R,R1,D,D1;
ll dx[4]= {0,-1,0,1};
ll dy[4]= {1,0,-1,0};

int main()
{
    cin>>H>>W>>R>>R1>>D>>D1;
    char s[H+1][W+1];
    ll dp[H+1][W+1];
    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
            cin>>s[i][j];
    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
            dp[i][j]=-1;
    deque<pair<ll,ll>> q;
    ll m=0;
    q.push_back({R,R1});
    q.push_back({1e4,1e4});
    while(q.size()>1)
    {
        ll x = q.front().first;
        ll y = q.front().second;
        q.pop_front();
        if(x==1e4)
        {
            m++;
            q.push_back({1e4,1e4});
            continue;
        }

        if(x<=0 || H<x || y<=0 || W<y || s[x][y]=='#' || dp[x][y]!=-1)
            continue;
        dp[x][y] = m;
        for(int i=0; i<4; i++) q.push_front({x+dx[i],y+dy[i]});

        for(int i=-2; i<3; i++)
            for(int j=-2; j<3; j++)
                q.push_back({x+i,y+j});
    }
    cout<<dp[D][D1]<<endl;
}


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

int main()
{
  int M, x;
  cin >> M;
  x = 24 + (24 - M);
  if ((1 <= M) && (M <= 23))
  {
    cout << x << endl;
  }
  else
  {
    cout << "1から23でお願いします。" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[100000],b;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>b;
    a[b-1]=i;
  }
  for(int i=0;i<n;i++)
    cout<<a[i]+1<<endl;
  return(0);
}

Measured memory_bytes: 1152
import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)

heapq.heapify(a)

for i in range(m):
    b,c=bc[i]
    for g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))

Measured memory_bytes: 27084
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val s = readLine()!!
  val eCount = IntArray(n)
  val wCount = IntArray(n)
  eCount[0] = if (s[0] == 'E') 1 else 0
  wCount[0] = if (s[0] == 'W') 1 else 0
  for (i in 1 until n) {
    eCount[i] = eCount[i - 1] + if (s[i] == 'E') 1 else 0
    wCount[i] = wCount[i - 1] + if (s[i] == 'W') 1 else 0
  }
  fun count(i: Int): Int {
    val westCount = if (i == 0) 0 else wCount[i - 1]
    val eastCount = eCount[n - 1] - eCount[i]
    return westCount + eastCount
  }
  val ans = (0 until n).map { count(it) }.min()!!
  println(ans)
}


Measured memory_bytes: 48260
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		Map<Integer, Integer> modevalue = new HashMap<Integer, Integer>();
		int i = 0;
		int minValue = 101;
		int maxValue = -1;
		
			while (sc.hasNext()) {
				i = sc.nextInt();
				
					if (i == 0) break;
				minValue = Math.min(i, minValue);
				maxValue = Math.max(i, maxValue);
				
					if (modevalue.containsKey(i)) {
						modevalue.put(i, modevalue.get(i) + 1);
					} else {
						modevalue.put(i, 1);
					}
			}
			

			
			int maxFreq = -1;
			
			for (int n = minValue; n <= maxValue; n++) {
				if (modevalue.containsKey(n)) {
					maxFreq = Math.max(maxFreq, modevalue.get(n));
				}
			}
			
			for (int n = minValue; n <= maxValue; n++) {
				if (modevalue.containsKey(n) && modevalue.get(n) == maxFreq) System.out.println(n);
			}
	}

}


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

int main(){
    int N; cin >> N;
    vector<string> S(N);
    rep(i, 0, N) cin >> S[i];
    int cnt = 0;
    rep(i, 0, N) if(S[i] == "E869120") cnt++;

    cout << cnt << endl;
}


Measured memory_bytes: 3288
import java.util.*;

public class Main{
  public static void main(String[] args){
    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();
    }
    Arrays.sort(a);
    System.out.println(a[n/2]-a[n/2-1]);
  }
}


Measured memory_bytes: 51924
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		int d=sc.nextInt();
		int c=0;
		for(int i=1;i<=m;i++) {
			for(int j=20;j<=d;j++) {
				int x=j/10;
				int y=j%10;
				if(x*y==i) {
					if(y!=1)
					    c++;
				}
			}
		}
		System.out.println(c);
				

	}

}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  vector<string> s(3);
  cin >> s.at(0) >> s.at(1) >> s.at(2);
  rep(i,3){
    cout << (char)(s.at(i).at(0) - 'a' + 'A');
  }
                
}


Measured memory_bytes: 256
using System;
using static System.Console;

public static class Program
{
    public static void Main()
    {
        var s = ReadLine();
        var t = ReadLine();
        int minCount = int.MaxValue;
        for(int i = 0; i + t.Length - 1 < s.Length; ++i)
        {
            int count = 0;
            for(int j = 0; j < t.Length; ++j)
            {
                if (s[i + j] != t[j]) ++count;
            }
            minCount = Math.Min(count, minCount);
        }
        WriteLine(minCount);
    }
}

Measured memory_bytes: 25920
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int n;
	cin >> n;
	printf("%.10lf", n * 2 * 3.14159265358);
	cout << endl;
}



Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
ll cnm(ll n,ll m)
{
	if(m>n/2)
	m=n-m;
	ll a=1,b=1;
	for(int i=1;i<=m;i++)
	{
		a*=n+1-i;
		b*=i;
		if(a%b==0)
		{
			a/=b;
			b=1;
		}
	}
	return a/b;
}
const int N=1e5*2+2;
int a[N],num[N];
ll c[N];
int main(){
	int k;
	scanf("%d",&k);
	int maxn=0;
	for (int i=1;i<=k;i++){
		scanf("%d",&a[i]);
		maxn=max(maxn,a[i]);
		num[a[i]]++;
	}
	for (int i=2;i<=k;i++){
		c[i]=cnm(i,2);
	}
	ll ans=0;
	for (int i=1;i<=maxn;i++){
		if (num[i])ans+=c[num[i]];
	}
	for (int i=1;i<=k;i++){
		ll ansn=ans;
		ansn-=c[num[a[i]]];
		ansn+=c[num[a[i]]-1];
		printf("%lld\n",ansn);
	}
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 1000000007 
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int binaryS(int x, int sb[], int m){
    int l = 0, r=m;
    int mid = (l+r)/2;
    while(l<r){
        mid = (l+r)/2;
        if(sb[mid]<x) l= mid+1;
        else if(sb[mid]>x) r = mid-1;
        else return mid;
    }
    return l;
}
int main(){
    fastio;
    vector<vc>pf(1000001);
    rep(i,2,1000001){
        if(pf[i].empty()){
            for(int j=i; j<=1000001; j+=i){
                pf[j].pb(i);
            }
        }
    }
    int n; cin>>n;
    int arr[n]; take(arr,n);
    um mp; bool pairw = true, setw = true;
    rep(i,0,n){
        repit(it,pf[arr[i]]){
            mp[*it]++;
            if(mp[*it]>1) pairw = false;
            if(mp[*it]==n) setw = false;
        }
    }
    if(pairw) cout<<"pairwise coprime";
    else if(setw) cout<<"setwise coprime";
    else cout<<"not coprime";
    return 0;
}


Measured memory_bytes: 65868
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int W = int.Parse (str[0]);
            int H = int.Parse (str[1]);
            int x = int.Parse (str[2]);
            int y = int.Parse (str[3]);
            int r = int.Parse (str[4]);

            if (r <= x && r <= W - x && r <= y && r <= H - y)
            {
                Console.WriteLine ("Yes");
            }
            else
            {
                Console.WriteLine ("No");
            }
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}


Measured memory_bytes: 17996
#include <iostream>
using namespace std;
typedef long long ll;
ll t,n;
ll a[5];
string b;
string a1="AC",a2="WA",a3="TLE",a4="RE";
int main()
{
	cin>>n;
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>b;
		if(b==a1)
		a[1]++;
		else if(b==a2)
		a[2]++;
		else if(b==a3)
		a[3]++;
		else if(b==a4)
		a[4]++;
		
	}
	cout<<"AC x "<<a[1]<<endl;
	cout<<"WA x "<<a[2]<<endl;
	cout<<"TLE x "<<a[3]<<endl;
	cout<<"RE x "<<a[4]<<endl;

}



Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;


ll n, m;
vector<int> G[ARRAY_MAX];
int color[ARRAY_MAX];//各頂点の色(1:黒、2;白,0:まだ塗られていない)
bool ans = true;//二部グラフかどうか


void dfs(int now) {


	for (auto to : G[now])
	{
		if (color[now] == color[to])
		{
			//二部グラフではない
			//ループができている
			ans = false;
			return;
		}
		if (color[to] == 0)
		{
			//まだ塗られていない
			color[to] = 3 - color[now];//color[now]==1なら2が、color[now]==2なら1が入る(隣同士で違う色が塗られる)
			dfs(to);
		}


	}
}



int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	color[0] = 1;//1は黒を表す
	dfs(0);
	
	if (ans)
	{
		//二部グラフなら完全二部グラフにできる
		//二部に分けた両者の間で全頂点間に辺を張ることができる

		int black = 0, white = 0;
		for (int i = 0; i < n; i++)
		{
			if (color[i] == 1)
			{
				black++;
			}
			else
			{
				white++;
			}
		}
		ll ans = 1LL * black * white - m;
		cout << ans << endl;
	}
	else
	{
		//二部グラフではないなら完全グラフにできる
		//奇数長の閉路がある場合は任意の2地点を奇数距離で移動できるので結ぶことができる
		ll ans = 1LL * n * (n - 1) / 2 - m;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>

int main(){
  int n, i,fn;
  double ave = 0, min = 100;
  scanf("%d",&n);
  int f[n];
  for(i=0;i<n;i++){
    scanf("%d",&f[i]);
    ave += (double)f[i]/n;
  }
  for(i=0;i<n;i++){
    if(f[i] >= ave){
	    if(min > f[i]-ave){
    		min = f[i] - ave;
			fn = i;
    	}
    }else{
    	if(min > ave - f[i]){
        	min = ave - f[i];
          	fn = i;
      	}
    }
  }
  printf("%d\n",fn);
  return 0;
}

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

int main(){
	int N, K;
	cin >> N >> K;
	int h[N];
	for(int i=0; i<N; i++){
		cin >> h[i];
	}
	ll dp[N];
	dp[0] = 0;
	for(int i=1; i<N; i++){
		ll min = abs(h[i] - h[i-1]) + dp[i-1];
		for(int j=2; j<=i && j<=K; j++){
			if(min > abs(h[i] - h[i-j]) + dp[i-j]){
				min = abs(h[i] - h[i-j]) + dp[i-j];
			}
		}
		dp[i] = min;
	}
	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vector<int> s(100010);
    s[0] += 1;
    s.back()-=1;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        s[a]++;
        s[b+1]--;
    }
    rep(i, s.size()-1) {
        s[i+1] += s[i];
    }
    repr(i, s.size()) {
        if(s[i] >= i) {
            cout << i-1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3124
import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val n = readInputLine().toInt()
    val s = readInputLine().toCharArray()

    val rCnt = s.count { it == 'R' }.toLong()
    val gCnt = s.count { it == 'G' }.toLong()
    val bCnt = s.count { it == 'B' }.toLong()

    var ans = rCnt * bCnt * gCnt

    for (i in s.indices) {
        for (j in i - 1 downTo 0) {
            if (i - (i - j) * 2 < 0) {
                break
            }
            if (s[i] != s[j] && s[i] != s[i - (i - j) * 2] && s[j] != s[i - (i - j) * 2]) {
                ans--
            }
        }
    }

    pw.println(ans)

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36216
l=[[1,3,5,7,8,10,12],[4,6,9,11],[2]]
x,y=map(int,input().split())
f=0
for i in range(3):
  if x in l[i] and y in l[i]:
    f=1
if f:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3188
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 10000
#define MAX_R 5000

void
solve(int n)
{
	int bins[MAX_N / 2];
	int remains[MAX_R];

	int ix = 0;
	for (int i = 1; i < n; ++i)
	{
		int r = (i * i) % n;

		int j;
		for (j = 0; j < ix; ++j)
		{
			if (r == remains[j])
				break;
		}

		if (j >= ix)
			remains[ix++] = r;
	}

	int m = (n - 1) / 2;
	for (int i = 1; i <= m; ++i)
		bins[i] = 0;

	for (int i = 0; i < ix; ++i)
	{
		for (int j = 0; j < ix; ++j)
		{
			if (i != j)
			{
				int d = remains[i] - remains[j];
				if (d < 0)
					d += n;

				if (d > m)
					d = n - d;

				bins[d]++;
			}
		}
	}

	for (int i = 1; i <= m; ++i)
		printf("%d\n", bins[i]);
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		solve(n);
	}

	return 0;
}

Measured memory_bytes: 1748
#include<iostream>
#include<string>
typedef unsigned int uint;
using namespace std;

bool brute_force(string &haystack,string &needle){
  uint n_index=0;

  for(uint h_index=0;h_index<haystack.size();h_index++){
    while(haystack.at( (h_index + n_index)%haystack.size() ) == needle.at(n_index)){
      n_index++;
      if(n_index >= needle.size()) return true;
    }
    n_index = 0;
  }
  return false;
}

int main(){
  string haystack;
  string needle;
  cin>>haystack>>needle;
  if(brute_force(haystack,needle)){
    cout<<"Yes"<<endl;
  }
  else
    cout<<"No"<<endl;
  return 0;

}

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

struct mint { // auto MOD int
  ll x;
  mint(ll x=0) : x((x%MOD+MOD)%MOD){}  //コンストラクタ
  mint operator-() const { return mint(-x); } //符号変換
  mint operator+(const mint &a) const { return mint(*this) += a; } //算術演算子
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  mint pow(ll n) const {  //繰り返し累乗
    if (!n) return 1;
    mint a = pow(n>>1);
    a *= a;
    if (n&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD-2); } // for prime mod
  mint& operator+=(const mint a){ if((x+=a.x) >= MOD) x-=MOD;  return *this; } //代入演算子
  mint& operator-=(const mint a){ if((x+=MOD-a.x) >= MOD) x-=MOD;  return *this; }
  mint& operator*=(const mint a){ (x *= a.x) %= MOD;  return *this; }
  mint& operator/=(const mint a){ return (*this) *= a.inv(); }
  friend ostream& operator<<(ostream &stout, const mint &tmp){ stout << tmp.x; return stout; }
};

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<mint> dp(n+1);
  dp[0] = 1;
  for(int i = 1; i <= n; i++){
    for(int j = 3; j <= i; j++){
      dp[i] += dp[i-j];
    }
  }
  cout << dp[n];
  cout << "\n";
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  if (S == "RRR") cout << 3 << endl;
  else if (S == "SRR" || S == "RRS") cout << 2 << endl;
  else if (S == "SSS") cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,i;
    float down;
    cin>>n;
    vector<float> a(n);
    for(i=0;i<n;i++){
      cin>>a[i];
    }
    for(i=0;i<n;i++){
      down+=1.0/a[i];
    }
  cout<<1.0/down<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

signed main() {
    string S;
    cin >> S;
    int N = S.size();

    // 0101...
    int ans1 = 0;
    REP(i, N) {
        if (i % 2 == 0 && S[i] == '1') ans1++;
        else if (i % 2 == 1 && S[i] == '0') ans1++;
    }
    int ans2 = 0;
    REP(i, N) {
        if (i % 2 == 0 && S[i] == '0') ans2++;
        else if (i % 2 == 1 && S[i] == '1') ans2++;
    }
    cout << min(ans1, ans2) << LF;

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

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

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

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

int main() {
  int n, x = 0, y = 0, z = 0;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  for (int i = 0; i < n; ++i) {
    if (a[i] % 4 == 0) ++x;
    else if (a[i] % 2 == 0) ++y;
    else ++z;
  }
  if (y) ++z;
  cout << (x + 1 >= z) << endl;
}



Measured memory_bytes: 640
#!/usr/bin/env python3

from collections import defaultdict


def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N, M = MII()

    d = defaultdict(int)

    py = []
    for i in range(M):
        P, Y = MII()
        py.append((i, P, Y))
    py = sorted(py, key=lambda x: x[2])
    

    ans = [''] * M
    for i, j, k in py:
        d[j] += 1
        ans[i] = f'{j:06d}{d[j]:06d}'
    
    print('\n'.join(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40896
N = int(input())

b = [0]*(N+1)

button2 = [] # 2があるボタン

for i in range(1,N+1):
    a = int(input())
    b[i] = a
    if a == 2:
        button2.append(i)
        
now = 1
count = -1

for i in range(0, N+1):

    if now == 2:
        count = i
        break
    
    now = b[now]

print(count)

Measured memory_bytes: 6900
import java.util.Scanner;

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.nextLine();
        String S = sc.nextLine();

        char[] s = S.toCharArray();
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'a') {
                if (A + B > 0) {
                    System.out.println("Yes");
                    if (A > 0) {
                        A--;
                    } else {
                        B--;
                    }
                } else {
                    System.out.println("No");
                }
            } else if (s[i] == 'b') {
                if (A + B > 0) {
                    if (B > 0) {
                        System.out.println("Yes");
                        B--;
                    } else {
                        System.out.println("No");
                    }
                } else {
                    System.out.println("No");
                }
            } else {
                System.out.println("No");
            }
        }
        
        sc.close();
    }
}

Measured memory_bytes: 34820
#include<bits/stdc++.h>
#define ll long long
#define cri const register int
#define re register
#define END return puts("NO"),0;
using namespace std;
int in[410],out[410],f[410],n,H,c[410],v[410];
int getf(cri x){ return f[x]==x?x:f[x]=getf(f[x]); }
int main(){
	cin>>n>>H;
	for(int i=1;i<=H+H;i++) f[i]=i;
	for(int i=1,a,b,c,d,L,R;i<=n;i++){
		cin>>a>>b>>c>>d;
		if(c) L=-c;else L=a;
		if(d) R=d;else R=-b;
		L+=H;R+=H;v[L]=v[R]=1;
		in[R]++;out[L]++;
		f[getf(L)]=getf(R);
	}
	for(int i=1;i<=H;i++) if(in[i]<out[i]) END;
	for(int i=H+1;i<=H+H;i++) if(in[i]>out[i]) END;
	for(int i=1;i<=H+H;i++) c[getf(i)]|=in[i]!=out[i];
	for(int i=1;i<=H+H;i++) if(v[i]&&!c[getf(i)]) END;
	puts("YES");
}

Measured memory_bytes: 3644
/*
  AOJ 2583
  Title:JAG-channel
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

char line[1000][51];
char prefix[1001];
int  prefix_len;
int  level[1000];
int  last_brother[1000];
int n;

void read_line(char line[],int * lev)
{
  int i;

  char buf[1051];
  scanf("%s",buf);
  i=0;
  while(buf[i]=='.')
    i++;
  *lev=i;
  strcpy(line,&buf[i]);
}
void check_last_brother(int line)
{
  int i,lv,elder_brother;

  elder_brother = -1;
  
  for(i=line+1,lv=level[line];i<n && level[i]>lv;i++)
    {
      if(i>n || level[i]<=lv)
	return;
      if(level[i]==lv+1)
	{
	  if(elder_brother>=0)
	    {
	      last_brother[elder_brother]=-1;
	    }
	  check_last_brother(i);
	  elder_brother=i;
	}
    }
}
void    print_result()
{
  int i,j;
  
  printf("%s\n",line[0]);

  prefix_len=0;
  for(i=1;i<n;i++)
    {
      if(level[i]==level[i-1]+1)
	{
	  if(last_brother[i-1]==0 && prefix_len>0)
	    prefix[prefix_len-1]=' ';  
	  prefix[prefix_len]='|';  
	  prefix_len++;
	}
      else
	prefix_len=level[i];

      for(j=0;j<prefix_len-1;j++)
	printf("%c",prefix[j]);
      printf("+%s\n",line[i]);
    }
}
clear()
{
  memset(line,0,1000*51);
  memset(level,0,1000*sizeof(int));
  memset(last_brother,0,1000*sizeof(int));
}
main()
{
  int i;
  while(scanf("%d",&n) && n)
    {
      clear();
      for(i=0;i<n;i++)
	read_line(&line[i][0],&level[i]);

      check_last_brother(0);
      print_result();
    }
  return(0);
}

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

namespace _0183
{
    public class Program
    {

        static public int[][] winPattern = new int[][]
        {
             new int[] {0,1,2}
            ,new int[] {3,4,5}
            ,new int[] {6,7,8}
            ,new int[] {0,3,6}
            ,new int[] {1,4,7}
            ,new int[] {2,5,8}
            ,new int[] {0,4,8}
            ,new int[] {2,4,6}
        };

        public static void Main(string[] args)
        {
            while (true)
            {
                string line1 = Console.ReadLine();
                if (line1 == "0") return;

                string line2 = RSt();
                string line3 = RSt();

                Console.WriteLine(Judge(line1 + line2 + line3));
            }
        }

        private static string Judge(string v)
        {
            foreach (var item in winPattern)
            {
                if (item.All(x => v[x] == 'b')) return "b";
                if (item.All(x => v[x] == 'w')) return "w";
            }
            return "NA";
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 18212
import math

n=int(input())
t=int(input())

mnt=t
t1=int(input())
if t1<t:
    mnt=t1
mxt=t1-t


for i in range(2,n):
    t=int(input())

    if t-mnt>mxt:
        mxt=t-mnt
    if t<mnt:
        mnt=t

print(int(mxt))



Measured memory_bytes: 5668
#include<bits/stdc++.h>
#define ll long long
#define a109 1000000009
#define pb push_back
using namespace std;

int n ,m;
vector<int>v[100005];
int dp[100005],visit[100005];
int dpf(int x){
	if(dp[x]!=-1){
		return dp[x];
	}
	visit[x]=1;
	int mx=0;
	for(int i=0;i<v[x].size();i++){
		mx=max(mx,dpf(v[x][i]) );
	}
	dp[x]=mx+1;
	return dp[x];
}


int main(){

	// freopen("a.gir","r",stdin);
 //    freopen("a.cik","w",stdout);
    for(int i=0;i<100005;i++){
   		dp[i]=-1;
  	}
  	int mxx=0;
  	scanf("%d %d",&n,&m);
  	for(int i=0;i<m;i++){
  		int a,b;
  		scanf("%d %d",&a,&b);
  		v[a].pb(b);
  	}
  	for(int i=1;i<=n;i++){
  		if(visit[i]==0){
  			mxx=max(mxx,dpf(i));
  		}
  	}
  	printf("%d\n",mxx-1);
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define re register
const int mod=998244353;
int f[310][310][310],g[310][310][310];
char ss[310];
int main()
{
	re int n;
	scanf("%s",ss+1);
	n=strlen(ss+1);
	g[0][0][0]=1;
	for(re int i=1;i<=n;i++)
	{
		for(re int j=0;j<=n;j++)
			for(re int k=0;k<=n;k++)
			{
				if(ss[i]=='0'&&j)g[i][j][k]|=g[i-1][j-1][k+1];
				if(ss[i]=='1'&&k)g[i][j][k]|=g[i-1][j+1][k-1];
				g[i][j][k]|=g[i-1][j][k];
				if(i>=2)
				{
					if((ss[i]=='0'||ss[i-1]=='0')&&j)g[i][j][k]|=g[i-2][j-1][k];
					if((ss[i]=='1'||ss[i-1]=='1')&&k)g[i][j][k]|=g[i-2][j][k-1];
				}
			}
	}
	for(re int i=0;i<=n;i++)
	{
		if(ss[n]=='0')f[n][0][i]=1;
		else f[n][i][0]=1;
	}
	for(re int i=n-1;i>=0;i--)
	{
		for(re int j=0;j<=n;j++)
		{
			for(re int k=0;k<=n;k++)
			{
				f[i][j][k]=f[i+1][j][k];
				if(ss[i]=='0'&&k)f[i][j][k]=(f[i][j][k]+f[i][j][k-1])%mod;
				if(ss[i]=='1'&&j)f[i][j][k]=(f[i][j][k]+f[i][j-1][k])%mod;
			}
		}
	}
	re int ans=0;
	for(re int i=0;i<=n;i++)
		for(re int j=0;j<=n;j++)
			for(re int k=0;k<=n;k++)
			if(i!=n||j||k){
				ans=(ans+g[i][j][k]*f[i][j][k])%mod;
				//if(g[i][j][k])printf("***%d %d %d %d %d\n",i,j,k,f[i][j][k],ans);
			}
	printf("%d\n",ans);
}

Measured memory_bytes: 225260