akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int H, W, N;
int sy, sx;
string s, t;

bool solve(char c1, char c2, int lim1, int ss) {
  int left = 1, right = lim1;
  if (s[N-1] == c1) left++;
  if (s[N-1] == c2) right--;
  // dbg2(left, right)
  // line()
  for (int i = N-2; i >= 0; i--) {
    if (t[i] == c1) {
      right = min(right+1, lim1);
    } else if (t[i] == c2) {
      left = max(1ll, left-1);
    }
    // dbg2(left, right)
    if (s[i] == c1) {
      left++;
    } else if (s[i] == c2) {
      right--;
    }
    // dbg2(left, right)
    // line()
    if (right < left) return false;
    // if (!(left <= ss and ss <= right)) {
      // return false;
    // }
  }
  // line()
  // line()

  return left <= ss and ss <= right;
}

signed main() {
  cin >> H >> W >> N;
  cin >> sy >> sx;
  cin >> s >> t;

  bool a1 = solve('L', 'R', W, sx);
  bool a2 = solve('U', 'D', H, sy);
  // dbg2(a1, a2)
  bool ans = a1 and a2;

  puts(ans?"YES":"NO");

  return 0;
}

Measured memory_bytes: 776
#include <iostream>

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

        std::cin >> x;
    
        if(x==0)
        {
            break;
        }
        else if(1 <= x <= 10000)
        {
            std::cout << "Case " << i << ": " << x << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2996
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<time.h>
#define ll long long
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define miin(a,b,c) min((a), min((b), (c)))
#define maax(a,b,c) max((a), max((b), (c)))

int a, b;

int main(){
    scanf("%d%d", &a, &b);
    int cnt = 0;
    while(a){
        a/=b;
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();

		int w = Math.abs(x2 - x1);
		int h = Math.abs(y2 - y1);

		if (x1 <= x2) {

			if (y1 <= y2) {
				// 1
				out.println((x2 - h) + " " + (y2 + w) + " " + (x1 - h) + " " + (y1 + w));
			} else {
				// 2
				out.println((x2 + h) + " " + (y2 + w) + " " + (x1 + h) + " " + (y1 + w));
			}
		} else {

			if (y1 <= y2) {
				// 1
				out.println((x2 - h) + " " + (y2 - w) + " " + (x1 - h) + " " + (y1 - w));
			} else {
				// 2
				out.println((x2 + h) + " " + (y2 - w) + " " + (x1 + h) + " " + (y1 - w));
			}
		}

		out.flush();

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


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

int main(){
  int N, M;
  cin >> N >> M;
  int c[N];
  for(int i=0; i<N; i++)
    c[i]=0;
  
  for(int i=0; i<M; i++){
    int a=0, b=0;
    cin >> a >> b;
    c[a-1]++;
    c[b-1]++;
  }
  for(int i=0; i<N; i++){
    cout << c[i] << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  map<string, int> res;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    res[s]++;
  }
  cout << "AC x " << res["AC"] << endl;
  cout << "WA x " << res["WA"] << endl;
  cout << "TLE x " << res["TLE"] << endl;
  cout << "RE x " << res["RE"] << endl;
}


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

int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  
  if (a == 0) cout << "1" << endl;
  else if (b == 0) cout << "2" << endl;
  else if (c == 0) cout << "3" << endl;
  else if (d == 0) cout << "4" << endl;
  else if (e == 0) cout << "5" << endl;
  
  return 0;
}

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

typedef long long ll;

const ll inf = 10000000;

using Graph = vector<vector<int>>;
vector<bool>seen(100005, false);
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto nv : G[v]) {
        if (seen[nv]) continue;
        dfs(G, nv);
    }
}

int main() {
    int N, M;
    int ans = 0;
    cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    for (int i = 0; i < N; i++) {
        if (!seen[i]) {
            ans++;
            dfs(G, i);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 10368
MOD = 10 ** 9 + 7

fac = [1] * 2000
finv = [1] * 2000
inv = [1] * 2000
for i in range(2, 2000):
  fac[i] = (fac[i - 1] * i) % MOD
  inv[i] = MOD - (inv[MOD % i] * (MOD // i))% MOD
  finv[i] = (finv[i - 1] * inv[i]) % MOD

def comb(n, r):
  return fac[n] * ((finv[r] * finv[n - r]) % MOD) % MOD

S = int(input())
ans = 0
for i in range(1, S // 3 + 1):
  ans += comb(S - 2 * i - 1, i - 1)
  ans %= MOD

print(ans)

Measured memory_bytes: 64900
import java.util.*;

public class Main {
	
	static int[] bambooLengths;
	static int N;
	static int A;
	static int B;
	static int C;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		
		bambooLengths = new int[N];
		for (int i = 0; i < N; i++) {
			bambooLengths[i] = sc.nextInt();
		}
		
		System.out.println(getMinCost(0, 0, 0, 0, 0));
	}
	
	public static int getMinCost(int i, int a, int b, int c, int cost) {
		if (i == N) {
			return (a != 0 && b != 0 && c != 0) ? cost + Math.abs(A-a) + Math.abs(B-b) + Math.abs(C-c) : Integer.MAX_VALUE;
		}
		int bambooLength = bambooLengths[i];
		int useForA = getMinCost(i+1, a + bambooLength, b, c, a == 0 ? cost : cost + 10);
		int useForB = getMinCost(i+1, a, b + bambooLength, c, b == 0 ? cost : cost + 10);
		int useForC = getMinCost(i+1, a, b, c + bambooLength, c == 0 ? cost : cost + 10);
		int dontUse = getMinCost(i+1, a, b, c, cost);
		
		return Math.min(useForA, Math.min(useForB, Math.min(useForC, dontUse)));
	}
  
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
  int main() {
    int a , b ;
    cin >> a >> b ;

    if (  ( a + b ) % 2 == 0 ) {
      cout << ( a + b ) / 2  << endl;
    }
    else{
      cout << ( a + b ) / 2 + 1  << endl;
    }
  }  

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

using ll=long long;



void solve(){
    string s;
    cin>>s;
    int cnt=0;
    for(auto e:s){
        if(e=='2')cnt+=1;
    }
    cout<<cnt<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 102;

bool flag[MAX_N];
P rt[MAX_N];
P ch[MAX_N];
int pr[MAX_N];
int n;

ll gcd(ll a,ll b)
{
	if(b==0LL){
		return a;
	}
	return gcd(b,a%b);
}

ll mobile(int a,int b,ll c,ll d)
{
	ll res = gcd(a*c,b*d);
	return b*c*d/res+a*c*d/res;
}	

ll dfs(int u)
{
	if(ch[u].first==-1&&ch[u].second==-1){
		return mobile(rt[u].first,rt[u].second,1LL,1LL);
	}else if(ch[u].first == -1){
		return mobile(rt[u].first,rt[u].second,1LL,dfs(ch[u].second));
	}else if(ch[u].second == -1){
		return mobile(rt[u].first,rt[u].second,dfs(ch[u].first),1LL);
	}else{
		return mobile(rt[u].first,rt[u].second,dfs(ch[u].first),dfs(ch[u].second));
	}
}
int main()
{
	while(1){
	scanf("%d",&n);
	if(n==0){
		break;
	}
	fill(pr,pr+n,-1);
	rep(i,n){
		scanf("%d%d%d%d",&rt[i].first,&rt[i].second,&ch[i].first,&ch[i].second);
		ch[i].first--,ch[i].second--;
		if(ch[i].first != -1){
			pr[ch[i].first] = i;
		}
		if(ch[i].second != -1){
			pr[ch[i].second] = i;
		}
	}
	int id=0;
	while(pr[id]!=-1){
		id = pr[id];
	}
	ll ans = dfs(id);
	printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3096
package main

import (
  "fmt"
  "math"
  "container/heap"
)

type Item struct {
  Index int
  Distance float64
}
type PriorityQueue []*Item
func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
  return pq[i].Distance < pq[j].Distance
}
func (pq *PriorityQueue) Pop() interface{} {
  old := *pq
  n := len(old)
  item := old[n - 1]
  *pq = old[0:n - 1]
  return item
}
func (pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  *pq = append(*pq, item)
}
func (pq PriorityQueue) Swap(i, j int) {
  pq[i], pq[j] = pq[j], pq[i]
}

func dist(B *[][]float64, s, t int) (ret float64) {
  ret = math.Sqrt(math.Pow(((*B)[s][0] - (*B)[t][0]), 2.0) + math.Pow(((*B)[s][1] - (*B)[t][1]), 2.0)) - (*B)[s][2] - (*B)[t][2]
  if ret < 0 {
    ret = 0.0
  }
  return
}

func dijkstra(D *[][]float64, s int) (L []float64) {
  n := len((*D))
  L = make([]float64, n)
  for i := 1; i < n; i++ {
    L[i] = math.Inf(0)
  }
  L[s] = 0.0
  Q := new(PriorityQueue)
  heap.Push(Q, &Item{Index: s, Distance: L[s]})
  V := make([]bool, n)
  for i, _ := range(V) {
    V[i] = false
  }
  for ; len(*Q) > 0; {
    node := heap.Pop(Q).(*Item)
    if V[node.Index] {
      continue
    }
    V[node.Index] = true
    for t := 0; t < n; t++ {
      if V[t] {
        continue
      }
      if node.Distance + (*D)[node.Index][t] < L[t] {
        L[t] = node.Distance + (*D)[node.Index][t]
        heap.Push(Q, &Item{Index: t, Distance: L[t]})
      }
    }
  }
  return
}

func main() {
  var sx, sy, tx, ty float64
  fmt.Scan(&sx, &sy, &tx, &ty)
  var N int
  fmt.Scan(&N)
  B := make([][]float64, N + 2)
  for i, _ := range(B) {
    B[i] = make([]float64, 3)
  }
  B[0] = []float64{sx, sy, 0.0}
  B[N + 1] = []float64{tx, ty, 0.0}
  var x, y, r float64
  for i := 1; i <= N; i++ {
    fmt.Scan(&x, &y, &r)
    B[i] = []float64{x, y, r}
  }
  D := make([][]float64, N + 2)
  for i, _ := range(D) {
    D[i] = make([]float64, N + 2)
  }
  for i := 0; i < N + 2; i++ {
    D[i][i] = 0.0
    for j := i + 1; j < N + 2; j++ {
      D[i][j] = dist(&B, i, j)
      D[j][i] = dist(&B, j, i)
    }
  }
  L := dijkstra(&D, 0)
  fmt.Println(L[N + 1])
}

Measured memory_bytes: 23168
N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(M)]
ans = [0] * N
for i in range(M):
	ans[a[i][0] - 1] += 1
	ans[a[i][1] - 1] += 1
for j in range(N):
	print(ans[j])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX INT_MAX
#define MIN INT_MIN
#define MOD 1000000007
int ceiling(int a, int b) {
	return (a+b-1)/b;
}
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
void solve() {
 	int r, c, s;
 	cin >> r >> c >> s;
 	cout << ceiling(s, max(r, c));   
    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#define INF INT_MAX
using namespace std;

int N, X;
int x[100010];
int D;
int y[100010];

int gcd(int a, int b){
	return a%b ? gcd(b, a%b) : b;
}

int main(){
	cin >> N >> X;
	if (N == 1){
		cin >> x[0];
		cout << abs(x[0] - X) << endl;
		return 0;
	}
	for (int i = 0; i < N; i++){
		cin >> x[i];
		if (i > 0){
			y[i] = abs(x[i] - x[i - 1]);
		}
	}
	for (int i = 1; i < N; i++){
		if (i == 1)D = y[i];
		D = gcd(y[i], D);
	}
	D = gcd(abs(X - x[1]), D);
	cout << D << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, A, B;
  cin >> N >> A >> B;
  
  long long q = N / (A + B);
  long long p = N % (A + B);
  long long n_blue = q * A + min(p, A);
  cout << n_blue << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <deque>
#include <cstring>
using namespace std;
deque<char> dq;
char s[100010];
int q,t,f,flag;
char c;
int main(){
    while (scanf("%s",&s)!=EOF) {
        flag = 0;
        while (!dq.empty())
            dq.pop_front();

        for (int i=0;i<strlen(s);i++)
            dq.push_back(s[i]);

        scanf("%d",&q);
        while (q--) {
            scanf("%d",&t);
            if (t == 1) {
                flag = (flag+1)%2;
            }
            else if (t == 2) {
                scanf("%d %c",&f,&c);
                if ((f+flag)%2) {
                    dq.push_front(c);
                }
                else {
                    dq.push_back(c);
                }
            }
        }
        if (flag) {
            while (!dq.empty()) {
                printf("%c",dq.back());
                dq.pop_back();
            }
        }
        else {

            while (!dq.empty()) {
                printf("%c",dq.front());
                dq.pop_front();
            }
        }
        printf("\n");
    }
    return 0;
}


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



void solve(std::string S, std::string T){

ll cnt = 0;
    for (size_t i = 0; i < S.size(); i++)
    {
        if(S[i]!=T[i])
            cnt++;
    }
    cout << cnt << endl;

}

signed main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 4124
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    s=STR()
    if s[:n//2]==s[n//2:]:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <string.h>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	REP(i, n)
	{
		char buf1[101], buf2[101];
		memset(buf1, 0, 101);
		memset(buf2, 0, 101);
		char sum[101];
		memset(sum, 0, 101);
		scanf("%s", buf1);
		scanf("%s", buf2);
		int l, l1 = 0, l2 = 0;
		for (l = 0; l < 100; l++)
		{
			if (buf1[l] == '\0' && l1 == 0)
			{
				l1 = l;
			}
			if (buf2[l] == '\0' && l2 == 0)
			{
				l2 = l;
			}
			if (l1 > 0 && l2 > 0) break;
		}
		l1--;
		l2--;
		l = (l1 > l2) ? l1 : l2;
		if (l >= 80)
		{
			printf("overflow\n");
			continue;
		}
		l++;
		bool plus = false;
		for (;l >= 0; l--)
		{
			int v1 = (l1 >= 0) ? buf1[l1] - '0': 0;
			int v2 = (l2 >= 0) ? buf2[l2] - '0': 0;
			int v = v1 + v2 + ((plus) ? 1 : 0);
			if (v > 9) 
			{
				plus = true;
				v -= 10;
			}
			else
			{
				plus = false;
			}
			sum[l] = '0' + v;
			l1--;
			l2--;
			if (l1 < 0 && l2 < 0 && !plus) break;
		}
		if (sum[0] == '\0')
		{
			printf("%s\n", &sum[1]);
		}
		else if (sum[80] != 0)
		{
			printf("overflow\n");
		}
		else
		{
			printf("%s\n", sum);
		}
	}
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;
// mat dtable(M, vl(N, 0)); M行N列 のサイズで,0で初期化


const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int N, M; cin >> N >> M;
    vl S(N+1), T(M+1);
    REP(i, N) cin >> S[i];
    REP(i, M) cin >> T[i];
    mat dp(N+1, vl(M+1, 0));
    FOR(i, 1, N+1){
        FOR(j, 1, M+1){
            if (T[j-1] == S[i-1]){
                dp[i][j] = ((dp[i][j-1] + dp[i-1][j]) + 1) % MOD;
            }else{
                dp[i][j] = (((dp[i][j-1] + dp[i-1][j]) % MOD) + MOD - dp[i-1][j-1]) % MOD;
            }
        }
    }

    cout << ((dp[N][M]+1)%MOD) << endl;
}

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <bitset>

using namespace std;

typedef pair<int,int> pii;
void fast_stream(){
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
}
typedef pair<pii,int> ppii;
int N,R;
int field[2][10011];
vector<ppii> rangeSet[10010];
int line[10010];
const int dy[]={-1,0,0,1};
const int dx[]={0,-1,1,0};
const int INF=1000000000;
int main(){
  fast_stream();
  while(cin>>N>>R&&(N|R)){
    int miny,minx,maxy,maxx;
    miny=minx=INF;
    maxx=maxy=-INF;
    for(int i=0;i<10001;i++)rangeSet[i].clear();
    memset(line,0,sizeof(line));
    memset(field,0,sizeof(field));
    for(int i=0;i<N;i++){
      int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
      rangeSet[y1].push_back(make_pair(pii(x1,x2),1));
      rangeSet[y2].push_back(make_pair(pii(x1,x2),-1));
      maxy=max(y2+1,maxy);
      maxx=max(x2,maxx);
      miny=min(y1,miny);
      minx=min(x1,minx);
    }
    int S=0;
    int E=0;
    int cur=miny%2;
    int prv=cur^1;
    for(int y=miny;y<maxy;y++){
      memset(field[cur],0,sizeof(field[cur]));
      for(int i=0;i<(int)rangeSet[y].size();i++){
	int sx=rangeSet[y][i].first.first;
	int ex=rangeSet[y][i].first.second;
	int a=rangeSet[y][i].second;
	for(int j=sx;j<ex;j++)line[j]+=a;
      }
      for(int x=minx;x<maxx;x++){
	if(line[x]>0){
	  S++;
	  field[cur][x]=1;
	}
      }
      for(int x=minx;x<maxx;x++){
	if(field[prv][x]^field[cur][x])E++;
	if(field[cur][x]==1){
	  if(x-1<0||field[cur][x-1]==0)E++;
	  if(field[cur][x+1]==0)E++;
	}
      }
      swap(cur,prv);
    }
    cout<<S<<endl;
    if(R==2)cout<<E<<endl;
  }
  return 0;
}

Measured memory_bytes: 2052
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

n = int(input())
s = input()

if (n % 2 != 0):
    print("No")
    exit()

for i in range(n//2):
    if (s[i] != s[n//2 + i]):
        print("No")
        exit()
print("Yes")



Measured memory_bytes: 9036
s=input()
n=len(s)
p=10**9+7
 
dp=[[0]*13 for i in range(n)]
m=[0]*(n-1)+[1]
for i in range(n-1):
    m[-i-2]=m[-i-1]*10%13
 
if s[0]!='?':
    a=int(s[0])*m[0]%13
    dp[0][a]=1
else:
    for k in range(10):
        a=k*m[0]%13
        dp[0][a]=1
 
for i in range(1,n):
    if s[i]!='?':
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(s[i])*m[i])%13]%p
    else:
        for k in range(10):
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-k*m[i])%13]%p
print(dp[n-1][5]%p)

Measured memory_bytes: 64348
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int _ = 0; _ < n; ++_) {
        int outs = 0, score = 0, a = 0, b = 0, c = 0;
        while(outs < 3){
            string s;
            cin >> s;
            if(s == "HIT"){
                score += c; c = b; b = a; a = 1;
            }else if(s == "HOMERUN"){
                score += a+b+c+1; a = b = c = 0;
            }else {
                outs++;
            }
        }
        cout << score << "\n";
    }
    return 0;
}


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

const ll MAX_N = 100010;
ll N, M, K;
vector<vector<ll>> F(MAX_N, vector<ll>(0));
vector<ll> next_to(MAX_N, 0);
vector<ll> flag(MAX_N, -1);
ll flag_num = 0;
map<ll, ll> cnt;

void link(int x) {
  if (flag[x] != -1) return;
  flag[x] = flag_num;
  cnt[flag_num]++;
  for (auto f : F[x]) link(f);
}

int main() {
  cin >> N >> M >> K;
  for (ll i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    --a; --b;
    F[a].push_back(b);
    F[b].push_back(a);
    next_to[a]++;
    next_to[b]++;
  }
  for (ll i = 0; i < N; i++) {
    link(i);
    flag_num++;
  }
  for (ll i = 0; i < K; i++) {
    ll c, d;
    cin >> c >> d;
    --c; --d;
    if (flag[c] == flag[d]) {
      next_to[c]++;
      next_to[d]++;
    }
  }
  for (ll i = 0; i < N; i++) {
    cout << (cnt[flag[i]] - next_to[i] - 1) << " ";
  }
  cout << endl;
}


Measured memory_bytes: 13184
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            string[] RSP = Console.ReadLine().Split(' ');
            string T = Console.ReadLine();
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            int R = int.Parse(RSP[0]);
            int S = int.Parse(RSP[1]);
            int P = int.Parse(RSP[2]);

            int len = T.Length;
            int[] renzoku = new int[K];
            int count = 0;
            int ans = 0;
            for (int i = 0; i < len; i++)
            {
                if (T[i] == 'r')
                {
                    if (renzoku[count] == 1)
                    {
                        renzoku[count] = 0;
                    }
                    else
                    {
                        ans += P;
                        renzoku[count] = 1;
                    }
                }
                if (T[i] == 's')
                {
                    if (renzoku[count] == 2)
                    {
                        renzoku[count] = 0;
                    }
                    else
                    {
                        ans += R;
                        renzoku[count] = 2;
                    }
                }
                if (T[i] == 'p')
                {
                    if (renzoku[count] == 3)
                    {
                        renzoku[count] = 0;
                    }
                    else
                    {
                        ans += S;
                        renzoku[count] = 3;
                    }
                }
                count++;
                if (count == K) count = 0;
            }
            Console.WriteLine(ans);
        }
       
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */
/*
      static long func(long n)
      {
          long d = 0;
          for (long i = 0; i < 10; i++)
          {
              if (n / longPow(10, i) == 0)
              {
                  d = i;
                  break;
              }
          }
          long ret = A * n + B * d;
          return ret;
      }
      static long longPow(long a, long n)
      {
          long b = 1;
          for (long i = 0; i < n; i++) b = b * a;
          return b;
      }
      */


Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int max = 0;
    int ans = 0;
    rep(i,n){
        if(max <= h[i]){
            max = h[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;



int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	long long n;
	cin >> n;
	long long res = n - 1;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			res = min(res, i + n / i - 2);
		}
	}

	cout << res;
	return 0;
}

Measured memory_bytes: 256
main(){
  int in[8];
  int h,b,i,j;

  while (scanf("%d",in)>0){
    for(i=1;i<8;i++) scanf("%d",&in[i]);
    for(b=0,i=0;i<4;i++)
      for(j=4;j<8;j++)
        if(in[i]==in[j]){b++;break;}
    for(h=0,i=0;i<4;i++)
      if(in[i]==in[4+i])h++;
    printf("%d %d\n", h, b-h);
  }
  return 0;
}

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

using namespace std;

int main() {

	int value, num, i=0, total=0, ave=0;

	while(scanf("%d, %d", &value, &num)!=EOF) {
		total+=value*num;
		ave+=num;
		i++;
	}

	cout << total << endl << (int)(ave/(double)i+0.5) << endl;

	return 0;

}

Measured memory_bytes: 0
from collections import deque


def main():
    S = input()
    Q = int(input())

    d = deque(S)

    r = False
    for _ in range(Q):
        q = input()
        if q == '1':
            r = not r
        else:
            _, b, c = q.split()
            if r:
                if b == '1':
                    d.append(c)
                else:
                    d.appendleft(c)
            else:
                if b == '1':
                    d.appendleft(c)
                else:
                    d.append(c)

    if r:
        d.reverse()
    print("".join(d))


if __name__ == "__main__":
    main()


Measured memory_bytes: 8564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll N; cin>>N;
  ll cnt=0;
  rep(i,0,N){
    ll X; cin>>X;
    if(X%2==1) cnt++;
  }
  string ans="NO";
  if(cnt%2==0) ans="YES";
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  int n,k; cin >>n >>k;
  cout <<(k == 1 ? 0 : n-k) <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll n;
  cin>>n;
  ll a[n];
  fo(i,n)
  cin>>a[i];
  ll ans[n]={0};
  for(ll i=n-2;i>=0;i--)
  {
  	if(a[i]>=a[i+1])
  		ans[i]=ans[i+1]+1;
  	else
  		ans[i]=0;
  }
  ll p=mx(ans,ans+n);
  cout<<p;
  return 0;
}

Measured memory_bytes: 5216
from collections import defaultdict as dd
from collections import deque as dq
N = int(input())
e = dd(list)
inf = 10 ** 15
for _ in range(N - 1):
  u, v, d = map(int, input().split())
  e[u].append((v, d))
  e[v].append((u, d))
Q, K = map(int, input().split())
d = [inf] * (N + 1)
d[K] = 0
q = dq([])
q.append(K)
while len(q):
  p = q.popleft()
  for t in e[p]:
    temp = d[p] + t[1]
    if d[t[0]] > temp:
      d[t[0]] = temp
      q.append(t[0])
for _ in range(Q):
  u, v = map(int, input().split())
  print(d[u] + d[v])

Measured memory_bytes: 90840
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    
    int BusA   = sc.nextInt();
    int BusB   = sc.nextInt();
    int TrainA = sc.nextInt();
    int TrainB = sc.nextInt();
    
    int Bus   = BusA > BusB ? BusB : BusA;
    int Train = TrainA > TrainB ? TrainB : TrainA;
    System.out.println(Train + Bus);
    }
}


Measured memory_bytes: 21844
import math
def main():
    n=int(input())
    if n<357:
        print(0)
    else:
        numRange=math.ceil(math.log10(n))
        num=[0]*numRange
        num[0:3]=[0,1,1]
        check=0
        ans=0
        for i in range((3**(numRange+1)-1)//2-13):
            num[0]+=1
            j=0
            while j<numRange-1 and num[j]==4:
                num[j+1]+=1
                num[j]=1
                j+=1
            if 1 in num and 2 in num and 3 in num:
                j=0
                check=0
                while j<numRange and num[j]!=0:
                    a=0
                    if num[j]==1:
                        a=3
                    elif num[j]==2:
                        a=5
                    else:
                        a=7
                    check+=a*10**j
                    j+=1
                if check<=n:
                    ans+=1
                else:
                    break
        print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 9336
import sys
import fileinput
import math
from collections import Counter
from decimal import Decimal

RADIAN180 = math.pi
ANGLE90 = 90

counter = Counter()


def is_triangle(edges):
    return edge[0] + edge[1] > edge[2] and \
           edge[1] + edge[2] > edge[0] and \
           edge[2] + edge[0] > edge[1]


def calculate_radian(edges):
    edge.sort()
    radian = []

    s = sum(edge) / 2
    s = Decimal.sqrt(s * (s - edge[0]) * (s - edge[1]) * (s - edge[2]))
    h = 2 * s / edge[2]

    radian.append(math.asin(h / edge[0]))
    radian.append(math.asin(h / edge[1]))

    radian.append(RADIAN180 - sum(radian))

    return radian


for input_list in fileinput.input():

    edge = [Decimal(item) for item in input_list.split(" ")]

    if is_triangle(edge):

        counter["ALL"] = counter["ALL"] + 1

        radian = calculate_radian(edge)

        max_radian = max(radian)
        max_angle = Decimal(math.degrees(max_radian))
        max_angle = max_angle.quantize(Decimal("1.0"))

        if max_angle < ANGLE90:
            counter["ACUTE"] += 1
        elif max_angle == ANGLE90:
            counter["RIGHT"] += 1
        else:
            counter["OBTUSE"] += 1
    else:
        for garbage in sys.stdin:
            pass
        break

print(counter['ALL'], counter["RIGHT"], counter["ACUTE"], counter["OBTUSE"])



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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0;
  rep(i,n) {
    cin >> a[i];
    ans += a[i];
  }
  
  map<ll,ll> mp;
  rep(i,n) mp[a[i]]++;
  
  ll q;
  cin >> q;
  rep(i,q) {
    ll b, c;
    cin >> b >> c;
    ans += mp[b] * (c-b);
    cout << ans << endl;
    mp[c] += mp[b];
    mp[b] = 0;
  }
}

Measured memory_bytes: 10052
n = int(input())
color = [None for i in range(n)]
tree = {}
res = 0
et = []
for i in range(n-1):
    u, v = [int(x) for x in input().strip().split()]
    et.append((u,v))
    if u not in tree:
        tree[u] = []
    if v not in tree:
        tree[v] = []
    tree[u].append(v)
    tree[v].append(u)
    res = max(res, len(tree[u]),len(tree[v]))

# for i in range(1,n+1):
#     if i not in tree:
#         tree[i] = []

edge = {}
color[0] = 0

for i in range(1,n+1):
    for v in tree[i]:
        if v>i:
            tc = color[i-1]+1
            if tc>res:
                tc = tc%res
            color[i-1] = tc
            color[v-1] = tc
            if i not in edge:
                edge[i] = {}
            if v not in edge[i]:
                edge[i][v] = {}
            edge[i][v] = tc

# res = max(edge)
print(res)
for e in et:
    print(edge[e[0]][e[1]])




Measured memory_bytes: 55344
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////


int main(){
	int s;
	cin >> s;
	bool f[1000000] = {};

	f[s] = 1;

	int cnt = 2;
	while(1){
		if(s%2) s = 3 * s + 1;
		else s /= 2;
		
		if(f[s]) break;

		f[s] = 1;
		cnt++;
	}

	cout << cnt << endl;

	ret 0;
}

Measured memory_bytes: 1280
// ITP1_6_C:   Official House
// 2017.7.27

#include <stdio.h>

int main()
{
	int b, f, r, v;;
	int house[5][4][11];
	int i, n;

	for (b = 1; b <= 4; b++)
	{
		for (f = 1; f <= 3; f++)
		{
			for (r = 1; r <= 10; r++)
			{
			    house[b][f][r] = 0;
			}
		}
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d%d%d%d", &b, &f, &r, &v);
		house[b][f][r] += v;
	}

	for (b = 1; b <= 4; b++)
	{
		for (f = 1; f <= 3; f++)
		{
			for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
			putchar('\n');
		}
		if (b < 4) puts("####################");
	}
	return 0;
}



Measured memory_bytes: 2040
#include<iostream>
using namespace std;
int xx[8]={-1,1,0,0,-1,-1,1,1};
int yy[8]={0,0,-1,1,-1,1,-1,1};
int n,m,h[10001][3];
char a[101][101];
void js(int p,int q){
	int x,y,ans;
	//h[1][1]=p;h[1][2]=q;
//	do{
		
		ans=0;
		//t++;
		for(int i=0;i<8;i++){
			
			x=p+xx[i];
			y=q+yy[i];
			if(x>0&&x<=n&&y>0&&y<=m&&a[x][y]=='#'){
				ans++;
//				w++;
//				h[w][1]=x;
//				h[w][2]=y;
			}
//			a[p][q]=ans+'0';
		}
		a[p][q]=ans+'0';
//	}while(t<w);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]!='#')js(i,j);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *x = map(int, read().split())

x2=sorted(x)
mid_left = x2[n // 2 - 1]
mid_right = x2[n // 2]

for v in x:
    if v <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

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

int main(void){
	int n,i=2,num=0;cin>>n;
	while(num<n){
		i+=5;int check=1;
		for(int j=2;j*j<=i;j++){
		    if(i%j==0){
		        check=0;
		        break;
		    }
		}
		if(check==1){cout<<i<<" ";num++;}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define prdouble(x)  cout<< fixed <<setprecision(10) <<x ;  
double dp[3000][3000] ; //dp[i][j] represents the probability of getting atleast j heads from the first i coins . 
double solve(vector<double>& prob,int n,int j){
     if(j==0){
         return 1 ; 
     }
     if(n==0){
         return 0 ; 
     }
     if(dp[n][j]>-0.9){ //0.9 has no significance . it is just to makes ure cause double have issues in ==.
         return dp[n][j] ;
     }
     return dp[n][j] = prob[n]*solve(prob,n-1,j-1)+ (1-prob[n])*solve(prob,n-1,j) ; 
    
}
int main(){
    int n;  cin>>n; 
    vector<double> prob(n+1) ; 
      memset(dp,-1,sizeof(dp)) ;
    for(int i =1 ; i<n+1 ; i++){
        cin>>prob[i] ; 
    }
    //vector storing the probabilities .
   prdouble(solve(prob,n,(n+1)/2)) ;
}

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

using namespace std;

#define N 120

int n,m,a[N][N],pre[N];
bool vis[N],g[N][N];

bool dfs(int u){
	for (int v=1;v<=n;++v)
		if (g[u][v]&&!vis[v]){
			vis[v]=1;
			if (!pre[v]||dfs(pre[v])){
				pre[v]=u;
				return 1;
			}
		}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j) scanf("%d",a[i]+j);
	for (int i=1;i<=m;++i){
		memset(g,0,sizeof g);
		for (int j=1;j<=n;++j)
			for (int k=i;k<=m;++k)
				g[j][(a[j][k]+m-1)/m]=1;
		memset(pre,0,sizeof pre);
		for (int j=1;j<=n;++j){
			memset(vis,0,sizeof vis);
			dfs(j);
		}
		for (int j=1;j<=n;++j){
			int r=pre[j];
			for (int k=i;k<=m;++k)
				if ((a[r][k]+m-1)/m==j){
					swap(a[r][k],a[r][i]);
					break;
				}
		}
	}
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j) printf(j==m?"%d\n":"%d ",a[i][j]);
	for (int i=1;i<=m;++i){
		for (int j=1;j<=n;++j)
			for (int k=j;k<=n;++k)
				if (a[j][i]>a[k][i]) swap(a[j][i],a[k][i]);
	}
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j) printf(j==m?"%d\n":"%d ",a[i][j]);
	
	return 0;
}
			

Measured memory_bytes: 384
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;


ll N,M,ans;
string S;


int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	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
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    for (int i = 1; i <= n; i += 2)
    {
        int cnt = 0;
        rep2(j, 1, n + 1)
        {
            if (i % j == 0)
            {
                cnt++;
            }
        }
        if (cnt == 8)
        {
            ans++;
        }
    }

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


Measured memory_bytes: 3584
#include <cstdio>
int main(){
	int x, y, sum;
	scanf("%d%d", &x, &y);
	int a[x][y];
	for(int i = 0; i < x; i++){
		sum = 0;
		for(int j = 0; j < y; j++){
			scanf("%d", &a[i][j]);
			printf("%d ", a[i][j]);
			sum += a[i][j];
		}
		printf("%d\n", sum);
	}
	int all = 0;
	for(int i = 0; i < y; i++){
		sum = 0;
		for(int j = 0; j < x; j++){
			sum += a[j][i];
		}
		printf("%d ", sum);
		all += sum;
	}
	printf("%d\n", all);
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin>>N;
	int cur = 0,a;
	for(int i = 0;i < N;i++) {
		cin>>a;
		cur ^= a&1;
	}
	cout<<(cur?"NO":"YES")<<'\n';
	return 0;
}
/**/


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();


  string s;
  cin>>s;
  stack<char>st;
  int cnt = 0;
  for(int i  =0;i<s.length();i++)
  {
    if(!st.empty() && st.top()!=s[i])
      st.pop(),cnt++;
    else
      st.push(s[i]);
  }
  cout<<2*cnt;

  return 0;
}

Measured memory_bytes: 512
N = int(input())

F = []

for _ in range(N):
    f = list(input().strip().split())
    F.append(int("".join(f), 2))


P = [list(map(int, input().split())) for _ in range(N)]

ans = -float('inf')

for i in range(1, 2**10):
    candi = 0
    for n in range(N):
        tmp = i & F[n]
        p = format(tmp, 'b').count("1")
        candi += P[n][p]
    if candi == 0:
        foo = 1
    ans = max(ans, candi)

print(ans)


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

using namespace std;

int getL(int n){
	int len = 0;
	while(n!=0){
		len++;
		n /= 10;
	}
	return len;
}

int p(int n){
	int rs = 1;
	for(int i=1;i<=n;i++){
		rs *= 10;
	}
	return rs;
}

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    int len = getL(n);
    for(int i=1;i<=len;i+=2){
    	for(int j=p(i-1);j<p(i)&&j<=n;j++){
    		ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define X first
#define Y second
#define P first
#define C second

using namespace std; 

typedef pair<int, int> pii;
typedef pair<pii, int> mouse;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main(void){
    int w, h, n, res = 0; cin >> h >> w >> n;
    vs m(h);
    rep(y, h) cin >> m[y];
    pii s;
    rep(y, h) rep(x, w) if(m[y][x] == 'S') s = mp(x, y);

    rep(i, n){
        queue<mouse> q;
        q.push(mp(s, 0));

        vector< vector<bool> > used(h);
        rep(y, h) used[y].resize(w);

        while(!q.empty()){
            mouse cur = q.front();
            q.pop();

            if(used[cur.P.Y][cur.P.X]) continue;
            used[cur.P.Y][cur.P.X] = true;

            if(m[cur.P.Y][cur.P.X] == i + 1 + '0'){
                res += cur.C;
                s = mp(cur.P.X, cur.P.Y);
                break;
            }

            rep(i, 4){
                mouse next = mp(mp(cur.P.X + dx[i], cur.P.Y + dy[i]), cur.C + 1);
                if(0 <= next.P.X && next.P.X < w &&
                   0 <= next.P.Y && next.P.Y < h &&
                   m[next.P.Y][next.P.X] != 'X') q.push(next);
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2424