akhauriyash/Code-Regression huggingface dataset:
"""
問題自体は単純で、配列Pを先頭から見ていき、
見ている箇所より左側（インデックス番号が見ている箇所より小さいもの）が
すべて見ている値よりも大きければ答えをカントアップ。
配列全てを確認し終わった時点の答えを出力すれば良い。

ただし、Pの最大サイズが 2 × 10**5 なので、

for i in range(N):
    for j in range(i):
        if P[i] < P[j]:
            ans +=1
            
などとすると、　N ** 2 ≒ 10 ** 10 となり間に合わない。
ので、以下のソースのように、確認するインデックス（ i )より
左側の最小値を for文を使用せず保持して比較していけば、
計算量が N になるため、十分に間に合う。
"""


def main():
    # 入力の取得
    N = int(input())
    P = list(map(int, input().split()))

    # i = 0 (配列の先頭の値)は常に条件が成立するので、
    # 答えをカウントアップしておき、for文は i = 1から回す。
    ans = 1

    # 見ている箇所より前の部分までの最小値を保持しておく。
    # for文を回し始める時（i = 1 の時）、確認する箇所より左側は
    # インデックスが０の値しかないので、それを最小値として保持しておく。
    min_val = P[0]

    # インデックス１から配列Pを順番に確認していく。
    for i in range(1, N):
        # インデックス i - 1までのうち最小の値と比較
        if P[i] <= min_val:
            # 成立しているので答えをカウントアップ
            ans += 1

            # インデックス i - 1までの最小値よりも小さいので、最小値を更新
            min_val = P[i]

            # 問題文から、Pは１以上の値しかとらず、値の被りがないので、
            # 値；１が出てきたらそれ以降は常にP[i] > 1 となるので比較するだけ無駄。
            # なので、for文を終了させる。（この処理はなくても間に合うはず）
            if min_val == 1:
                break

    # 答えを出力
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s,t,u;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  cin>>u;
  if (u==s) cout<<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
    int n, l, r, sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> l;
        cin >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int n2= sc.nextInt();

        if (n>=10 || n2>=10)
        {
            System.out.println(-1);
        }else
        {
            System.out.println(n*n2);
        }

        sc.close();
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        vll v;
        rep(i, n){
            cin >> a;
            v.pb(a);
        }
        for(ll i = n - 2; i >= 0; i--){
            v.pb(v[i]);
        }
        cnt = 0;
        rep(i, v.size()){
            cnt = max(cnt, i + v[i] / 10);
            if(cnt < i + 1 && i != v.size() - 1){
                print("no");
                return 0;
            }
        }
        print("yes");
    }
}



Measured memory_bytes: 11320
class Node():
    def __init__(self, value, parent=None):
        self.value = value
        self.parent = parent
        self.left = None
        self.right = None

    def get_depth(self):
        if self.parent is None:
            return 0

        return self.parent.get_depth() + 1

    def get_height(self):
        if self.left is None and self.right is None:
            return 0
        l = 0 if self.left is None else self.left.get_height()
        r = 0 if self.right is None else self.right.get_height()

        return max(l, r) + 1

    def print(self):
        depth = self.get_depth()
        height = self.get_height()
        p = str(self.parent.value if self.parent else -1)
        s = -1
        if self.parent and self.parent.right == self and self.parent.left:
            s = self.parent.left.value
        if self.parent and self.parent.left == self and self.parent.right:
            s = self.parent.right.value
        s = str(s)
        d = bool(self.left) + bool(self.right)
        t = 'leaf'
        if self.parent is None:
            t = 'root'
        elif self.left or self.right:
            t = 'internal node'

        print('node ' + str(self.value) + ': parent = ' + p + ', sibling = ' + s + ', degree = ' + str(d) + ', depth = ' + str(depth) + ', height = ' + str(height) + ', ' + t)


n = int(input())
m = {}
for _ in range(n):
    l = list(map(int, input().split()))
    p = m[l[0]] if m.get(l[0]) else Node(l[0])
    left = None
    right = None
    if l[1] != -1:
        left = m[l[1]] if m.get(l[1]) else Node(l[1])
    if l[2] != -1:
        right = m[l[2]] if m.get(l[2]) else Node(l[2])
    if left:
        left.value = l[1]
        left.parent = p
        p.left = left
        m[left.value] = left
    if right:
        right.value = l[2]
        right.parent = p
        p.right = right
        m[right.value] = right
    m[l[0]] = p

for i in range(n):
    m[i].print()



Measured memory_bytes: 5620
N,*A = map(int, open(0).read().split())
init = A[0]
cash = 1000
stock = 0
if A[1] <= A[0]:
    dif = -1
else:
    stock,cash = divmod(cash,A[0])
    dif = 1
for i in range(2,N):
    if A[i] > A[i-1]:
        if dif == -1:
            stock,cash = divmod(cash,A[i-1])
            dif = 1
    elif A[i] < A[i-1]:
        if dif == 1:
            cash = cash + stock * A[i-1]
            stock = 0
            dif = -1
if dif == 1:
    cash = cash + stock * A[N-1]
print(cash)

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

using namespace std;

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

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

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

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

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

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

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < m; ++i) cin >> p[i].second >> p[i].first;
  sort(p);
  int t = -1, res = 0;
  for (auto i : p) {
    if (t <= i.second) {
      ++res;
      t = i.first;
    }
  }
  cout << res << endl;
}



Measured memory_bytes: 1152
N, K = input().split()
N = int(N)
K = int(K)
Sunuke = set(range(N))
for i in range(K):
  d = int(input())
  X = list(map(int, input().split()))
  for x in X:
    Sunuke.discard(x-1)
print(len(Sunuke))

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

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

using namespace std;

const int MOD = 1000000007;

void init();
void preorderDFS(int v);

int n, k;
long long ans = 1;
vector<vector<int>> g;
vector<int> vcnt;
vector<bool> done;

int main()
{
	init();

	preorderDFS(0);

	cout << ans << endl;
}

void init()
{
	cin >> n >> k;
	g.resize(n);

	REP(_i, n - 1)
	{
		int a, b; cin >> a >> b; --a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vcnt.resize(n, 0);
	done.resize(n, false);
}

void preorderDFS(int v)
{
	int c = k;
	int fixed = 0;
	for (int u : g[v])
		if (done[u])
		{
			c -= vcnt[u];
			++fixed;
		}

	if (c < 0) { ans = 0; return; }

	ans = ans * c % MOD;
	done[v] = true;
	vcnt[v] = 1 + fixed;

	for (int u : g[v])
		if (!done[u])
		{
			preorderDFS(u);
			++vcnt[v];
		}
}

//// done E in 50mins on 30th Sep, 2019 ////


Measured memory_bytes: 9600
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(s[k-1])



Measured memory_bytes: 2940
n,k=map(int, input().split())
a=[]*k
cnt=0
d=[]
for i in range(k):
    d.append(int(input()))
    b=list(map(int,input().split()))
    a.append(b)
for i in range(1,n+1):
    for j in range(k):
        if i in a[j]:
            break
    else:
        cnt+=1
print(cnt)


Measured memory_bytes: 9188
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string S;
    cin >> S;

    vector<bool > N(26, false);

    for(ll i = 0; i < S.length(); i++){
        N[S[i]-'a'] = true;
    }

    for(ll i = 0; i < 26; i++){
        if(N[i] == false){
            cout << (char) (i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
int N, a[100010], n[100010];
struct A {
    int bf;
    int af;
    int num;
};
vector<A> p;
void solve()
{
    FOR(i, 0, N)
    {
        A b;
        b.bf = a[i];
        b.af = abs(a[i]);
        b.num = i + 1;
        p.push_back(b);
    }
    sort(all(p), [](A& x, A& y) {
        return x.af < y.af;
    });
    int c = -1;
    FOR(i, 0, N)
    {
        if (p[i].bf < 0) {
            n[i] = -1;
        } else {
            n[i] = 1;
        }
    }
    int tn = 0, tp = 0;
    ;
    FOR(i, 0, N - 1)
    {
        /*
        if (p[i].bf * p[i + 1].bf <= 0) {
            c = i;
            break;
        }*/
        if (n[i] == 1) {
            tp++;
        } else {
            tn++;
        }
    }
    bool flag = true;
    int ans = 0;
    int fp = 0, fn = 0;
    if (tp == N || tn == N) {
        flag = false;
        if (n[0] == 1) {
            n[0] = -1;
            fn = 0;
            fp = 1;
        } else {
            n[0] = 1;
            fn = 1;
            fp = 0;
        }
    }
    if (flag)
        FOR(i, 0, N)
        {
            if (n[i] == -1 && !fn) {
                fn = i;
            } else if (n[i] == 1 && !fp) {
                fp = i;
            }
        }
    /*
    FOR(i, 0, N)
    {
        if (n[i] == 1) {
            ans += p[i].bf;
        } else {
            ans -= p[i].bf;
        }
    }
    */
    {
        int t = 0;
        t = p[fn].bf;
        FOR(i, 0, N)
        {
            if (i != fn && i != fp && n[i] == 1) {
                t -= p[i].bf;
            }
        }
        t = p[fp].bf - t;
        FOR(i, 0, N)
        {
            if (i != fn && i != fp && n[i] == -1) {
                t -= p[i].bf;
            }
        }
        ans = t;
    }
    cout << ans << endl;
    int t = 0;
    t = p[fn].bf;
    int COUNT = 0;
    FOR(i, 0, N)
    {
        if (i != fn && i != fp && n[i] == 1) {
            cout << t << " " << p[i].bf << endl;
            t -= p[i].bf;
            COUNT++;
        }
    }
    if (COUNT != N - 1) {
        cout << p[fp].bf << " " << t << endl;
        t = p[fp].bf - t;
    }
    FOR(i, 0, N)
    {
        if (i != fn && i != fp && n[i] == -1) {
            cout << t << " " << p[i].bf << endl;
            t -= p[i].bf;
        }
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> a[i];
    }
    solve();
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)
used = [False] * (2**N)
used[0] = True
for r in range(N):
    cur = deque()
    rem = 2**r
    for i in range(2**N):
        if used[i]:
            cur.append(S[i])
        elif cur and cur[0] > S[i]:
            cur.popleft()
            used[i] = True
            rem -= 1
            if rem == 0:
                break
    if rem > 0:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 98456
#include <stdio.h>
#include <stdlib.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int N,L;
  scanf("%d %d",&N,&L);

  int MIN = 999;
  int ans = 0;
  int flag = 1;
  for (int i = 0; i < N; i++) {
    ans += L+i;
    if(MIN > abs(L+i)){
      MIN = abs(L+i);
      if(L+i < 0) flag = 0;
    }
  }

  if(flag == 0) MIN *= -1;
  printf("%d\n",ans-MIN);

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n, i, b, f, r, v, j, k, l;
	int sogou[4][3][10] = { 0 };
	

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d""%d""%d""%d", &b, &f, &r, &v);

		sogou[b - 1][f - 1][r - 1] = sogou[b - 1][f - 1][r - 1] + v;
	}

		for (l = 0; l < 4; l++)
		{
			for (j = 0; j < 3; j++)
			{
				for (k = 0; k < 10; k++)
				{
					printf(" %d", sogou[l][j][k]);
				}

				printf("\n");
			}
			if (l != 3)
				printf("####################\n");
		}
	return 0;
}



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

int main(){
  int N;cin>>N;
  char A[210000];cin>>A;
  string S;
  S=A;
  int black[210000]={};
  int white[210000]={};
  if(S[0]=='#'){
    black[0]=1;
  }
  for(int i=1;i<N;i++){
    black[i]=black[i-1];
    if(S[i]=='#'){
      black[i]++;
    }
  }
  if(S[N-1]=='.'){
    white[N-1]=1;
  }
  for(int i=N-2;i>=0;i--){
    white[i]=white[i+1];
    if(S[i]=='.'){
      white[i]++;
    }
  }
  int ans=white[0];
  for(int i=1;i<N;i++){
    int tmp=black[i-1]+white[i];
    ans=min(tmp,ans);
  }
  ans=min(ans,black[N-1]);
  cout<<ans<<endl;
}

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

#define ll long long
#define ft first
#define sd second
#define pb push_back
using namespace std;
const int mod = 1e9+7;

ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) a += mod;
    return a;
}
ll mul(ll a, ll b) {
    a *= b;
    if(a >= mod) a %= mod;
    return a;
}
ll power(ll a, ll b, ll m = mod) {
    ll res = 1;
    while(b) {
        if(b & 1) {
            res = 1LL * res * a % m;
        }
        a = 1LL * a * a % m;
        b /= 2;
    }
    return res;
}
const int N = 5e4+9;
int a[N];


signed main() {  

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    
    int n, x; cin >> n >> x;
    int d = 0;
    int ans = 1;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        d = d + a[i];
        if(d > x) break;
        ans++;
    }
    cout << ans << "\n";






    return 0;
    
}

Measured memory_bytes: 256
N=gets.to_i
v=gets.chomp.split.map(&:to_i)
c=gets.chomp.split.map(&:to_i)
t=[]
N.times do |i|
  t << v[i]-c[i]
end
t.sort!.reverse!
ans=0
t.each do |n|
 break if n <= 0
 ans+=n
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i,n+1)rep(j,n+1)if(r*i+g*j <= n){
        int t = n - r*i - g*j;
        if(t%b == 0){
            ans++;
            //cout << i << " " << j <<" " << t << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
(defun S (n)
  (cond
    ((zerop n) 0)
    (t
     (multiple-value-bind (q r) (floor n 10)
       (+ r (S q))))))

(defun answer (n)
  (zerop (mod n (S n))))

(princ (if (answer (read))
           "Yes" "No"))

Measured memory_bytes: 13284
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_LEN_MAX		100005									// 最大文字列長

// 内部変数
static FILE *szpFpI;											// 入力
static char sc1Str[D_LEN_MAX];									// 文字列
static int siLen;												// 文字列長
static int si1ACnt[D_LEN_MAX];									// 累積AC数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 文字列長・質問数 - 取得
	int liQCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siLen, &liQCnt);

	// 文字列 - 取得
	fgets(sc1Str, sizeof(sc1Str), szpFpI);

	// 累積AC数 - セット
	for (i = 1; i < siLen; i++) {
		if (sc1Str[i - 1] == 'A') {
			if (sc1Str[i] == 'C') {
				si1ACnt[i] = 1;
			}
		}
		si1ACnt[i] += si1ACnt[i - 1];
	}

	// 質問 - 取得
	for (i = 0; i < liQCnt; i++) {
		int liLNo, liRNo;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &liLNo, &liRNo);

		// AC数 - セット
		sprintf(lc1Buf, "%d\n", si1ACnt[liRNo - 1] - si1ACnt[liLNo - 1]);

		// AC数 - 出力
		fOut(lc1Buf);
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1ACnt, 0, sizeof(si1ACnt));						// 累積AC数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1280
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

o = v[1::2]
e = v[::2]

cnt_o = Counter(o).most_common() + [(0,0)]
cnt_e = Counter(e).most_common() + [(0,0)]

print(n-cnt_o[0][1]-cnt_e[0][1] if cnt_o[0][0] != cnt_e[0][0] else n-max(cnt_e[0][1]+cnt_o[1][1], cnt_e[1][1]+cnt_o[0][1]))





Measured memory_bytes: 21212
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc  = new Scanner(System.in);
int x = sc.nextInt();
int result =0;
int div=0;
if(x>=500){
   div = x/500;
    result = div*2*500;

}

x = x-(div*500);


result+= x;

if(x%5!=0){
result=result- (x%5);


}
System.out.println(result);
}

}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

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

  int N = S.size();

  vector<int> b;
  b.pb(0);
  repp(i, 1, N - 1) {
    if (S[i - 1] == 'R' && S[i] == 'L') b.pb(i);
    if (S[i - 1] == 'L' && S[i] == 'R') b.pb(i);
  }
  b.pb(N);

  int M = b.size();

  int pt = 0;
  for (int i = 1; i < M; i += 2) {
    while (pt < b[i] - 1) {
      cout << 0 << ' ';
      pt++;
    }
    int l = (b[i] - b[i - 1] + 1) / 2 + (b[i + 1] - b[i]) / 2;
    cout << l << ' ';
    pt++;

    int r = (b[i] - b[i - 1]) / 2 + (b[i + 1] - b[i] + 1) / 2;
    cout << r << ' ';
    pt++;
  }
  while (pt < N) {
    cout << 0 << ' ';
    pt++;
  }
  cout << endl;
}

Measured memory_bytes: 1144
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  array<array<int, 10>, 10> table = {};
  for (int i = 1; i <= N; ++i) {
    int d = log10(i) + 1;
    ++table[i / (int)pow(10, d - 1)][i % 10];
  }
  int ans = 0;
  for (int i = 1; i <= 9; ++i)
    for (int j = 1; j <= 9; ++j) {
      ans += table[i][j] * table[j][i];
    }
  cout << ans << endl;
}


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

Measured memory_bytes: 1408
L = []
n,x = map(int, input().split())
while not(n == 0 and x == 0):
 L.append([n, x])
 n, x = map(int, input().split())

for i in L:
 ans = 0
 for j in range(1, i[0] - 1):
  if j > i[1] - 3:
   break
  else:
   for k in range(j + 1, i[0]):
    m = i[1] - (j + k)
    if m <= k:
     break
    elif m <= i[0]:
     ans += 1
    else:
     continue
 print(ans)

Measured memory_bytes: 7604
import sys

H, W = map(int, input().split())
s = [input() for i in range(H)]

for i in range(H):
    for j in range(W):
        flg = 0
        if s[i][j] == '#':
            for k in range(4):
                x = i + [1, 0, -1, 0][k]
                y = j + [0, 1, 0, -1][k]
                if x < 0 or x >= H or y < 0 or y >= W:
                    continue
                if s[x][y] == '#':
                    flg = 1
            if flg == 0:
                print('No')
                sys.exit()

print('Yes')

Measured memory_bytes: 3064
(defn card-game-for-two [a]
  (count (distinct a)))

(defn create-data [n]
  (loop [counter 0 arr ()]
    (if (>= counter n)
      arr
      (recur (inc counter) (cons (read) arr)))))

(println (card-game-for-two (create-data (read))))

Measured memory_bytes: 67356
#include<bits/stdc++.h>
#define maxn 5001
#define LL long long
#define ri register int
using namespace std;
int n,a[30]={},ans=0;
int qwe[60][30]={};
int main()
{
	memset(a,10,sizeof(a));
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		//cout<<s.size();
		for(int j=0;j<s.size();j++)
		{
			qwe[i][s[j]-'a'+1]++;
			//cout<<1;
		//cout<<s[j]-'a'+1<<" ";
		}
	}
	
	for(int i=1;i<=n;i++)
	for(int j=1;j<=26;j++)
	{
		//printf("%d %d %d %d\n",i,j,qwe[i][j],a[j]);
		a[j]=min(qwe[i][j],a[j]);
	}
	
	for(int i=1;i<=26;i++)
	if(a[i])
	{
		for(int j=1;j<=a[i];j++)
		cout<<char(i+'a'-1);
	}
	
	
	
	return 0;
}

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

using namespace std;

int main() {
    int N;
    int array[100000] = {};
    vector< pair <int,int> > vect;
    
    cin >> N;
    for (int i=0; i<N; i++) {
        cin >> array[i];
    }
    
    for (int i=0; i<N; i++) {
        vect.push_back(std::make_pair(array[i], i+1));
    }

    sort(vect.begin(), vect.end());


    for (auto elem = vect.begin(); elem != vect.end(); ++elem) {  
        cout << elem->second << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2164
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	h := nextInt()
	m := nextInt()

	ans := func() float64 {
		recA := math.Pi * (float64(h)/6 + float64(m)/(60*6))
		recB := math.Pi * float64(m) / 30
		rec := math.Abs(recA - recB)

		s := float64(a*a+b*b) - float64(2*a*b)*math.Cos(rec)
		return math.Sqrt(s)
	}()

	fmt.Printf("%.10f\n", ans)
}


Measured memory_bytes: 1760
#include<cstdio>
#include<cmath>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
long long INF = 1e18;
const int MOD = 1e9 + 7;
 
using namespace std;
 
int vp[2*300*300+1],vl[300*300+1],answer[100000];
int h,w,d,q,d2;
 
int inline dist(int i2){
    return abs(vp[i2]-vp[i2-d2]) + abs(vp[i2+1]-vp[i2-d2+1]);
}
 
int main(){
    scanf("%d %d %d",&h,&w,&d);
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            int a;
            scanf("%d",&a);
            vp[2*a] = i;
            vp[2*a+1] = j;
        }
    }
 
    scanf("%d",&q);
    d2 = 2*d;
    FOR(i,1,d+1) vl[i] = 0;
    FOR(i,d+1,h*w+1) vl[i] = vl[i-d] + dist(2*i);
 
    REP(i,q){
        int l,r;
        scanf("%d %d",&l,&r);
        answer[i] = vl[r] - vl[l];
    }
    REP(i,q) printf("%d\n",answer[i]);
    return 0;
}

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	int a,b;
	cin>>a>>b;
	if(a==1 && b!=1)
		cout<<"Alice";
	else if(b==1 && a!=1)
		cout<<"Bob";
	else if(a>b)
		cout<<"Alice";
	else if(a<b)
		cout<<"Bob";
	else
		cout<<"Draw";
}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  dp=[0]*100100

  for i in range(k):
    for x in l:
      y=dp[i]

      if y==0 and i+x<100100:
        dp[i+x]=1

  if dp[k]==1:
    return 'First'
  return 'Second'

# main()
print(main())


Measured memory_bytes: 5932
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;






int main() {

    int s[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;

    cout << s[k-1] << endl;

    return 0;
}




//              g++ -std=c++1z






Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N,M = cin.mapInt()
    ans = min(N,M // 2)
    N -= ans 
    M -= ans * 2
    ans += M // 4
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 38512
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
int n,m;
int d[30];
vector<pii> G[500];

#define TO first
#define COST second
void dijkstra(int s){
    rep(i,30)d[i]=INF;
    priority_queue<pii,vector<pii>,greater<pii>> que;
    que.push(pii(0,s));
    d[s]=0;
    
    while(que.size()){
        pii q=que.top();
        que.pop();
        
        int v=q.second;
        if(d[v]<q.first)continue;
        
        rep(i,G[v].size()){
            pii e=G[v][i];
            if(d[e.TO]>d[v]+e.COST){
                d[e.TO]=d[v]+e.COST;
                que.push(pii(d[e.TO],e.TO));
            }
        }
    }
}

int main(){
    int n,m;
    char ch;
    cin>>n>>m;
    rep(i,m){
        int a,b,c,f;
        cin>>a>>ch>>b>>ch>>c>>ch>>f;
        G[a].pb(pii(b,c));
        G[b].pb(pii(a,f));
    }
    int a,b,c,f;
    cin>>a>>ch>>b>>ch>>c>>ch>>f;
    int s=0;
    dijkstra(a);
    s+=d[b];
    dijkstra(b);
    s+=d[a];
    cout<<c-f-s<<endl;
}

Measured memory_bytes: 1212
a = int(input())
b = list(map(int, input().split()))
b = sorted(b)
c = b[0]
if c == 0:
  print(c)
  exit()
else:
  for i in range(a-1):
    c *= b[i+1]
    if c > 1000000000000000000:
      break

if c > 1000000000000000000:
  print(-1)
else:
  print(c)

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

int main () 
{
    int x;
    int count = 0;
    
    while (1)
    {
        std::cin >> x;
        
        if (x == 0) break;
        
        count++;
        
        std::cout << "Case " << count << ": " << x << std::endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<cstdio>
#include<cstring>
#include<cmath>
#include <algorithm>
using namespace std;
int arr[1005][1005];
int main(){
	int n,x1,x2,y1,y2;
	scanf("%d",&n);
	for(int i = 0; i<n; i++){
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		arr[x1][y1]++;
		arr[x2][y2]++;
		//why --
		arr[x1][y2]--;
		arr[x2][y1]--;
	}
	/*for(int i = 0; i<6; i++){
  		for(int j = 0; j<6; j++){
  			printf("%d ",arr[i][j]);
		  }
		  printf("\n");
	}printf("\n");*/
	int ans = 0;
	for(int i=0;i<1001;i++){
    	for(int j=0;j<1001;j++){
      		if(i) arr[i][j]+=arr[i-1][j];
      		if(j) arr[i][j]+=arr[i][j-1];
      		if(i&&j) arr[i][j]-=arr[i-1][j-1];
      		ans= max(ans,arr[i][j]);
    	}
  	}
  	/*for(int i = 0; i<6; i++){
  		for(int j = 0; j<6; j++){
  			printf("%d ",arr[i][j]);
		  }
		  printf("\n");
	  }*/
  	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6676
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(M)]

first = set()
second = set()
for a, b in ab:
    if a == 1:
        first.add(b)
    elif b == N:
        second.add(a)

if len(first & second):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


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

void solve() {
  int a, b;
  cin >> a >> b;
  if(a <= 5) cout << 0 << endl;
  else if(a <= 12) cout << b/2 << endl;
  else cout << b << endl;
}

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		try {
			// 標準入力
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			String array[] = br.readLine().split(" ");

			int a = Integer.parseInt(array[0]);

			int b = Integer.parseInt(array[1]);

			if(a == b) {
				System.out.print("Draw");
			}else if(a == 1 || (b != 1 && a > b)) {
				System.out.print("Alice");
			}else{
				System.out.print("Bob");
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}


Measured memory_bytes: 22612
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
}   
int main()
{
	FAST
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<n;i++){
		cout<<s[i]<<t[i];
	}
	return 0;
}















Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#define LL long long
#define maxn 200005

using namespace std;

int n,a[maxn];
LL ans,sum[maxn],mp[maxn];

int main()
{
    cin >>n;
    for (int i=0;i<n;i++) cin >>a[i],mp[a[i]]++;
    for (int i=1;i<=n;i++) if (mp[i]) ans+=mp[i]*(mp[i]-1)/2;
    for (int i=0;i<n;i++) printf("%lld\n",ans-mp[a[i]]*(mp[a[i]]-1)/2+(mp[a[i]]-1)*(mp[a[i]]-2)/2);


    return 0;
}


Measured memory_bytes: 3968
n = int(input())
n_set = set()
_n_ls = set()
for i in range(1, 10**6+2):
    if n % i == 0:
        n_set.add(i)
        n_set.add(n // i)
    if (n-1) % i == 0:
        _n_ls.add(i)
        _n_ls.add((n-1) // i)

def check(n, k):
    if n < k:
        return n == 1
    else:
        if n % k == 0:
            n //= k
        else:
            n %= k
        return check(n, k)

cnt = len(_n_ls)
if 1 in _n_ls:
    cnt -= 1
for i in list(n_set):
    if i == 1:
        continue
    if check(n, i):
        cnt += 1
print(cnt)

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

int main() {
    
  for( int i=1; i <= 10000; i++){
      
    int x = 0;
    cin >> x;
    
    if( x == 0 ){
        
        break;
        
    }
      
      cout << "Case" << " " << i << ":" << " " << x << endl;
      
  }

}



Measured memory_bytes: 3080
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000000ll
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll h,w,m;
    cin>>h>>w>>m;
    map<int,set<int>> yb,xb;
    rep(i,m){
        int y,x;
        cin>>y>>x;
        y--;x--;
        yb[y].insert(x);
        xb[x].insert(y);
    }

    int curx=0,cury=0;
    rep(i,h){
        chmax(cury,(int)yb[i].size());
    }
    rep(i,w){
        chmax(curx,(int)xb[i].size());
    }

    vec vx,vy;
    rep(i,h) if(yb[i].size()==cury) vy.push_back(i);
    rep(i,w) if(xb[i].size()==curx) vx.push_back(i);


    for(auto x: vx){
        for(auto y: vy){
            if(!xb[x].count(y)){
                cout<<curx + cury<<endl;
                return 0;
            }
        }
    }
    cout<<curx + cury -1<<endl;

}

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

bool has_strawberry(const vector<vector<int>>& grid, int xfirst, int xlast, int yfirst, int ylast)
{
  for (int x = xfirst; x <= xlast; x++) {
    for (int y = yfirst; y <= ylast; y++) {
      if (grid.at(x).at(y) != 0) {
        return true;
      }
    }
  }
  return false;
}

void print_2d_vec(const vector<vector<int>>& vv)
{
  for (int x = 0; x < (int)vv.size(); x++) {
    assert(vv.at(x).at(0) != 0);
    printf("%d", vv.at(x).at(0));
    for (int y = 1; y < (int)vv.at(x).size(); y++) {
      assert(vv.at(x).at(y) != 0);
      printf(" %d", vv.at(x).at(y));
    }
    printf("\n");
  }
}

int main()
{
  int h, w, k;
  char lf;
  scanf("%d %d %d\n", &h, &w, &k);
  vector<vector<int>> grid(h, vector<int>(w));
  int cnt = 1;
  vector<pair<int, int>> p;
  for (int x = 0; x < h; x++) {
    for (int y = 0; y < w; y++) {
      char c = getchar();
      if (c == '.') {
        grid.at(x).at(y) = 0;
      } else if (c == '#') {
        grid.at(x).at(y) = cnt++;
        p.emplace_back(x, y);
      } else {
        fprintf(stderr, "Unknown char '%c' found\n", c);
        exit(1);
      }
    }
    lf = getchar(); // lf
    assert(lf == '\n');
  }
  for (int i = 0; i < (int)p.size(); i++) {
    int xfirst = p.at(i).first;
    int xlast  = p.at(i).first;
    int yfirst = p.at(i).second;
    int ylast  = p.at(i).second;
    while (0 <= yfirst-1 && grid.at(xfirst).at(yfirst-1) == 0) {
      yfirst--;
      grid.at(xfirst).at(yfirst) = i+1;
    }
    while (ylast+1 < w && grid.at(xlast).at(ylast+1) == 0) {
      ylast++;
      grid.at(xlast).at(ylast) = i+1;
    }
    while (0 <= xfirst-1 && !has_strawberry(grid, xfirst-1, xfirst-1, yfirst, ylast)) {
      xfirst--;
      for (int y = yfirst; y <= ylast; y++) {
        grid.at(xfirst).at(y) = i+1;
      }
    }
    while (xlast+1 < h && !has_strawberry(grid, xlast+1, xlast+1, yfirst, ylast)) {
      xlast++;
      for (int y = yfirst; y <= ylast; y++) {
        grid.at(xlast).at(y) = i+1;
      }
    }
  }
  print_2d_vec(grid);
  return 0;
}


Measured memory_bytes: 1908
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#define N 100001
#define M 200001
#define INF 0x7fffffff
#define ri register int
#define in inline
using namespace std;
struct edge
{
	int to,w,next;
}e[M<<1];
//vis数组表示已松弛的点
//book数组表示进入队列的点 
int head[N],vis[N],dis[N];
int m,n;
bool book[N];
in bool spfa(int s);
int main()
{
	ios::sync_with_stdio(false);
	int u,v,w;
	cin>>n>>m;
	for(ri i=1;i<=m;i++)
	{
		cin>>u>>v>>w;
		e[i]=(edge) {v,w,head[u]}; head[u]=i;
		e[i+m]=(edge) {u,-w,head[v]}; head[v]=i+m;
	}
	//一组数据为一个问题，不能将fill数组放在spfa里 
	fill(dis+1,dis+n+1,INF);
	//所有约束条件需要考虑到
	//可能有多个分块，前10个约束条件与后10个 无关联 
	for(ri i=1;i<=n;i++)
		if(!vis[i])
		{
			if(spfa(i))
			{cout<<"No"; return 0;}
			vis[i]=1;
		}	
	cout<<"Yes";
	return 0;
}
in bool spfa(int s)
{
	queue <int> q;
	int k;
	q.push(s); book[s]=1;
	dis[s]=0;
	while(q.size())
	{
		k=q.front(); q.pop();
		book[k]=0;//出队列应置为0 
		for(ri i=head[k]; i ;i=e[i].next)
		{
			int v=e[i].to;
			if(!vis[v]&& dis[k]<INF)
			{
				dis[v]=dis[k]+e[i].w;
				if(!book[v])
				{q.push(v); book[v]=1;}
				vis[v]=1;
			}
			else if(dis[k]<INF && dis[v]<INF && dis[v]!=dis[k]+e[i].w) return true;
			//此时相当于自相矛盾
			//思想：即先认定一开始所给条件均正确（此时松弛）
		    //最后再来验证接下来的条件是否满足原先条件 
		}
	}
	return false;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var R = int.Parse(Console.ReadLine());
            var G = int.Parse(Console.ReadLine());

            Console.WriteLine(2 * G - R);
        }
    }
}


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

int main () {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> vec(n+1);
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    vec[a] = 1;
  }
  int cnt1 = 0;
  for (int i = 1; i < x; i++)
    cnt1 += vec[i];
  int cnt2 = 0;
  for (int i = x+1; i < n+1; i++)
    cnt2 += vec[i];
  cout << min (cnt1, cnt2) << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  int ans = 0;
  rep(i, 3) {
    int cnt = 0;
    if (s[i] == 'R') {
      REP(j, i, 3) {
        if (s[j] == 'S') break;
        cnt++;
      }
      ans = max(ans, cnt);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(j, n) for (int j = 0; j < (n); j++)

typedef long long ll;

int main(){
  ll n,ans=0;
  bool a=true;
  cin>>n;
  while(n>9){
    ans+=9;
    if(n%10!=9)a=false;
    n/=10;
  }
  if(a)ans+=n;
  else ans+=(n-1);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

string S; int N;

bool f(int k) {
    if (k > N) return false;
    bool ok = true;
    for (int i = N-k+1; i < k; i++) {
        if (S[i] != S[i-1]) ok = false;
    }
    return ok;
}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> S;
    N = S.size();

    int left = 0;
    int right = N+1;
    while (right - left > 1) {
        int mid = (left+right)/2;
        if (f(mid)) left = mid;
        else right = mid;
    }

    cout << left << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()


int main() {
      int n, g;
      cin >> n >> g;
      vector<int> p(n+1), c(n+1);
      for(int i=1; i<=n; i++){
        cin >> p[i] >> c[i];
      }
      int ans = MOD;

    vector<int> one_case;
    for (int i = 1; i <= n; i++) { // one_case = {0,1,2,3,...n-1} とする
        one_case.emplace_back(i);
    }

    do{
        int cnt = 0, score = 0;
        for(int i=0; i<one_case.size(); i++){
          int num = one_case[i];
          if(g >  score + num * 100 * p[num]){
            cnt += p[num];
            score += num * 100 * p[num] + c[num];
            if(score >= g){
              ans = min(ans, cnt);
              break;
            }
          } else {
            int m = (g - score) / (num * 100);
            cnt += m;
            if((g - score)% (num * 100) != 0) cnt++;
            ans = min(ans, cnt);
            break;          
          }
        }     
    } while (next_permutation(one_case.begin(), one_case.end()));

  cout << ans << ln;
}


Measured memory_bytes: 256