akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int n, a, b;
vector<LL> v;
map<LL, int> mp;
/**********************************************/
void comb(vector<vector <LL> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

signed main(){
    cin >> n >> a >> b;
    v.resize(n);
    REP(i, n) cin >> v[i];

    sort(all(v), greater<LL>());
    REP(i, n) mp[v[i]]++;
    

    if(mp[v[0]] >= a){
        printf("%.6f\n", (double)v[0]);
        LL ans = 0;
        vector<vector<LL>> vec(mp[v[0]]+1, vector<LL>(mp[v[0]]+1, 0));
        comb(vec);
        FOR(i, a, b+1){
            if(i <= mp[v[0]]) ans += vec[mp[v[0]]][i];
        }
        cout << ans << endl;
    }else{
        double ave = 0;
        REP(i, a){
            ave += v[i];
        }
        ave /= a;
        printf("%.6f\n", ave);
        
        LL ans = 0;
        vector<vector<LL>> vec(mp[v[a-1]]+1, vector<LL>(mp[v[a-1]]+1, 0));
        comb(vec);
        LL k = 0;
        REP(i, n){
            if(i > a) break;
            if(v[a-1] == v[i]) k++;
        }
        ans += vec[mp[v[a-1]]][k-1];
        cout << ans << endl;

    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint a(N);
    rep(i, N) cin >> a[i];
    ll ans = 0;

    rep(i, N) {
        ans += a[i] - 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 1e5 + 27;

int cnt[N];

int main()
{
	int n;

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		int x;

		cin >> x;

		cnt[x]++;
		cnt[x + 1]++;
		cnt[x + 2]++;
	}	

	int mx = 0;	

	for (int i = 0; i < N; i++)
		mx = max(mx, cnt[i]);

	cout << mx;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll A, B, N;
//---------------------------------------------------------------------------------------------------
ll f(ll x) { return (A * x) / B - A * (x / B); }
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B >> N;

	ll ans = 0;
	chmax(ans, f(N));
	if (B - 1 <= N) chmax(ans, f(B - 1));
	cout << ans << endl;
}







Measured memory_bytes: 3640
#include<stdio.h>
 
#define N 100005
 
struct Node{ int p, l, r;};
struct Node T[N];
  
void inorder(int);
void preorder(int);
void postorder(int);
  
int main(int argc,char *argv[]){
  int i, v,n;    
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
      T[i].p = T[i].l = T[i].r = -1;
    }
    for ( i = 0; i < n; i++ ){
      scanf("%d",&v);
      scanf("%d %d",&T[v].l,&T[v].r);   
      T[T[v].l].p = v;
      T[T[v].r].p = v;
    }
      
      
    printf("Preorder\n");
     for(i=0; i<n; i++){
     if(T[i].p == -1)
    preorder(i);
    }
    printf("\nInorder\n");
    for(i=0; i<n; i++){
      if(T[i].p == -1)
    inorder(i);
    }
    printf("\nPostorder\n");
    for(i=0; i<n; i++){ 
      if(T[i].p == -1)
    postorder(i);
    }
    printf("\n");
     
    return 0;  
}
 
void inorder(int u){
  if(u != -1){
    inorder(T[u].l);
    printf(" %d",u);   
    inorder(T[u].r); 
  }
}
void preorder(int u){
  if(u != -1){
    printf(" %d",u);  
    preorder(T[u].l);
    preorder(T[u].r);
  }
}
 
void postorder(int u){
  if(u != -1){
    postorder(T[u].l);
    postorder(T[u].r);
    printf(" %d",u);
  }
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
    if you have any question about any part of my code,
    please don't shy to ask anytime :)
*/

void solve()
{
    ll x[5];
    ll ans=0;
    for(int i=0;i<5;i++)
    {
        cin>>x[i];
        if(x[i]==0)
        {
            ans = i+1;
        }
    }

    cout<<ans<<endl;
}

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

    // ll t;
    // cin >> t;

    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 3600
n = int(input())
s_list = []
h_list = []
c_list = []
d_list = []
for i in range(n):
	v = input().split()
	mark = v[0]
	num = int(v[1])
	if mark == 'S':
		s_list.append(num)		
	elif mark == 'H':
		h_list.append(num)
	elif mark == 'C':
		c_list.append(num)
	else:
		d_list.append(num)
nums = list(range(1, 14))
for n in nums:
	if not n in s_list: 
		print('S', n)
for n in nums:
	if not n in h_list:
		print('H', n)
for n in nums:
	if not n in c_list: 
		print('C', n)
for n in nums:
	if not n in d_list: 
		print('D', n)


Measured memory_bytes: 5604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-10
using namespace std;
typedef long long ll;
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y < p.y;
		else return x < p.x;
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
	return a.x * b.x + a.y * b.y;
}
double det(Vector a,Vector b){
	return a.x * b.y - b.x * a.y;
}
bool vertical(Line l1,Line l2){
	return abs(dot(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
bool parallel(Line l1,Line l2){
	return abs(det(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
Point proj(Point p,Line l){
	Vector a = l.p2 - l.p1;
	double r = dot(a,p - l.p1) / a.norm();
	return l.p1 + a * r;
}
Point ref(Point p,Line l){
	Point A = proj(p,l);
	return A + (A - p);
}
int ccw(Segment/*Directed Segment*/ s,Point p){//
	Vector a = s.p2 - s.p1,b = p - s.p1;
	if(det(a,b) > EPS) return 1;
	else if(det(a,b) < -EPS) return -1;
	else if(dot(a,b) < -EPS) return 2;
	else if(a.norm() < b.norm() - EPS) return -2;
	else return 0;
}
int main(){
	Segment s; Point p;
	scanf("%lf%lf%lf%lf",&s.p1.x,&s.p1.y,&s.p2.x,&s.p2.y);
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%lf%lf",&p.x,&p.y);
		int ans = ccw(s,p);
		if(ans == 1) puts("COUNTER_CLOCKWISE");
		else if(ans == -1) puts("CLOCKWISE");
		else if(ans == 2) puts("ONLINE_BACK");
		else if(ans == -2) puts("ONLINE_FRONT");
		else puts("ON_SEGMENT");
	}
	return 0;
}



Measured memory_bytes: 3248
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! {
        x: usize, y: usize, z: usize, k:usize,
        mut a: [u64; x], 
        mut b: [u64; y],
        mut c: [u64; z]
    }
    let mut ans :Vec<u64> = vec![];
    a.sort(); a.reverse();
    b.sort(); b.reverse();
    c.sort(); c.reverse();
    let mut ab = vec![];
    for i in 0..x {
        for j in 0..y {
            ab.push(a[i]+b[j]);
        }
    }
    ab.sort(); ab.reverse();
    let mut abc = vec![];
    for i in 0..std::cmp::min(x*y, k) {
        for j in 0..z {
            abc.push(ab[i]+c[j]); 
        }
    }
    abc.sort(); abc.reverse();
    for i in 0..k { println!("{}", abc[i]); }
}

Measured memory_bytes: 44280
w,h,n=gets.split.map(&:to_i)
arr=n.times.map{gets.split.map(&:to_i)}
brr=h.times.map{|i| ('w'*w).chars }
arr.each do |i|
  case i[2]
  when 1
    brr.each do |j|
      t_x=i[0]
      t_x.times do |k|
        j[k] = 'b'
      end
    end
  when 2
    brr.each do |j|
      t_x=i[0]
      w.times do |k|
        j[k] = 'b' if k >= t_x
      end
    end
  when 3
    t_y=i[1]
    brr.each_with_index do |el, j|
	  el.map!{|k|k = 'b'} if j < t_y
    end
  when 4
    t_y=i[1]
    brr.each_with_index do |el, j|
	  el.map!{|k|k = 'b'} if j >= t_y
    end
  end
end
p brr.map{|i|i.count('w')}.inject(:+)


Measured memory_bytes: 5244
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  string S;
  cin>>S;
  bool YYMM=false,MMYY=false;
  if(S[0]=='0'&&S[1]!='0'){
      MMYY=true;
  }
  else if(S[0]=='1'&&S[1]<='2'){
      MMYY=true;
  }
  
  if(S[2]=='0'&&S[3]!='0'){
      YYMM=true;
  }
  else if(S[2]=='1'&&S[3]<='2'){
      YYMM=true;
  }
  
  if(MMYY==true&&YYMM==false){
      cout<<"MMYY"<<endl;
  }
  else if(MMYY==false&&YYMM==true){
      cout<<"YYMM"<<endl;
  }
  else if(MMYY==true&&YYMM==true){
      cout<<"AMBIGUOUS"<<endl;
  }
  else if(MMYY==false&&YYMM==false){
      cout<<"NA"<<endl;
  }
  
}

Measured memory_bytes: 3604
n, m = map(int, input().split())

a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

import sys

for r in range(n - m + 1):
  for c in range(n - m + 1):
    for x in range(m):
      if a[r+x][c:c+m] != b[x]:
        break
    else:
      print("Yes")
      sys.exit()

print("No")

Measured memory_bytes: 3064
def func(a, idx, m, v, p):
    if len(a) - idx <= p:
        return True
    if a[idx] + m < a[-p]:
        return False
    lim = 0
    for i in range(len(a)):
        if i <= idx:
            lim += m
        elif i <= len(a)-p:
            lim += a[idx] + m - a[i]
        else:
            lim += m
    if lim >= m*v:
        return True
    else:
        return False

def main():
    n, m, v, p = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    L, R = -1, n-1
    while L+1 < R:
        P = (L+R)//2
        if func(a, P, m, v, p):
            R = P
        else:
            L = P
    print(n-R)

if __name__ == "__main__":
    main()

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){

  int x; cin>>x;

  if(x>=30)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 3632
l = list(input())
n = len(l)

def dfs(i,f,sum):
    if i == n-1:
       if sum == 7:
           print(f+"=7")
           exit()
    
    else:
        dfs(i+1,f+"+"+l[i+1],sum+int(l[i+1]))
        dfs(i+1,f+"-"+l[i+1],sum-int(l[i+1]))

dfs(0,l[0],int(l[0]))




Measured memory_bytes: 38384
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

mons=0
for i in range(N):
  if B[i]>A[i]:
    mons+=A[i]
    if B[i]>=A[i]+A[i+1]:
      mons+=A[i+1]
      A[i+1]=0
    else:
      mons+=B[i]-A[i]
      A[i+1]-=B[i]-A[i]
  else:
    mons+=B[i]
print(mons)

Measured memory_bytes: 24368
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict

N = int(readline())
C = (0,) + tuple(map(int, readline().split()))
m = map(int, read().split())
AB = zip(m, m)

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


root = 1
parent = [0] * (N + 1)
depth = [0] * (N + 1)  # 根を深さ 1 として
order = []
stack = [root]
depth[root] = 1
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        depth[y] = depth[x] + 1


def merge(v, p):
    A = dp[v]
    B = dp[p]
    size_A = size[v]
    size_B = size[p]
    c = C[p]
    if len(A) < len(B):
        A, B = B, A
        size_A, size_B = size_B, size_A
    answer[c] += (size_A - A[c]) * (size_B - B[c])
    # B を A にマージ
    for key, cnt in B.items():
        answer[key] -= cnt * A[key]
        A[key] += cnt
    size[p] = size_A + size_B
    dp[p] = A


answer = [0] * (N + 1)
dp = [defaultdict(int) for _ in range(N + 1)]
size = [0] * (N + 1)

for v in order[::-1]:
    c = C[v]
    n = size[v] + 1 - dp[v][c]
    answer[c] -= size[v] * n
    size[v] += 1
    dp[v][c] = size[v]
    if v == root:
        break
    p = parent[v]
    merge(v, p)

A = dp[root]
c = size[root]
for v in range(1, N + 1):
    print(c * A[v] + answer[v])


Measured memory_bytes: 238252
#include<bits/stdc++.h>
    using namespace std;
     
    int main(){
      string s[3];
      cin>>s[0]>>s[1]>>s[2];
      int turn=0;
      char c;
      while(true){
        if(s[turn]==""){
          cout<<(char)('A'+turn)<<endl;
          return 0;
        }
        c=s[turn].at(0);
        s[turn]=s[turn].substr(1,s[turn].length()-1);
        turn=c-'a';
      }
      return 0;
    }

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

int main() {
  int a;
  int b;
  int c = 0;
  
  cin >> a;
  cin >> b;
  
  for (int i = 0; true; i++) {
    a = a - b;
    c++; // :):):)
    if (a <= 0) {
      cout << c;
      return 0;
    }
  }
    
  return 0;   
}

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

int main()
{
    long long x;
    cin>>x;
    unsigned long long cnt=0,vf;
    
    if(x>=500)
    {
        vf=(x/500);
        cnt=vf*1000;
        x-=500*vf;
    }
    if(x>=5)
    {vf=x/5;
    cnt+=(vf*5);
    }
    cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val t = Array(n) {-1}
    repeat(m) {
        val s = sc.nextInt() - 1
        val c = sc.nextInt()
        if (t[s] == -1) {
            t[s] = c
        } else if (t[s] != c) {
            println(-1)
            return
        }
    }
    for (i in 0..999) {
        val str = i.toString()
        if (str.length != n) {
            continue
        }
        var flg = true
        for (j in 0 until n) {
            if (t[j] == -1 || t[j] == str[j] - '0') {

            } else {
                flg = false
                break
            }
        }
        if (flg) {
            println(i)
            return
        }
    }
    println(-1)
}

Measured memory_bytes: 31400
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n;
int a[200005];
bool check(int x){
	int dist1=inf,dist2=inf;
	for(int i=2;i<=n+n-1;i++){
		int v1=(a[i-1]>=x),v2=(a[i]>=x);
		if(v1&&v2)dist1=min(dist1,min(abs(n-i),abs(n-i+1)));
		if(!v1&&!v2)dist2=min(dist2,min(abs(n-i),abs(n-i+1)));
	}
	if(dist1==dist2){
		assert(dist1==inf);
		return a[1]>=x;
	}
	return dist1<dist2;
}
int main(){
	cin>>n;
	for(int i=1;i<=n+n-1;i++)cin>>a[i];
	int L=0,R=2e5;
	while(R-L>1){
		int mid=(L+R)/2;
		if(check(mid))L=mid;
		else R=mid;
	}
	cout<<L<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = gets.chomp.to_i

rates = []
n.times do
  rates << gets.chomp.to_i
end

minv = rates[0]
maxv = -20000000000
for num in 1..(n - 1) do
  maxv = [maxv, rates[num]-minv].max
  minv = [minv, rates[num]].min
end

puts maxv


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

sys.setrecursionlimit(10 ** 7)

# 1 ✕ N
N, M = list(map(int, input().rstrip().split()))

# N ✕ M
A = list(tuple(map(int, input().rstrip().split())) for _ in range(M))

array = []
for x, y in A:
    array.append((y, x))

array.sort()

ans = 0
t = 0
for e, s in array:
    if t <= s:
        ans += 1
        t = e

print(ans)


Measured memory_bytes: 26000
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T, typename S> T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int MAXN = 1e5 + 3;
int n;
vector<int> adj[MAXN];
LL arr[MAXN];
int deg[MAXN];

bool ok = true;
int par[MAXN];
LL C[MAXN];

void dfs(int r, int p) {
  bool leaf = true;
  LL sum = 0;
  for(auto &elem: adj[r]) {
    if(elem != p) {
      dfs(elem, r);
      sum += C[elem];
      leaf = false;
    }
  }
  if(p == 0) {
    C[r] = 0;
    LL maxim = 0;
    for(auto &elem: adj[r]) {
      maxim = max(maxim, C[elem]);
    }
    if(maxim*2 > 2ll*arr[r] or sum != 2*arr[r]) {
      ok = false;
    }
  } else if(leaf) {
    C[r] = arr[r];
  } else {
    C[r] = 2ll*arr[r] - sum;
    if(C[r] < 0) {
      ok = false;
      return ;
    }
    LL maxim = C[r];
    for(auto &elem: adj[r]) {
      if(elem != p) {
        maxim = max(maxim, C[elem]);
      }
    }
    if(maxim*2 > 2ll*arr[r]) {
      ok = false;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  int a, b;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  int root = -1;
  for(int i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].push_back(b), adj[b].push_back(a);
    deg[a]++, deg[b]++;
    if(deg[a] > 1) root = a;
    else if(deg[b] > 1) root = b;
  }
  if(root == -1) {
    if(arr[1] == arr[2]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
  }
  dfs(root, 0);
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var ret = new List<string>();
            var a = new List<string>();

            for (int i = 1; i <= HW[0]; i++)
            {
                a.Add(Console.ReadLine());
            }

            for (int i = 0; i < HW[0] + 2; i++)
            {
                ret.Add("");
                for (int j = 0; j < HW[1] + 2; j++)
                {
                    if(i == 0 || j==0 || i == HW[0]+1 || j == HW[1]+1)
                    {
                        ret[i] = ret[i] + "#";
                    }
                    else
                    {
                        ret[i] = ret[i] + a[i-1][j-1].ToString(); ;
                    }
                }
            }

            foreach (var item in ret)
            {
                Console.WriteLine(item);
            } 
        }
    }
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

bool forwrd[N][27], backward[N][27] ;

int main() {
  int n , ans = INT_MIN, count =0;
  string s ;
  cin >> n >> s ;

  forwrd[0][s[0]-'a'] = true ;
  for(int i =1 ;i<n-1 ;i++){
    forwrd[i][s[i]-'a'] = true ;
    for(int j = 0 ; j<26;j++)
      forwrd[i][j]|=forwrd[i-1][j] ;
  }

  backward[n-1][s[n-1]-'a'] = true ;
  for(int i = n-2 ; i>0 ; i--){
    backward[i][s[i]-'a'] = true ;
    for(int j = 0 ; j<26 ; j++)
      backward[i][j] |= backward[i+1][j] ;
  }

  for(int i = 0 ;i<n-1 ;i++){
    count = 0 ;
    for(int j = 0 ; j<26 ; j++)
      if(forwrd[i][j] && backward[i+1][j])count++ ;
    ans = max(ans, count) ;
  }

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

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=1e6+11;
int n,K,ans;
int a[N];
bool check(int x){
	int cnt=0;
	rep(i,1,n)
		cnt+=a[i]/x+(a[i]%x>0)-1;
	return cnt>K;
}
int main(){
	scanf("%d%d",&n,&K);
	rep(i,1,n)
		scanf("%d",a+i);
	_rep(i,30,0)
		if(check(ans|(1<<i)))
			ans|=1<<i;
	++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4604
#include <stdio.h>
main(){

  int S[100000],T[50000];
  int n,q,i,j,ans = 0,mid,left = 0,right;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){

    scanf("%d",&S[i]);

  }

  scanf("%d",&q);

  for(i = 0 ; i < q ; i++ ){

    scanf("%d",&T[i]);

  }

 

  for(i = 0 ; i < q ; i++ ){
   
    left = 0;
    right = n;

  while(left<=right)
    {
      
      mid = (left + right) / 2;

      if(S[mid] == T[i]) {
	ans++;
	break;
      }
      if(S[mid] < T[i]) left = mid + 1;    
      else right = mid - 1;
      
    }
  }
  
  
  
  
  printf("%d\n",ans);
  
  return 0;

}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int N, f[12]; int dig[30002][11]; string s;
int ans = 0;
int main(){
    scanf("%d", &N);
    cin >> s; s=" "+s;
    for (int i = s.size()-1; i >=1; i--) {
        f[s[i]-'0']=i;
        if(i==s.size()-1) continue;
        for (int j = 0; j < 10; j++)dig[i][j] = dig[i+1][j];
        dig[i][s[i+1]-'0'] = i+1;
    }
    for (int i = 0; i <= 10; i++) {
        for (int j = 0; j <= 10; j++) {
            if(dig[f[i]][j]!=0){
                for (int k = 0; k <= 10; k++) {
                    if(dig[dig[f[i]][j]][k] != 0) ans++;
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

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

  int *a = new int[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  int cnt = 0;
  bool even = true;
  for(;;){
    for(int i=0; i<n; i++){
      if(a[i]%2==0){
        a[i] /= 2;
      }
      else{
        even = false;
        break;
      }
    }
    if(!even){
      break;
    }
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}


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

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

    if(s=="A")
    {
        cout<<"T"<<endl;
    }

    if(s=="T")
    {
        cout<<"A"<<endl;
    }

        if(s=="C")
    {
        cout<<"G"<<endl;
    }

        if(s=="G")
    {
        cout<<"C"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,check=0,count=0;
  scanf("%d",&n);
  int a[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  while(check==0){
    for(i=0;i<n;i++){
      if(a[i]%2==0)
        a[i]/=2;
      else
        check=1;
    }
    if(check==0)
      count++;
  }
  printf("%d\n",count);
  return 0;
}


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

int main() {
  int h,w,n;
  int ans = 0;
  
  cin >> h;
  cin >> w;
  cin >> n;
  
  if(h >= w){
    if(n % h == 0){
      ans = n / h;
    } else{
      ans = n / h + 1;
    }
  } else{
    if(n % w == 0){
      ans = n / w;
    } else{
      ans = n / w + 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);} while(0)
  #define trcc(v) do { cerr << "name : " << #v << "\n"; int cnt = 0; each(x , v){cerr << (cnt++) << " : "; trc(x); } } while(0)
#else
  #define trc(...)
  #define trca(...)
  #define trcc(...)
  int main(){solve();}
#endif

#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define in2(s,t)   rep(i,sz(s)){in(s[i] , t[i]);}
#define in3(s,t,u) rep(i,sz(s)){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////////////

void solve(){
  set<int> s;
  rep(i,3){
    ini(n); s.emplace(n);
  }
  out(sz(s) == 2 ? "Yes" : "No");
}

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define sz(x) ((int)(x).size())

typedef vector<int> vi;
typedef vector<vi> vvi;

void show(vvi b){
  rep(i, sz(b)){
    rep(j, sz(b[i])){
      if(b[i][j] >= 0) cout << " ";
      cout << b[i][j];
    }
    cout << endl;
  }
  cout << endl;
}

int main(){
  int n,k; cin >> n >> k;
  int size = 6 * k; // 必要なのは真ん中の2k * 2k
  vvi b(size, vi(size));
  rep(i,n){
    int x, y; char c;
    cin >> x >> y >> c;
    if(c == 'W') y += k;
    x %= 2 * k;
    y %= 2 * k;
    // 条件を満たす"右下"マスの集合の市松模様を考える
    rep(j,2){
      rep(z, 2) rep(w, 2){
	  b[x + 2 * z * k][y + 2 * w * k]++;
	  b[x + 2 * z * k][y + k + 2 * w * k]--;
	  b[x + k + 2 * z * k][y + 2 * w * k]--;
	  b[x + k +  2 * z * k][y + k + 2 * w * k]++;
      }
      x += k; y += k;
    }
    //show(b);
  }
  //show(b);

  // 累積和
  rep(i, size) rep(j, size - 1) b[i][j + 1] += b[i][j];
  rep(i, size - 1) rep(j, size) b[i + 1][j] += b[i][j];
  //show(b);

  int ans = 0;
  FOR(i,2*k,4*k) FOR(j,2*k,4*k) ans = max(ans, b[i][j]);
  cout << ans << endl;
}

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

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

    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R') {
            count++;
        }
    }

    if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') {
        cout << "1" << endl;
        return 0;
    }

    cout << count << endl;
}

Measured memory_bytes: 3624
n = int(input())
abc = [list(map(int, input().split())) for i in range(n-1)]
q,k = map(int, input().split())
tree = [list() for i in range(n+1)]
visited = [0] * (n+1)
dist = [0] * (n+1)
for a,b,c in abc:
  tree[a].append((b,c))
  tree[b].append((a,c))
stack = [k]
visited[k] = 1
while stack:
  now = stack.pop()
  for NEXT,d in tree[now]:
    if not visited[NEXT]:
      visited[NEXT] = 1
      dist[NEXT] = dist[now] + d
      stack.append(NEXT)
for i in range(q):
  x,y = map(int, input().split())
  print(dist[x]+dist[y])


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    int search = M/N;
    while(search > 0) {
        int M2 = M;
        M2 -= search * N;
        if(M2 % search == 0) break;
        search--;
    }
    cout << search << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;cin>>a;
  if(a.at(0)==a.at(1)&&a.at(1)==a.at(2)){
    cout<<"Yes"<<endl;
  }
  else if(a.at(1)==a.at(2)&&a.at(2)==a.at(3)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
string S;
int P;

ll solve()
{
    if (P == 2 || P == 5)
    {
        ll res = 0;
        for (int i = 0; i < N; i++)
        {
            if ((S[N - 1 - i] - '0') % P == 0) res += N - i;
        }
        return res;
    }
    vector<ll> val(P, 0);
    ll fac = 1;
    ll cur = 0;
    val[cur]++;
    for (int i = 0; i < N; i++)
    {
        cur = (cur + fac * (S[N - 1 - i] - '0')) % P;
        fac = (fac * 10) % P;
        val[cur]++;
    }
    ll res = 0;
    for (int p = 0; p < P; p++) res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main()
{
    cin >> N >> P >> S;
    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3752
def fib_memo(n,broken):
    memo = [0]*(n+1)
    memo[0] = 1
    for x in range(1,n+1):
        if x < 1:
            continue
        if broken[x]==1:
            continue
        memo[x] = (memo[x-1] + memo[x-2])%1000000007

    return memo[n]

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
broken = [0]*(n+1)
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)
    broken[x] = 1

result = fib_memo(n,broken)

print(result)

Measured memory_bytes: 8172
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    int n,m;
    cin >> n >> m;
    if(abs(n-m)>1){
        cout << 0<<endl;
        return 0;
    }
    ll ans = 1;
    for(int i=1;i<=n;i++){
        ans=ans%mod;
        ans*=i;
        ans=ans%mod;
    }
    for(int i=1;i<=m;i++){
        ans=ans%mod;
        ans*=i;
        ans=ans%mod;
    }
    if(abs(n-m)==0){
        ans=ans%mod;
        ans*=2;
        ans=ans%mod;
    }
    ans=ans%mod;
        cout << ans << endl;
}



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

#define MOD 1000000007
typedef unsigned long long ull;

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), penalty(n);
  int ac_count = 0, penalty_count = 0;
  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;
    p--;

    // AC済なら無視
    if (ac[p] != 0) {
      continue;
    }
    // 未AC
    if (s == "WA") {
      penalty[p]++;
    } else {
      ac[p]++;
      ac_count++;
      penalty_count += penalty[p];
    }
  }

  cout << ac_count << " " << penalty_count;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string S;
	int K;
	cin >> S;
	cin >> K;
	vector<string> cands;
	REP(i, S.size()){
		REP(j, K){
			if(i+j<=S.size()) cands.push_back(S.substr(i, j+1));
		}
	}
	sort(cands.begin(), cands.end());
	cands.erase(unique(cands.begin(), cands.end()), cands.end());
	//vprint(cands);
	cout << cands[K-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        long[] a = new long[n.length()];
        int ans = 0;
        for(int p = 0; p < n.length(); p++){
            a[p] = Long.parseLong(String.valueOf(n.charAt(p)));
            ans += a[p];
        }
        if(ans % 9 == 0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 52368
import time
import random
import math
def sigmoid(x):
  return 1/(1+math.exp(-x))
def score(a,c,s,d):
  l=[-1 for i in range(26)]
  r=0
  for i in range(d):
    l[a[i]]=i
    r+=s[i][a[i]]
    for j in range(26):
      r-=c[j]*(i-l[j])
  return r
  
st=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

ans=[]
l=[-1 for i in range(26)]
ld=[]
for i in range(d):
  ms=-10**9
  mt=None
  for j in range(26):
    js=c[j]*(i-l[j])+s[i][j]
    if ms<js:
      ms=js
      mt=j
  l[mt]=i
  ans.append(mt)
  ld.append([l[mt],d])
  if l[mt]>=0:
    ld[l[mt]][1]=i

os=score(ans,c,s,d)
nt=st
rate=1000
while nt-st<1.50:
  nt=time.time()
  na=[ans[i] for i in range(d)]
  na[random.randint(1,d-1)]=random.randint(0,25)
  ns=score(na,c,s,d)
  if sigmoid((ns-os)/rate/((2-nt+st)**2)-0.5)>random.random():
    os=ns
    ans=na
  
  


for i in ans:
  print(i+1)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int A,B,s,m,b,a;
  cin >> A >> B;
	s=A+B;
  m=A-B;
  b=A*B;
  if(s>m){
    if(s>b){
      a=s;
    }else{
      a=b;
    }
  }else{
    if(m>b){
      a=m;
    }else{
      a=b;
    }
  }
  cout << a << endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mpp make_pair
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    fast;
    ll n,sum=0;
    cin>>n;
    ll arr[n+5];
    for(ll i=1; i<=n; i++)
    {
        cin>>arr[i];
    }
    for(ll i=1; i<n; i++)
    {
        if(arr[i]>arr[i+1])
        {
            sum+=(arr[i]-arr[i+1]);
            //cout<<sum<<" "<<i<<endl;
            arr[i+1]+=(arr[i]-arr[i+1]);
        }
    }
//    for(ll i=1; i<=n; i++)
//    {
//        cout<<arr[i]<<" ";
//    }
//    cout<<endl;
    cout<<sum<<endl;
}


Measured memory_bytes: 5120
ki = {"R","U","D"}
gu = {"L","U","D"}

n = str(input())
n_l = len(n)
N = []
for i in range(n_l):
    N.append(n[i])

n_ki = set(N[::2])
n_gu = set(N[1::2])
if n_ki.issubset(ki) and n_gu.issubset(gu):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		Map<String, String> M = new HashMap<>();

		Scanner sc = new Scanner(System.in);

		String str = sc.next();

		M.put("a", "b");
		M.put("b", "c");
		M.put("c", "d");
		M.put("d", "e");
		M.put("e", "f");
		M.put("f", "g");
		M.put("g", "h");
		M.put("h", "i");
		M.put("i", "j");
		M.put("j", "k");
		M.put("k", "l");
		M.put("l", "m");
		M.put("m", "n");
		M.put("n", "o");
		M.put("o", "p");
		M.put("p", "q");
		M.put("q", "r");
		M.put("r", "s");
		M.put("s", "t");
		M.put("t", "u");
		M.put("u", "v");
		M.put("v", "w");
		M.put("w", "x");
		M.put("x", "y");
		M.put("y", "z");

		System.out.println(M.get(str));

	}
}


Measured memory_bytes: 21972
#!/usr/bin/env python3
from itertools import permutations
import sys


def solve(A: int, B: int, C: int):
    m = 0
    for n1, n2, n3 in permutations([A, B, C]):
        exp1 = "%d+%d%d" % (n1, n2, n3)
        exp2 = "%d%d+%d" % (n1, n2, n3)
        m = max(m, eval(exp1), eval(exp2))
    print(m)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define V(a) a.begin(), a.end()
typedef vector<int> vi;

int main()
{
	vi a[2], C;

	for (auto &i : a) {
		int n;
		cin >> n;
		i = vi(n);
		for (int &j : i)
			cin >> j;
		sort(V(i));
	}

	set_intersection(V(a[0]), V(a[1]), inserter(C, C.end()));

	cout << C.size() << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  for(int i = 0; i <= b-a; i++) {
    if((a+i) % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

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

int main(void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M, u, v, S, T;
	cin >> N >> M;
	vector<int> G[N];
	vector<vector<int>> dist(N, std::vector<int> (3,-1));
	for(int i = 0; i < M; ++i){
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
	}
	cin >> S >> T;
	S--; T--;
	queue<pair<int, int>> q;
	q.emplace(0,S);
	dist[S][0] = 0;
	while(!q.empty()){
		int v = q.front().second;
		int d = q.front().first;
		q.pop();
		for(auto x : G[v]){
			if(dist[x][(d+1)%3] == -1){
				dist[x][(d+1)%3] = d+1;
				q.emplace(d+1,x);
			}
		}
	}
	cout << (dist[T][0] != -1 ? dist[T][0]/3 : -1) << endl;
	return 0;
}


Measured memory_bytes: 11264
my $MOD = 10 ** 9 + 7;

my (@fact, @inv);

sub invmod {
    my ($a, $m) = @_;
    my ($c, $d, $uc, $vc, $ud, $vd) = ($a % $m, $m, 1, 0, 0, 1);
    my $q;
    while ($c != 0) {
        ($q, $c, $d) = (int($d / $c), $d % $c, $c);
        ($uc, $vc, $ud, $vd) = ($ud - $q * $uc, $vd - $q * $vc, $uc, $vc);
    }
    return $ud % $m;
}

sub count_routes {
    my ($h, $w) = @_;
    --$h;
    --$w;
    return 1 unless ($h && $w);
    my $c = $fact[$h + $w];
    $c = ($c * $inv[$h]) % $MOD;
    $c = ($c * $inv[$w]) % $MOD;
    return $c;
}

my ($H, $W, $A, $B) = split(/\s+/, <>);
@fact = map { 1 } (0 .. $H + $W);
@inv = map { 1 } (0 .. ($H > $W ? $H : $W));
$fact[$_] = ($fact[$_ - 1] * $_) % $MOD for (1 .. $#fact);
$inv[$_] = invmod($fact[$_], $MOD) for (1..$#inv);

my $count = count_routes($H, $W);
my ($i, $j) = ($H - $A + 1, $B);
while ($i <= $H && $j > 0) {
    my $first  = count_routes($i, $j);
    my $second = count_routes($H - $i + 1, $W - $j + 1);
    $count = ($count - ($first * $second) % $MOD) % $MOD;
    ++$i;
    --$j;
}
print $count;

Measured memory_bytes: 21760