akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int allSum, ans;
int n, m, a[12];
string s;
vector<int> pos;

int getCost(int idx, int digit){
  if((n - idx) % 2 == 0){
    digit *= 2;
  }
  if(digit >= 10){
    digit = digit / 10 + digit % 10;
  }

  return digit;
}

void solve(int idx, int sum){
  if(idx == pos.size()){
    if((allSum + sum) % 10 == 0){
      ans++;
    }
    return;
  }

  for(int i = 0; i < m; i++){
    solve(idx + 1, sum + getCost(pos[idx], a[i]));
  }
}

int main(){
  while(cin >> n){
    cin >> s;
    cin >> m;
    for(int i = 0; i < m; i++){
      cin >> a[i];
    }

    allSum = 0;
    pos.clear();

    for(int i = 0; i < n; i++){
      if(s[i] == '*'){
	pos.push_back(i);
      }
      else{
	allSum += getCost(i, s[i] - '0');
      }
    }

    ans = 0;
    solve(0, 0);
    cout << ans << endl;
  }

}

Measured memory_bytes: 1356
//	Author : amnptl 
//	   Godbless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NeedForSpeed() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD (1000000007); // 1e9+7
int main()
{
	NeedForSpeed();
	int n; cin>>n; map<string,int> m;
	for(int i=0; i<n; i++)
	{
		string s; cin>>s;
		m[s]++;
	}		
	int ans = m.size();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19228
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())
    q = S[0]
    ret = 0
    for s in S:
        if q != s:
            ret += 1
            q = s
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    int a=1;
    cin>>N>>K;
    for(int i=0;i<N;i++){
        if(a<K){
            a*=2;
        }
        else a+=K;
    }
    cout<<a<<endl;
}

Measured memory_bytes: 256
N=int(input())
para = [int(input()) for i in range(N)]
para.sort(reverse=True)


def gcd(a,b):
    if b == 0 : 
        return a  
    return gcd(b,a%b)

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

for i in range(N-1,-1,-1):
    if i == N-1:
        p = lcm(para[i-1],para[i])
    else :
        a = max(para[i],p)
        b = min(para[i],p)
        p = lcm(a,b)
print(p)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    ll n;
    cin >> n;
    long double ans = 0;
    for (ll i=0;i<n;i++){
        long double tmp;
        cin >> tmp;
        ans += 1 / tmp;
    }
    cout << setprecision(20) << 1/ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>

typedef long long ll;


#define V vector


#include <math.h>


typedef long long ll;
using namespace std;
class NT
{
public:
	
	~NT();
	static ll toN(ll x, ll n, ll mod);
	
	
};


class Solution {
public:
	ll MD = 998244353;
	ll C(int n, int k) {
		ll up = F[n];
		ll down = (F[k] * F[n - k]) % MD;
		return (up * NT::toN(down, MD - 2, MD)) % MD;
	}
	V<ll> F;
    void solve(int num, std::istream& in, std::ostream& out) {
		int n, m, k; in >> n >> m >> k;
		F.resize(5 * n + 1);
		F[0] = 1; for (int i = 1; i < F.size(); i++) F[i] = (i * F[i - 1]) % MD;

		if (m == 1) {
			if (k == n - 1) out << 1;
			else out << 0;
			return;
		}
		ll rez = 0;
		ll t = 1;
		for (int i = 1; i <= n; i++) {
			int rs = n - i;
			if (rs <= k) {
				rez = (rez + ((C(rs + i - 1, rs) * t) % MD) ) % MD;
			}
			t = (t * (m - 1)) % MD;
		}

		rez = (rez * m) % MD;

		out << rez;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
	//int T; in >> T;
	//for(int i = 0;i < T;i++)
		//solution.solve(i+1, in, out);
	solution.solve(0, in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}


NT::~NT()
{
}

ll NT::toN(ll x, ll n, ll mod) {
	ll rez = 1;
	ll tmp = x;
	while (n) {
		if (n & 1) rez = (rez * tmp) % mod;
		tmp = (tmp * tmp) % mod;
		n >>= 1;
	}
	return rez;
}




Measured memory_bytes: 10672
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_6_A-in9.txt"));

		int q = scan.nextInt();

		for (int i = 0; i < q; i++) {
			String s1 = scan.next();
			String s2 = scan.next();
			for (int x = 0; x < save.length; x++)
				for (int y = 0; y < save[0].length; y++)
					save[x][y] = -1;
			System.out.println(Msubs(s1, s2, 0, 0));
		}

		scan.close();
		System.exit(0);
	}

	static int[][] save = new int[1000][1000];

	private static int Msubs(String s1, String s2, int p1, int p2) {
		if (p1 == s1.length() || p2 == s2.length())
			return 0;
		if (save[p1][p2] == -1) {
			if (s1.charAt(p1) == s2.charAt(p2))
				save[p1][p2] = 1 + Msubs(s1, s2, p1 + 1, p2 + 1);
			else
				save[p1][p2] = Math.max(Msubs(s1, s2, p1 + 1, p2), Msubs(s1, s2, p1, p2 + 1));
		}
		return save[p1][p2];
	}
}

Measured memory_bytes: 33072
S = list(input())
cnt = 0

if len(S)%2 == 0:
    for i in range(len(S)//2):
        if S[i] != S[-i-1]:
            cnt += 1
else:
    for i in range(len(S)//2):
        if S[i] != S[-i-1]:
            cnt += 1
print(cnt)

Measured memory_bytes: 38256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <optional>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int h, w;
    cin >> h >> w;

    map<int, int> opt; // 最適なペアを管理
    multiset<int> mul; // 値を管理

    rep(x, w)
    {
        opt[x] = x;
        mul.insert(0);
    }

    rep(y, h)
    {
        int l, r;
        cin >> l >> r;
        --l;

        auto it1 = opt.lower_bound(l);
        auto it2 = opt.lower_bound(r);
        for (auto it = it1; it != it2; ++it)
        {
            mul.erase(mul.find(it->first - it->second));
        }
        if (it1 != it2 and r < w and (it2 == opt.end() or r < it2->first))
        {
            auto [b, a] = *prev(it2);
            opt.erase(it1, it2);
            opt[r] = a;
            mul.insert(r - a);
        }
        else
        {
            opt.erase(it1, it2);
        }

        cout << (mul.empty() ? -1 : *mul.begin() + y + 1) << '\n';
    }

    return 0;
}


Measured memory_bytes: 22288
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
from queue import Queue

H, W = map(int, input().split())

A = [list(input()) for _ in range(H)]


def solve():
    q = Queue()
    q.put((0, 0, 1))
    A[0][0] = "#"

    dx = [0, -1, 0, 1]
    dy = [-1, 0, 1, 0]
    while not q.empty():
        cx, cy, cnt = q.get()

        if cx == W - 1 and cy == H -1:
            return cnt

        for xx, yy in zip(dx, dy):
            nx, ny = cx + xx, cy + yy
            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue
            if A[ny][nx] == "#":
                continue
            A[ny][nx] = "#"
            q.put((nx, ny, cnt + 1))
        pass

    return -1

sh = 0
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            sh += 1

d = solve()
print(H * W - d - sh if d >= 0 else -1)

Measured memory_bytes: 9952
n = int(input())
p = list(int(i) for i in input().split()) 
q = sorted(p)
#print(q)
cnt = 0
for x in range(n):
    #print(p[x], q[x])
    if(p[x] != q[x]):
        cnt += 1
    if(cnt>2):
        print("NO")
        exit()

print("YES")
#print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 50;
int main()
{
    std::ios::sync_with_stdio(false);
    ll a;
    long double b;
    cin >> a >> b;
    ll ans = ((b * 1000) * a) / 1000;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>

int main(void)
{
	char s[12];
	int a,b,i;
	scanf("%d%d%s",&a,&b,s);
	for(i=0;i<=a+b;i++){
		if(i==a){
			if(s[i]!='-'){
				puts("No");
				return 0;
			}
		}
		else if('0'>s[i]||s[i]>'9'){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] xi = new int[n];
        int[] yi = new int[n];
        int[] hi = new int[n];
 
        for(int i = 0; i < n; i++) {
            xi[i] = scanner.nextInt();
            yi[i] = scanner.nextInt();
            hi[i] = scanner.nextInt();
        }

        int xt = 0, yt = 0, ht = 0;
        for(int i = 0; i < n; i++) {
            if(hi[i] > 0) {
                xt = xi[i];
                yt = yi[i];
                ht = hi[i];
                break;
            }
        }
 
        for(int cx = 0; cx <= 100; cx++) {
            for(int cy = 0; cy <= 100; cy++) {
                int H = ht + Math.abs(xt - cx) + Math.abs(yt - cy);
                boolean check = true;
                for(int i = 0; i < n; i++) {
                    if(hi[i] != Math.max(0, H - Math.abs(xi[i] - cx) - Math.abs(yi[i] - cy))) {
                        check = false;
                        break;
                    }
                }
                if(check) {
                    System.out.println(cx + " " + cy + " " + H);
                    return;
                }
            }
        }
    }
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if (D2 == 1) {
        print("1");
    } else {
        print("0");
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>                                                                  
#include <vector>                                                                    
#include <array>                                                                     
#include <set>                                                                       
#include <cmath>                                                                     
#include <string>                                                                    
#include <queue>                                                                     
#include <list>                                                                      
#include <unordered_map>                                                             
#include <algorithm>                                                                 
#include <functional>                                                                
#include <iomanip> // std::std::setprecision(X)                                      
#include <limits>  //std::numeric_limits<int>::max(), min()                          
                                                                                     
int main (void) {                                                                    
  long long N; std::cin >> N;                                                        
                                                                                     
  int k = std::floor(std::sqrt(N));                                                  
  std::cout << k*k << std::endl;                                                     
                                                                                     
  return 0;                                                                          
}                                                                                    

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pf printf
#define sc scanf
#define endl "\n"
#define dbug(x) cout << #x << ": " << x << endl
#define gi(k) scanf("%d",&k)
#define gl(k) scanf("%lld",&k) 
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define rep(i,n) for(int i = 1; i <= n; i++)
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,cur) N=(N|(1LL<<cur))
#define Reset(N,cur) N=(N&(~(1LL<<cur)))
#define Check(N,cur) (!((N&(1LL<<cur))==0))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define NMAX 2147483647
#define LMAX 9223372036854775807LL
#define mem CLR
 
using namespace std;
 
 
#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
 
inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

 
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;
 
 
int t,n,mid,pid; 
std::vector<pii> v;
vlong ar[1000],mminus,pplus;
 
int main () {
 	
 	#ifdef forthright48
    freopen ( "00_input.txt", "r", stdin ); //freopen ( "00_output.txt", "w", stdout );
 	#endif

 	gi(n);

 	pplus = -1e9;
 	mminus = 1e9;

 	rep(i,n) {
 		gl(ar[i]);

 		if(mminus > ar[i]) {
 			mminus = ar[i];
 			mid = i;
 		}

 		if(pplus < ar[i]) {
 			pplus = ar[i];
 			pid = i;
 		}
 	}


 	if(pplus + mminus >= 0) {
 		FOR(i,2,n) {
 			while(ar[i] < ar[i-1]) {
 				ar[i] += pplus;
 				v.pb(MP(pid,i));

 				if(ar[i] > pplus) {
 					pplus = ar[i];
 					pid = i;
 				}
 			}
 		}
 	}


 	else {
 		for(int i = n-1; i >= 1; i--) {
 			while(ar[i] > ar[i+1]) {
 				ar[i] += mminus;
 				v.pb(MP(mid,i));

 				if(ar[i] < mminus) {
 					mminus = ar[i];
 					mid = i;
 				}
 			}
 		}
 	}

 	cout << SZ(v) << endl;

 	FOR(i,0,SZ(v)-1) {
 		pf("%d %d\n",v[i].ff,v[i].ss);
 	}
 
 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int alice,bob;
  char str[8];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d",&alice,&bob);
  if (alice == bob)
  {
    printf("Draw\n");
  }
  else
  {
    if(alice == 1)
    {
      printf("Alice\n");
    }
    else
    {
      if(bob == 1)
      {
        printf("Bob\n");
      }
      else
      {
        if ((alice - bob) > 0)
        {
          printf("Alice\n");
        }
        else
        {
          printf("Bob\n");
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
#include<atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, q = 0, ch = 0, p = 0, l = 0, r = 0; lli x = 0ll;
	cin >> n >> q;
	fenwick_tree<lli> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> x; v.add(i, x);
	}
	for (int i = 0; i < q; ++i)
	{
		cin >> ch;
		if (ch == 0)
		{
			cin >> p >> x; v.add(p, x);
		}
		else
		{
			cin >> l >> r; cout << v.sum(l, r) << "\n";
		}
	}
}

Measured memory_bytes: 8256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      double[][] point = new double[4][2];
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
          point[i][j] = sc.nextDouble();
        }
      }
      double[] vecAB = {point[1][0]-point[0][0],point[1][1]-point[0][1]};
      double[] vecCD = {point[3][0]-point[2][0],point[3][1]-point[2][1]};
      if(vecAB[0]*vecCD[0]+vecAB[1]*vecCD[1] == 0) {
        System.out.println("YES");
      }
      else {
        System.out.println("NO");
      }
    }
  }
}

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

int main(){
    int n, m;          // matrix A: n x m
    cin >> n >> m;

    int A[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> A[i][j];
        }

    }

    int B[m];
    for(int j=0; j<m; j++){
        cin >> B[j];
    }

    // multiply matrix
    for(int i=0; i<n; i++){
        int ansi = 0;
        for(int j=0; j<m; j++){
            int ansj = A[i][j] * B[j];
            ansi += ansj;
        }
        cout << ansi << endl;
    }
}


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

using namespace std;

int main() {
  int N, L;
  cin >> N >>L;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  string ans = "";
  for (int i = 0; i < N; i++) {
    ans += s[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
bs = gets.split.map {|e| e.to_i }

score = 0
if bs[0] > bs[1]
  score += bs[0]
  bs[0] -= 1
else
  score += bs[1]
  bs[1] -= 1
end
if bs[0] > bs[1]
  score += bs[0]
  bs[0] -= 1
else
  score += bs[1]
  bs[1] -= 1
end
puts score


Measured memory_bytes: 1788
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
char q1[200100],q2[200100];
int main()
{
	int n,q;
	cin>>n>>q;
	int l=0,r=n;
	string s;cin>>s;
	rep(i,q) cin>>q1[i]>>q2[i];
	for(int i=q-1;i>=0;i--){
		if(l>=r) break;
		if(s[l]==q1[i] && q2[i]=='L') l++;
		else if(l>0 && s[l-1]==q1[i] && q2[i]=='R') l--;
		if(s[r-1]==q1[i] && q2[i]=='R') r--;
		else if(r<n && s[r]==q1[i] && q2[i]=='L') r++;
	}
	cout<<r-l<<endl;
}


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

import static java.lang.Integer.parseInt;

/**
 * Problem A: It's our delight!!
 */
public class Main {

	static final int Lmin = 660;
	static final int Lmax = 900;
	static final int Dmin = 1080;
	static final int Dmax = 1260;
	static final int Mmin = 1260;
	static final int Mmax = 1560;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int L, D, M, Lsum, Dsum, Msum;
			L = D = M = 0;
			Lsum = Dsum = Msum = 0;

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

				words = br.readLine().split("[: ]");

				int s = parseInt(words[0]) * 60 + parseInt(words[1]);
				int t = parseInt(words[0]) * 60 + parseInt(words[2]);
				if (t < s) {
					t += 60;
				}
				if (s < 120) {
					s += 1440;
					t += 1440;
				}

				if (Lmin <= s && s < Lmax) {
					Lsum++;
					if (s + 8 >= t) L++;
				} else if (Dmin <= s && s < Dmax) {
					Dsum++;
					if (s + 8 >= t) D++;
				} else if (Mmin <= s && s < Mmax) {
					Msum++;
					if (s + 8 >= t) M++;
				}
			}

			System.out.println("lunch " + (Lsum == 0 ? "no guest" : L * 100 / Lsum));
			System.out.println("dinner " + (Dsum == 0 ? "no guest" : D * 100 / Dsum));
			System.out.println("midnight " + (Msum == 0 ? "no guest" : M * 100 / Msum));

		}
	}
}

Measured memory_bytes: 27284
#include <cstdio>
#include <map>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int64;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())

int main() {
	int n, x, y, ans = 0;
	scanf("%d%d", &n, &x);
	vector<int> v;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &y);
		v.pb(y);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; ++i) {
		if (x >= v[i]) {
			ans++;
			x -= v[i];
		}
	}
	if ((x > 0) && (ans == n)) {
		ans--;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int n, m;
vector<vector<int>> d(200005);
vector<bool> memo(200005, 0);
vector<int> num(200005, 0);

void bfs(){
  queue<int> q;
  q.push(0);
  memo[0] = 1;
  while(!(q.empty())){
    int front = q.front();
    rep(i, d[front].size()){
      int next = d[front][i];
      if(memo[next]) continue;
      num[next] = front + 1;
      memo[next] = 1;
      q.push(next);
    }
    q.pop();
  }
  bool f = 1;
  rep(i, n){
    if(!(memo[i])) f = 0;
  }
  if(f){
    puts("Yes");
    rep(i, n - 1){
      cout << num[i + 1] << endl;
    }
  }else{
    puts("No");
  }
  // int k = q.front();
  // q.pop();
  // cout << k << endl;
}

int main(){
  cin >> n >> m;
  rep(i, m){
    int a, b; cin >> a >> b;
    a --; b --;
    d[a].pb(b);
    d[b].pb(a);
  }
  bfs();


  return 0;
}


Measured memory_bytes: 12864
#include <array>
#include <iostream>
#include <utility>
#include <vector>

int N;
const int nmax = 200005;
std::array<int, nmax> ans;
std::vector<int> left, right;
std::array<std::vector<int>, nmax> adjlist;

void dfs(int u, int distance, int parent)
{
    // color[u] = distance % 2;
    if (distance % 2 == 0)
    {
        left.push_back(u);
    }
    else
    {
        right.push_back(u);
    }

    for (auto v : adjlist[u])
    {
        if (v != parent)
        {
            dfs(v, distance + 1, u);
        }
    }
}

int main()
{

    std::cin >> N;
    int a, b;
    for (size_t i = 0; i < N - 1; ++i)
    {
        std::cin >> a >> b;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }

    dfs(1, 0, -1);
    // std::cout << "left: ";
    // for (int i = 0; i < left.size(); ++i)
    //     std::cout << left[i] << " ";
    // std::cout << std::endl;
    // std::cout << "right: ";
    // for (int i = 0; i < right.size(); ++i)
    //     std::cout << right[i] << " ";
    // std::cout << std::endl;

    auto k = N / 3;
    auto num1 = k + (N % 3 == 0 ? 0 : 1);
    auto num2 = k + (N % 3 == 2 ? 1 : 0);
    auto num0 = k;
    //std::cout << "num 0, 1, 2 = " << num0 << ", " << num1 << ", " << num2 << std::endl;

    if (right.size() <= k)
    {
        auto ct0 = 0;
        auto ct1 = 0;
        auto ct2 = 0;
        for (auto u : left)
        {
            int p;
            if (ct1 < num1)
                p = 3 * (ct1++) + 1;
            else if (ct2 < num2)
                p = 3 * (ct2++) + 2;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
        for (auto u : right)
        {
            ans[u] = 3 * (++ct0);
        }
    }
    else if (left.size()  <= k)
    {
        auto ct0 = 0;
        auto ct1 = 0;
        auto ct2 = 0;
        for (auto u : right)
        {
            int p;
            if (ct1 < num1)
                p = 3 * (ct1++) + 1;
            else if (ct2 < num2)
                p = 3 * (ct2++) + 2;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
        for (auto u : left)
        {
            ans[u] = 3 * (++ct0);
        }
    }
    else
    {
        auto ct0 = 0;
        auto ct1 = 0;
        auto ct2 = 0;

        for (auto u : left)
        {
            int p;
            if (ct1 < num1)
                p = 3 * (ct1++) + 1;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
        for (auto u : right)
        {
            int p;
            if (ct2 < num2)
                p = 3 * (ct2++) + 2;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
    }

    for (int i = 1; i <= N - 1; ++i)
    {
        std::cout << ans[i] << " ";
    }
    std::cout << ans[N] << std::endl;
}


Measured memory_bytes: 21748
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		ll x;
		cin >> x;
		ans += (x >= k);
	}
	cout << ans;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n;
    cin>>n;
    vector<long long int> a(n);
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<vector<long long int>> x(n+1);
    vector<vector<long long int>> y(n+1);
    int play=0;
    if(n%2==0)
        play=1;

    x[1]=vector<long long int> (n,0);
    y[1]=vector<long long int> (n,0);

    if(play==0)
    {
        for(i=0;i<n;i++)
            x[1][i]=a[i];
    }
    else
    {
        for(i=0;i<n;i++)
            y[1][i]=a[i];
    }
    
    play=(play+1)%2;
    for(i=2;i<=n;i++)
    {
        x[i]=vector<long long int> (n,0);
        y[i]=vector<long long int> (n,0);
        
        for(j=0;j<=n-i;j++)
        {
            if(play==0)
            {
                long long int diff1=a[j]+x[i-1][j+1]-y[i-1][j+1];
                long long int diff2=a[j+i-1]+x[i-1][j]-y[i-1][j];
                if(diff1>diff2)
                {
                    x[i][j]=a[j]+x[i-1][j+1];
                    y[i][j]=y[i-1][j+1];
                }
                else
                {
                    x[i][j]=a[j+i-1]+x[i-1][j];
                    y[i][j]=y[i-1][j];
                }
                
            }
            else
            {
                long long int diff1=x[i-1][j+1]-y[i-1][j+1]-a[j];
                long long int diff2=x[i-1][j]-y[i-1][j]-a[j+i-1];
                if(diff1<diff2)
                {
                    y[i][j]=y[i-1][j+1]+a[j];
                    x[i][j]=x[i-1][j+1];
                }
                else
                {
                    y[i][j]=y[i-1][j]+a[j+i-1];
                    x[i][j]=x[i-1][j];
                }
                
            }
            
        }

        play=(play+1)%2;

    }
    cout<<(x[n][0]-y[n][0])<<endl;

}

Measured memory_bytes: 141184
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

ll modpow(ll a, ll b){
  if(b == 0) return 1;
  if(b % 2){
    return a * modpow(a, b - 1) % MOD;
  }else{
    ll half = b / 2;
    half = modpow(a, half);
    return half * half % MOD;
  }
}

ll modfact(ll n){
  ll res = 1;
  rep(i, n) res = res * (i + 1) % MOD;
  return res;
}

ll modcomb(ll n, ll r){
  ll res = 1;
  rep(i, r) res = res * (n - i) % MOD;
  return res * modpow(modfact(r), MOD - 2) % MOD;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;
  ll ans = 1;
  rep(n, 2, 100000){
    if(M == 1) break;
    int num = 0;
    while(M % n == 0){
      M /= n;
      num++;
    }
    if(num){
      ans *= modcomb(num + N - 1, N - 1);
      ans %= MOD;
    }
  }
  if(M != 1){
    ans *= modcomb(N, N - 1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = INT_MAX/3;

int dp[31][1<<16];

int main()
{
    cin.tie(0);ios::sync_with_stdio(false);
    int n,c;
    while(cin >>n >>c,n)
    {
        vector<int> a(n),b(c);
        rep(i,n)rep(j,16)
        {
            int x;
            cin >>x;
            a[i] |= x<<j;
        }
        rep(i,c)rep(j,16)
        {
            int x;
            cin >>x;
            b[i] |= x<<j;
        }

        fill(dp[0],dp[31],-INF);
        dp[0][0]=0;

        rep(i,n)rep(mask,1<<16)
        {
            rep(j,c)
            {
                int mm = mask|a[i];
                int get = mm&b[j];
                int nmask = mm^get;
                dp[i+1][nmask] = max(dp[i+1][nmask], dp[i][mask]+__builtin_popcount(get));
            }
        }

        int ans = 0;
        rep(mask,1<<16) ans = max(ans,dp[n][mask]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 11152
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    int ans = 0;
    while (N > 0) {
        if (N % 10 == 2) {
            ans++;
        }
        N /= 10;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

int dx8[8] = { -1,-1,-1, 0, 1, 1, 1, 0 };
int dy8[8] = { -1, 0, 1, 1, 1, 0,-1,-1 };

vector<vector<int>>as;
int w,h;

void check(int y, int x) {
    for (int i = 0; i < 8; ++i) {
        int nx = x + dx8[i];
        int ny = y + dy8[i];
        if (as[ny][nx]) {
            as[ny][nx] = 0;
            check(ny, nx);
        }
    }
}

int main() {
    while (1) {
        cin >> w >> h;
        if (!w)break;
        vector<vector<int>>as2(h+2);
        as = as2;
        for (int i = 0; i <= h+1; ++i) {
            as[i].emplace_back(0);
            if (i != 0 && i != h + 1) {
                for (int j = 0; j < w; ++j) {
                    int c; cin >> c;
                    as[i ].emplace_back(c);
                }
            }
            else {
                for (int j = 0; j < w; ++j) {
                    as[i].emplace_back(0);
                }
            }
            
            as[i].emplace_back(0);
        }
        int ans = 0;
        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                if (as[i][j]) {
                    ans++;
                    check(i, j);
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3236
(() => {

    var lines = [];

    require('readline').createInterface({
        input: process.stdin,
    }).on('line', (line) => {
        lines.push(parseInt(line, 10));
    });

    process.stdin.on("end", function(){
        console.log(lines.filter(isPrime).length);
    });

    const isPrime = function(x){
        if(x == 2){
            return true;
        }

        if(x < 2 || (x & 0x01) === 0){
            return false;
        }

        const sqrt_x = Math.sqrt(x);
        for(let i = 3; i <= sqrt_x; i+=2){
            if(x % i === 0){
                return false;
            }
        }
        return true;
    }


})();


Measured memory_bytes: 19468
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 重さの検索
    def weighting(self, x):
        self.find(x)
        return self.weight[x]

    # 併合
    def union(self, x, y, w):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] < self.rank[py]:
                self.par[px] = py
                self.weight[px] = w - self.weight[x] + self.weight[y]
            else:
                self.par[py] = px
                self.weight[py] = -w - self.weight[y] + self.weight[x]
                if self.rank[px] == self.rank[py]:
                    self.rank[px] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 各頂点間の絶対距離
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

N, M = 1, 1

while True:
    N, M = map(int, input().split())
    if (N == 0) & (M == 0):
        quit()
    info = [list(input().split()) for i in range(M)]
    wuf = WeightedUnionFind(N)
    for i in range(M):
        if info[i][0] == "!":
            wuf.union(int(info[i][1]), int(info[i][2]), int(info[i][3]))
            #print("parent:", wuf.par)
            #print("weight:", wuf.weight)
            #print("rank:", wuf.rank, "\n")
        else:
            if wuf.same(int(info[i][1]), int(info[i][2])):
                print(wuf.diff(int(info[i][1]), int(info[i][2])))
                #print("parent:", wuf.par)
                #print("weight:", wuf.weight)
                #print("rank:", wuf.rank, "\n")
            else:
                print("UNKNOWN")
                #print("parent:", wuf.par)
                #print("weight:", wuf.weight)
                #print("rank:", wuf.rank, "\n")





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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int swap=0;
		
		if(a>b) {
			swap=a;
			a=b;
			b=swap;
		}
		if(a>c) {
			swap=a;
			a=c;
			c=swap;
		}
		if(b>c) {
			swap=c;
			c=b;
			b=swap;
		}
		
		System.out.printf("%d %d %d%n",a,b,c);
	}

}


Measured memory_bytes: 26332
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll H,W;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> H >> W;
}

int solve(){
    ll ans=0;
    if(H==1 || W==1) {ans=1; cout << ans << endl; return 0;}
    ans=(H/2)*W;
    if(H%2==1) ans+=(W+1)/2;
    cout << ans << endl;

    return 0;
}   

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
static const double pi = 3.141592653589793;
typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-6;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

D dot(P a, P b) {
  return (conj(a)*b).X;
}
D cross(P a, P b) {
  return (conj(a)*b).Y;
}
P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}
P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;  // same line
  if (EQ(d2, 0)) return P(0,0);   // 交点がない
  return a1 + d1/d2 * (a2-a1);
}
namespace std {
  bool operator<(const P a, const P b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}
int W, H, N;
int main() {
	/*
	ifstream in("Ain.txt");
	cin.rdbuf(in.rdbuf());
	ofstream ofs("Aout.txt");
	cout.rdbuf(ofs.rdbuf());
	*/
	cout << setprecision(10); 
	while(cin >> W >> H >> N, N) {
		vector<P> points;
		P pwh = P(W, H);
		P pw = P(W, 0);
		D x,y;
		vector<P> pointsr1 = {pwh, pw};
		rep(n, 2 * N) {
			cin >> x >> y;
			points.push_back(P(x,y));
		}
		rep(n, 2 * N) {
			rep(m, n) {
				P pr = crosspointLL(points[n], points[m], pwh, pw);
				pr = P(W, pr.Y);
				if (pr.Y > 0 and pr.Y < H) {
					pointsr1.push_back(pr);
				}
			}
			P pr2 = crosspointLL(points[n], P(0,0), pwh, pw);
				pr2 = P(W, pr2.Y);
				if (pr2.Y > 0 and pr2.Y < H) {
					pointsr1.push_back(pr2);
				}
			P pr3 = crosspointLL(points[n], P(0,H), pwh, pw);
				pr3 = P(W, pr3.Y);
				if (pr3.Y > 0 and pr3.Y < H) {
					pointsr1.push_back(pr3);
				}
		}
		sort(pointsr1.begin(),pointsr1.end());
		vector<P> pointsr2;
		rep(i, pointsr1.size()) {
			if (i == 0) {
				pointsr2.push_back(pointsr1[i]);
			} else if (pointsr1[i] != pointsr1[i - 1]) {
				pointsr2.push_back(pointsr1[i]);
			}
		}
		double sum = 0.0;
		//for(auto i : pointsr2) cout << i << endl;
		for(int i = 0;i + 1 < pointsr2.size();i++){
			vector<pair<D,P>> points2;
			P pr1 = (pointsr2[i] + pointsr2[i + 1]) / P(2,0);
			pr1 = P(W, pr1.Y);
			D dy = pointsr2[i + 1].Y - pointsr2[i].Y;
			rep(j, points.size()) {
				P p1 = points[j];
				D ar = arg(p1 - pr1);
				if (ar < 0) {
					ar += 2 * pi;
				}
				points2.push_back(make_pair(ar, p1));
			}
			sort(points2.begin(), points2.end());
			P pb = points2[N].second;
			P pt = points2[N - 1].second;
			D lt, lb;
			if (EQ(pt.X , (double)W)) lt = H;
			else lt = min(crosspointLL(P(0,0), P(0,H), pr1 , pt).Y, (double)H);
			if (EQ(pb.X,(double)W)) lb = 0;
			else lb = max(crosspointLL(P(0,0),P(0,H), pr1 , pb).Y, 0.0);
			sum += max(0.0, (lt - lb) * dy);
		}
		sum = sum / H / H;
		cout << sum << endl;
	}
}
			
			


Measured memory_bytes: 3860
#include <iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;

	if (b * 2 >= a) 
	{
		std::cout << 0 << std::endl;
	}
	else 
	{
		std::cout << a - (b * 2) << std::endl;
	}
}


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

using namespace std;

#define pb            push_back
#define mp            make_pair
#define po            pop_back
#define fi            first
#define se            second
#define mxn           100005
#define ll            long long int
#define ldb           long double
#define fr(i,a,b,k)   for(int i=a ; i<b ; i+=k)
#define frr(i,a,b,k)  for(int i=a ; i>b ; i-=k)
#define all(v)        v.begin(),v.end()
#define endl          "\n"
#define deg(x)        cout<<endl<<#x<<" = "<<(x)<<endl;
#define casep(x)      cout<<"Case #"<<(x)<<": ";
#define fast          ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

typedef pair<ll,ll> pp;
typedef vector<ll> vi;
typedef vector<pp> vpp;
typedef vector<vi> vvi;

const int inf = INT_MAX;

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b){ return __gcd(a,b);}
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
vector<vector<ll>> adj;
vector<bool> vis;


void solve(ll test){

    ll x,k,d;
    cin >> x >> k >> d;

    x = abs(x);
    if((ll)(x/d) > k){
        cout << x - k*d;
    }
    else{
        k -= (ll)x/d;
        if(k%2 == 0){
            cout << abs(x-((ll)x/d)*d);
        }
        else{
            // deg(x-((ll)x/d)*d);
            cout << abs(x-d-((ll)x/d)*d);
        }
    }

}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
using namespace std;
int n,a[1000000];
int g[100];
int cnt=0;

void shellsort(int j){
    int h=g[j];
    int i;
    for(i=h;i<n;i++){
        int v=a[i];
        int k=i-h;
        while(k>=0&&a[k]>v){
            a[k+h]=a[k];
            cnt=cnt+1;
            k-=h;
        }
        a[k+h]=v;
    }
}

int main()
{
    cin>>n;
    int i,j,k;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    memset(g,0,sizeof(g));
    i=0;
    g[i]=1;
    //??????????????????
    if(n==1)i=1;
    else
        while(g[i]<n){g[i+1]=g[i++]*3+1;}
    cout<<i<<endl;
    for(j=i-1;j>=0;j--){
        cout<<g[j];
        if(j!=0)cout<<" ";
    }
    cout<<endl;
    for(j=i-1;j>=0;j--){
        shellsort(j);
    }
    cout<<cnt<<endl;
    for(k=0;k<n;k++){
        cout<<a[k]<<endl;
    }
    return 0;
}

Measured memory_bytes: 7004