akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;


// ABC122C - GeT AC
// https://atcoder.jp/contests/abc122/tasks/abc122_c
void ABC122C() {
	int N, Q;
	cin >> N >> Q;

	string S;
	cin >> S;

	vector<int> l(Q), r(Q);
	for (int i = 0; i < Q; i++)
	{
		int a, b;
		cin >> a >> b;
		l[i] = a - 1; // 配列のインデックスにしたいので-1
		r[i] = b - 1; // 配列のインデックスにしたいので-1
	}


	/*
		前処理 : ACの個数の累積和を求める
		本処理 : 指定区間内のACの個数を累積和から計算する
	*/
	//"AC"の個数の累積和
	vector<int> CS(N+1, 0);
	for (int i = 0; i < N; i++)
	{
		if (S.substr(i, 2) == "AC") {
			CS[i+1] = CS[i] + 1;
		}
		else {
			CS[i + 1] = CS[i];
		}
	}

	
	for (int i = 0; i < Q; i++)
	{
		int left  = l[i];
		int right = r[i];

		cout << CS[right] - CS[left] << endl;
	}
}

int main() {
	ABC122C();

	return 0;
}

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

const int mod = 1e9 + 7;
#define ll long long
ll ans = 0;
ll len = 0;

int main(){
	ll x;
	cin >> x;
	ll k=len = x / 11;
	ll n = x % 11;
	if (n > 6)len += 2;
	else if (n > 0)len++;
	len += k;
	cout << len << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    vector<int> A(10);
    for (int i = 0; i < 4; i++){
        int a;
        cin >> a;
        A.at(a)++;
    }
    if (A.at(1) && A.at(4) && A.at(7) && A.at(9)){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int[][] array = new int[4][13];
		for (int i = 0; i < a; i++) {
			String b = scanner.next();
			int c = scanner.nextInt();
			if (b.equals("S"))
				array[0][c - 1] = 1;
			else if (b.equals("H"))
				array[1][c - 1] = 1;
			else if (b.equals("C"))
				array[2][c - 1] = 1;
			else
				array[3][c - 1] = 1;
			}
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 13; j++) {
					if (array[i][j] == 0)
					if (i == 0)
						System.out.println("S " + (j + 1));
					else if (i == 1)
						System.out.println("H " + (j + 1));
					else if (i == 2)
						System.out.println("C " + (j + 1));
					else
						System.out.println("D " + (j + 1));
			}
		}
	}
}




Measured memory_bytes: 26260
#include <iostream>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i < (b); ++i)

using namespace std;
//const int MOD = 10e9+7;
const int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  

int a[100100][3];
int dp[100100][3];    

signed main (){
    int N; 
    cin >> N ;
    REP(i,N)REP(j,3) cin >> a[i][j];
    REP(i,N)REP(j,3) dp[i][j] = 0; 
    REP(i,N){
        REP(j,3){
            //前日にやったやついがいのものをやりつづければいい。
            REP(k,3){
                if(k == j) continue;
                dp[i+1][j] = max(dp[i][k]+a[i][j],dp[i+1][j]);
            }
        }   
    }
    int ans = 0;
    REP(j,3) ans = max(ans,dp[N][j]);
    cout << ans << endl;
}


Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		// スペース区切りの整数の入力
		String S = sc.next();
		
		int K = sc.nextInt();
		
		String[] a = S.split("");
		char[] b = new char[S.length()];
		char r = a[K - 1].charAt(0);
		
		for(int n = 0; n < N; n++) {
			b[n] = a[n].charAt(0);
		}
		
		for(int i = 0; i < N; i++) {
			if(b[i] == r) {
				System.out.print(b[i]);
			}
			else if(b[i] != r) {
				b[i] = '*';
				System.out.print(b[i]);
			}
		}

		// 出力
		System.out.println();
	}
}

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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int p = 0;
		int oc = 0;
		int rui[4] = {1,0,0,0};
		while(1){
			string s;
			getline(cin,s);
			if(s=="OUT") oc++;
			else if(s=="HIT"){
				if(rui[3]==1) p++;
				for(int j=3;j>0;j--) rui[j] = rui[j-1];
			}
			else if(s=="HOMERUN"){
				for(int j=1;j<4;j++){
					if(rui[j]==1) p++;
					rui[j] = 0;
				}
					p++;
			}
			if(oc==3) break;
		}
		cout << p << endl;
	}
}

Measured memory_bytes: 1212
/*
AizuOnline A0011
Drawing Lots
*/
#include <stdio.h>


main()
{
  int lc,bars,from,to;
  int lines[31];
  int i;
  int w;

  scanf("%d",&lc);
  scanf("%d",&bars);

  for(i=1;i<=lc;i++)
    lines[i] = i;
    
  for(i=0;i<bars;i++)
    {   scanf(" %d,%d",&from,&to);
        w = lines[from];
        lines[from]=lines[to];
        lines[to]=w;
    }
  for(i=1;i<=lc;i++)
    printf("%d\n",lines[i]);
    

return(0);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }
    public void Exe()
    {
        string input = Console.ReadLine();
        string abc = "ABC";
        string arc = "ARC";
        string ans = string.Compare(input, abc) == 0 ? arc : abc;
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 25940
import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

# 最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)
  
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

A, B = map(int,input().split())

if min([A, B]) == 1:
  print(1)
  exit()
  
num = gcd_list([A, B])
lst = factorization(num)
ans = 1 + len(lst)

print(ans)





Measured memory_bytes: 15236
# C-Slimes.rb
# https://atcoder.jp/contests/abc143/tasks/abc143_c
#
N = gets.strip.to_i
S = gets.strip.split('')
a = S[0]
count = 1
(1..(N-1)).each do |i|
  if a != S[i]
    a = S[i]
    count += 1
  end
end
puts count


Measured memory_bytes: 6908
#include <stdio.h>
int cube(int x)
{
  int y;
  y = (x)*(x)*(x);
  return(y);
}

int main(void)
{
  int x,a;
  scanf("%d",&x);
  a = cube(x);
  printf("%d\n",a);
  return(0);
}

Measured memory_bytes: 2720
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  setComb();

  int S;
  cin>>S;

  ll ans=0;
  for(int k=1;k<=S;k++){
    if(3*k>S) break;

    ll rest=S-3*k;
    ll res=hcomb(k,rest);
    add(ans,res);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 27084
H, W, K = [int(_) for _ in input().split()]

MOD = 1000000007

pats = [[0]]

for i in range(1, W):
    pats = [p + [i] for p in pats] + [p[:-1] + [i, i - 1] for p in pats if p[-1] == i - 1]

rs = [1] + [0] * (W - 1)

for j in range(H):
    rs = [sum(rs[p[i]] for p in pats) % MOD for i in range(W)]

print(rs[K - 1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  if (s>=t) cout << "No" <<endl;
  else cout << "Yes" << endl;
  return 0;
}


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

namespace Competition
{
    class Program
    {
        static int[] dx = { 1, 0, -1, 0 };
        static int[] dy = { 0, 1, 0, -1 };
        static int H, W;
        static int sx, sy, gx, gy;
        static string[] field = new string[1010];
        static long[,] d = new long[1010,1010];

        public static void bfs()
        {
            Queue<Tuple<int, int>> que = new Queue<Tuple<int, int>>();
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    d[i, j] = 1 << 29;
                }
            }
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (field[i][j] == '#')
                    {
                        que.Enqueue(new Tuple<int, int>(i, j));
                        d[i, j] = 0;
                    }
                }
            }

            while (que.Count() > 0)
            {
                var p = que.Dequeue();
                for(int i = 0; i < 4; i++)
                {
                    var ny = p.Item1 + dy[i];
                    var nx = p.Item2 + dx[i];

                    if (nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] != '#' && d[ny,nx] == 1 << 29)
                    {
                        que.Enqueue(new Tuple<int, int>(ny,nx));
                        d[ny,nx] = d[p.Item1, p.Item2] + 1;
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            H = hw[0]; W = hw[1];

            for (int i = 0; i < H; i++)
            {
                field[i] = Console.ReadLine();
            }
            bfs();
            long res = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (d[i, j] > res) res = d[i, j];
                }
            }
            Console.WriteLine(res);
        }
    }
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int i = 0;

		while(i*i <= N) {
			i++;
		}
		System.out.println((i-1)*(i-1));
	}

}


Measured memory_bytes: 21844
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int cnt = 0;

		for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == '1'){
					cnt++;

				}
			}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
int  main(){
    int n,count=0;
    cin >> n;
    vector<double> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    for(int i = 0; i < n; i++){
        while(ceil(v[i]/2.0) == floor(v[i]/2.0) && v[i] > 0){
            v[i] /= 2.0;
            count++;
        }
    }
    cout << count;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> P(N), pos(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        pos[P[i]] = i + 1;
    }

    multiset<ll> st;
    ll ans = 0;
    st.insert(0);
    st.insert(0);
    st.insert(N + 1);
    st.insert(N + 1);
    for (ll i = N; i >= 1; i--) {
        auto itr = st.lower_bound(pos[i]);
        ll xr = *itr;
        itr++;
        ll xrr = *itr;
        itr--;
        itr--;
        ll xl = *itr;
        itr--;
        ll xll = *itr;

        ans += i * (xr - pos[i]) * (xl - xll);
        ans += i * (xrr - xr) * (pos[i] - xl);

        st.insert(pos[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <array>

int main(){
	int num1,num2,num3,num4;
	while(std::cin >> num1 >> num2 >> num3 >> num4){
		//player A number
		std::array<int, 4> a_num = {{num1, num2, num3, num4}};
		std::cin >> num1 >> num2 >> num3 >> num4;
		//player B number
		std::array<int, 4> b_num = {{num1, num2, num3, num4}};
		
		int hit=0,blow=0;
		for(int i=0; i<4; ++i){
			for(int j=0; j<4; ++j){
				//equal numbers
				if(a_num[i] == b_num[j]){
					//same place number
					if(i == j){
						++hit;
					}
					//different place number
					else{
						++blow;
					}
				}
			}
		}
		//hit and blow output
		std::cout << hit << " " << blow << std::endl;
	}
}

Measured memory_bytes: 3060
x=int(input())
X=str(x)
if x<100:
  print(0)
else:
  m=int(X[len(X)-2:len(X)])
  n=0
  for a in range(1,6):
    while m>=6-a:
      n+=1
      m-=6-a
  if int(X[0:len(X)-2])>=n:
    print(1)
  else:
    print(0)

Measured memory_bytes: 3064
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

X =  list(map(int, sys.stdin.readline().split()))

if X.count(X[0]) == 1:
    print(X[0])
elif X.count(X[1]) == 1:
    print(X[1])
else:
    print(X[2])




Measured memory_bytes: 66028
#include <iostream>
using namespace std;
int main(){
  int N,D,X;cin>>N>>D>>X;
  int A[N];for(int i = 0; N > i; i++)cin >> A[i];
  int sm = 0;
  for(int i = 0; N > i; i++){
    if(D % A[i] != 0) sm += D/A[i]+1;
    else sm += D/A[i];
  }
  cout << X + sm<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){	
	long long int n, money = 1000, stock = 0;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	vector<int> v1;
	v1.pb(arr[0]);
	for(int i = 1; i < n; i++){
		if(arr[i] != arr[i - 1]){
			v1.pb(arr[i]);
		}
	}

	for(int i = 0; i < v1.size() - 1; i++){
		money += stock * v1[i];
		stock = 0;
		if(v1[i] < v1[i + 1]){
			stock = money / v1[i];
			money %= v1[i];
		}
	}

	money += stock * v1[v1.size() - 1];

	cout << money;
}

Measured memory_bytes: 3632
def lcs(s,t):
    m,n = len(s),len(t)
    a = [[0 for j in range(n+1)]for i in range(m+1)]
    k,p = "",0
    for i in range(m+1):
        for j in range(n+1):
            if i==0 or j==0:
                a[i][j]=0
            elif s[i-1]==t[j-1]:
                a[i][j]=a[i-1][j-1]+1
            else:
                a[i][j] = max(a[i-1][j],a[i][j-1])
    i,j = m,n
    while i>0 and j>0:
        if s[i-1]==t[j-1]:
            k+=s[i-1]
            i-=1
            j-=1
        elif a[i-1][j]>a[i][j-1]:
            i-=1
        else:
            j-=1
    return k[::-1]
s = input()
t = input()
k = lcs(s,t)
print(k)

Measured memory_bytes: 119900
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      int N = sc.nextInt();
      int T = sc.nextInt();
      int[] c = new int[N];
      int[] t = new int[N];
      for (int i=0; i<N; i++) {
        c[i] = sc.nextInt();
        t[i] = sc.nextInt();
      }
      int min =10000;
      for (int i=0; i<N; i++) {
        if (t[i] <= T) {
          min = Math.min(c[i],min);
        }
      }
      if (min == 10000) {
        System.out.println("TLE");
      } else {
        System.out.println(min);
      }
    }
}

Measured memory_bytes: 22868
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{
    static string S = Console.ReadLine();
    static string[] M = new string[] { "dream", "dreamer", "erase", "eraser" };
    static void Main()
    {
        string s = "";
        int cnt = 0;
     for(int i = S.Length - 1; i >= 0; i--)
        {
            s = S[i] + s;
            cnt++;
            if (cnt > 7)
            {
                Console.WriteLine("NO");
                return;
            }
            if (cnt == 5)
            {
                if (s == "dream" || s == "erase")
                {
                    cnt = 0;
                    s = "";
                }
            }
            if (cnt == 6)
            {
                if (s == "eraser")
                {
                    cnt = 0;
                    s = "";
                }
            }
            if (cnt == 7)
            {
                if (s == "dreamer")
                {
                    cnt = 0;
                    s = "";
                }
            }
        }
        if (cnt == 0)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 7128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N,M,X;
   cin >> N >> M >> X;
   int cost[N];
   int A[N][M];
   for(int i = 0 ; i < N ; i++){
      cin >> cost[i];
      for(int j = 0 ; j < M ; j++){
         cin >> A[i][j];
      }
   }
   int ans = INT_MAX;

   for(int i = 0 ; i < (1<<N); i++){
      int B[M];
      memset(B,0,sizeof(B));
      int curCos=0;
      for(int j = 0 ; j < N ; j ++){
         if((i&(1<<j))>0){
            curCos+=cost[j];
            for(int k = 0 ; k < M; k++){
               B[k]+=A[j][k];
            }
         }
      }
      bool ok=true;
      for(int k = 0 ; k < M; k++){
         if(B[k]<X){
            ok=false;
            break;
         }
      }
      if(ok) ans=min(ans,curCos);
   }
   if(ans==INT_MAX) cout << -1 << endl;
   else cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3644
package main

import (
  "fmt"
)

func main() {
  var N, Ma, Mb int
  fmt.Scan(&N, &Ma, &Mb)
  ABC := make([][]int, N)
  var a, b, c int
  A := 0
  B := 0
  C := 1
  for i := range ABC {
    fmt.Scan(&a, &b, &c)
    ABC[i] = []int{a, b, c}
    A += a
    B += b
    C += c
  }
  DP := make([][][]int, N + 1)
  DP[0] = make([][]int, A + 1)
  for j := 0; j < A + 1; j++ {
    DP[0][j] = make([]int, B + 1)
    for k := 0; k < B + 1; k++ {
      DP[0][j][k] = C
    }
  }
  DP[0][0][0] = 0
  for i := 0; i < N; i++ {
    DP[i + 1] = make([][]int, A + 1)
    for j := range DP[i + 1] {
      DP[i + 1][j] = make([]int, B + 1)
      for k := range DP[i + 1][j] {
        DP[i + 1][j][k] = DP[i][j][k]
      }
    }
    a, b, c = ABC[i][0], ABC[i][1], ABC[i][2]
    for j := a; j < A + 1; j++ {
      for k := b; k < B + 1; k++ {
        if DP[i][j - a][k - b] + c < DP[i + 1][j][k] {
          DP[i + 1][j][k] = DP[i][j - a][k - b] + c
        }
      }
    }
  }
  cost := C
  for m := 1; m * Ma < A + 1 && m * Mb < B + 1; m++ {
    if DP[N][m * Ma][m * Mb] < cost {
      cost = DP[N][m * Ma][m * Mb]
    }
  }
  if C <= cost { cost = -1 }
  fmt.Println(cost)
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#define ll long long
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define gcd(A,B) (__gcd(A,B))
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define mod 1000000007LL
#define all(x) x.begin(), x.end()
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

typedef pair<int,int> pii;
char str[1010];
int main()
{
    scanf("%s",str+1);
    for (int i = 1; i<=4; i++)
    {
        if (str[i] == str[i-1])
        {
            printf("Bad");
            return 0;
        }
    }
    printf("Good");
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int k;
    cin >> k;

    int t1 = 0, t2 = 0;
    for (int i = 1; i <= k; i++)
    {
        if (i % 2 == 0)
            t1++;
        else
            t2++;
    }
    cout << t1 * t2 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			char c = sc.next().charAt(0);
			if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
				System.out.println("vowel");
			} else {
				System.out.println("consonant");
			}
		}
	}
}


Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 100;

ll frq[N];
ll sum;
int main(){
  ios_base::sync_with_stdio(false);
  cout.tie(0); cin.tie(0);
  int n; cin >> n;
  ll x;
  for(int i =1 ;i <= n ; ++i){
    cin >> x;
    sum += x;
    frq[x]++;
  }
  int q; cin >> q;
  for(int i = 0;i < q ; ++i){
    ll b , c; cin >> b >> c;
    sum += (c-b)*frq[b];
    frq[c] += frq[b];
    frq[b] = 0;
    cout << sum << '\n';
  }

  return 0;
}



Measured memory_bytes: 4432
#include<iostream>
#include<string>
#include<vector>

using namespace std;


#define int long long

int s2tree(string &A, vector<int> &na, vector<pair<int,int>> &a, int b, int e){
	int inb = 0, ine = 0, number = 0;
	int ca = 0;
	
	if(e - b <= 1) return -1;
	
	for(int i = b, depth = 0; i < e; i++){
		if(A[i] == '(') {
			depth++;
		} else if(A[i] == ')'){
			depth--;
		}
		
		if(A[i] == '[' && !depth) {
			inb = i+1;
		}
		
		if(A[i] == ']' && !depth) {
			ine = i;
		}
	}
	
	for(int i = inb; i < ine; i++){
		number = number * 10 + A[i] - '0';
	}
	
	na.push_back(number);
	a.push_back(make_pair(-1,-1));
	
	ca = (int)a.size()-1;
	int fa = s2tree(A, na, a, b + 1, inb-2);
	
	int sa = s2tree(A, na, a, ine + 2, e-1);
	
	a[ca].first  = fa;
	a[ca].second = sa;
	
	return ca;
}

int synthesis(
vector<pair<int,int> > &a, vector<pair<int,int> > &b, vector<pair<int,int> > &c, vector<int> &na, vector<int> &nb, vector<int> &nc, int ca = 0, int cb = 0){
	int cc;
	
	nc.push_back(na[ca] + nb[cb]);
	c.push_back(make_pair(-1,-1));
	
	cc = c.size()-1;
	
	
	if(a[ca].first != -1 && b[cb].first != -1) {
	int temp = synthesis(a, b, c, na, nb, nc, a[ca].first, b[cb].first);
		c[cc].first = temp;
	}
	
	if(a[ca].second != -1 && b[cb].second != -1) {
		int temp = synthesis(a, b, c, na, nb, nc, a[ca].second, b[cb].second);
		c[cc].second = temp;
	}
	
	return cc;
}

string tree2s(vector<int>& nc, vector<pair<int,int> > &c, int cc = 0){
	string ra, rb, rc;
	
	if(cc == -1) return "";
	
	ra = tree2s(nc, c, c[cc].first);
	rc = tree2s(nc, c, c[cc].second);
	
	return "(" + ra + ")" + "[" + to_string(nc[cc]) + "]" + "(" + rc + ")";
}
signed main(){
	string A, B, C;
	vector<int> na, nb, nc;
	vector<pair<int,int> > a, b, c;
	
	cin>>A>>B;
	s2tree(A, na, a, 0, A.size());
	s2tree(B, nb, b, 0, B.size());
	synthesis(a, b, c, na, nb, nc);
	C = tree2s(nc, c);
	
	cout<<C<<endl;
}


Measured memory_bytes: 3312
//萌新看过（膜拜）大佬后写出（逃） 
#pragma GCC optimize("Ofast",3,"inline")
#include <bits/stdc++.h>
using namespace std;
string s;
int ans[100000],turn[2];
int main(){
	ios_base::sync_with_stdio(false);
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='R'&&s[i+1]=='L'){
			memset(turn,0,sizeof(turn));
			for(int j=i;j>=0;j--){
				if(s[j]=='R')turn[(i-j)%2]++;
				else break;
			}
			for(int j=i+1;j<s.size();j++){
				if(s[j]=='L') turn[(j-i)%2]++;
				else break;
			}
			ans[i]=turn[0];
			ans[i+1]=turn[1];
		}
	}
	for(int i=0;i<s.size();i++) cout<<ans[i]<<' ';
	return 0;
}



Measured memory_bytes: 1104
#include<stdio.h>

int main(void)

{

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(x>=W||x<=0){

printf("No\n");

}

else if(y>=H||y<=0){

printf("No\n");

}

else if(x+r>W||x-r<0){

printf("No\n");

}

else if(y+r>H||y-r<0){

printf("No\n");

}

else

printf("Yes\n");

return 0;

}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    int n;
    string s;
    cin >> n >> s;
    string s1 = s.substr(0, n/2);
    string s2 = s.substr(n/2, n);
    if(s1 == s2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;
  vector<string> S(N);
  cin >> S;

  sort(all(S));

  int len = 0, i = 0;
  while (i < N) {
    string s = S[i];
    int c = 1;
    while (i + c < N) {
      if ((string)S[i + c] == s)
        c++;
      else
        break;
    }
    chmax(len, c);
    i += c;
  }

  i = 0;
  while (i < N) {
    string s = S[i];
    int c = 1;
    while (i + c < N) {
      if ((string)S[i + c] == s)
        c++;
      else
        break;
    }
    if (c == len) {
      out(s);
    }
    i += c;
  }
}


Measured memory_bytes: 12928
use std::io;
use std::collections::HashSet;

/// https://beta.atcoder.jp/contests/abc064/tasks/abc064_c
fn main() {
    let _n = read_one::<usize>();
    let vec = read::<usize>();

    let under = vec.iter()
        .filter(|&x| *x < 3200)
        .map(|x| x / 400)
        .collect::<HashSet<usize>>()
        .len();

    let over = vec.iter()
        .filter(|&x| *x >= 3200)
        .count();

    if under == 0 {
        println!("1 {}", over);
    } else {
        println!("{} {}", under, under + over);
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a < b) {
    for (int i = 0; i < b; i++) {cout << a;}
  }
  else {
    for (int i = 0; i < a; i++) {cout << b;}
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
 
typedef long double ld;
 
const ld eps = 1e-20, INF = 1e3;
 
int N;
bool exist[256];
ld disappear[256];
ld Px[256], Py[256], Pz[256], Vx[256], Vy[256], Vz[256], R[256], Vr[256];
 
ld collision(int i, int j) {
  ld vx = Vx[i] - Vx[j], vy = Vy[i] - Vy[j], vz = Vz[i] - Vz[j], vr = Vr[i] + Vr[j];
  ld px = Px[i] - Px[j], py = Py[i] - Py[j], pz = Pz[i] - Pz[j], r = R[i] + R[j];
  ld a = vx * vx + vy * vy + vz * vz - vr * vr;
  ld b = 2 * (vx * px + vy * py + vz * pz + vr * r);
  ld c = px * px + py * py + pz * pz - r * r;
  if (abs(a) < eps) {
    if (abs(b) < eps) return INF;
    ld res = -c / b;
    if (res < 0) return INF;
    return res;
  }
  ld D = b * b - 4 * a * c;
  if (D < 0) return INF;
  ld resa =  (-b - sqrt(D)) / 2 / a;
  ld resb =  (-b + sqrt(D)) / 2 / a;
  if (resa > 0) return resa;
  if (resb > 0) return resb;
  return INF;
}
 
int main() {
  while (cin >> N, N) {
    REP(i,N) cin >> Px[i] >> Py[i] >> Pz[i] >> Vx[i] >> Vy[i] >> Vz[i] >> R[i] >> Vr[i];
    REP(i,N) exist[i] = true;
    ld res = 0;
    while (true) {
      bool flag = true;
      REP(i,N) if(exist[i]) flag = false;
      if (flag) break;
      int cola = 0, colb = -1;
      ld coltime = INF;
      REP(i,N) if (exist[i]) {
        ld t = R[i] / Vr[i];
        if (t < coltime) {
          cola = i;
          coltime = t;
        }
      }
      REP(i,N) {
        if (!exist[i]) continue;
        REP(j,i) {
          if (!exist[j]) continue;
          ld t = collision(i, j);
          if (t < coltime) {
            coltime = t;
            cola = i; colb = j;
          }
        }
      }
      res += coltime;
      exist[cola] = false;
      disappear[cola] = res;
      if (colb >= 0) {
        exist[colb] = false;
        disappear[colb] = res;
      }
      REP(i,N) {
        Px[i] += Vx[i] * coltime;
        Py[i] += Vy[i] * coltime;
        Pz[i] += Vz[i] * coltime;
        R[i] -= Vr[i] * coltime;
      }
    }
    REP(i,N) cout << setprecision(10) << fixed << disappear[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1324
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back
#define INF 1000000007

int main(void)
{
  int n;
  cin >> n;
  vec<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] = INF - 1 - a[i];

  vec<int> s(n, INF);
  vec<int> id(n);
  rep(i, n) {
    id[i] = distance(s.begin(), upper_bound(s.begin(), s.end(), a[i]));
    s[id[i]] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  cout << m + 1 << endl;
  return 0;
}



Measured memory_bytes: 1656
import sys
from collections import deque
input = sys.stdin.readline

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)

dist = [[-1] * n for _ in range(n)]
for i in range(n):
    queue = deque([(i, 0)])
    while queue:
        v, c = queue.popleft()
        for v_next in graph[v]:
            if dist[i][v_next] == -1:
                dist[i][v_next] = c + 1
                queue.append((v_next, c+1))

# print(dist)
ans_len = n + 1
for i in range(n):
    if dist[i][i] != -1:
        ans_len = min(ans_len, dist[i][i])
if ans_len == n + 1:
    print(-1)
else:
    for i in range(n):
        if dist[i][i] == ans_len:
            start_v = i
            break

    dist = [-1] * n
    prev_v = [-1] * n
    queue = deque([(start_v, 0)])
    while queue:
        v, c = queue.popleft()
        if v == start_v and c != 0:
            break
        for v_next in graph[v]:
            if dist[v_next] == -1:
                dist[v_next] = c + 1
                prev_v[v_next] = v
                queue.append((v_next, c+1))

    ans = []
    # print(start_v)
    # print(dist)
    # print(prev_v)
    v = start_v
    for i in range(ans_len):
        ans.append(v+1)
        v = prev_v[v]

    print(ans_len)
    print(*ans, sep='\n')


Measured memory_bytes: 35060
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int m,n=1110101;
int a[111111];
int wh(int xx)
{
	int aa=0;
	while(xx>0)
	{
		aa+=xx%10;
		xx/=10;
	}
	return aa;
}
int main()
{
	cin>>m;
	for(int x=1;x<m/2+1;x++)
	{
		n=min(n,wh(x)+wh(m-x));
	}
	cout<<n<<endl;
}

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

int main(){

    int a,b,c;

    cin >> a >> b >> c;
    if(a==b){
        cout << c << endl;
    }else if(a==c){
        cout << b << endl;
    }else{
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,c= [int(i) for i in input().split()]
t_tk_r=0
t_md_r=0
g_tk_r=0
g_md_r=0
t_tk_m=0
t_md_m=0
g_tk_m=0
g_md_m=0
t_tk=[]
t_md=[]
g_tk=[]
g_md=[]
a=[]
d1=0

for i in range(n):
  a.append([int(i) for i in input().split()])

for d0,v0 in a:
  t_tk_r += v0-(d0-d1)
  t_md_r += v0-(d0-d1)*2
  t_tk_m = max(t_tk_m,t_tk_r)
  t_md_m = max(t_md_m,t_md_r)
  t_tk.append(t_tk_m)
  t_md.append(t_md_m)
  d1=d0
  
d1=0  
for d0,v0 in a[::-1]:
  g_tk_r += v0-((c-d0)-d1)
  g_md_r += v0-((c-d0)-d1)*2
  g_tk_m = max(g_tk_m,g_tk_r)
  g_md_m = max(g_md_m,g_md_r)
  g_tk.append(g_tk_m)
  g_md.append(g_md_m)
  d1=(c-d0) 
mx=max(max(t_tk),max(g_tk),0)

for i in range(n-1):
  mx=max(mx,t_tk[i]+g_md[n-2-i],t_md[i]+g_tk[n-i-2])
print(mx)


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

int main(void)
{
    using namespace std;
    int r, c;
    scanf("%d %d", &r, &c);
    int num;
    int total;
    int total_row[c] = {0};

    for (int i = 0; i < r; i++) {
        total = 0;
        for (int j = 0; j < c; j++) {
            scanf("%d", &num);
            printf("%d ", num);
            total += num;
            total_row[j] += num;
        }
        printf("%d\n", total);
    }

    total = 0;
    for (int i = 0; i < c; i++) {
        total += total_row[i];
        printf("%d ", total_row[i]);
    }
    printf("%d\n", total);
} 


Measured memory_bytes: 3208
# ABC105C

n = int(input())
def sub(n):
    if n==0:
        return []
    k = 1
    count = 0
    pos = 1
    neg = 0
    while True:
        if (n>0 and pos>=n) or (n<0 and abs(neg)>=abs(n)):
            break
        count += 1
        k *= (-2)
        if k>0:
            pos += k
        else:
            neg += k
#     print(n, pos, neg, k)
    return [count] + (sub(n-k) if n>0 else sub(n-k))
out = sub(n)
if not out:
    print(0)
else:
    s = ["0"] * (max(out)+1)
    for item in out:
        s[item] = "1"
    print("".join(s[::-1]))

Measured memory_bytes: 38576
#include <cstdio>
#include <unordered_map>
#include <algorithm>
#include <map>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
const int N = 1000001;
char s[N];
int n , q;
int main()
{
    scanf("%d", &n);
    scanf("%s", s);
    scanf("%d", &q);
    while (q --)
    {
        int len;
        scanf("%d", &len);
        long long ans = 0;
        long long sum = 0;
        int x = 0, y = 0;
        int r = 0;
        if (s[0] == 'M') x++;
        else
            if (s[0] == 'C' ) y ++;
        for (int i = 0; i < n ; i ++)
        {
            if (i)
            {
                if (s[i - 1] == 'M') sum -= y, x --;
                else
                    if (s[i - 1] == 'C') y --;
            }
            while (r + 1 < n && r + 1 - i + 1 <= len)
            {
                r ++;
                if (s[r] == 'M') x ++;
                else
                    if (s[r] == 'C') sum += x, y ++;
            }
            if (s[i] == 'D')
                ans += sum;
        }
        printf("%lld\n" ,ans);
    }
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{
  int f[N2],space,MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
  int sum=0;
  for(int i=0;i<N2;i++){
    if(pz.f[i]==N2) continue;
    sum=sum+MDT[i][pz.f[i]-1];
  }
  return sum;
}

bool isSolved() {
  for(int i=0;i<N2;i++){
    if(state.f[i]!=i+1) return false;
  }
  return true;
}

bool dfs(int depth,int prev){
  if(state.MD==0) return true;
  if(depth+state.MD>limit) return false;

  int sx=state.space/N;
  int sy=state.space%N;
  Puzzle tmp;

  for(int r=0;r<4;r++){
    int tx=sx+dx[r];
    int ty=sy+dy[r];
    if(tx<0||ty<0||tx>=N||ty>=N) continue;
    if(max(prev,r)-min(prev,r)==2) continue;
    tmp=state;
       
    state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty],state.f[sx*N+sy]);
    state.space=tx*N+ty;
    if(dfs(depth+1,r)){
      path[depth]=r;
      return true;
    }
    state=tmp;
  }
  
  return false;
}

string iterative_deepening(Puzzle in){
  in.MD=getAllMD(in);

  for(limit=in.MD;limit<=LIMIT;limit++){
    state=in;
    if(dfs(0,-100)){
      string ans="";
      for(int i=0;i<limit;i++){
	ans+=dir[path[i]];
      }
      return ans;
    }
  }

  return "unsolvable";
}

int main(){
  for(int i=0;i<N2;i++){
    for(int j=0;j<N2;j++){
      MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
    }
  }

  Puzzle in;

  for(int i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }

  string ans=iterative_deepening(in);
  cout<<ans.size()<<endl;

  return 0;
}

Measured memory_bytes: 3168
import copy
n = int(input())
x = list(map(int,input().split()))
a = copy.copy(x)
a.sort()
half = n//2
for i in range(n):
	if x[i] < a[half]:
		print(a[half])
	elif x[i] == a[half]:
		print(a[half-1])
	else:
		print(a[half-1])

Measured memory_bytes: 26528
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const ll maxn = 1000005;
const double pi = acos(-1.0);

int n;
int p[maxn];

int main()
{
    while(cin >> n)
    {
        for(int i = 0; i < n;i ++)
            cin >> p[i];
        int ans = 0;
        for(int i = 0; i < n; i ++)
        {
            if(i > 0 && i < n - 1)
            {
                if(p[i] > min(p[i - 1], min(p[i], p[i + 1])) && p[i] < max(p[i - 1], max(p[i], p[i + 1])))
                    ans ++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[55], b[55], c[55], d[55];
int x[15];
int n, m, q;
int ans = 0;
void dfs(int i, int mx){
    if(i == n+1){
        int sum = 0;
        for(int j=1;j<=q;j++){
            if(x[b[j]]-x[a[j]] == c[j]) sum += d[j];
        }
        ans = max(ans, sum);
        return;
    }
    for(int j=mx;j<=m;j++){
        x[i] = j;
        dfs(i+1, j);
    }
}

int main(){
    scanf("%d%d%d", &n, &m, &q);
    for(int i=1;i<=q;i++) scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
    dfs(1, 1);
    printf("%d\n", ans);
}

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

using namespace std;

bool pal(int x){
	int d[10], s;
	for(s = 0;x;s++){
		d[s] = x % 10;
		x /= 10;
	}
	for(int i = 0;i < s;i++){
		if(d[i] != d[s - i - 1])return false;
	}
	return true;
}
int main(){
	int n;
	cin >> n;
	int l = 0;
	while(true){
		if(pal(n - l)){
			n -= l;
			break;
		}
		if(pal(n + l)){
			n += l;
			break;
		}
		l++;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	while(true){

			int n,m,r,x;
			cin >> n >> m;
			if(n==0 && m==0) break;

			vector<int>a(n+1);
			vector<int>c(n+1);
			vector<int>t(n+1);
			vector<int>p(n+1);


            rep(i,3){
			cin >> r;
			rep(j,r){ cin >> x; p[x]=i;}
            }

            t[n]=2;
            a[n]=p[n]; c[n]=2-p[n];

            for(int k=n;k>1;k--){

            t[k-1]=3*t[k]+2;

            if(p[k-1]==0){

            a[k-1]=a[k];
            c[k-1]=c[k]+2*t[k]+2;

            }

            if(p[k-1]==1){

            a[k-1]=c[k]+t[k]+1;
            c[k-1]=a[k]+t[k]+1;

            }

            if(p[k-1]==2){

            a[k-1]=a[k]+2*t[k]+2;
            c[k-1]=c[k];

            }

            }

            if(min(a[1],c[1])<=m)
            cout << min(a[1],c[1]) << endl;
            else cout << -1 << endl;


            }

	return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections.Generic;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            Console.ReadLine();
            var s = new HashSet<string>(Console.ReadLine().Split());
            Console.ReadLine();
            int count = 0;
            foreach(var item in Console.ReadLine().Split()) {
                count += s.Contains(item) ? 1 : 0;
            }
            Console.WriteLine(count);
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	ll n,k;
	cin>>n>>k;
	bool arr[10];
	fill(arr,arr+10,true);
	while(k--){
		int val;
		cin>>val;
		arr[val] = false;
	}
	while(1) {
		bool flag = true;
		ll val = n;
		while(val>0) {
			if(!arr[val%10]){
				flag=false;
				break;
			}
			val/=10;
		}
		if(flag) {
			cout<<n;
			break;
		}
		n++;
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	string s;
	cin>>s;
	bool f = true;
	int n = s.size();
	if(n%2==0) f = false;
	for(int i=0;i<n;i++){
		if(s[i]!=s[n-1-i]){
			f = false;
			break;
		}
	}
	for(int i=0;i<n/2;i++){
		if(s[i] != s[n/2-1-i]){
			f = false;
			break;
		}
	}
	for(int i=n/2+1;i<n;i++){
		if(s[i] != s[n-1+n/2+1-i]){
			f = false;
			break;
		}
	}
	if(f){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define vi           vector<int>
#define vll          vector<long long>
#define all(x)       x.begin(),x.end()
#define mod 1000000007 
#define mx 1000005
#define mii          map<int,int>
#define mumii        multimap<int,int> 
#define mx2 65
#define inf 4e18
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gt           greater<int>()
//The ASCII value of the lowercase alphabet is from 97 to 122.
//The ASCII value of the uppercase alphabet is from 65 to 90.

void solve()
{
     int x,y,z;
     cin>>x>>y>>z;
     swap(x,y);
     swap(x,z);
     
     cout<<x<<" "<<y<<" "<<z; 
}
int main()
{
	fast;
	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

using namespace std;

 int main(){
	int n, k;
	cin>>n>>k;
	vector<int> vec(n,0);
	int ans=n;
	for(int i=0; i<k; i++){
		int x;
		cin>>x;
		for(int j=0; j<x; j++){
			int h;
			cin>>h;
			if(vec[h-1]==0){
				vec[h-1]=1;
				ans-=1;
			}
		}
	}
	cout<<ans<<"\n";
 }


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  cin >> n;
  vi w(n);
  re(i, n) cin >> w[i];

  int sum = 0;
  re(i, n) sum += w[i];

  int m = INF;
  re(i, n) {
    int s = 0;
    re(j, i+1) s += w[j];
    m = min(m, abs((sum-s)-s));
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long x,y,result;
    x=max(a*c,a*d);
    y=max(b*c, b*d);
    result=max(x,y);
    cout << result << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for(int i=0; i<N; i++){
    cin >> s[i] >> t[i];
  }
  string X;
  cin >> X;

  int flag = 0;
  int ans = 0;
  for(int i=0; i<N; i++){
    if(flag == 1) ans += t[i];
    if(s[i] == X) flag = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections
N=int(input())
S=[""]*N
ans=[]
for k in range(N):
    S[k]=input()
count = collections.Counter(S)
maximum = max(count.values())
for i,j in count.items():
    if j == maximum:
        ans.append(i)
ans.sort()
for j in range(len(ans)):
    print(ans[j])

Measured memory_bytes: 35560