akhauriyash/Code-Regression huggingface dataset:
use std::collections::VecDeque;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    // 葉を選んだとき => 選んだ葉以外の葉をむしる
    // 葉以外を選んだとき => 葉を全てむしる

    // 直径の端点 => 直径を1減らす
    // その他の点 => 直径を2減らす

    // 0=>first
    // 1=>second
    // 2=>first
    // 3

    let n = sc.read();
    if n == 1 {
        println!("First");
        return;
    }
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut dist = vec![n; n];
    let mut q = VecDeque::new();
    q.push_back(0);
    dist[0] = 0;

    while let Some(v) = q.pop_front() {
        for &next in graph[v].iter() {
            if dist[next] > dist[v] + 1 {
                dist[next] = dist[v] + 1;
                q.push_back(next);
            }
        }
    }
    let (_, d1) = dist
        .into_iter()
        .enumerate()
        .map(|(i, d)| (d, i))
        .max()
        .unwrap();

    let mut dist = vec![n; n];
    q.push_back(d1);
    dist[d1] = 0;
    while let Some(v) = q.pop_front() {
        for &next in graph[v].iter() {
            if dist[next] > dist[v] + 1 {
                dist[next] = dist[v] + 1;
                q.push_back(next);
            }
        }
    }

    let (dist, _) = dist
        .into_iter()
        .enumerate()
        .map(|(i, d)| (d, i))
        .max()
        .unwrap();

    let inf = n * 10;
    let mut grundy = vec![inf; dist + 1];
    grundy[0] = 1;
    grundy[1] = 0;
    grundy[2] = 1;
    for i in 3..(dist + 1) {
        let mut next = vec![];
        next.push(grundy[i - 1]);
        next.push(grundy[i - 2]);
        grundy[i] = (0..).find(|i| !next.contains(i)).unwrap();
    }
    if grundy[dist] == 0 {
        println!("Second");
    } else {
        println!("First");
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 23668
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,c[200010],p[200010],dsu[200010],sz[200010],sum[200010];
vector<int> v[200010];

inline int find_set(int x)
{
	return dsu[x]==x?x:dsu[x]=find_set(dsu[x]);
}

struct node{
	pair<pair<int,int>,int> p;
};

bool operator < (const node x,const node y){
	int val1=x.p.first.first*y.p.first.second,val2=y.p.first.first*x.p.first.second;
	if(val1!=val2) return val1<val2;
	else return x.p.second<y.p.second;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) dsu[i]=i,sz[i]=1;
	for(int i=2;i<=n;i++) cin>>p[i];
	for(int i=1;i<=n;i++) cin>>c[i];
	for(int i=1;i<=n;i++) sum[i]=c[i];
	set<node> s;
	for(int i=1;i<=n;i++){
		node xx;xx.p=make_pair(make_pair(sum[i],sz[i]),i);
		s.insert(xx);
	}
	int ans=0;
	while(!s.empty()){
		int t=(*s.begin()).p.second;
		pair<int,int> val=(*s.begin()).p.first;
		s.erase(s.begin());
		if(val.first!=sum[t]||val.second!=sz[t]) continue;
		if(t==1) continue;
		dsu[t]=p[t];
		int root=find_set(t);
		ans+=sum[root]*(sz[t]-sum[t]);
		sz[root]+=sz[t];sum[root]+=sum[t];
		node xx;xx.p=make_pair(make_pair(sum[root],sz[root]),root);
		s.insert(xx);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 28676
Q = int(input())

from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(n: int):
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    for p in range(3, int(n**0.5)+1, 2):
        if n % p == 0:
            return False
    return True

like_2017s = []
for i in range(3, 10**5, 2):
    if is_prime(i) and is_prime((i+1)//2):
        like_2017s.append(i)

from bisect import bisect_left, bisect_right
for _ in range(Q):
    l, r = map(int, input().split())
    li = bisect_left(like_2017s, l)
    ri = bisect_right(like_2017s, r)
    print(ri-li)

Measured memory_bytes: 66268
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<' ';
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,m; cin>>n>>m;
    vint c(m,0);
    rep(i,n){
        int k; cin>>k;
        rep(i,k){
            int tmp; cin>>tmp;
            c[--tmp]++;
        }
    }
    int ans = 0;
    rep(i,m){
        if(c[i] == n)ans++;
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
a, b = gets.split.map(&:to_i)

def f(x)
  c = 0

  64.times do |i|
    i = i+1
    bb = x & (1<<i)

    ## 0..b
    c ^= bb == 0 ? 0 : x.even? ? bb : 0
  end
  c ^= [1,2].include?(x%4) ? 1 : 0

  c
end

puts a == 0 ? f(b) : f(b) ^ f(a-1)

Measured memory_bytes: 1788
//When I wrote this only God and I knew what it is
//Now, only The_Blitz knows...
#pragma GCC optimize ("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e3 + 2;

const ll oo = 1e9 + 2; 

int cost[N];
vector<int> pos[N];
ll dp[N][1 << 12 + 1];
int n, m;

ll go(int p, int mask){
	if(mask == (1 << n) - 1) return 0;
	if(p == m) return oo;
	ll &ans = dp[p][mask];
	if(ans != -1) return ans;
	//no tomar
	ans = oo;
	ans = min(ans, go(p+ 1, mask));
	//tomar
	int nmask = mask;
	for(int x: pos[p]){
		nmask |= (1 << x);
	}
	ans = min(ans, go(p+1, nmask) + cost[p]);
	return ans;
}

int main(){
	fastio;
	cin >> n >> m;
	for(int i = 0; i < m; ++ i){
		cin >> cost[i];
		int k; cin >> k;
		for(int j = 0; j < k; ++ j){
			int x; cin >> x;
			x --;
			pos[i].pb(x);
		}
	}
	memset(dp, -1, sizeof(dp));
	ll ret = go(0, 0);
	if(ret >= oo) cout << -1 << endl;
	else cout << ret << endl;
	return 0;
}



Measured memory_bytes: 67920
#include<stdio.h>
int main()
{
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x+r>w ||x-r<0 || y+r>h ||y-r<0)
	printf("No");
	else
	printf("Yes");
	printf("\n");
	return 0;
} 


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

vector<ll> decimalConvert(ll x, ll b, int keta = 64) {
	vector<ll> res;
	while (x) {
		res.push_back(x % b);
		x /= b;
	}
	while (res.size() < keta) res.push_back(0);
	reverse(ALL(res));
	
	return res;
}

ll decode(vector<ll>::iterator begin, vector<ll>::iterator end, ll b = 2) {
	ll res = 0;
	while (begin != end) {
		res *= b;
		res += *begin;
		++begin;
	}
	return res;
}

int main() {
	ll A, B;
	cin >> A >> B;
	
	if (A == B) {
		cout << 1 << endl;
		return 0;
	}
	
	vector<ll> a = decimalConvert(A, 2), b = decimalConvert(B, 2);
		
	int p = 0;
	while (a[p] == b[p]) p++;
	p++;
	

if (debug) {
	REP(i, a.size()) printf("%lld", a[i]); puts("");
	REP(i, b.size()) printf("%lld", b[i]); puts("");
	REP(i, p) putchar(' ');
	puts("@");
}
	
	ll na = decode(a.begin() + p, a.end());
	int s = 64 - p;
	
	for (int i = p; i < 64;) {
		while (i < 64 && b[i] == 0) i++;
		if (i == 64) break;
		while (i < 64) b[i++] = 1;
	}
	
	ll nb = decode(b.begin() + p, b.end());
	
	
	ll ans = (1ll<<s) - na;
	if (na <= nb) ans += (1ll<<s);
	else ans += (1ll<<s)-na + nb + 1;
	
if (debug) {
	cout << na << endl;
	cout << nb << endl;
}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end


N,K=gets.chomp.split(' ').map{|n| n.to_i}
S=gets.chomp.split(' ').map{|n| n.to_i}
if(N<K)
	puts 1
	exit(0)
end
min = 9999999999
mini = 0
S.each_with_index{|a,i|
	a < min ? (min = a; mini = i) : a
}
num = 1
mintmpnum = 9999999999
0.upto(K-1){|offset|
	tmpnum = 0
	lefti = mini-0-(K-1)+offset-1
	if(0<=lefti)
		tmpnum += ((lefti+1)*1.0 / (K-1)).ceil
		dputs "lefti"; dputs lefti
		dputs "tmpnum"; dputs tmpnum
	end
	righti = mini+(K-1)-(K-1-offset)+1
	if(righti<=N-1)
		tmpnum += ((N-1-righti+1)*1.0 / (K-1)).ceil
		dputs "righti" ; dputs righti
		dputs "tmpnum"; dputs tmpnum
	end
	tmpnum < mintmpnum ? mintmpnum = tmpnum : mintmpnum
}
puts num+mintmpnum



Measured memory_bytes: 11504
#include <stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d", &a,&b, &c);
	
	int sum;
	sum = ((b/c*c-(a+c-1)/c*c)/c+1);
	
	printf("%d", sum);
	
	return 0;
}

Measured memory_bytes: 1676
#include <stdio.h>

int main(void)
{
	char id_S[11];
	char id_T[12];
	int i, c;

	scanf("%s", id_S);
	scanf("%s", id_T);

	c = 0;

	for (i = 0; id_S[i] != '\0'; i++)
	{
		if (id_S[i] != id_T[i])
		{
			c++;
			break;
		}
	}

	if (c == 0)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 1696
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private int A;
    private int B;
    private String S;

    public Main() {
	A = Integer.parseInt(scan.next());
	B = Integer.parseInt(scan.next());
	S = scan.next();

	scan.close();
    }

    public final void answer() {

	String ans = "Yes";

	for (int i = 0; i < A+B+1; i++) {

	    if(i == A) {
		if(S.charAt(i) != '-') {
		    ans = "No";
		    break;
		}
		
	    } else {
		int d = S.charAt(i) - '0';
		if(d < 0 || d > 9) {
		    ans = "No";
		    break;
		}
	    }
	}

	System.out.println(ans);
	
    }
}


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

import math
from decimal import *

def main():
    h,w = map(int, input().split())
    if h == 1:
        print(1)
        exit()
    elif w ==1:
        print(1)
        exit()
    else:
        print(math.ceil(h*w/2))

if __name__ == '__main__':
    main()

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  string result;
  if (s == "Sunny") {
    result = "Cloudy";
  } else if (s == "Cloudy") {
    result = "Rainy";
  } else {
    result = "Sunny";
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int A,B,C;cin>>A>>B>>C;
  if ((A==B || B==C || A==C) && !(A==B && B==C)) {
    p("Yes");
  } else {
    p("No");
  }
  return 0;
}



Measured memory_bytes: 256
//09
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    bool f[50][31]={{}};
    for(int i=0;i<n;i++){
      int nf;
      cin>>nf;
      while(nf--){
	int d;
	cin>>d;
	f[i][d]=true;
      }
    }
    long long m[50];
    for(int i=0;i<n;i++){
      m[i]=1LL<<i;
    }
    int i;
    for(i=1;i<=30;i++){
      long long cm=0;
      for(int j=0;j<n;j++){
	if(f[j][i]){
	  cm|=m[j];
	}
      }
      if(cm==(1LL<<n)-1)break;
      for(int j=0;j<n;j++){
	if(f[j][i]){
	  m[j]=cm;
	}
      }
    }
    cout<<((i<=30)?i:-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
dic={"a":input(),"b":input(),"c":input()}

#print(dic)
temp="a"

while 1:
  temp2=dic[temp][:1]
  #print(temp)
  dic[temp]=dic[temp][1:]
  temp=temp2
  #print(dic)
  
  if dic[temp]=="":
    if temp=="a":
      print("A")
    elif temp=="b":
      print("B")
    elif temp=="c":
      print("C")
    break

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

int gcd(int a,int b){
    if(a<b) gcd(b,a);
    else{
        while(a%b){
            int r=a%b;
            a=b,b=r;
        }
        return b;
    }
}
int main(){
    int xt[100009];
    ll n,x,g;
    cin>>n>>x;
    rep(i,n){
        ll k;
        cin>>k;
        k = abs(k-x);
        if(i==0) g=k;
        else g=gcd(g,k);
    }
    cout<<g<<endl;
}


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

void koch(double x0, double y0, double x1, double y1, int n){
  if(n == 0){
    cout << x0 << " " << y0 << endl;
  } else {
    double x01 = x0 + (x1-x0)/3;
    double y01 = y0 + (y1-y0)/3;
    double x02 = x0 + (x1-x0)/2 - (y1-y0)*sqrt(3)/6;
    double y02 = y0 + (y1-y0)/2 + (x1-x0)*sqrt(3)/6;
    double x03 = x0 + (x1-x0)*2/3;
    double y03 = y0 + (y1-y0)*2/3;

    koch(x0, y0, x01, y01, n-1);
    koch(x01, y01, x02, y02, n-1);
    koch(x02, y02, x03, y03, n-1);
    koch(x03, y03, x1, y1, n-1);
  }
}

int main(){
    int n;
    cin >> n;
    koch(0,0,100,0,n);
    cout << 100 << " " << 0 << endl;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=1e5+10;
vector<map<ll,ll>> G(N);
vec d(N,inf);

ll dfs(ll f) {
  for(auto p:G[f]) {
    ll t=p.first;
    ll td=d[f]+p.second;
    if(d[t]==inf) {
      d[t]=td;
      if(!dfs(t)) return 0;
    }
    else if(d[t]!=td){
      return 0;
    }
  }
  return 1;
}

int main() {
  ll n,m;
  cin >> n >> m;
  for(ll i=0;i<m;i++) {
    ll l,r,d;
    cin >> l >> r >> d;
    G[l][r]=d;
    G[r][l]=-d;
  }
  for(ll i=1;i<=n;i++) {
    if(d[i]!=inf) continue;
    d[i]=0;
    if(!dfs(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int num(char ch) {
  if(ch=='I') return 1;
  if(ch=='V') return 5;
  if(ch=='X') return 10;
  if(ch=='L') return 50;
  if(ch=='C') return 100;
  if(ch=='D') return 500;
  if(ch=='M') return 1000;
}

int main() {
  string s;
  while(cin >> s) {
    int n=0,y=0;
    for(int i=s.size()-1; i>=0; i--) {
      int x=num(s[i]);
      if(x<y) n-=x;
      else {
	n+=x;
	y=x;
      }
    }
    cout << n << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll N;
  ll x[222222],y[222222];
  cin >> N;
  ll i;
  for(i=0;i<=N-1;i++)
    cin >> x[i] >> y[i];
  ll xx[222222],yy[222222];
  for(i=0;i<=N-1;i++){
    xx[i] = x[i] - y[i];
    yy[i] = x[i] + y[i];
    }
  ll mx,my;
  sort(xx,xx+N);
  sort(yy,yy+N);
  mx = xx[N-1] - xx[0];
  my = yy[N-1] - yy[0];
  if(mx > my) cout << mx <<endl;
  else cout << my <<endl;
}

Measured memory_bytes: 9820
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long 
int main(){
  ll e;
  while(cin >> e && e){
    ll m = 100000000000;
    for(ll z = 0; z * z * z <= e; z++){
      for(ll y = 0; y * y + z * z * z <= e; y++){
	m = min(m, y + z + e - y * y - z * z * z);
      }
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 3072
#include<stdio.h>

int main(void){
    int n = 0;
    scanf("%d", &n);
    char a[n];
    scanf("%s", a);
    int k = 0;
    scanf("%d", &k);
    char b;
    b = a[k-1];
    for(int i=0; i<n; i++){
        if(a[i] != b){
            a[i] = '*';
        }
    }
    printf("%s", a);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

    char A[81];
    char B[81];
    while (number_of_datasets-- > 0) {
        fill_n(A, 81, '\0');
        fill_n(B, 81, '\0');
        string input;
        cin >> input;
        if (input.length() > 80) {
            cin >> input;
            cout << "overflow" << endl;
            continue;
        }
        copy(input.rbegin(), input.rend(), A);
        cin >> input;
        if (input.length() > 80) {
            cout << "overflow" << endl;
            continue;
        }
        copy(input.rbegin(), input.rend(), B);

        for (char & n : A) {
            if (n == '\0') {
                break;
            }

            n -= '0';
        }

        for (char & n : B) {
            if (n == '\0') {
                break;
            }

            n -= '0';
        }

        char carry = 0;
        for (int i = 0; i < 81; i++) {
            A[i] += B[i] + carry;
            if (A[i] >= 10) {
                A[i] -= 10;
                carry = 1;
            } else {
                carry = 0;
            }
        }
        
        if (A[80] != 0) {
            cout << "overflow";
        } else {
            int last_valid_place = 0;
            for (int i = 80; i >= 0; i--) {
                if (A[i] != 0) {
                    last_valid_place = i;
                    break;
                }
            }

            for (int i = last_valid_place; i >= 0; i--) {
                A[i] += '0';
                cout << A[i];
            }
        }

        cout << endl;
    }
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
    int i;
    bool alphabet[26] = {false};
    string S;
    cin >> S;
    for (i = 0; i < S.length(); i++) alphabet[S[i]-'a'] = true;
    for (i = 0; i < 26; i++)
        if (!alphabet[i]) {
            cout << (char)(i+'a') << endl;
            return 0;
        }
    cout << "None" << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		long ans = 1;
		for(int i = 1;i<=n;i++){
			ans*=i;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25876
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 998244353;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 1e6+55;
int const inf = 2e16;
//int a[N];
int b[N];

void solve(){
    int i,j,l;  
    int a[5];
    for(i=0;i<5;i++){
        cin>>a[i];
    }
    for(i=0;i<5;i++){
        if(a[i] == 0) cout<<i+1<<endl;
    }
}               


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*


*/

Measured memory_bytes: 3604
d,g=[int(_) for _ in input().split()]
l=[0]+[list(map(int,input().split())) for _ in  range(d)]
def f(i,g):
	if i==0:return 10**9
	c=min(g//(100*i),l[i][0])
	s=100*i*c
	if c==l[i][0]:s+=l[i][1]
	if s<g:
		c+=f(i-1,g-s)
	return min(c,f(i-1,g))
print(f(d,g))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;



signed main(){  
    char a; cin >> a; 
    if(a <= 'Z')
        cout << "A";
    else
        cout << "a";
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


string to_string(string s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(char ch) {
	return string("'")+ch+string("'");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <class InputIterator>
string to_string (InputIterator first, InputIterator last) {
	bool start = true;
	string res = "{";
	while (first!=last) {
		if (!start) {
			res += ", ";
		}
		start = false;
		res += to_string(*first);
		++first;
	}
	res += "}";
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



const int mod=1e9+7;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
	return res;
	}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=200005;


void solve()
{  

	string s;
	cin>>s;
	int m1=(s[0]-'0')*10+(s[1]-'0');
	int m2=(s[2]-'0')*10+(s[3]-'0');
    if((m1>12||m1==0)&&(m2>0&&m2<=12))cout<<"YYMM";
    else if((m2>12||m2==0)&&(m1>0&&m1<=12))cout<<"MMYY";
    else if(m1<=12&&m2<=12&&m1>0&&m2>0)cout<<"AMBIGUOUS";
    else cout<<"NA";
	}
	
   
	
	

int main()
{   
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//cin>>tc;
    while(tc--)
	{
        solve();
		}
	
	}


Measured memory_bytes: 256
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	ll n;
	cin >> n;
	ll tp;
	cin >> tp;
	ll a[n+1], aa[n+1];
	memset(a, -1, sizeof a);
		memset(aa, 0, sizeof aa);
	while(tp--){
		string s;
		ll b;
		cin >> b >> s;
		if(s == "AC" && a[b] == -1) a[b] = 1;
		else if(a[b] == 1) continue;
		else aa[b]++;
	}
	ll count = 0, sum = 0;
	for(int i = 0; i <= n; i++){
		if(a[i] == 1)
			sum += aa[i], count++;
	}
	cout << count << " " << sum << endl;
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}
	


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

int main()
{
    ll N; cin >> N;
    vector<ll> a(N, 0);
    ll sum = 0;
    rep(i,N) {
        cin >> a[i];
        sum += a[i];
    }
    ll asum = 0;
    ll minv = 0;
    rep(i,N-1) {
        asum += a[i];
        ll b = sum - asum;
        ll tmp = abs(b-asum);    
        if (i == 0) {
            minv = tmp;
        }
        else if (minv > tmp) {
            minv = tmp;
        }
    }
    cout << minv << endl;

    

}

Measured memory_bytes: 4820
n = gets.to_i
heights = gets.split.map(&:to_i)

i = 0
cnt = 0
records = [0]

if n >= 2 then
  while i <= n-2 do
    if heights[i]>=heights[i+1] then
      cnt += 1
      records= records.push(cnt)
    else
      records= records.push(cnt)
      cnt = 0
    end
    i += 1
  end
end
  
puts records.max

Measured memory_bytes: 9476
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int a,n,m;
    cin >> a >> n >> m;
    int i = 1;
    int x,y;
    int ans = 0;
    while(pow(a+i,n)<=m) {
        x = pow(a+i,n);
        y = 0;
        while(x>0) {
            y += x%10;
            x /= 10;
        }
        if(y == i)ans++;
        i++;
    }
    cout << ans << endl;
}


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

public class Program
{
    public static void Main(string[] args)
    {
        var line = Console.ReadLine();
        var spl = line.Split(' ');
        var a = int.Parse(spl[0]);
        var b = int.Parse(spl[1]);
        Console.WriteLine(Math.Max(a + b, Math.Max(a - b, a * b)));
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define txt freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout)
#define a3 INT_MAX
#define i3 INT_MIN
#define a6 INT64_MAX
#define i6 INT64_MIN
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define div2(a) (!(a&1))
#define deb(x) cout<<(#x)<<" "<<(x)<<"\n";
#define newl cout<<"\n" 
#define all(s) s.begin(),s.end()
#define pi 3.14159265358979323846
#define fp(x) fixed<<setprecision(x)<<
template<class T>
T mod(T a){
   if(a < 0){
       a += 1000000007;
   }
   return a%1000000007; 
}
template<class T>
T addmod(T a, T b){
   return (mod(a) + mod(b)) % 1000000007;
}
template<class T>
T prodmod(T a, T b){
   return (mod(a) * mod(b)) % 1000000007;
}
template<class T>
T bin_exp(T a, T b)
{
   T res = 1;
   T temp = 1;
   if (b <= 1)
       return a;
   if (b %2 == 0)
       res = bin_exp(a * a, b / 2);
   else
   {
       res *= a;
       temp = bin_exp(a, --b);
   }
   return res * temp;
}
template<class T>
T bin_expmod(T a, T b)
{
   T res = 1;
   T temp = 1;
   if (b <= 1)
       return a;
   if (b %2 == 0)
       res = bin_expmod(prodmod(a,a), b / 2);
   else
   {
       res = prodmod(a,res);
       temp = bin_exp(a, --b);
   }
   return prodmod(res , temp);
}

template<class T>
int digit(T a)
{
   vector<long long> dig = {
       0,
       9,
       99,
       999,
       9999,
       99999,
       999999,
       9999999,
       99999999,
       999999999,
       9999999999,
       99999999999,
       999999999999,
       9999999999999,
       99999999999999,
       999999999999999,
       9999999999999999,
       99999999999999999,
       999999999999999999,
       INT64_MAX};
   auto it = lower_bound(dig.begin(), dig.end(), a);
   int idx = (it - dig.begin());
   return idx;
}
template<class T>
int sumAllInts(T n){
   int a = 1;
   int su = 0;
   while(n){
       su += n%10;
       n/=10;
   }
   return su;
}
template<class T>
void split(char c,T s){
   int n = s.size();
   int i = 0;
   while ((cout<<s[i],i+=1) && (i<n) && (cout<<c<<' '));
}
void solve(){
   int n; cin>>n;
   int payBack = n/15;
   payBack*=200;
   n*= 800;
   n-=payBack;
   cout<<n;
   
}
int main(){
   quickie;
   //txt;
   int t = 1;
   while(t--){
       solve(); 
       newl; 
   } 
   return 0;
}

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

using namespace std;
#define endl '\n'
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const int maxn=200005;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;

namespace Reader{
    const int L=1<<20;
    char buf[L],*s,*t;
    inline char nc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,L,stdin);
            if(s==t)return EOF;
        }
        return *s++;
    }
    template<class T>inline bool readInt(T&x){
        int c,ng=1;
        for(c=nc();~c&&c<33;c=nc());
        if(c==-1)return 0;
        if(c=='-')ng=-1,c=nc();
        for(x=0;c>32;x=(x+(x<<2)<<1)+(c^'0'),c=nc());
        x*=ng;return 1;
    }
    inline int readString(char *dest){
        int len=0;char c;
        for(c=nc();isalpha(c);dest[len++]=c,c=nc());
        dest[len]='\0';return len;
    }
}
using namespace Reader;

char mp[5][5];

int main () {
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    for(int i=1;i<=2;++i){
        for(int j=1;j<=3;++j){
            cin>>mp[i][j];
        }
    }
//    for(int i=1;i<=2;++i){
//        for(int j=1;j<=3;++j){
//            cout<<mp[i][j];
//        }
//    }
    if(mp[1][2]==mp[2][2]&&mp[1][1]==mp[2][3]&&mp[1][3]==mp[2][1])
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
// abc.cpp :
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define irp(i,n) for(int i=(n);i>=0;i--)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
void bye(auto x, int code=0){cout<<(x)<<endl;exit(code);}

void p1(vi v){
  for(auto a: v){ot(a);ot(",");}
}
void p2(vvi &x){
  for(auto v: x){ot("[");p1(v);ot("]\n");}
}

int compare(pair<int,int> &a, pair<int,int> &b){
	int r = a.first<b.first || a.first==b.first && a.second>b.second;
	return r;
}

int main(){
	int n,m;cin>>n>>m;
	vvi jb(m);
	up(i,0,n,1){
		int a,b;cin>>a>>b;
		if(m<a) continue;
		jb[m-a].push_back(b);
	}

	priority_queue<int> q;

	ll ans = 0;
	irp(i, m-1){
		up(j, 0, jb[i].size(), 1){
			q.push(jb[i][j]);
		}
		if(!q.empty()){
			ans += q.top();
			q.pop();
		}
	}

	ote(ans);
}

Measured memory_bytes: 5632
// Example program
#include <iostream>
#include <string>
using namespace std;

int main(){
  int x=0,n;
  string s;
  cin>>n>>s;
  int max=0;
  for(int i=0;i<n;i++){
      if(s[i]=='I'){
          ++x;
      }else if(s[i]=='D'){
        --x;   
      }
      if(x > max){
          max = x;
      }
  }
  cout<<max;
  return 0;
}


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

using namespace std;
typedef long long ll;

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

  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //cout.setf(ios::fixed), cout.precision(20);

  ll n,k;
  cin >> n >> k;
  ll arr[n];
  ll dp[n];
  for(int j=0;j<n;j++)
    cin >> arr[j];

  dp[n-1]=0;
  for(int j=n-2;j>=0;j--)
    {
      ll temp=999999999999999;
      for(int i=1;i<=k;i++)
	  if(j+i < n)
	    temp=min(dp[j+i] + abs(arr[j+i]-arr[j]),temp);
      dp[j]=temp;
    }
 
 
  cout<<dp[0]<<" ";
  return 0;
}



Measured memory_bytes: 1792
import numpy as np
import statistics

n = int(input())
inputs = [int(i) for i in input().split()]
a = np.array(inputs)

z = a - np.array(range(1, n + 1))
nums = list(set(inputs))

print(int(sum(abs(z - np.ones(len(a)) * statistics.median(z)))))


Measured memory_bytes: 38356
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  ll ans = 0, a;
  rep(i, N){
    cin >> a;
    ans += a - 1;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;


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

		int H = sc.nextInt();
		int W = sc.nextInt();
		boolean result = true;

		String S[] = new String[50];

		for (int i = 0; i < H; i++) {
			S[i] = sc.next();
		}

		loop1: for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (S[i].charAt(j) == '.') {
					continue;
				}

				boolean existBlack = false;

				if (i - 1 >= 0 && S[i - 1].charAt(j) == '#') {
					existBlack = true;
				} else if (i + 1 < H  && S[i + 1].charAt(j) == '#') {
					existBlack = true;
 				} else if (j - 1 >= 0 && S[i].charAt(j - 1) == '#') {
					existBlack = true;
 				} else if (j + 1 < W && S[i].charAt(j + 1) == '#') {
					existBlack = true;
				}

				if (!existBlack) {
					result = false;
					break loop1;
				}
			}
		}

		System.out.println(result ? "Yes" : "No");
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////

int main() {

	int A, B, C, K;
	cin >> A >> B >> C >> K;

	ll ans = 0;
	K -= A;
	if (K < 0)ans += K + A;
	else {
		ans += A;

		K -= B;
		if (K > 0) {
			ans -= K;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main()
{
	cin>>n>>a>>b;
	if(a==b){
		cout<<"0"<<endl;
		return 0;
	}
	if((b-a)%2==0)
	{
		cout<<(b-a)/2<<endl;
		return 0;
	}
	cout<<min(a-1,n-b)+(b-a)/2+1<<endl;
	
}

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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n,m;
    cin>>n>>m;
    vector<int>v(n+1,0);
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        v[a]++;
        v[b]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(v[i]%2!=0)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,a[200000],b[200000],ans=0;
    double h;
    cin>>n>>h;
    rep(i,n) cin>>a[i]>>b[i];
    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());
    for(int i=0;a[0]<=b[i]&&h>0;i++) h-=b[i],ans++;
    if(h<=0) cout<<ans;
    else cout<<ans+int(ceil(h/a[0]));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  int a,b,c,d,e,f;cin>>a>>b;
  c=a+b;
  d=a*b;
  e=a-b;
  f=max(max(c,d),e);
  cout << f << endl;
}


Measured memory_bytes: 256
from bisect import bisect_right
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

A_m = sorted(set(A))
n = len(A_m)
ok = n-1
ng = -1
while ng+1 < ok:
    c = (ok+ng)//2
    a = A_m[c]
    idx = bisect_right(A, a)
    if idx > N-P:
        ok = c
        continue
    if M < A[-P]-a:
        ng = c
        continue
    s = 0
    for aa in A[-P:idx-1:-1]:
        s += aa-a
    if s > M*(N-V):
        ng = c
    else:
        ok = c
a = A_m[ok]
print(sum(a<=aa for aa in A))


Measured memory_bytes: 14652
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val S = in.next().reverse

  //
  val imos = new Array[Int](N+1)
  for (i <- 0 to N) {
    if (S(i) == '0')
      imos(i) = 1
  }

  for (i <- 1 to N)
    imos(i) += imos(i-1)

  // 条件を満たす最小の値を返す
  def binarySearch(_min: Int, _max: Int, base: Int): Int = {
    def check(i: Int): Boolean = {
      imos(i) == base
    }

    def func(min: Int, max: Int): Int = {
      val mid: Int = (max + min) / 2
        (max - min) match{
        case 0 | 1 =>
          check(min) match{
            case true  => min
            case false => max
          }
        case _ =>
          (check(mid)) match{
            case true  => func(min, mid)
            case false => func(mid, max)
          }
      }
    }

    func(_min, _max)
  }

  var ans = List[Int]()

  var now = 0
  var flag = false
  breakable {
    while (now + M < N) {
      if (imos(now) == imos(now+M)) {
        flag = true
        break
      }
      else {
        val next = binarySearch(now+1, now+M, imos(now+M))
        ans = (next - now) :: ans
        now = next
      }
    }
  }

  ans = (N-now) :: ans

  if (flag)
    println(-1)
  else
    println(ans.mkString(" "))
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 39784
#include <iostream>
#include <cmath>
#include <vector>

int main()
{
  int N, D;
  std::cin >> N >> D;
  
  std::vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++)
  {
    std::cin >> X[i] >> Y[i];
  }
  
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    double d = std::sqrt(std::pow(X[i], 2) + std::pow(Y[i], 2));
    if (D >= d)
      count++;
  }
  
  std::cout << count;
  
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  if (A + B < C + D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    ll N, T;
    cin >> N >> T;
    int max_a[N], A[N];
    int max_v = 0;
    rep(i, 0, N) cin >> A[i];

    for(int i = N - 1; i >= 0; i--) {
        max_v = max(max_v, A[i]);
        max_a[i] = max_v;
    }

    max_v = -1e9 - 7;
    int rsl = 0;
    rep(i, 0, N) {
        int tmp = max_a[i] - A[i];
        if(max_v < tmp) {
            max_v = tmp;
            rsl = 1;
        } else if(max_v == tmp) rsl++;
    }
    cout << rsl << endl;



}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<string>s(n);
    map<string ,int>mp;
    for (int i = 0; i < n; i++)
    {
        cin>>s[i];
        mp[s[i]]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
     cout<<"WA x "<<mp["WA"]<<endl;
      cout<<"TLE x "<<mp["TLE"]<<endl;
       cout<<"RE x "<<mp["RE"]<<endl;

    return 0;
}

Measured memory_bytes: 6376
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int n, ma, mb;
    scanf("%d%d%d", &n, &ma, &mb);
    int a[n], b[n], c[n];
    rep(i, n) scanf("%d%d%d", &a[i], &b[i], &c[i]);
    
    const int INF = mod;
    int dp[2][410][410];
    rep(i, 2)rep(j, 410)rep(k, 410) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i, n){
        rep(j, 410)rep(k, 410)if(dp[0][j][k] >= 0){
            dp[1][j][k] = min(dp[1][j][k], dp[0][j][k]);
            if(j+a[i] < 410 && k+b[i] < 410){
                dp[1][j+a[i]][k+b[i]] = min(dp[1][j+a[i]][k+b[i]], dp[0][j][k] + c[i]);
            }
        }
        rep(j, 410)rep(k, 410){
            dp[0][j][k] = dp[1][j][k];
            dp[1][j][k] = INF;
        }
    }
    
    int ans = INF;
    for(int i=1; ma*i<410 && mb*i<410; ++i){
        ans = min(ans, dp[0][ma*i][mb*i]);
    }
    
    printf("%d\n", (ans == INF ? -1 : ans));
}

Measured memory_bytes: 1536
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N,Q);
    Cins(S);
    vector<int> l(Q),r(Q);
    rep(i,Q){
        cin >> l[i] >> r[i];
        l[i]--;
    }
    vector<int> accSum(N+1,0);
    rep(i,N) accSum[i+1] += accSum[i] + ((S.substr(i,2)=="AC")? 1:0);
    rep(i,Q){
        cout << accSum[r[i]-1] - accSum[l[i]] << nn;
    }
    return 0;
}

Measured memory_bytes: 2256