akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long int lli;

const lli inf = 1707050917070509;

inline lli dist(lli x, lli y)
{
	if(x <= y) return y-x;
	else return inf;
}

int main(void)
{
	lli x, y;
	scanf("%lld%lld", &x, &y);
	printf("%lld\n", min(min(dist(x, y), dist(-x, y)+1), min(dist(x, -y)+1, dist(-x, -y)+2)));
}

Measured memory_bytes: 256
def dfs(s,plus,i):

    i += 1

    if i == 4:
        ans = int(s[0])
        for j in range(1,4):
            ans += int(s[j])*plus[j-1]
        if ans == 7:
            ret = s[0]
            for k in range(1,4):
                if plus[k-1] == 1:
                    ret += '+'
                else:
                    ret += '-'
                ret += s[k]
            ret += '=7'
            print(ret)
            exit()
        return

    plus[i-1] = 1
    dfs(s, plus, i)

    plus[i-1] = -1
    dfs(s, plus, i)

    return


dfs(input(), [0,0,0], 0)


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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define sc second
#define ft first
#define int long long
void prip(int a[], int n){f(n) cout << a[i] << ' '; cout << '\n';}

const int inf = 2e9, mxp = 10, maxn = 2e6, mod = 1e9 + 7;
int bp(int a, int n)
{
    if(n == 0) return 1;
    if(n & 1ll) return (a * bp(a, n - 1)) % mod;
    int res = bp(a, n >> 1);
    return (res * res) % mod;
}
int fc[maxn + 1], rc[maxn + 1];
int cnk(int n, int k)
{
    if(k > n) return 0;
    int ans = (fc[n] * rc[k]) % mod;
    return (ans * rc[n - k]) % mod;
}

main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    fc[0] = 1, rc[0] = 1;
    for(int i = 1; i <= maxn; i++) fc[i] = (fc[i - 1] * i) % mod;
    for(int i = 1; i <= maxn; i++) rc[i] = bp(fc[i], mod - 2);
    ic(k)
    string s;
    cin >> s;
    int n = s.size();
    int pw[k + 1];
    pw[0] = 1;
    for(int i = 1; i <= k; i++) pw[i] = (pw[i - 1] * 25) % mod;
    int p = 1, ans = 0;
    for(int i = 0; i <= k; i++)
    {
        int ad = (p * pw[k - i]) % mod;
        ans = (ans + ad * cnk(n - 1 + k - i, k - i)) % mod;
        p = (p * 26) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 43432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout<<s<<endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}


int main()
{
    int y,m,d;
    char c1,c2;
    cin>>y>>c1>>m>>c2>>d;
    if(m>4){
        p("TBD");
    }else{
        p("Heisei");
    }

}

Measured memory_bytes: 256
class UFTree
  def initialize(n)
    @parent = (0...n).to_a
    @rank = Array.new(n, 0)
  end
     
  def find(x)
    return x if @parent[x] == x
    return @parent[x] = find(@parent[x])
  end
     
  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b
    if @rank[a] < @rank[b]
      @parent[a] = b
    else
      @parent[b] = a
      @rank[a] += 1 if @rank[a] == @rank[b]
    end
  end
end
    
def smaller(a, b)
  a < b ? a : b
end
    
N = gets.to_i
G = []
(0...N).each do |i|
  a, b = gets.split.map(&:to_i)
  G << [a, b, i]
end

Q = []
H = G.sort{|a, b| a[0] <=> b[0]}
H.zip(H.drop(1)).take(N - 1).each do |a, b|
  Q << [a[2], b[2], smaller((a[0] - b[0]).abs, (a[1] - b[1]).abs)]
end
     
J = G.sort{|a, b| a[1] <=> b[1]}
J.zip(J.drop(1)).take(N - 1).each do |a, b|
  Q << [a[2], b[2], smaller((a[0] - b[0]).abs, (a[1] - b[1]).abs)]
end

tree = UFTree.new(N)
cost = 0
n = 0
Q.sort!{|a, b| a[2] <=> b[2]}.each do |a, b, c|
  break if n == N
  next if tree.find(a) == tree.find(b)
  cost += c
  tree.unite(a, b)
  n += 1
end
     
puts cost

Measured memory_bytes: 26968
s = input()
 
oddStep = ['R','U','D']
evenStep = ['L','U','D']
CNST_NO = 'No'
CNST_YES = 'Yes'
good_step = CNST_YES
 
for i in range( len( s ) ):
  if i % 2 == 1: # 0 start
    if not ( s[ i ] in evenStep ):
      good_step = CNST_NO
  else:
    if not( s[ i ] in oddStep ):
      good_step = CNST_NO
  if good_step == CNST_NO:
    break
print( good_step )

Measured memory_bytes: 3064
<?php

while (TRUE) {
    $a = fscanf(STDIN, '%d %d %d %d');
    $b = fscanf(STDIN, '%d %d %d %d');
    if (!$a) {
        break;
    }
    $hit  = 0;
    $blow = 0;
    for ($i = 0; $i < 4; $i++) {
        for ($j = 0; $j < 4; $j++) {
            if ($a[$i] !== $b[$j]) {
                continue;
            }
            if ($i === $j) {
                $hit++;
            } else {
                $blow++;
            }
        }
    }

    echo sprintf('%d %d', $hit, $blow);
    echo PHP_EOL;
}

Measured memory_bytes: 6600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int r = 0;
        while (b * (r + 1) + (r + 2) * c <= a) {
            r++;
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	ll a,b;
	cin>>a>>b;
	ll temp;ll jw=10000;
	ll tempa;
	ll cnt=0;
	for(ll i=a;i<=b;i++){
		temp=0;
		tempa=i;
		jw=10000;
		while(jw!=0){
			temp+=(tempa%10*jw);
			jw/=10;
			tempa/=10;
		}
		if(temp==i){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::input;
fn main (){
let mut d: i128;
let mut t: i128;
let mut s: i128;

input! {
    d: i128,
    t: i128,
    s: i128,
}
 if d <= t*s {
     println!("Yes");
 }else{
     println!("No");
 }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

string s[30];
int c[30][30];
vector<P> v;
int d[30][30];
int n,m;

void bfs(int k) {
  fill(d[0],d[30],MAX);
  d[v[k].F][v[k].S]=0;
  queue<P> que;
  que.push(v[k]);
  while(!que.empty()) {
    P p=que.front();que.pop();
    int nx=p.F,ny=p.S;
    rep(i,v.size()) {
      if(v[i].F==nx && v[i].S==ny) {
	c[k][i]=d[nx][ny];
	c[i][k]=d[nx][ny];
      }
    }
    rep(i,4) {
      int x=nx+dx[i],y=ny+dy[i];
      if(!check(n,m,x,y) || s[x][y]=='x' || d[x][y]<=d[nx][ny]+1) continue;
      d[x][y]=d[nx][ny]+1;
      que.push(P(x,y));
    }
  }
}
  
int main() {
  while(cin >> m >> n && n) {
    fill(c[0],c[30],MAX);
    v.clear();
    int sx,sy;
    rep(i,n) {
      R s[i];
      rep(j,m) {
	if(s[i][j]=='*') v.pb(P(i,j));
	if(s[i][j]=='o') sx=i,sy=j;
      }
    }
    v.pb(P(sx,sy));
    rep(i,v.size()) bfs(i);
    int k=v.size()-1;
    int dp[1<<k][k];
    fill(dp[0],dp[1<<k],MAX);
    rep(i,k) dp[1<<i][i]=c[i][k];
    REP(t,1,1<<k) {
      rep(i,k) {
	rep(j,k) {
	  if(!(t&(1<<k)))dp[t|(1<<j)][j]=min(dp[t|(1<<j)][j],dp[t][i]+c[i][j]);
	}
      }
    }
    int ans=MAX;
    rep(i,k) ans=min(ans,dp[(1<<k)-1][i]);
    if(ans==MAX) ans=-1;
    pr(ans);
  }
  return 0;
}


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

using namespace std;

const int MAX = 100001;

int main() {
	int n;

	cin >> n;

	vector<pair<int, int>> odd(MAX), even(MAX);

	for (int i = 0; i < MAX; i++) {
		odd[i].first = even[i].first = 0;
		odd[i].second = even[i].second = i;
	}

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		if (i % 2 == 0) even[tmp].first++;
		else odd[tmp].first++;
	}

	sort(even.begin(), even.end(),greater<pair<int,int>>());
	sort(odd.begin(), odd.end(), greater<pair<int, int>>());

	int ans = 0;
	if (even[0].second != odd[0].second) {
		ans = n - even[0].first - odd[0].first;
	}
	else {
		if (even[0].first + odd[1].first > even[1].first + odd[0].first) {
			ans = n - even[0].first - odd[1].first;
		}
		else {
			ans = n - even[1].first - odd[0].first;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ans := "No"
	cnt := 0
	var d1, d2 int
	for i := 0; i < n; i++ {
		fmt.Scan(&d1, &d2)
		if d1 == d2 {
			cnt++
		} else {
			cnt = 0
		}
		if cnt >= 3 {
			ans = "Yes"
		}
	}
	fmt.Println(ans)
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll cnt = 0;
    REP(i,0,N) {
        ll x, y;
        cin >> x >> y;
        if(x*x+y*y <= D*D) ++cnt;    
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 3632
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

//const int INF = INT_MAX / 2;
const int MOD = (int)1e9 + 7;
const int P = 2 * 1e5;


int main() {
	char x;
	cin >> x;
	switch (x) {
	case 'A':
		printf("T");
		break;
	case 'C':
		printf("G");
		break;
	case 'G':
		printf("C");
		break;
	default:
		printf("A");
		break;
	}

	/*
	int n;
	int c[P + 5] = {0};
	int out;
	cin >> n >> c[0];
	int j = 1;
	for (int i = 1; i < n;i++) {
		cin >> c[j];
		if (c[j-1] != c[j]) j++;
	}
	for (int i = 0; i < n; i++) {
		for (int k = i + 1; k < n; k++) {

		}
	}
	reverse(S.begin(), S.end());
	for (size_t i = 0; i < S.size() - 1;) {
		int counter = 0;
		if (S[i] == 'A' && S[i + 1] == 'W') {
		
			for (size_t j = i + 1; j < S.size();j++) {
				if (S[j] != 'W') break;
				else counter++;
			}
			for (size_t j = i; j < i + counter; j++) {
				S[j] = 'C';
			}
			S[i + counter] = 'A';
			
		}
		i += counter + 1;
	}
	reverse(S.begin(), S.end());
	*/
	//cout <<  << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    A = [ria() for _ in range(3)]
    N = ri()
    B = [ri() for _ in range(N)]
    d = set()
    for n in B: d.add(n)

    for i in range(3):
        cnt = 0
        for j in range(3):
            if A[i][j] in d: cnt += 1
        if cnt == 3:
            print("Yes")
            sys.exit(0)
    for j in range(3):
        cnt = 0
        for i in range(3):
            if A[i][j] in d: cnt += 1
        if cnt == 3:
            print("Yes")
            sys.exit(0)

    if A[0][0] in d and A[1][1] in d and A[2][2] in d:    
            print("Yes")
            sys.exit(0)
    if A[0][2] in d and A[1][1] in d and A[2][0] in d:    
            print("Yes")
            sys.exit(0)

    print("No")

if __name__ == "__main__":
    main()
    


Measured memory_bytes: 12524
#include <iostream>

using namespace std;

int main()
{
	int x, soma=17;
	for(int i=0;i<3;i++)
	{
		cin >> x;
		soma = soma - x;
	}
	if(soma==0)
		cout << "YES"<< endl;
	else
		cout <<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,m,x,y,ans=0,cnt=0,tmp;
string s;
int main(){
  cin >> n >> m >> x >> y;
  long long a[n],b[m];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  sort(a,a+n);
  sort(b,b+m);
  for(int i=x+1;i<y;i++){
    if(a[n-1]<i and b[0]>=i){
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	int n=s.length();
	cout<<s;
	if(s[n-1]=='s')
	cout<<"es";
	else
	cout<<"s";	
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    long long n,m;
    scanf("%lld%lld",&n,&m);
    if(n==1&&m==1){
        printf("%d\n",1);
        return 0;
    }
    if(n==1||m==1){
        printf("%lld\n",n*m-2);
        return 0;
    }
    if(n==2||m==2){
        printf("0\n");
        return 0;
    }
    long long sum=n*m-2ll*n-2ll*m+4ll;
    printf("%lld\n",sum);
    return 0;
}

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

int main() {
    int n, h[100010];
    int ans = 0, tans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n-1; i++) {
        if (h[i+1] <= h[i]) {
            tans++;
        } else {
            ans = max(ans, tans);
            tans = 0;
        }
    }
    ans = max(ans, tans);
    cout << ans << endl;
}

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

int main()
{
    string s,t; cin >> s >> t;
    int cnt=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            cnt++;
        }
    }
    cout << cnt;
    /*int cnt[30]={0},c[30]={0};
    for(int i=0;i<s.size();i++)
    {
        cnt[s[i]-'a']++;
        c[t[i]-'a']++;
    }
    for(int i=0;i<30;i++)
    {
        if(c[i]!=cnt[i])
    }*/
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


auto solve() {
    int N;
    cin >> N;

    if(N == 7 || N==5 || N==3)
        return true;
    else
        return false;
}

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


//    cout << solve() << endl;
    cout << (solve()?"YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))
t_sum = 0

if N == 1 :
    print(T)
else :
    for i in range(N) :
        if i == N - 1 :
            t_sum += T
        else :
            if t[i+1] - t[i] < T :
                t_sum += (t[i+1] - t[i])
            else :
                t_sum += T

    print(t_sum)

Measured memory_bytes: 25200
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
  
  int n, q, command, t, x;
  
  cin >> n;
  queue<int> Q[n];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> command;
    
    if(command == 0){
      cin >> t >> x;
      Q[t].push(x);
    }else if(command == 1){
      cin >> t;
      if(Q[t].size()) cout << Q[t].front() << endl;
    }else if(command ==2){
      cin >> t;
      if(Q[t].size()) Q[t].pop();
    }
  }
  
  return 0;
}


Measured memory_bytes: 4332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String ans;
		Scanner scn = new Scanner(System.in);
		String N = scn.nextLine();
		char n = N.charAt(N.length()-1);
		if(n == '3') {
			ans = "bon";
		}else if(n == '0' || n == '1' || n == '6' || n == '8') {
			ans = "pon";
		}else {
			ans = "hon";
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 26944
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<"a > b"<<"\n";
  }
  if(a<b){
    cout<<"a < b"<<"\n";
  }if(a==b){
    cout<<"a == b"<<"\n";
  } 
  return(0);
}



Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str;
		char[] chr= new char[1200];

		str=scan.nextLine();
		chr=str.toCharArray();

		for(int i=0;i<chr.length;i++){
			str=String.valueOf(chr[i]);
		 if(Character.isUpperCase(chr[i])){
			 str=str.toLowerCase();
		}else if(Character.isLowerCase(chr[i])){
			str=str.toUpperCase();
		}
		  chr[i]=str.charAt(0);
		}

		str=String.copyValueOf(chr);
		System.out.println(str);
	}

}

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

int main(){
  int k,n;
  cin >> k >> n;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  sort(A.begin(),A.end());
  int ans = 0;
  rep(i,n-1){
    ans = max(ans,A[i+1]-A[i]);
    
  }
  ans = max(ans,A[0]+k-A[n-1]);
  cout << k - ans << endl;
  return 0;
}


Measured memory_bytes: 1024
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())

for i in range(n):
    b, f, r, v = map(int, input().split())
    rooms[b-1][f-1][r-1] += v

for i in range(len(rooms)):
    for j in range(len(rooms[0])):
        for k in range(len(rooms[0][0])):
            print(f' {rooms[i][j][k]}', end='')
        if j!= len(rooms[0])-1:print()
    print()
    if i!=len(rooms)-1:
        print('####################')


Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
int n,m;
pair<int,int> a[10009];
vector<int> v[10009];
int vis[10009];
int dfs(int i,int p)
{
    if(vis[i]==1)return 0;
    if(i==p)return 1;
    vis[i]=1;
    for(int j=0;j<v[i].size();j++)
    {
        int k=v[i][j];
        if(dfs(k,p))return 1;
    }
    return 0;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        a[i].first=x;
        a[i].second=y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int sum=0;
    for(int i=0;i<m;i++)
    {
        memset(vis,0,sizeof(vis));
        int x=a[i].first,y=a[i].second;
        for(int j=0;j<v[x].size();j++)
            if(v[x][j]==y)
                v[x].erase(v[x].begin()+j,v[x].begin()+j+1);
        if(!dfs(x,y))
            sum++;
        v[x].push_back(y);
    }
    cout<<sum;
}
/*
#include <bits/stdc++.h>
using namespace std;
long long n,k;
pair<long long,long long> a[1009];
long long max1=LONG_LONG_MAX;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i].first>>a[i].second;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            long long x=a[i].first,xx=a[j].first;
            long long y=a[i].second,yy=a[j].second;
            if(x>xx)swap(x,xx);
            if(y>yy)swap(y,yy);
            int sum=0;
            for(int k=0;k<n;k++)
            {
                if(a[k].first>=x&&a[k].first<=xx&&a[k].second>=y&&a[k].second<=yy)
                    sum++;
                //else if(a[k].first>=y&&a[k].first<=yy&&a[k].second>=x&&a[k].second<=xx)
                  //  sum++;
            }
            if(sum>=k)
                max1=min((long long)max1,(long long)abs(x-xx)*abs(y-yy));
        }
    }
    if(max1==LONG_LONG_MAX)
        cout<<-1;
    else
    cout<<(long long)max1;
}
*/


Measured memory_bytes: 512
#include<iostream>
#include<string>
int main() {
	std::string n;
	std::cin>>n;
	if (n == "a") {
		std::cout << "vowel" << std::endl;
	}
	else if (n == "i") {
		std::cout << "vowel" << std::endl;
	}
	else if (n == "u") {
		std::cout << "vowel" << std::endl;
	}
	else if (n == "e") {
		std::cout << "vowel" << std::endl;
	}
	else if (n == "o") {
		std::cout << "vowel" << std::endl;
	}
	else {
		std::cout << "consonant" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for _ in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
for i in range(h):
    for j in range(w):
        c=0
        if s[i][j]==".":
            continue
        for d in range(4):
            ni=i+dy[d]
            nj=j+dx[d]

            if ni<0 or h<=ni:
                continue
            if nj<0 or w <=nj:
                continue
            if s[ni][nj]=="#":
                c=1
        if c==0:
            print("No")
            exit()
print("Yes")

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

using namespace std;

int a[2000010];

int main(){
	int l=100000,r=0;
	int n,k;
	cin>>n>>k;
	int d;
	for(int i=1;i<=n;i++)
	{
		cin>>d;
		a[d]++;
		l=min(l,d);
		r=max(r,d);
	}
	
	if(r-l+1<=k) {
		cout<<0;
		return 0;
	}
	sort(a+l,a+r+1);
	
	int ans=0;
	while(r-l+1>k)
	{
		ans+=a[l];
		l++;
	}
	cout<<ans;
	return 0;
}

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

int main(void){
    long long int i, j, k, n, m, ans=0, po=0, x[5], bb = 0;
    scanf("%lld %lld %lld", &n, &m, &k);
    long long int a[n+1], b[m+1];
    a[0] = 0;
    b[0] = 0;
    for(i=1; i<n+1; i++) scanf("%lld", &a[i]);
    for(i=1; i<m+1; i++) scanf("%lld", &b[i]);
    for(i=1; i<n+1; i++) a[i] += a[i-1];
    for(i=1; i<m+1; i++) b[i] += b[i-1];
    for(i=n; i>=0; i--){
        if(a[i]<=k){
            while(1){
                if(bb>=m||a[i]+b[bb+1]>k) break;
                bb++;
            }
            if(i+bb>ans) ans = i+bb;
        }
    }
    printf("%lld", ans);
     
    
}

Measured memory_bytes: 4856
#include <algorithm>
#include <iostream>

int main() {
  uint64_t N;
  std::cin >> N;

  uint64_t result = N + 1;
  for (uint64_t i = 2; i * i <= N; ++i) {
    if (N % i == 0) {
      const uint64_t j = N / i;
      result = std::min(result, i + j);
    }
  }

  std::cout << (result - 2);
  return 0;
}


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

string solve(string a,string b){
    int A = a.size();
    int B = b.size();
    int r = 0;
    while(!(r<=N && (N-r)%A==0)) r += B;
    string res;
    while(res.size() < N-r) res += a;
    while(res.size() < N)   res += b;
    return res;
}

int main(){
    string s,t;
    cin>>N>>s>>t;
    cout<<min(solve(s,t),solve(t,s))<<endl;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int min;
    int temp;
    int count=1;
    cin>>min;
    for (int i=1; i<n; i++){
        cin>>temp;
        if (temp<=min){ 
            min = temp;
            count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, d[3003][3003], mod = 1000000007;
string s;
int main() {
    cin >> n >> s;
    for (int i = 1; i <= n; i++) d[1][i] = 1;
    for (int i = 2; i <= n; i++) {
        if (s[i - 2] == '<') {
            for (int j = 1; j <= n - i + 1; j++) {
                d[i][j] = (d[i][j - 1] + d[i - 1][j]) % mod;
            }
        } else {
            for (int j = n - i + 1; j; j--) {
                d[i][j] = (d[i][j + 1] + d[i - 1][j + 1]) % mod;
            }
        }
    }
    cout << d[n][1] << '\n';
}

/*
 d[i][j]=d[i][j-1]+d[i-1][j]
 d[i][j]=d[i][j+1]+d[i-1][j+1]
 d[i][j+1]=d[i-1][n-i+1]+d[i-1][n-i]+...
 */


Measured memory_bytes: 35200
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

namespace SieveLP {

#define MAXP 1000000

// Linear-time prime sieve
// http://e-maxx.ru/algo/prime_sieve_linear

int lp[MAXP+1];  // lp[n] = least prime divisor of n
vector<int> primes;
void sieve() {
   for (int i = 2; i <= MAXP; ++i) {
      if (lp[i] == 0) {
         lp[i] = i;
         primes.push_back(i);
      }
      for (int j = 0; j < int(primes.size()) && primes[j] <= lp[i]; ++j) {
         llong xj = i * 1LL * primes[j];
         if (xj > MAXP) break;
         lp[xj] = primes[j];
      }
   }
}

vector<int> factorize(int n) {
   vector<int> res;
   while (n > 1) {
      int p = lp[n];
      if (res.empty() || res.back() != p)
         res.push_back(p);
      n /= p;
   }
   return res;
}

}


int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   SieveLP::sieve();

   int N;
   cin >> N;

   VI A(N);
   REP(i, N)
      cin >> A[i];

   VI freq(MAXP+1);
   REP(i, N) {
      VI pf = SieveLP::factorize(A[i]);
      for (int p : pf)
         ++freq[p];
   }

   bool pairwise_coprime = true;
   FOR(p, 2, MAXP) {
      if (freq[p] == N) {
         cout << "not coprime" << endl;
         return 0;
      }
      if (freq[p] > 1) {
         pairwise_coprime = false;
      }
   }

   if (pairwise_coprime)
      cout << "pairwise coprime" << endl;
   else
      cout << "setwise coprime" << endl;

   return 0;
}


Measured memory_bytes: 15280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	int N;
	cin >> N;
  int ans = 0;
  for(int i=1;i<=N;i++){
    string n = to_string(i);
    if(n.size() & 1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    if (n == m)
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long N, long long K, long long X, long long Y)
{
    if (N <= K)
    {
        cout << N * X << endl;
    }
    else
    {
        cout << K * X + (N - K) * Y << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    solve(N, K, X, Y);
    return 0;
}


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

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

    int x = 0;
    for (std::string::iterator it = s.begin(); it != s.end(); ++it)
    {
        x = (x * 10 % 9 + (*it ^ 48)) % 9;
    }

    if (x)
    {
        std::cout << "No" << std::endl;
    }
    else
    {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
int a[100005];
int main() {
    cin >> N;
    rep(i, N) cin >> a[i];
    rep(i, N) a[i]--;
    int ans = 0;

    rep(i, N) {
        if (i == a[a[i]]) ans++;
    }
    cout << ans / 2 << endl;


    return 0;
}


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

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int need_left = 0;
    int pointer = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '(') {
            pointer++;
        } else {
            //)のとき
            if(pointer == 0) {
                need_left++;
            } else {
                pointer--;
            }
        }
    }
    // pointerは残った(の数
    int need_right = pointer;
    string res = " ";
    for(int i = 0; i < need_left; i++) {
        res += "(";
    }
    res += S;
    for(int i = 0; i < need_right; i++) {
        res += ')';
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

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

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

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

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

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

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

constexpr int INF=1e9;
int D, c[30], s[400][30];
int ans[400];
int tans[400];

// 乱数
unsigned int xor32() {
  static unsigned int x = 2463534242;
  x = x ^ (x << 13); x = x ^ (x >> 17);
  return x = x ^ (x << 15);
}

// スコアを全部計算
int val(){
  int last[30];
  REP(i, 26){
    last[i]=0;
  }
  int res=0;
  FOR(i, 1, D+1){
    last[tans[i]]=i;
    res+=s[i-1][tans[i]];
    REP(j, 26){
      res-=c[j]*(i-last[j]);
    }
  }
  return res;
}

// スコアを差分計算
int diff(){
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  time_t start=clock();

  // 入力
  cin>>D;
  REP(i, 26){
    cin>>c[i];
  }
  REP(i, D){
    REP(j, 26){
      cin>>s[i][j];
    }
  }

  // 初期解
  int score=0;
  int last[30];
  REP(i, 26){
    last[i]=0;
  }
  REP(i, D){
    int ma=0, idx=-1;
    REP(j, 26){
      if(ma<s[i][j]+c[j]*(i+1-last[j])){
        ma=s[i][j]+c[j]*(i+1-last[j]);
        idx=j;
      }
      score-=c[j]*(i+1-last[j]);
    }
    ans[i]=idx;
    tans[i]=ans[i];

    score+=s[i][idx]+c[idx]*(i+1-last[idx]);
    last[idx]=i;
  }
  // DEBUG(score);

  while(true){
    time_t end=clock();
    if((double)(end-start)/CLOCKS_PER_SEC*1000>1980){
      break;
    }
    int d1=xor32()%D;
    int d2=max(0, min(D-1, d1-2+(int)xor32()%5));
    if(d1==d2){
      continue;
    }
    swap(tans[d1], tans[d2]);
    int tmp=val();
    if(tmp>score){
      score=tmp;
      swap(ans[d1], ans[d2]);
    }
  }
  // DEBUG(score);
  REP(i, D){
    cout<<ans[i]+1<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3648
import sys
input = sys.stdin.readline
from math import gcd
def solve():
    N = int(input())
    AB = [tuple(map(int,input().split())) for i in range(N)]
    MOD = 10**9+7

    from collections import Counter
    ctr = Counter()
    az = bz = zz = 0
    for a,b in AB:
        if a==b==0:
            zz += 1
        elif a==0:
            az += 1
        elif b==0:
            bz += 1
        else:
            g = gcd(a,b)
            a,b = a//g, b//g
            if b < 0:
                b *= -1
                a *= -1
            ctr[(a,b)] += 1
    ans = pow(2,az,MOD) + pow(2,bz,MOD) - 1

    used = set()
    for (a1,b1),v in ctr.items():
        if (a1,b1) in used: continue
        a2,b2 = -b1,a1
        if b2 < 0:
            b2 *= -1
            a2 *= -1
        if (a2,b2) in ctr:
            used.add((a2,b2))
        r = pow(2,v,MOD) + pow(2,ctr[(a2,b2)],MOD) - 1
        ans *= r
        ans %= MOD
    ans += zz - 1
    ans %= MOD
    print(ans)
solve()

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

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

int main() {
    int N;
    cin >> N;
    int D;
    int X;
    cin >> D >> X;
    vector<int> A(N);
    vector<int> C(N);
    REP(i, N) {
        cin >> A[i];
        C[i] = (D - 1) / A[i] + 1;
    }
    cout << X + accumulate(C.begin(), C.end(), 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline().rstrip())


import math

def sieve_of_eratosthenes(n):
    prime_list = []  # n以下の素数のリスト
    A = [1]*(n+1)    # A[i] = iが素数なら1,その他は0
    A[0] = A[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(math.floor(math.sqrt(n))+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list


prime_list = sieve_of_eratosthenes(1361)

ANS = [2]
for p in prime_list:
    if p == 2:
        continue
    else:
        if p % 10 == 1:
            ANS.append(p)
            if len(ANS) == N:
                break

print(*ANS)

Measured memory_bytes: 63676
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<functional>
#include<cmath>
#include<algorithm>
typedef long long ll;

int main() {
	int a, b;
	int f = 0,sum = 0;
	std::cin >> a >> b;
	f = b - a;
	for (int i = 1; i <= f; i++) {
		sum += i;
	}
	std::cout << sum - b << std::endl;
	return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t count_i(int64_t k, int64_t p) {
    int64_t t = 0;
    while (k % p == 0) {
        ++t;
        k /= p;
    }

    return min(t, 9L);
}

int main() {
    int64_t n;
    cin >> n;

    vector<pair<int64_t, int64_t>> a(n);
    for (auto&& aa : a) {
        string s;
        cin >> s;

        auto idx = s.find('.');

        if (idx == string::npos) {
            s += "000000000";
        } else {
            int64_t r = s.size() - idx - 1;
            s.erase(idx, 1);

            for (auto _ : irange(0L, 9L - r)) {
                s += "0";
            }
        }

        int64_t dd = stoll(s);
        int64_t g = gcd(dd, 1000000000L);

        aa = {dd / g, 1000000000L / g};
    }

    vector m(10, vector(10, vector(10, vector(10, 0L))));
    for (auto aa : a) {
        auto b2 = count_i(aa.first, 2);
        auto b5 = count_i(aa.first, 5);
        auto c2 = count_i(aa.second, 2);
        auto c5 = count_i(aa.second, 5);

        ++m[b2][b5][c2][c5];
    }

    for (auto i : irange(0L, 10L)) {
        for (auto j : irange(0L, 10L)) {
            for (auto k : irange(0L, 10L)) {
                for (auto k2 : irange(1L, 10L)) {
                    m[i][j][k][k2] += m[i][j][k][k2 - 1];
                }
            }
            for (auto k : irange(1L, 10L)) {
                for (auto k2 : irange(0L, 10L)) {
                    m[i][j][k][k2] += m[i][j][k - 1][k2];
                }
            }
        }
    }

    int64_t ans = 0;
    for (auto aa : a) {
        auto b2 = count_i(aa.first, 2);
        auto b5 = count_i(aa.first, 5);
        auto c2 = count_i(aa.second, 2);
        auto c5 = count_i(aa.second, 5);

        for (auto i2 : irange(c2, 10L)) {
            for (auto i5 : irange(c5, 10L)) {
                ans += m[i2][i5][b2][b5];
            }
        }

        if (aa.second == 1) {
            --ans;
        }
    }

    assert(ans % 2 == 0);
    cout << ans / 2 << endl;
}

Measured memory_bytes: 6360
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<math.h>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;

const ll INF = ll(1e18) + 1;

unsigned long long int a(ulli n, ulli b) {
	if (b <= 1) {
		return n;
	}
	else {
		return a(n * 2, b - 1);
	}
}

void Main()
{
	unsigned long long h, depth = 0; cin >> h;
	while (h!=0) {
		h >>= 1;
		depth++;
	}
	cout << a(2,depth) - 1 << endl;
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	string s; cin >> s;
	
	int n = int(s.size());
	
	int l = 0, r = n - 1;
	
	for(int i = 0; i < n; i++){
		if(s[i] == 'A'){
			l = i;
			break;
		}
	}
	for(int i = n - 1; i >= 0; i--){
		if(s[i] == 'Z'){
			r = i;
			break;
		}
	}
	
	cout << r - l + 1;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int a[200000];
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  bool flag = true;
  if(a[0]!= 0) flag = false;
  for(int i=1;i<n;i++){
  	if(a[i-1]<a[i]-1 || a[i] > i){flag = false; break;}
  }
  long long ans = 0;
  for(int i=n-1;i>0;i--){
  	if(a[i]<=a[i-1]) ans = ans + a[i];
    else ans++;
  }
  if(flag) cout << ans << endl;
  else cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
#include<algorithm>
#include<string>
#include<set>
#include<cstring>
 
using namespace std;
 
struct edge{int to,cost;};
typedef pair<int,int> P;
const int INF=1<<15;

string make_table(string x,string y)
{
	string res=y;
	string y2=y;
	for(int i=0;i<=y.size();i++){
		y2.erase(0,1);
		string tmp=x+y2;
		if(tmp.find(x)!=string::npos && tmp.find(y)!=string::npos) res=y2;
	}
	
	return res;
}
 
int main(void)
{
	
	//cout<<make_table("abc","xyz")<<endl;
	//cout<<make_table("abc","abc")<<endl;
	//cout<<make_table("abc","bcd")<<endl;
	
	int n;
	while(cin>>n,n){
		vector<string> vs;
		string ans="";
		for(int i=0;i<n;i++){
			string tmp;
			cin>>tmp;
			bool ok=true;
			for(int j=0;j<vs.size() && ok;j++) ok=(vs[j].find(tmp)==string::npos);
			if(ok){vs.push_back(tmp); ans+=tmp;}
		}
		
		vector<int> order(vs.size());
		for(int i=0;i<order.size();i++) order[i]=i;

		vector<vector<string> > table(vs.size(),vector<string>(vs.size()));

		for(int i=0;i<vs.size();i++){
			for(int j=0;j<vs.size();j++) table[i][j]=make_table(vs[i],vs[j]);
		}		

		//int cnt=0;
		do{
			//cout<<cnt++<<endl;
			string res=vs[order[0]];
			for(int i=1;i<order.size();i++){
				res+=table[order[i-1]][order[i]];
	  		}
/*
			if(ans=="") ans=res;
			else if(ans.size()>res.size()){cout<<ans<<"->"<<res<<"(size)"<<endl; ans=res;}
			else if(ans.size()==res.size() && ans>res){cout<<ans<<"->"<<res<<"(order)"<<endl; ans=res;}
*/			
			if(ans.size()>res.size() || ans.size()==res.size() && ans>res) ans=res;
		}while(next_permutation(order.begin(),order.end()));

		cout<<ans<<endl;
	 }

	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
#define int ll
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, k; cin >> n >> k;
  int r, s, p; cin >> r >> s >> p;
  string str; cin >> str;

  vvi dp(n, vi(3, 0));
  
  for(int i=0;i<k;++i) {
    if(str[i] == 's') {
      dp[i][0] = r;
    } else if(str[i] == 'p') {
      dp[i][1] = s;
    } else {
      dp[i][2] = p;
    }
    for(int j=i+k;j<n;j+=k) {
      if(str[j] == 's') {
        dp[j][0] = max(dp[j-k][1] + r, dp[j-k][2] + r);
        dp[j][1] = max(dp[j-k][0], dp[j-k][2]);
        dp[j][2] = max(dp[j-k][0], dp[j-k][1]);
      } else if(str[j] == 'p') {
        dp[j][1] = max(dp[j-k][2] + s, dp[j-k][0] + s);
        dp[j][2] = max(dp[j-k][0], dp[j-k][1]);
        dp[j][0] = max(dp[j-k][1], dp[j-k][2]);
      } else {
        dp[j][2] = max(dp[j-k][0] + p, dp[j-k][1] + p);
        dp[j][0] = max(dp[j-k][1], dp[j-k][2]);
        dp[j][1] = max(dp[j-k][0], dp[j-k][2]);
      }
    }
  }

  ll ans = 0;
  if(n%k == 0) {
    for(int i=n-k;i<n;++i) {
      ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
    }
  } else {
    for(int i=n-k;i<n;++i) {
      ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 5840
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if(sum(A) < sum(B)):
  print(-1)
else:
  C = [A[i] - B[i] for i in range(N)]
  D = sorted([c for c in C if c > 0])
  E = [c for c in C if c < 0]
  ans = 0
  num = sum(E)
  while num < 0:
    num += D.pop()
    ans += 1
  print(ans + len(E))

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

long long int gcd(long long int a,long long int b){
    if(a<b){
        long long int tmp=a;
        a=b;
        b=tmp;
    }

    long long int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

long long int lcm(long long int a,long long int b){
    long long int g = gcd(a,b);
    return (a/g)*b;
}


int main() {
    int N,A,B;
    cin >> N >> A >> B;

    if((abs(A-B)-1)%2==1){
        pl("Alice")
    } else {
        pl("Borys")
    }

    return 0;
}


Measured memory_bytes: 256
#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=5e18;

int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  mat ans(h,vec(w));
  ll x=0,y=0;
  for(ll i=0;i<n;i++) {
    while(a[i]--) {
      ans[y][x]=i+1;
      if(y%2==0) {
        if(x+1<w) {
          x++;
        }
        else {
          y++;
        }
      }
      else {
        if(x>0) {
          x--;
        }
        else {
          y++;
        }
      }
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      if(j) cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
}

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

char c[55][55]; int H, W, cnt;

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') cnt++;
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256