akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::cout << 800*N - (N/15)*200 << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define push_back pb
typedef long long int ll;
typedef long int li;

using namespace std;

int main()
{
	string s1, s2, s3;
	cin>>s1;
	cin>>s2;

	int n1 = s1.length();
	s3=s1;
	int n2 = s2.length();
	if(n1==n2)
	{
		int i;
		for (i = 0; i < n1; ++i)
		{
			int k=0,j=n1-1;
			while(k<n1)
			{
				if(j<n1)
					s3[k++] = s1[j++];
				else
					j=0;
			}
			if(s3==s2)
				break;
			else
				s1=s3;
		}
		if(i<n1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
  string pat = "CODEFESTIVAL2016";
  string S; cin >> S;
  vector<bool> v(S.size());
  for (int i = 0; i < S.size(); i++) {
    v[i] = (pat[i]^S[i]) > 0;
  }
  cout << accumulate(v.begin(), v.end(), 0, [](int acc, bool x) { return acc + x; }) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>

using namespace std;

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

  int q;
  cin>>q; 
  deque<char>sta;
  for(int j=0; j<s.size();j++){
    sta.push_back(s.at(j));
  }
  
  bool bo=true;
  while(q--){
    int a;
    cin>>a;
    if(a==2){
      int b;
      cin>>b;
      char c;
      cin>>c;
      if(b==1){
        if(bo){
          sta.push_front(c);
        }
        else{
          sta.push_back(c);
        }
      }        
      else if(b==2){
        if(bo){
          sta.push_back(c); 
        }
        else{
          sta.push_front(c);
        }
      }
    }
    else if(a==1){
      if(bo){      
        bo=false;
      }      
      else{
        bo=true;
      }      
    }
  }
      
   if(bo){
     while(!sta.empty()){
       cout<<sta.front();
       sta.pop_front();
     }
   }
  else{
     while(!sta.empty()){        
       cout<<sta.back();
       sta.pop_back();
    }
  } 
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;
string s, t;

int main () {
	cin >> n >> m;
	cin >> s >> t;
	int d = gcd (n, m);
	int ok = 1;
	for (int i = 0; i < d; i++)
		if (s[i * (n / d)] != t[i * (m / d)])
			ok = 0;
	if (ok) cout << (ll)n * m / d << endl; else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b

int main() {
	int n;
	S(d, n);
	P(d, (n == 0 || n == 2) ? 1 : n == 1 ? 2 : 0);
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
 
int gcd(int a, int b){
  if(a == 0){
    return b;
  }else if(a > b){
    return gcd(a%b, b);
  }else if(a < b){
    return gcd(b%a, a);
  }
}
 
int main(){
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\n", gcd(a, b));
  return 0;
}



Measured memory_bytes: 2740
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,v[30],c[30],ans=0;
    cin>>n;
    rep(i,n){
        cin>>v[i];
    }
    rep(i,n){
        cin>>c[i];
        v[i]=max(0ll,v[i]-c[i]);
    }
    rep(i,n){
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i=0; i<N; ++i) cin >> h[i];
    int DP[N+1];
    DP[2] = abs(h[0]-h[1]);
    for(int i=3; i<=N; ++i){
        DP[i] = min(DP[i-1]+abs(h[i-1]-h[i-2]), DP[i-2]+abs(h[i-1]-h[i-3]));
    }
    cout << DP[N] << "\n";
    return 0;
}

Measured memory_bytes: 1024
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()
T = readline().decode().rstrip()

print("Yes") if T[:-1] == S else print('No')


Measured memory_bytes: 9108
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	
	if len(s) == 2 {
		fmt.Println(s)
	} else {
   		fmt.Printf("%v%v%v",string(s[2]),string(s[1]),string(s[0]))
	}
}

Measured memory_bytes: 1832
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9 + 7;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

ll C[5002][5002];
inline void init() {
    for (reg int i = 0; i <= 5000; i++) C[0][i] = 1;
    for (reg int i = 1; i <= 5000; i++)
        for (reg int j = i; j <= 5000; j++) {
            C[i][j] = (C[i][j - 1] + C[i - 1][j - 1]) % mod;
        }
}

ll n, k;
int main() {
    n = read(), k = read();
    init();
    for (reg ll i = 1; i <= k; i++) {
        reg ll num = 0;
        if (n - k == 0 && i == 1) { cout << 1 << endl; continue; }
        if (n - k - 1 < 0) { puts("0"); continue; }
        if (i - 2 >= 0) num = (num + C[i - 2][n - k - 1]) % mod;
        num = (num + C[i - 1][n - k - 1] * 2 % mod) % mod;
        num = (num + C[i][n - k - 1]) % mod;
        cout << C[i - 1][k - 1] * num % mod << endl;
    }
    return 0;
}


Measured memory_bytes: 194944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  ll x[n+1]={};
  vector<ll> v,w;
  for(int i=0;i<n;i++){
    cin>>x[i];
    if(x[i]>0)v.push_back(x[i]);
    else if(x[i]<0) w.insert(w.begin(),x[i]);
    else k--;
  }
  if(k<=0){
    cout<<0<<endl;
    return 0;
  }
  ll ans=1e18;
  if(w.size()>=k) ans=min(ans,-w[k-1]);
  if(v.size()>=k) ans=min(ans,v[k-1]);
  for(int i=0;i<v.size()&&i<k;i++){
    ll tmp=v[i]*2;
    if(k-i-1<=w.size()&&i!=k-1){
      tmp-=w[k-i-2];
      ans=min(tmp,ans);
    }
  }
  for(int i=0;i<w.size()&&i<k;i++){
    ll tmp=w[i]*2;
    tmp*=(-1);
    if(k-i-1<=v.size()&&i!=k-1){
      tmp+=v[k-i-2];
      ans=min(tmp,ans);
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

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

#define forn(i, n) for(int i=0; i<n; i++)
#define mp makepair
#define pb push_back

int main(){
    ll N, W;
    scanf("%lld %lld", &N, &W);
    vi v(N), w(N);
    for(int i=0;i<N;i++) {
        scanf("%d%d",&w[i],&v[i]);
    }

    int max_value = 0;
    for(int i=0;i<N;i++)
        max_value += v[i];
    ll inf = 1e18L + 5;
    vll dp(max_value + 1, inf);

    dp[0] = 0;
    for(int item=0;item<N;item++){
        for(int value=max_value;value>=v[item];value--){
            dp[value] = min( w[item] + dp[value - v[item]], dp[value] );
        }
    }
    
    ll ans=0;
    for(int i=0;i<=max_value;i++)
        if(dp[i] <= W)
            ans = i;

    printf("%lld\n", ans);
}


Measured memory_bytes: 1024
N,M=map(int, input().split())
A=[]
for i in range(N):
  A.append(list(map(int,input().split())))

ans=N
# i は外した種目の個数
for i in range(M-1):
  sanka=[0]*M
  for j in range(N):
    sanka[A[j][0]-1]+=1
#  print(sanka)
  saidai=max(enumerate(sanka), key=lambda x: x[1])[0]+1
#  print(saidai)
  ans=min(ans,max(sanka))
  for j in range(N):
    A[j].remove(saidai)

print(ans)

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

int main(){
	string a,b;
	int ren;
	string ans="No";

	cin>>a>>b;

	ren=stoi(a+b);

	for(int i=0;i<1000;i++){
		if(ren==i*i){
			ans="Yes";
			break;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            var h = input1[0];
            var w = input1[1];
            long k = input1[2];

            var hoge = Enumerable.Range(0, h)
                .Select(_ => Console.ReadLine().ToCharArray()).ToArray();

            var result = 0;
            foreach (var maskR in Enumerable.Range(0, (1 << h) - 1))
                foreach (var maskC in Enumerable.Range(0, (1 << w) - 1))
                {
                    var count = 0;
                    foreach (var i in Enumerable.Range(0, h))
                        foreach (var j in Enumerable.Range(0, w))
                        {
                            if (((maskR >> i) & 1) == 0 && ((maskC >> j) & 1) == 0 && hoge[i][j] == '#')
                            {
                                count++;
                            }
                        }

                    if (count == k)
                    {
                        result++;
                    }
                }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 29308
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


N = int(input())
if N <= 2:
    print(0)
    exit()
array = make_divisors(N)
len_array = len(array)
# print(array)
if len_array % 2 == 1:
    print(sum(array[1::2]) - len_array // 2)
else:
    if array[-1] - array[-2] == 1:
        print(sum(array[1:-2:2]) - (len_array // 2 - 1))
    else:
        print(sum(array[1::2]) - len_array // 2)


Measured memory_bytes: 38768
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <utility>
using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	cout << x + (y / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w,k = map(int,input().split())
y1,x1,gy,gx = map(int,input().split())
m = ["@"*(w+2)]+["@"+input()+"@" for i in range(h)]+["@"*(w+2)]
opt = [(1,0),(0,1),(-1,0),(0,-1)]
dq=deque([(y1,x1)])
ans = 0
temp = [[-1]*(w+2) for i in range(h+2)]
temp[y1][x1] = 0
cnt = 0
while dq:
    # cnt += 1
    # print(cnt)
    y,x = dq.popleft()
    # print(dq,y,x)
    for j in opt:
        y1 = y+j[0]
        x1 = x+j[1]
        if m[y1][x1] == "@":
            # print(y1,x1,"@@")
            continue
        if temp[y1][x1] == -1 or temp[y1][x1]-temp[y][x]>0:
            for i in range(k):
                if (temp[y1+i*j[0]][x1+i*j[1]] == -1 or temp[y1+i*j[0]][x1+i*j[1]]-temp[y][x]>0) and m[y1+i*j[0]][x1+i*j[1]] == ".":
                    if temp[y1+i*j[0]][x1+i*j[1]]-temp[y][x]==1:
                        continue
                    temp[y1+i*j[0]][x1+i*j[1]] = temp[y][x]+1
                    dq.append((y1+i*j[0],x1+i*j[1]))
                    # print(y1+i*j[0],x1+i*j[1],"a",k,m[y1+i*j[0]][x1+i*j[1]],temp[y1+i*j[0]][x1+i*j[1]])
                else:
                    # print(y1+i*j[0],x1+i*j[1],"b",k,m[y1+i*j[0]][x1+i*j[1]],temp[y1+i*j[0]][x1+i*j[1]])
                    break
    # for i in temp:
    #     print(i)
# print(temp)
print(temp[gy][gx])

Measured memory_bytes: 101004
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L> T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;L D(L a){Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++){L d=I->first;if(d-P[a])P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){return i?B[i]+M(i-(i&-i)):0;}L S(L x,L i){for(x=G(x)-M(i+1)+M(i++);i<1<<17;B[i]+=x,i+=i&-i);}L W(){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;for(cin>>a;cin>>s>>a>>b;*s&2?W():A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

Measured memory_bytes: 33380
import java.util.Scanner;

public class Main {
  /*
     input: 1 2
     output: a < b
  */
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    String relation;
    if (a < b) {
        relation = "<";
    } else if (a > b) {
        relation = ">";
    } else {
        relation = "==";
    }
    System.out.printf("a %s b\n", relation);
  }
}



Measured memory_bytes: 26320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest_20191116
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());

            if (k % 2 == 0)
            {
                Console.WriteLine((k / 2) * (k / 2));
            }
            else
            {
                Console.WriteLine((k / 2) * (k / 2) + k / 2);
            }
                    


        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <utility>

int main(int argc, char const *argv[])
{
  int A, B, K, result = 0, count = 0;
  scanf("%d %d %d", &A, &B, &K);
  if (A > B) std::swap(A, B);

  for (result = A; result >= 1; --result) {
    if (A % result == 0 && B % result == 0) ++count;
    if (count == K) break;
  }

  printf("%d\n", result);

  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, P: "List[int]"):
    count=0
    mi=P[0]
    for i in range(1,N+1):
        if i==1:
            count+=1
            #print(i)
        else:
            if min(mi,P[i-1])==P[i-1]:
                count+=1
                mi=P[i-1]
                #print(i)
    print(count)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


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

int main()
{  int cnt = 0;
   string s;
   cin >> s;
   for(int i =0; i < s.size(); i++){
       if(s[i]=='o'){
           cnt++;
       }
   }
   cnt+=(15-s.size());
   if(cnt >= 8){
       cout << "YES\n";
       return 0;
   }
   cout << "NO\n";
}


Measured memory_bytes: 256
/*input
4 3
0 1 W
1 2 W
5 3 B
5 4 B
*/
#include <iostream>
using namespace std;
int lt[2005][1005],rt[2005][1005],ans[2005];
int main(){
	ios_base::sync_with_stdio(0);
	int n,k,x,y;
	char c;
	for(cin>>n>>k;n--;){
		cin>>x>>y>>c;
		for(int delta = 0; delta < 2*k; ++delta){
			if((c=='B')^((x/k%2)^((y+delta)/k%2)))
				++lt[delta][x%k],++ans[delta];
			else ++rt[delta][x%k];
		}
	}
	int res = 0;
	for(int i=0;i<2*k;++i){
		int run = ans[i];
		res = max(res,run);
		for(int j=0;j<k;++j){
			run += rt[i][j] - lt[i][j];
			res=max(res,run);
		}
	}
	cout<<res;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  string s;cin>>s;
  auto ca = count(all(s),'a');
  auto cb = count(all(s),'b');
  auto cc = count(all(s),'c');
  if(abs(ca-cb)>=2||abs(ca-cc)>=2||abs(cc-cb)>=2){
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}


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

int main(void){
    int x, ans = 1;
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x;
    for (int b = 2; b <= x; ++b) {
        for (int p = 2; (int)pow((double)b, (double)p) <= x; ++p) {
            ans = max(ans, (int)pow((double)b, (double)p));
        }
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
MOD = (10 ** 9) + 7

N = int(input())
s = list(input())

dp = [[0] * (N + 2) for i in range(N + 1)]

for n in range(N + 1):
	for l in range(n + 1):
		if n == 1:
			dp[n][l] = 1
		elif l == 0:
			dp[n][l] = (dp[n - 1][0] + 2 * dp[n - 1][1]) % MOD
		else:
			dp[n][l] = (dp[n - 1][l - 1] + 2 * dp[n - 1][l + 1]) % MOD

print(dp[N][len(s)])

Measured memory_bytes: 230280
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e4 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1e9 + 7, INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i,a,b) for(RR i=(a);i<=(b);++i)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
int n;
char s[MAXN][13];
int cnt1, cnt2, cnt3;
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	int ans = 0;
	rep(i, 1, n)cin >> (s[i] + 1);
	rep(i, 1, n) {
		if (s[i][1] == 'B') {
			int len = strlen(s[i] + 1);
			if (s[i][len] == 'A') {
				cnt1++;
			}
			else cnt2++;
		}
		else if (s[i][strlen(s[i] + 1)] == 'A') {
			cnt3++;
		}
	}
	rep(i, 1, n) {
		rep(j, 2, strlen(s[i] + 1)) {
			if (s[i][j] == 'B' && s[i][j - 1] == 'A')ans++;
		}
	}

	bool pre = false;
	rep(i, 1, n) {
		if (pre) {
			if (cnt1) {
				cnt1--;
				ans++;
			}
			else if (cnt2) {
				cnt2--;
				pre = false;
				ans++;
			}
			else break;
		}
		else {
			if (cnt3) {
				cnt3--;
				pre = true;
			}
			else if (cnt1) {
				cnt1--;
				pre = true;
			}
			else break;
		}	
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
import math

def read_input():
    n, k = map(int, input().split())
    return n, k


# x*2^d >= k となる最小のkを求める
def calc_d(x, k):
    return int(math.ceil(math.log2(k/x)))


def submit():
    n, k = read_input()

    result = 0
    for i in range(1, n + 1):
        if i < k:
            result += math.pow((1/2), calc_d(i, k))
        else:
            result += 1.0

    print(result/n)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 3188
#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(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>

int main(){
    //Input
    int h,w;cin>>h>>w;
    vvi magic(10,vi(10));
    REP(i,10){
        REP(j,10){
            cin>>magic[i][j];
        }
    }
    vvi tile(h,vi(w));
    REP(i,h){
        REP(j,w){
            cin>>tile[i][j];
        }
    }
    //Solve
    REP(k,10){
        REP(i,10){
            REP(j,10){
                if(i==j)continue;
                magic[i][j]=min(magic[i][j],magic[i][k]+magic[k][j]);
            }
        }
    }
    int res=0;
    REP(i,h){
        REP(j,w){
            if(tile[i][j]==-1)continue;
            res+=magic[tile[i][j]][1];
        }
    }
    cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H[] = new int[N];
		for(int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}
		
		int height = Integer.MAX_VALUE;
		for(int i = N - 1; i >= 0; i--) {
			if(height < H[i]) {
				if(height == H[i] - 1) {
					height = H[i] - 1;
				} else {
					System.out.println("No");
					return;
				}
			} else {
				height = H[i];
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 50752
#include <iostream>
#include <string>
#include <set>
#include <unordered_map>
#include <vector>
#include <utility>
#include <cassert>
#include <algorithm>
#include <cstring>

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using pii64 = pair<int64_t, int64_t>;

int main(int argc, char *argv[]) {
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  double max_sq = (double)W * H / 2;
  double mx = (double)W / 2;
  double my = (double)H / 2;
  bool has_multiple = (mx == x && my == y);
  cout << max_sq << " " << (has_multiple ? 1 : 0) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
    	int a[]=new int[26];String s;
    	
    	for(;;){ 
    		if(sc.hasNextLine()==false) break;
    		s=sc.nextLine();   
    	char CA[] = s.toCharArray(); 
    	
    	for(int i=0;i<s.length();i++){
    		for(int j=0;j<26;j++){
    			if(CA[i]==j+97||CA[i]==j+65){
    			a[j]++;break;
    		}
    	}
    }
    	}
    	
    	for(int j=0;j<26;j++)System.out.println(s=(char)(j+97)+" : "+a[j]);
    }
}

Measured memory_bytes: 25996
#include <stdio.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define ll long long

ll a[100001];
ll b[100001];
 int main(void)
 {
 	int n,k;
 	ll res=0;
 	scanf("%d %d",&n,&k);
 	FOR(i,1,n+1){
 		scanf("%lld",&a[i]);
 		b[i]=MAX(0,a[i]);
 		a[i]+=a[i-1],b[i]+=b[i-1];
 	}
 	FOR(i,k,n+1){
 		ll p=a[i]-a[i-k];
 		ll q=b[n]-b[i]+b[i-k];
 		if(p>0) res=MAX(res,p+q);
 		else res=MAX(res,q);
 	}
 	printf("%lld",res);
 	return 0;
 }
    
    

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
//union by size + path having
class UnionFind{
	public:
	vector<long long> par; // 各元の親を表す配列
	vector<long long> siz; // 素集合のサイズを表す配列(1 で初期化)


	// Constructor
	UnionFind(long long sz_) : par(sz_), siz(sz_,1LL){
		for (long long i = 0; i < sz_; ++i)
		par[i] = i; // 初期では親は自分自身
	}
	void init(long long sz_){
		par.resize(sz_);
		siz.assign(sz_,1LL); // resize だとなぜか初期化されなかった
		for (long long i = 0; i < sz_; ++i)
			par[i] = i; // 初期では親は自分自身
	}
	// Member Function


	// Find
	long long root(long long x){ // 根の検索
		while (par[x] != x){
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}
	// 結合(Unite, Merge)
	bool merge(long long x, long long y){
		x = root(x);
		y = root(y);
		if (x == y){
			return false;
		}
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]){
			swap(x, y);
		}
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}


	// 連結判定(つながっているときはture,つながっていなければfalse)
	bool issame(long long x, long long y){ 
		return root(x) == root(y);
	}


	// 素集合のサイズ
	long long size(long long x){ 
		return siz[root(x)];
	}
};
int main(){
	int n,m,k;
	cin >>n>>m>>k;
	Vi fre(n,0);
	Vi ans(n,0);
	UnionFind dis(n);
	vector<vector<int>> bin(n);
	int a,b;
	rep(i,m){
		cin>>a>>b;
		a--;
		b--;
		fre[a]++;
		fre[b]++;
		dis.merge(a,b);
	}
	rep(i,n){
		ans[i]=dis.size(i)-1-fre[i];
	//	clog<<ans[i]<<" ";
	}
	//clog<<endl;
	rep(i,k){
		cin>>a>>b;
		a--;
		b--;
		if(dis.issame(a,b)){
			ans[a]--;
			ans[b]--;
		}
	}
	rep(i,n){
		cout<<ans[i];
		if(i!=n-1){
			cout<<" ";
		}
	}
	cout<<endl;

}
/*
1 10 9
6 7 3 8 2 5 4
*/

Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    string S; cin >> S;
    if(S == "RRR") Out(3);
    else if(S == "RRS" || S == "SRR") Out(2);
    else if(S == "SSS") Out(0);
    else Out(1);

    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string t;
    cin >> t;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == '?') t[i] = 'D';
    }
    cout << t << '\n';
    return 0;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	string str;
	cin>>str;
	set<char> strSet;
	bool ans = true;
	for(int i = 0 ; i < str.length(); i++){
		if(strSet.count(str[i]) != 0){
			ans = false;
			break;
		}else{
			strSet.insert(str[i]);
		}
	}
	if(ans == true){
		cout<<"yes"<<endl;
	}else{
		cout<<"no"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair <int,int> P;
string mp[501];
int m,n,used[30];
vector <P>  a[30];

int saiki(int);

bool check_x(int y,int x1,int x2){
  for(int i=x1+1;i<x2;i++)
    if(mp[y][i]!='.'&&!saiki(mp[y][i]-'A'))return 0;
  return 1;
}

bool check_y(int y1,int y2,int x){
  for(int i=y1+1;i<y2;i++)
    if(mp[i][x]!='.'&&!saiki(mp[i][x]-'A')) return 0;
  return 1;
}


int saiki(int ch){  
  if(ch<0) return 0;
  int x1=a[ch][0].x,x2=a[ch][1].x;
  int y1=a[ch][0].y,y2=a[ch][1].y;
  int res=0;
  if(used[ch]||mp[y1][x1]=='.')return 0;
  used[ch]=1;
  
  if(x1==x2&&y2-y1!=1) res=check_y(y1,y2,x1);
  if(y1==y2&&x2-x1!=1) res=check_x(y1,x1,x2);
  if(x1!=x2&&y1!=y2) {
    if(x1<x2){
      res=check_x(y1,x1,x2+1)&check_y(y1,y2,x2);
      res|=check_y(y1,y2+1,x1)&check_x(y2,x1,x2);
    }
    else{
      swap(x1,x2);
      res=check_x(y1,x1-1,x2)&check_y(y1,y2,x1);
      res |=check_y(y1,y2,x2)&check_x(y2,x1,x2+1);
      swap(x1,x2);
    }
  }
    

  if(res) mp[y1][x1]=mp[y2][x2]='.';
  used[ch]=0;
  return res;
}

int main(){

  cin>>m>>n;
  for(int i=0;i<m;i++)cin>>mp[i];

  int ans=0;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      if(mp[i][j]!='.')a[mp[i][j]-'A'].push_back(P(j,i)),ans++;
  
  int flg=1;
  while(flg){
    flg=0;
    for(int i=0;i<30;i++)if(a[i].size() && saiki(i)) a[i].clear(),flg=1;
  }

  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++) if(mp[i][j]!='.') ans--;

  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1480
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let ss = (read string).ToCharArray() |> Array.toList
    let rec f xs ys = function
        | [] -> (xs, ys)
        | a :: b :: rs -> f (a :: xs) (b :: ys) rs
        | a :: rs -> (a :: xs, ys)
    let (bs, cs) = f [] [] ss
    let b1 = List.forall (fun x -> x = 'R' || x = 'U' || x = 'D') bs
    let b2 = List.forall (fun x -> x = 'L' || x = 'U' || x = 'D') cs
    if b1 && b2 then
        printfn "Yes"
    else
        printfn "No"
    0

Measured memory_bytes: 13532
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>

using namespace std;

int main() {
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		pair<int,int> a[m];
		for(int i=0;i<m;i++){
			a[i].first=0;
			a[i].second=(i+1)*-1;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				int x=0;
				cin>>x;
				if(x==1){
					a[j].first++;
				}
			}
		}
		sort(a,a+m);
		for(int i=m-1;0<=i;i--){
			cout<<a[i].second*-1;
			if(i!=0){
				cout<<' ';
			}else{
				cout<<endl;
			}
		}
	}
}

Measured memory_bytes: 2984
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


int main() {
    ull x;
    cin >> x;
    ull a = x / 500;
    x -= a * 500;
    ull b = x / 5;
    cout << (a * 1000) + (b * 5) << endl;
    return 0;
}



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

int main(){
  int X;
  cin >> X;
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  int A,B;
  int i=X;
  while(true){
    bool a=false;
    for(int j=0;j<N;j++){
      if(i==P.at(j)){
        a=true;
        break;
      }
    }
    if(!a){
      A=i;
      break;
    }
    i--;
  }
  i=X;
  while(true){
    bool b=false;
    for(int j=0;j<N;j++){
      if(i==P.at(j)){
        b=true;
        break;
      }
    }
    if(!b){
      B=i;
      break;
    }
    i++;
  }
  if(abs(A-X)<=abs(B-X)){
    cout << A << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan  = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] list = new int[n][2];
		int count = 0;

		for(int i = 0;i < n;i++) {
			for(int j = 0;j < 2;j++) {
				list[i][j] = scan.nextInt();
			}
		}

		for(int i = 0;i < n;i++) {
			if(Math.sqrt(Math.pow(list[i][0], 2) + Math.pow(list[i][1], 2)) <= d) {
				count++;
			}
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 65044
#include "bits/stdc++.h"
#define lp(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;
using un = unsigned;

int n, res = 0, ccc = 0;
string s;

int main()
{
	string s;
	cin >> s;
	if (s == "ABC") cout << "ARC";
	else cout << "ABC";
}



Measured memory_bytes: 3596
n = int(input())
d, x = map(int,input().split())
pList = []
for i in range(n):
  pList.append(int(input()))

result = 0
for i in pList:
  if d % i == 0:
    result += d//i
  else:
    result += d//i+1

print(result+x)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 998244353;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

int main() {
    init_combination();
    ll N;
    cin >> N;
    ll Total = beki(3, N);
    ll BAN = 0;
    for(ll i = N / 2 + 1; i <= N; i++) {
        ll now = combination(N, i);
        now *= beki(2, N - i);
        now %= mod;
        BAN += now;
    }
    BAN *= 2;
    ll ans = Total - BAN;
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 234624
def resolve():
    import itertools
    impossible = 10 ** 20
    n, m, x = map(int, input().split())
    ans = impossible
    books = [None] * n
    for i in range(n):
        books[i] = list(map(int, input().split()))
    for i in itertools.product([True, False], repeat=n):
        u = [0] * m
        yen = 0
        for index, j in enumerate(i):
            if not j:
                continue
            yen += books[index][0]
            for k in range(m):
                u[k] += books[index][k + 1]
        for j in u:
            if j < x:
                break
        else:
            ans = min(yen, ans)
    print(ans if ans < impossible else -1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9208
X = 1
Y = 0

class Editor
  def initialize
    @text = []
    @buffer = ''
    @cursor = [0, 0]
  end

  def line_start?
    @cursor[Y] == 0
  end

  def line_end?
    @cursor[Y] == @text.size - 1
  end

  def str_start?
    @cursor[X] == 0
  end

  def str_end?
    y = @cursor[Y]
    @cursor[X] == @text[y].size
  end

  def character?
    (not str_end?)
  end

  def command_a
    @cursor[X] = 0
  end

  def command_e
    y = @cursor[Y]
    @cursor[X] = @text[y].size
  end

  def command_p
    @cursor[Y] -= 1 unless line_start?
    @cursor[X] = 0
  end

  def command_n
    @cursor[Y] += 1 unless line_end?
    @cursor[X] = 0
  end

  def command_f
    if not str_end?
      @cursor[X] += 1
    elsif not line_end?
      @cursor[Y] += 1
      @cursor[X] = 0
    end
  end

  def command_b
    if not str_start?
      @cursor[X] -= 1
    elsif not line_start?
      @cursor[Y] -= 1
      y = @cursor[Y]
      @cursor[X] = @text[y].size
    end
  end

  def command_d
    x = @cursor[X]
    y = @cursor[Y]

    if character?
      @text[y].slice!(x)
    elsif str_end? and not line_end?
      @text[y] << @text[y+1]
      @text.slice!(y+1)
    end
  end

  def command_k
    x = @cursor[X]
    y = @cursor[Y]

    if character?
      @buffer = @text[y].slice!(x..-1)
    elsif str_end? and not line_end?
      @buffer = '\n'
      @text[y] << @text[y+1]
      @text.slice!(y+1)
    end
  end

  def command_y
    unless @buffer.empty?
      x = @cursor[X]
      y = @cursor[Y]

      if @buffer == '\n'
        str = @text[y].slice!(x..-1)
        @text.insert(y+1, str)
        @cursor[X] = 0
        @cursor[Y] += 1
      else
        @text[y].insert(x, @buffer)
        @cursor[X] += @buffer.size
      end
    end
  end

  def write line
    @text << line
  end

  def print
    @text.each {|line| puts line}
  end
end

def main
  editor = Editor.new
  loop do
    line = gets.chomp
    break if line == 'END_OF_TEXT'
    editor.write(line)
  end

  loop do
    command = gets.chomp
    break if command == '-'
    eval("editor.command_#{command}")
  end

  editor.print
end

main

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

string s;
int n;
int cnt;

int main(){
    int n;
    cin >> n;
    
    string s;
    cin >> s;
    
    int numberOfPin = 0;
    
    //暗証番号000~999まで全通り試す
    for (int i = 0; i < 1000; i++){
        
        //iの100の位, 10の位, 1の位を保持する
        vector<int> c = {i/100, (i/10)%10, i%10};
        
        int f = 0;
        
        for (int i = 0; i < n; i++){
            if (s[i] == c[f] + '0') f++;
            if (f == 3) break; //f==3ならば, sから現在の暗証番号を作れる
        }
        if (f == 3) numberOfPin++;
    }
    cout << numberOfPin << endl;
    
}

Measured memory_bytes: 384
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
lis = []

for i in range(n):
    lis.append([a[i],i+1])
#print(lis)
ans = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if lis[0][0] == 0:
            del lis[0]
        ans[i][j] = lis[0][1]
        lis[0][0] -= 1
for i in range(h):
    if i % 2 != 0:
        ans[i].reverse()
for i in range(h):
    print(' '.join(map(str,ans[i])))

Measured memory_bytes: 4468
N, M = map(int, input().split())
broken = set()
for _ in range(M):
  broken.add(int(input()))

dp = [0 for _ in range(N+1)]
dp[0] = 1
if 1 not in broken:
  dp[1] = 1

for i in range(2,N+1):
  if i not in broken:
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
    
print(dp[-1])


Measured memory_bytes: 11884
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N,M = [int(i) for i in readline().split()]
#H = [int(i) for i in readline().split()]
#AB = [[int(i) for i in readline().split()] for _ in range(M)]
H = {i+1:int(e) for i,e in enumerate(readline().split())}
AB = [[int(i) for i in readline().split()] for _ in range(M)]

ng = []

for a,b in AB:
  if H[a] < H[b]:
    ng += [a]
  elif H[a] > H[b]:
    ng += [b]
  else:
    ng += [a,b]
#print(ng)
print(N-len(set(ng)))

Measured memory_bytes: 108588
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s1 = saori.nextHayami().split("");
		String[] s2 = saori.nextHayami().split("");
		String[] s3 = saori.nextHayami().split("");
		System.out.println(s1[0].toUpperCase() + s2[0].toUpperCase() + s3[0].toUpperCase());
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int dx[] = {1,0,0,-1};
  int dy[] = {0,1,-1,0};
  int h,w;
  scanf("%d %d",&h,&w);
  vector<string> v(h);
  rep(i,h)cin >> v[i];
  queue<P> que;
  rep(i,h)rep(j,w)if(v[i][j] == '#')que.push(make_pair(i,j));
  ll res = 0;
  while(!que.empty()){
    queue<P> q;
    res++;
    while(!que.empty()){
      P ov = que.front();que.pop();
      rep(i,4){
        P nv = make_pair(ov.first+dy[i],ov.second+dx[i]);
        if(nv.first < 0 || nv.first >= h || nv.second < 0 || nv.second >= w)continue;
        if(v[nv.first][nv.second] == '#')continue;
        v[nv.first][nv.second] = '#';
        q.push(nv);
      }
    }
    que =  q;
  }
  res--;
  cout << res << endl;





  return 0;
}

Measured memory_bytes: 9600
N = int(input())
ans1 = [0] * N
ans2 = [0] * N
ans3 = [0] * N

for x in range(1,101):
    for y in range(1,71):
        for z in range(1,58):
            if (x**2+y**2+z**2+x*y+y*z+z*x) <= N:
#                n = int(0.5*((x+y)**2+(y+z)**2+(z+x)**2))
                n = x**2+y**2+z**2+x*y+y*z+z*x
                if x == y and y == z and z == x:
                    ans1[n-1] = 1
#                elif x == y or y == z or z == x:
                elif x == y and x > z:
                    ans2[n-1] += 3
                elif y == z and x > z:
                    ans2[n-1] += 3
                elif x != y and y != z and z != x:
                    if x > y and y > z:
                        ans3[n-1] += 6
for x,y,z in zip(ans1, ans2, ans3):
    print(x+y+z)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


int N;
ll A[55], m = 0, M = 0;

int main(){
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    m = min(m, A[i]); M = max(M, A[i]);
  }

  if (m == 0){
    cout << N - 1 << endl;
    for (int i = 1; i < N; i++) cout << i << " " << i + 1 << endl;
    return 0;
  }

  if (M == 0){
    cout << N - 1 << endl;
    for (int i = N - 1; i >= 1; i--) {
      cout << i+1 << " " << i << endl;
    }
    return 0;
  }


  if (abs(M) >= abs(m)){
    int start = 0;
    for (int i = 1; i <= N; i++){
      if (M == A[i]) start = i;
    }

    cout << 2 * N - 1 << endl;
    for (int i = 1; i <= N; i++){
      cout << start << " " << i << endl;
    }
    for (int i = 1; i < N; i++){
      cout << i << " " << i + 1 << endl;
    }
    return 0;
  }

  int start = 0;
  for (int i = 1; i <= N; i++){
    if (m == A[i]) start = i;
  }

  cout << 2 * N - 1 << endl;
  for (int i = 1; i <= N; i++){
    cout << start << " " << i << endl;
  }
  for (int i = N - 1; i >= 1; i--) {
    cout << i+1 << " " << i << endl;
  }

  return 0;
}


Measured memory_bytes: 3616