akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int kNil = -1;

enum class Color {
  kWhite,
  kGrey,
  kBlack,
};

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
void BridgesVisit(
    const typename vector<Edge>::size_type node_now,
    typename vector<Edge>::size_type & time,
    const vector<vector<Edge>> & adjacency_list,
    vector<int> & d,
    vector<int> & low,
    vector<Color> & color,
    vector<int> & parent) {
  color[node_now] = Color::kGrey;
  d[node_now] = time;
  low[node_now] = time++;
  for (const auto & e: adjacency_list[node_now]) {
    if (color[e.v] == Color::kWhite) {
      parent[e.v] = e.u;
      BridgesVisit(e.v, time, adjacency_list, d, low, color, parent);
      low[e.u] = min(low[e.u], low[e.v]);
    } else if (parent[e.u] != e.v) {
      low[e.u] = min(low[e.u], d[e.v]);
    }
  }
  color[node_now] = Color::kBlack;
}

template <class Edge>
decltype(auto) Bridges(vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num) {
  using size_type = typename vector<Edge>::size_type;

  vector<vector<Edge>> adjacency_list(node_num, vector<Edge>());
  for (const auto & e: edges) {
    adjacency_list[e.u].push_back(e);
  }

  size_type time = 0;
  vector<int> d(node_num);
  vector<int> low(node_num);
  vector<Color> color(node_num, Color::kWhite);
  vector<int> parent(node_num, kNil);

  for (unsigned i = 0; i < node_num; ++i) {
    if (color[i] == Color::kWhite) {
      BridgesVisit(i, time, adjacency_list, d, low, color, parent);
    }
  }

  vector<Edge> bridges;
  for (const auto & e: edges) {
    if (d[e.u] < low[e.v]) {
      if (e.u < e.v) {
        bridges.push_back(e);
      } else {
        bridges.emplace_back(e.v, e.u, e.w);
      }
    }
  }

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

  return bridges;
}

int main(int argc, char const *argv[]) {
  using w_type = unsigned;

  vector<Edge<w_type>> edges;
  unsigned V, E;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    w_type w;
    cin >> u >> v;
    edges.emplace_back(u, v, 1);
    edges.emplace_back(v, u, 1);
  }

  auto bridges = Bridges(edges, V);
  for (const auto & e: bridges) {
    cout << e.u << " " << e.v << "\n";
  }

  return 0;
}

Measured memory_bytes: 7156
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
  unsigned int N;
  unsigned int a[2],b[2],c[2];
  bool ans = true;

  cin >> N;
  a[0] = b[0] = c[0] = ~0;
  a[1] = b[1] = c[1] = 0;

  for(int i=0; i<N; i++) {
    unsigned int x;
    cin >> x;
    if (a[0] == x) a[1]++;
    else if (b[0] == x) b[1]++;
    else if (c[0] == x) c[1]++;
    else {
      if (a[0] == ~0) {
        a[0]=x; a[1]++;
      } else if (b[0] == ~0) {
        b[0]=x; b[1]++;
      } else if (c[0] == ~0) {
        c[0]=x; c[1]++;
      } else {
        ans = false;
      }
    }
  }

  if (a[0] == 0 && b[0] == ~0 && c[0] == ~0) {
    cout << "Yes" << endl;
  } else if (ans && ((a[1]*2 == b[1] && a[0] == 0) || (a[1] == b[1]*2 && b[0] == 0)) && c[0]==~0 ) {
    cout << "Yes" << endl;
  } else if (ans && a[1] == b[1] && b[1] == c[1] && ((a[0] ^ c[0]) == b[0])) {
    cout << "Yes" << endl;
  } else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+1;
int main()
{
    FASTINOUT;
    ll x,y;
    cin>>x>>y;
    x*=500;
    if (x>=y)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


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

int main(void){
   
    int N,S;
    cin >> N >> S;
    string t[N];
    
    for(int i=0;i<N;i++) cin >> t[i];
    
    sort(t,t+N);
    
    for(int i=0;i<N;i++) cout << t[i];
    cout << endl;
}

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

using ll = long long;

int main() {
   ll x;
   cin >> x;
   ll cnt = (x / 11) * 2;
   x %= 11;

   if (x == 0) {
      cout << cnt << endl;
   } else if (x <= 6) {
      cout << cnt + 1 << endl;
   } else {
      cout << cnt + 2 << endl;
   }

   return 0;
}

Measured memory_bytes: 256
class Card
  attr_reader :suit
  attr_accessor :value
  def initialize(card_str)
    @suit = card_str[0]
    @value = card_str[1..-1].to_i
  end

  def to_s
    @suit + ' ' + @value.to_s
  end

  def ==(other)
    if other.is_a?(Card)
      suit == other.suit && value == other.value
    else
      false
    end
  end
end

def is_stable?(input, out)
  input == out
  # n = input.length
  # for i in 0...n
  #   if input[i] != out[i]
  #     return false
  #   end
  # end
  # true
end

def partition(arr, p, r)
  x = arr[r].value
  i = p - 1
  for j in p...r
    if arr[j].value <= x
      i += 1
      arr[i], arr[j] = arr[j], arr[i]
    end
  end
  arr[i + 1], arr[r] = arr[r], arr[i + 1]
  return i + 1
end

def quick_sort(arr, p, r)
  if p < r
    q = partition(arr, p, r)
    quick_sort(arr, p, q-1)
    quick_sort(arr, q+1, r)
  end
end

def merge(arr, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = []
  for i in 0...n1
    l << arr[left + i]
  end
  r = []
  for i in 0...n2
    r << arr[mid + i]
  end
  final = Card.new('finale 0')
  final.value = Float::INFINITY
  l << final
  r << final
  i = 0
  j = 0
  for k in left...right
    if l[i].value <= r[j].value
      arr[k] = l[i]
      i += 1
    else
      arr[k] = r[j]
      j += 1
    end
  end
end

def merge_sort(arr, left, right)
  if left + 1 < right
    mid = (left + right) / 2
    merge_sort(arr, left, mid)
    merge_sort(arr, mid, right)
    merge(arr, left, mid, right)
  end
end

n = gets.to_i
cards = []
n.times do
  cards << Card.new(gets)
end


sorted_cards = cards.dup
quick_sort(sorted_cards, 0, n-1)
merge_sort(cards, 0, n)
if is_stable?(cards, sorted_cards)
  puts "Stable"
else
  puts "Not stable"
end

sorted_cards.each do| card|
  puts card
end


Measured memory_bytes: 23444
#include "bits/stdc++.h"
using namespace std;

void push(int A);
int pop(void);

vector<int> S(1000);
int Top = 0;

int main(void) {

	string str;
	int a, b;
	Top = 0;
	while (cin >> str) {

		if (str == "+") {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (str == "-") {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (str == "*") {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(str.c_str()));
		}
	}
	cout << pop() << endl;

	return 0;
}

void push(int A) {
	S.at(++Top) = A;
}

int pop(void) {
	Top--;
	return S.at(Top + 1);
}


Measured memory_bytes: 3172
import math

l, r, d = map(int, input().split())

if l % d == 0:
  if r % d == 0:
    print(math.floor(r/d) - math.floor(l/d) + 1)
  else:
    print(math.floor(r/d) - math.floor(l/d) + 1)
else:
  if r % d == 0:
    print(math.floor(r/d) - math.floor(l/d))
  else:
    print(math.floor(r/d) - math.floor(l/d))


Measured memory_bytes: 9176
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
tmp=min(a)+min(b)
for i in range(m):
    x,y,c=map(int,input().split())
    if a[x-1]+b[y-1]-c<tmp:
        tmp=a[x-1]+b[y-1]-c
print(tmp)

Measured memory_bytes: 18612
#include<bits/stdc++.h>
using namespace std;
int dp[81][81][6400 * 2 + 2];
int find_it(int dif_sum , int i , int j , int &n , int &m , vector<vector<pair<int , int>>> & matrix){
    if(i == n - 1 && j == m - 1){
        return min(abs(dif_sum + matrix[i][j].first - matrix[i][j].second) , abs(dif_sum + matrix[i][j].second - matrix[i][j].first));
    }
    if(dp[i][j][dif_sum] != -1){
        return dp[i][j][dif_sum];
    }
    int minvalue = INT_MAX;
    int ff = dif_sum + matrix[i][j].first - matrix[i][j].second;
    int ss = dif_sum + matrix[i][j].second - matrix[i][j].first;
    if(i + 1 < n){
        minvalue = min(minvalue , find_it(ff , i + 1 , j , n , m , matrix));
        minvalue = min(minvalue , find_it(ss , i + 1 , j , n , m , matrix));

    }
    if(j + 1 < m){
        minvalue = min(minvalue , find_it(ff , i , j + 1 , n , m , matrix));
        minvalue = min(minvalue , find_it(ss , i , j + 1 , n , m , matrix));
    }
    return dp[i][j][dif_sum] = minvalue;

}
int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n , m;
    cin >> n >> m;
    vector<vector<pair<int , int> > > matrix(n , vector<pair<int , int>> (m));

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> matrix[i][j].first;
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> matrix[i][j].second;
        }
    }
    memset(dp , -1 , sizeof(dp));
    cout << find_it(0 , 0 , 0 , n , m , matrix);


return 0;
}


Measured memory_bytes: 328448
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define line                    cout << "\n===================\n"
bool Check(int mask, int pos){
    return (bool)(mask & (1 << pos));
}
 
vector<pii> t[20];
int mark[20];
bool visit[20];
int n;
 
int check(int mask){
	mem(mark, 0);
	mem(visit, false);
	vector<int> v;
	for (int i = 0; i < 15; i++){
		if (Check(mask, i)){
			v.pb(i + 1);
			mark[i + 1] = 1;
			visit[i + 1] = true;
		}
	}
	// cout << "v contains: ";
	// for (int i = 0; i < v.size(); i++){
	// 	cout << v[i] << " ";
	// }
	// cout << endl;
	int len = v.size();
	for (int i = 0; i < len; i++){
		int p = v[i];
		for (int j = 0; j < t[p].size(); j++){
			int x, y;
			x = t[p][j].fi;
			y = t[p][j].se;
			if (y == 1){
				if (mark[x] == -1){
					return -1;
				}
				else{
					if (!visit[x]){
						v.pb(x);
						visit[x] = true;
						len++;
					}
					mark[x] = 1;
				}
			}
			else{
				if (mark[x] == 1){
					return -1;
				}
				else{
					mark[x] = -1;
				}
			}
		}
	}
	// cout << "v contains: ";
	// for (int i = 0; i < v.size(); i++){
	// 	cout << v[i] << " ";
	// }
	// cout << endl;
	return len;
}
 
int main ()
{
    // freopen ("input.txt", "r", stdin);
    // freopen ("output.txt", "w", stdout);
    //fastRead;
 
	cin >> n;
	for (int i = 1; i <= n; i++){
		int a;
		cin >> a;
		while (a--){
			int x, y;
			cin >> x >> y;
			t[i].pb(mp(x, y));
		}
	}
	int res = 0;
    for (int mask = 1; mask < (1 << n); mask++){
    	int cnt = check(mask);
    	if (cnt != -1){
    		res = max(res, cnt);
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }



void solve(long long a, std::string s){
	if (a>=3200) cout << s << "\n";
	else cout << "red" << "\n";
}

int main(){
    long long a;
    scanf("%lld",&a);
    std::string s;
    std::cin >> s;
    solve(a, s);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
int z=0;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
//ここから始めよう
int n,x;int sl[55];
int solve(int l,int a){
    if(l==0&&a==1)return 1;
    else if(a==1)return 0;
    else if(1<a&&a<=1+sl[l-1]){
        return solve(l-1,a-1);
    }
    else if(a==2+sl[l-1])return solve(l-1,sl[l-1])+1;
    else if(2+sl[l-1]<a&&a<=2+2*sl[l-1]){
        return solve(l-1,sl[l-1])+1+solve(l-1,a-2-sl[l-1]);
    }else return 2*solve(l-1,sl[l-1])+1;
}
signed main(){
    cin>>n>>x;
    sl[0]=1;
    rep(i,1,n+1){
        sl[i]=2*sl[i-1]+3;
    }
    cout<<solve(n,x)<<endl;return 0;
}


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

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

int maze[25][25];
int h, w;

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

int bfs(pii s, pii g, vector<string> &table){
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            maze[i][j] = -1;
        }
    }
    maze[s.first][s.second] = 0;
    queue<pii> que;
    que.push(s);
    while(!que.empty()){
        pii p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if(table[nx][ny] == '#') continue;
            if(maze[nx][ny] != -1) continue;
            maze[nx][ny] = maze[x][y] + 1;
            que.push(pii(nx, ny));
        }
        if(maze[g.first][g.second] != -1){
            break;
        }
    }
    return maze[g.first][g.second];
}

int main(){
    cin >> h >> w;
    vector<string> table(h);
    for (int i = 0; i < h; ++i) {
        cin >> table[i];
    }

    int res = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            for (int k = 0; k < h; ++k) {
                for (int l = 0; l < w; ++l) {
                    if(table[i][j] == '#') continue;
                    if(table[k][l] == '#') continue;
                    res = max(res, bfs(pii(i, j), pii(k, l), table));
                }
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 764
package main

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

func main() {
	fsc := NewFastScanner()
	text := fsc.Next()
	result := strings.Split(text, ",")
	for _, word := range result {
		fmt.Print(word + " ")

	}
	fmt.Println()
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rint register int
using namespace std;
int n,cnt[200005],a[200005];
long long tot=0;
int main()
{
	scanf("%d",&n);
	for(rint i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	for(rint k=1;k<=n;k++)
		tot+=(long long)cnt[k]*(cnt[k]-1)/2;
	for(rint k=1;k<=n;k++)
		printf("%lld\n",tot-cnt[a[k]]+1);
	return 0;
} 

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

using namespace std;


#define MAXN 101
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, f[MAXN][10], p[MAXN][11];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 10; ++j) {
      cin >> p[i][j];
    }
  }
  int ans = -1e9-1;
  for (int i = 1; i < (1<<10); ++i) {
    int profit = 0;
    for (int j = 0; j < n; ++j) {
      int cnt = 0;
      for (int k = 0; k < 10; ++k) {
        cnt += (i>>k)&1 && f[j][k];
      }
      profit += p[j][cnt];
    }
    ans = max(ans, profit);
  }
  cout << ans << endl;
  return 0;
}


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

int dp[110][110][2]; 
vector<int> num;

int recur(int current_position, int count, int tight, int k) 
{ 
	if(count > k) {
		return 0;
	}
	
	if (current_position == num.size()) {
		return (count == k) ? 1 : 0;
	}

	if (dp[current_position][count][tight] != -1) 
		return dp[current_position][count][tight]; 

	int ans = 0; 

	int limit = (tight ? 9 : num[current_position]); 

	for (int dig = 0; dig <= limit; dig++) { 
		int currcount = count; 

		if (dig != 0) 
			currcount++; 

		int currTight = dig < num[current_position] ? 1 : tight; 

		ans += recur(current_position + 1, currcount, currTight, k); 
	}
	
	dp[current_position][count][tight] = ans; 
	return dp[current_position][count][tight];
} 

int main() 
{ 
	string x;
	cin >> x;
	int k;
	cin >> k;
	
	for(int i = 0; i < x.length(); i++) {
		num.push_back(x[i]-'0');
	}
	memset(dp, -1, sizeof(dp)); 
	cout << recur(0, 0, 0, k); 
	
	return 0; 
} 


Measured memory_bytes: 384
#include<iostream>
#include<math.h>

#define PI 3.141592653589793238

using namespace std;

int main() {

	int n = 0;
	
	cin >> n;

	while (n != 0) {

		int data[1000] = { 0 };
		double ave = 0;
		double sigma = 0;

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

			cin >> data[i];

		}

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

			ave += double(data[i]) / n;

		}

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

			sigma += pow(data[i] - ave, 2) / n;

		}

		sigma = sqrt(sigma);

		cout << fixed << sigma << endl;

		cin >> n;

	}

	return 0;

}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007

// void dfs(int x, int y, vector<vector<int>>& grid, vector<vector<int>>& ans,int& n, int& m)
// {
// 	ans[x][y]++;
// 	ans[x][y]%=M;

// 	if(x+1 < n && grid[x+1][y]==1)
// 		dfs(x+1,y,grid,ans,n,m);
// 	if(y+1 < m && grid[x][y+1]==1)
// 		dfs(x,y+1,grid,ans,n,m);
// }

int main()
{

	// #ifndef ONLINE_JUDGE
	// 		freopen("input", "r", stdin);
	// 		freopen("output","w",stdout);
	// #endif

	ios_base::sync_with_stdio(0);	cin.tie(NULL);	cout.tie(0);


	int n,m;	cin>>n>>m;
	// vector<vector<int>> v(n,vector<int>(m,0)), ans(n,vector<int>(m,0));
	int v[n][m], ans[n][m];

	memset(v,0,sizeof(v));
	memset(ans,0,sizeof(ans));

	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
		{
			char c;	cin>>c;
			if(c=='.')	v[i][j]=1;
		}

	ans[0][0]=1;
	

	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
			if(v[i][j]==1 && (j!=0 || i!=0))
				ans[i][j] = ((i-1>=0?ans[i-1][j]:0) + (j-1>=0?ans[i][j-1]:0))%M;

	cout<<ans[n-1][m-1]<<endl;

}

Measured memory_bytes: 11448
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    double n, m, d;
    cin >> m >> n >> d;
    double res = (m - d) * (n - 1) / m / m;
    if (d != 0) {
        res *= 2;
    }
    cout << std::setprecision(20) << res;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
   int N;
   cin>>N;
     int count = 0;
   for(int i = 1; i<=N; i++){
      int S;
      cin >>S;
      if(S% 2== 1 && i%2 == 1){
          count++;
      }
   }cout<<count<<endl;
   
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int n,m;
char mapp[1010][1010];
ll dp[1010][1010];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",mapp[i]+1);
	dp[0][1]=1;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			if (mapp[i][j]=='.'){
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
				dp[i][j]%=mod;
			}
			else dp[i][j]=0;
		}
	}
	printf("%lld\n",dp[n][m]);
	return 0;
} 

Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main( ){
  while(1){
    double D,E,min;
    cin>>D>>E;
    if(D==0&&E==0)break;
    for(int i=0;i<=D;i++){
      double l=fabs(sqrt(pow(D-i,2)+pow(i,2))-E);
      if(i==0)min=l;
      if(l<min)min=l;
    }
    printf("%f\n",min);
  }
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H,W,h,w;
  cin>>H>>W>>h>>w;
  cout << H*W - (h*W + H*w - h*w) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=5005;
int n,a[N],si[N],tot,head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
ll dp[N][N][2],f[N][2];
void dfs(int u,int p)
{
    if(a[u]<0) dp[u][1][1]=a[u];
    else dp[u][1][0]=a[u];
    si[u]=1;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        dfs(v,u);
        memset(f,inf,sizeof(f));
        for(int j=1;j<=si[u];j++)
            for(int k=1;k<=si[v];k++)
        {
            if((dp[v][k][0]<dp[0][0][0]||dp[v][k][1]<0)&&dp[u][j][0]<dp[0][0][0])
                f[j+k][0]=min(f[j+k][0],dp[u][j][0]);
            if((dp[v][k][0]<dp[0][0][0]||dp[v][k][1]<0)&&dp[u][j][1]<dp[0][0][0])
                f[j+k][1]=min(f[j+k][1],dp[u][j][1]);
            for(int h=0;h<2;h++)
                for(int p=0;p<2;p++)
                if(dp[u][j][h]<dp[0][0][0]&&dp[v][k][p]<dp[0][0][0])
                f[j+k-1][h|p]=min(f[j+k-1][h|p],dp[u][j][h]+dp[v][k][p]);
        }
        si[u]+=si[v];
        for(int j=1;j<=si[u];j++)
            dp[u][j][0]=f[j][0],dp[u][j][1]=f[j][1];
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    memset(dp,inf,sizeof(dp));
    dfs(1,0);
    int ans=n-1;
    for(int i=1;i<=n;i++)
        if(dp[1][i][0]<dp[0][0][0]||dp[1][i][1]<0){ans=i-1;break;}
    printf("%d\n",ans);
}


Measured memory_bytes: 392448
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,x,res=0,y;
    cin>>n>>x;
    for(int i=1;i<n;i++)
    {
        cin>>y;
        if(x>y)
        {
            ll k=x-y;
            res+=k;
        }
        else
        x=y;
    }
    cout<<res;
    return 0;
}


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

int main()
{
  char S[5];
  cin >> S;

  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]){
    cout << "Bad" << endl;
  }
  else cout << "Good" << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
import numpy as np

# N
n = int(input())

# an 数列
an = [list(map(int, input().split()))]

an_np = np.array(an)

num = 0

while True:
    if np.any(an_np % 2 == 0):
        an_np = an_np[an_np % 2 == 0] 
        num += len(an_np)
        an_np //= 2
    else:
        break
print(num)

Measured memory_bytes: 13256
a = input()
n = len(a)
d = {}
for i in a:
    d[i] = d.get(i,0)+1
def cov2(x):
    return x*(x-1)//2
ans = 1 + cov2(n)
for v in d.values():
    ans -= cov2(v)
print(ans)

Measured memory_bytes: 3500
from collections import defaultdict
import bisect
def main():
    s = list(input())
    t = list(input())
    dic_s = defaultdict(list)
    for i in range(len(s)):
        dic_s[s[i]].append(i)
    x,y = 0,-1
    for i in range(len(t)):
        if dic_s[t[i]] == []:
            print(-1)
            return
        next_y = bisect.bisect_left(dic_s[t[i]],y+1)
        if next_y == len(dic_s[t[i]]):
            x += 1
            y = dic_s[t[i]][0]
        else:
            y = dic_s[t[i]][next_y]
    print(x*len(s)+y+1)

if __name__ == "__main__":
    main()

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

int main(void) {
    int N,tmp,ans = 0;
    bool isPair = false;
    bool isCorr;
    cin >> N;
    for (int i=1; i<=N; i++) {
        cin >> tmp;
        isCorr = (tmp == i);
        if (isCorr && !isPair) { ans++; isPair = true; }
        else isPair = false;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;


int main(int argc, char *argv[])
{

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, P[8],Q[8];
    
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    
    for (int i = 0; i < N; i++) {
        cin >> Q[i];
        Q[i]--;
    }
    
    int R[8] = {0};
    int a = 0, b = 0, k = 1;
    
    iota(R, R + N, 0);
    
    do {
        bool equal = true;
        for (int i = 0; i < N; i++) {
            if (P[i] != R[i]) {
                equal = false;
                break;
            }
        }
        
        if (equal) {
            a = k;
        }
        
        equal = true;
        
        for (int i = 0; i < N; i++) {
            if (Q[i] != R[i]) {
                equal = false;
                break;
            }
        }
        
        if (equal) {
            b = k;
        }
        
        k++;
    } while (next_permutation(R, R + N));
    
    cout << abs(a - b) << endl;
    
}


Measured memory_bytes: 256
str = input()
moji = ('resare', 'esare', 'remaerd', 'maerd')
str = str[::-1]
for i in range(len(moji)):
    str = str.replace(moji[i], "")
    # print(str)
print("YES") if str == "" else print("NO")
# print(str.strip('nu'))


Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}else if(x<=y){
			printf("%d %d\n",x,y);
		}else if(x>=y){
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}

Measured memory_bytes: 2600
import functools
  
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

inputs = input().split()
n = int(inputs[0])
x = int(inputs[1])
point = list(map(int, input().split()))
point.sort()
space = []

space.append(abs(x - point[0]))

for i in range(1, n):
    space.append(abs(point[i] - point[i -1]))

gcd = functools.reduce(gcd, space)

print(gcd)


Measured memory_bytes: 14748
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;

int main(){
    double a,b,c,d,e,f;
    while (cin >> a ,cin >> b, cin >> c, cin >> d ,cin >> e ,cin >>f) {
        double x,y;
        y = (c*d-f*a)/(b*d - e*a);
        x = (c - b * y)/a;
        printf("%.3f",x);
        cout << " ";
        printf("%.3f",y);
        cout << endl;
    }
    
}

Measured memory_bytes: 1272
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	const mod = 1000000007
	n := nextInt()
	a := nextInts(n)
	// 各aの素因数分解
	pfs := primeFactors(a)
	// 最小公倍数の素因数分解
	lcmp := lcmPrimes(pfs)

	// 最小公倍数
	lcm := 1
	for x, y := range lcmp {
		for i := 0; i < y; i++ {
			lcm = (lcm * x) % mod
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		b := lcm * modPow(a[i], mod-2, mod)
		ans = (ans + b) % mod
	}
	puts(ans)
	wt.Flush()
}

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

// nまでの自然数の最小の素因数
func minFactors(n int) []int {
	mf := make([]int, n+1)
	mf[0], mf[1] = -1, -1
	for i := 2; i <= n; i++ {
		for j := 1; i*j <= n; j++ {
			if mf[i*j] == 0 {
				mf[i*j] = i
			}
		}
	}
	return mf
}

// 高速素因数分解
func primeFactors(a []int) []map[int]int {
	// 各数の素因数分解結果を入れるmap配列
	m := make([]map[int]int, len(a))
	for i := range m {
		m[i] = map[int]int{}
	}
	// 最小素因数テーブル
	mf := minFactors(max(a))
	for i := range a {
		for j := a[i]; j > 1; j /= mf[j] {
			m[i][mf[j]]++
		}
	}
	return m
}

func lcmPrimes(pfs []map[int]int) map[int]int {
	m := map[int]int{}
	for x, y := range pfs[0] {
		m[x] = y
	}
	for i := 1; i < len(pfs); i++ {
		for x := range pfs[i] {
			if pfs[i][x] > m[x] {
				m[x] = pfs[i][x]
			}
		}
	}
	return m
}

// (a^n) % mod
func modPow(a, n, mod int) int {
	ret := 1
	for n > 0 {
		if n&1 == 1 {
			ret = (ret * a) % mod
		}
		a = (a * a) % mod
		n >>= 1
	}
	return ret
}


Measured memory_bytes: 12184
$n = gets.to_i
A = gets.split.map(&:to_i)
q = gets.to_i
M = gets.split.map(&:to_i)

def solve(i, m)
  if m == 0
    return true
  end

  if i >= $n
    return false
  end

  res = solve(i + 1, m) || solve(i + 1, m - A[i])
  return res
end

M.each do |m|
  solve(0, m) ? puts('yes') : puts('no')
end



Measured memory_bytes: 6868
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int n, a[100000], b[100000], c[100000];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		cin >> b[i];
	for (int i = 0; i < n; ++i)
		cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);

	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ll s = lower_bound(a, a + n, b[i]) - a;
		ll t = n - (upper_bound(c, c + n, b[i]) - c);
		ans += s * t;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
const ll mx=1e18;
ll a[70]={0};
int main()
{
    ll n,ans=0;
    rep1(i,60) a[i]=a[i-1]+i;
    vector<ll> v;
    cin>>n;
    for(int i=2;i<=sqrt(n);i++)
    {
        ll cnt=0;
        while(n%i==0)
        {
            n/=i;
            cnt++;
        }
        if(cnt>0) v.pb(cnt);
    }
    if(n>1) v.pb(1);
    rep(i,v.size())
    {
        //cout<<v[i]<<"\n";
        rep1(j,60)
        {
            if(a[j]>v[i])
            {
                ans+=j-1;
                break;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n,m;
  cin>>n>>m;
  int upper = 10, lower = 1;
  for(auto&& i:irange(0,n-1)) {
    upper *= 10;
    lower *= 10;
  }
  if (n == 1) lower = 0;
  vector<pair<int,int>> vp;
  for(auto&& i:irange(0,m)) {
    int s,c;
    cin>>s>>c;
    vp.emplace_back(s,c);
  }
  for(auto&& i:irange(lower,upper)) {
    auto str = to_string(i);
    bool ok = true;
    for(auto&& p:vp) {
      int s,c;
      tie(s,c) = p;
      if (str[s-1] - '0' != c) {
        ok = false;
      }
    }
    if (ok) {
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class MainClass
    {
        public static void Main()
        {
           

            string[] input1 = Console.ReadLine().Split(' ');
            int X= int.Parse(input1[0]);
            int Y = int.Parse(input1[1]);
            int Z = int.Parse(input1[2]);

            Console.WriteLine(Z + " " + X + " " + Y);


            

            
        }
    }
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int D,N;
int T[200];
int A[200],B[200],C[200];

int dp[210][210];

signed main(){
    cin>>D>>N;
    rep(i,D)cin>>T[i];
    rep(i,N)cin>>A[i]>>B[i]>>C[i];

    fill_n(*dp,210*210,-1001001001001001001ll);
    rep(i,N){
        if(A[i]<=T[0]&&T[0]<=B[i])dp[1][i]=0;
    }

    for(int i=1;i<D;i++){
        rep(j,N){
            rep(k,N){
                if(A[k]<=T[i]&&T[i]<=B[k]){
                    chmax(dp[i+1][k],dp[i][j]+abs(C[j]-C[k]));
                }
            }
        }
    }

    int ma=-1001001001001001001ll;
    rep(i,N)chmax(ma,dp[D][i]);
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 1504
#include<bits/stdc++.h>
using namespace std;
#define int long long int 

int32_t main()
{
    int n;
    cin>>n;
    set<int> s;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        s.insert(x);
    }
    if((n-s.size())%2==0)
    cout<<s.size()<<endl;
    else
    cout<<s.size()-1<<endl;


}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	int n, m;
	cin >> n >> m;
	int s[n], c[n];
	for (int i = 1; i <= m; i++)
		cin >> s[i] >> c[i];
	FOR(1000)
	{
		string t = to_string(i);
		if (t.size() == n)
		{
			int j;
			for (j = 1; j <= m; j++)
				if (t[s[j] - 1] != c[j] + '0')
					break;
			if (j == m + 1)
			{
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << -1;
	return 0;
}

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

int isPrimeNum( int x )
{
    int i;

    for( i = 2; i <= sqrt((double)x); i++ )
        if( x % i == 0 ) return 0;
    return 1;
}

int main(){
  int num;
  int i,j;
  int *array;
  int count = 0;

  do{
  scanf("%d",&num);
  }while(num < 1 || num > 10000);

  array = (int *)malloc(sizeof(int)*num);

  for(i = 0;i < num;i++){
    do{
    scanf("%d",&array[i]);
    }while(array[i]<2 || array[i]>100000000);
  }

  for(i = 0;i < num;i++) {
        if( isPrimeNum( array[i] ) ) {
	  count++;
        }
    }

  printf("%d\n",count);
  
  free(array);
  
  return 0;
}



Measured memory_bytes: 2144
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

string s;
string t;
vi u;

int main(){
	ios_base::sync_with_stdio(0);
	cin>>s;
	s+="@";
	int c=0;
	rep(i,sz(s)){
		if(i==0 || s[i]==s[i-1]){
			c++;
		}else{
			t+=s[i-1];
			u.pb(c);
			c=1;
		}
	}
	int ans=0,J=0,O=0;
	rep(i,sz(t)){
		if(t[i]=='J'){
			J=u[i];
			O=0;
		}
		else if(t[i]=='O'){
			if(u[i]<=J){
				O=u[i];
			}else J=O=0;
		}else{
			if(u[i]>=O){
				ans=max(ans,O);
			}
			J=O=0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8648
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        cin >> a[i];
    }

    VI b=a;
    SORT(b);
    b.erase(unique(ALL(b)),b.end());
    FOR(i,1,SZ(b)){
        if(b[i-1]+1!=b[i]){
            cout << "Impossible" << ENDL;
            return 0;
        }
    }

    int mina = b[0];
    int maxa = b[SZ(b)-1];


    if(mina==maxa){
        if(mina==1 && n==2){
            cout << "Possible" << ENDL;
        }else{
            cout << "Impossible" << ENDL;
        }
        return 0;
    }

    if (maxa/2+1 < mina){
        cout << "Impossible" << ENDL;
        return 0;
    }

    VI c(maxa+1,0);
    REP(i,n){
        c[a[i]]++;
    }

    if (maxa%2==0 && c[b[0]]!=1){
        cout << "Impossible" << ENDL;
        return 0;
    }
    if (maxa%2!=0 && c[b[0]]!=2){
        cout << "Impossible" << ENDL;
        return 0;
    }

    FOR(i,(maxa%2==0?1:0),SZ(b)){
        if(c[b[i]]<2){
            cout << "Impossible" << ENDL;
            return 0;
        }
    }

    cout << "Possible" << ENDL;
    
    return 0;
}

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

int main(){
  int n,x,y;
  cin >> n >> x >>y;
  --x;--y;
  vector<int> ans(n);
  rep(sv,n){
    vector<int> dist(n,inf);
    queue<int> q;
    auto push = [&](int v, int d){
      if (dist[v] != inf) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv,0);
    while(!q.empty()){
      int v = q.front();q.pop();
      int d = dist[v];
      if (v-1 >= 0) push(v-1,d+1);
      if (v+1 < n) push(v+1,d+1);
      if (v == x) push(y,d+1);
      if (v == y) push(x,d+1);
    }
    rep(i,n) ans[dist[i]]++;
  }
  rep(i,n) ans[i] /= 2;
  for (int i = 1; i <= n-1; i++){
    cout << ans[i] << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long n,a,b,k,ind=0;cin>>n>>k;
  map<int,long> m;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    m[a]+=b;
  }
  if(k==1){cout<<(*m.begin()).first;}
  for(auto it=m.begin();it!=m.end();it++){
    ind+=(*it).second;
    if(ind>=k){cout<<(*it).first;return 0;}
  }
}

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

int main(){
    int n, x; cin >> n >> x;
    vector<int> m(n);
    rep(i,n) cin >> m[i];


    put(n + (x - accumulate(m.begin(), m.end(),0)) / *min_element(m.begin(), m.end()));
}

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

using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int a[105],b[105];
ll dp[maxn];

int main()
{
	ios::sync_with_stdio(false);
	int n,w;
	while(cin>>n>>w){
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i];
		}
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++){
			for(int j=w;j>=0;j--){
				if(a[i]<=j){
					dp[j]=max(dp[j-a[i]]+b[i],dp[j]);
				}
			}
		}
		cout<<dp[w]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static Scanner sc = new Scanner(System.in);
    public void run() throws Exception {

    	Scanner sc = new Scanner(System.in);
    	long aa[] = new long[4];
    	long a = sc.nextLong();
    	long b = sc.nextLong();
    	long c = sc.nextLong();
    	long d = sc.nextLong();
    	aa[0] = a*c;
    	aa[1] = a*d;
    	aa[2] = b*c;
    	aa[3] = b*d;

    	long res = Long.MIN_VALUE;
    	for(int i=0; i<4;i++){
    		if(res<aa[i]){
    			res = aa[i];
    		}
    	}

/*    	int n = 5;
    			int []aaa = {2, 0, 9, 0, -5};
    			int res = -10000000;
    			for(int i=0; i<n;i++){
    				if(res<aaa[i]){
    					res = aaa[i];
    				}
    			}*/
		System.out.println(res);
		
		
    }
    //再帰
    static long fib(int n){
	    if (n <= 1){
	    	return 1;
	    }else{
	    	return fib(n-1) + fib(n-2);
	    }
	}


    //動的計画法 DP
    static long nCr(int n,int r) {
    	  int dp[][]=new int[2001][2001];
    	  for(int i=0;i<2001;i++) {
    	    dp[0][i]=0;
    	  }
    	  for(int i=0;i<2001;i++) {
    	    dp[i][0]=1;
    	  }
    	  for(int i=1;i<2001;i++) {
    	    for(int j=1;j<2001;j++) {
    	      if(i==j) {
    	        dp[i][j]=1;
    	      }else {
    	        dp[i][j]=dp[i-1][j-1]+dp[i][j-1];
    	      }
    	    }
    	  }
    	  return dp[n][r];
    	}

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
    //2 つの Key をもつ Map.pair は二つの要素を入れる入れ物
    class pair{
    	  int wt,val;
    	  pair(int wt,int val){
    	    this.wt=wt;
    	    this.val=val;
    	  }
    }
}


Measured memory_bytes: 35972
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;	//using vi = vector<int>;

#define rep(i, N) for (int i = 0; i < N; i++)

int main()
{
	ull a,b;
	cin >> a >> b;
	
	if (b - a >= 2019) {
		cout << 0 << endl;
		return 0;
	}

	ull temp = 100000;
	for (ull i = a; i <= b-1; i++) {
		for (ull j = i+1; j <= b; j++) {
			
			if (temp > (i*j) % 2019) {
				temp = ((i * j) % 2019);
				//cout << "temp:" << temp << endl;
			}
		}
	}
	

	cout << temp << endl;

	//system("pause");
	return 0;
}

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

using namespace std;

string S; 
int K;

int main(){
  cin>>S>>K;
  vector<string> vec;
  for(int i=0;i<S.size();i++){
    for(int j=1;j<=K;j++){
      string temp=S.substr(i,j);
      vec.push_back(temp);
    }
  }

  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  cout<<vec[K-1]<<endl;

  return 0;
}


Measured memory_bytes: 1660
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

int a[100], n;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    int ans = 0;
    for (int i = 2; i < n; ++i) {
        int mn = min(a[i-1], a[i+1]);
        int mx = max(a[i-1], a[i+1]);
        if(mn < a[i] && a[i] < mx) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256