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

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (int i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;

int min (int a,int b){if(a>=b)return b;else return a;}
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
ll nsum(ll n){return (1ll * n * (n + 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}

#define MAX_SIZE 1005
/*void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
			for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
	for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}
        */


//vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};


// Lets start ...




int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        ll n,m;
        cin>>n>>m;
        vector<ll> l(n);
        ll sum=0;
        fi(i,0,n)cin>>l[i],sum+=l[i];
        rsrt(l);
        ll q=0;
        fi(i,0,m){
            if(l[i]*(4*m)<sum)q=1;
        }
        if(q==1)cout<<"No";
        else cout<<"Yes";
        
    }
    
    return 0;
    }

// Done:)








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

const int MAX = 1000005;
const int INF = 1 << 29;

int main(){
    vector<int> dp(MAX, INF), dp_odd(MAX, INF);
    // j を作るための最小数
    dp[0] = dp_odd[0] = 0;
    for(int i = 1; ; i++){
        int t = i * (i + 1) * (i + 2) / 6;
        if(t >= MAX) break;
        for(int j = t; j < MAX; j++){
            dp[j] = min(dp[j], dp[j - t] + 1);
            if(t & 1){
                dp_odd[j] = min(dp_odd[j], dp_odd[j - t] + 1);
            }
        }
    }
    int n;
    while(cin >> n, n){
        cout << dp[n] << " " << dp_odd[n] << endl;
    }
}



Measured memory_bytes: 10500
#include<stdio.h>

#define kk putchar(32)
#define hh putchar(10)

#define Ri(a) int a;scanf("%d",&a)
#define Rl(a) long long a;scanf("%lld",&a)
#define Rf(a) double a;scanf("%lf",&a)

#define Wi(a) printf("%d",a)
#define Wl(a) printf("%lld",a)
#define Wf(a) printf("%.3f",a)

#define mmax(a,b) (a>b?a:b)

int main()
{
    Ri(n);Ri(k);Ri(s);
    for(int i=1;i<=k;++i){
        Wi(s);
        if(i<k)kk;
    }
    if(k<n)kk;
    if(s==1)s+=4;
    for(int i=k+1;i<=n;++i){
        Wi(s-1);
        if(i<n)kk;
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;

int main() {
    string s,t,ans;
    cin >> s >> t;
    ans = t+s;
    cout << ans << el;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	k := getNextInt64(scanner)
	aa := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	nx := make([]int, n)
	m := map[int]int{}
	for i := n - 1; i >= 0; i-- {
		m[aa[i]] = n + i
	}

	for i := n - 1; i >= 0; i-- {
		nx[i] = m[aa[i]]
		for nx[i]+1 < n {
			nx[i] = nx[nx[i]+1]
		}
		m[aa[i]] = i
	}
	rng58 := makeInts(60, n+1)
	for i := n - 1; i >= 0; i-- {
		rng58[0][i] = nx[i] + 1
		if rng58[0][i] >= n {
			rng58[0][i] -= n
		}
	}
	for bit := 1; bit < 60; bit++ {
		for i := 0; i <= n; i++ {
			rng58[bit][i] = rng58[bit-1][rng58[bit-1][i]]
		}
	}

	s := n
	for i := 60 - 1; i >= 0; i-- {
		if k>>uint(i)&1 == 0 {
			continue
		}
		s = rng58[i][s]
	}

	ans := make([]int, n)
	ai := 0
	mm := map[int]int{}
	for i := s; i < n; i++ {
		if _, ok := mm[aa[i]]; ok {
			for ai > 0 {
				ai--
				delete(mm, ans[ai])
				if ans[ai] == aa[i] {
					break
				}
			}
			continue
		}
		ans[ai] = aa[i]
		mm[aa[i]] = 1
		ai++
	}

	for i := 0; i < ai; i++ {
		fmt.Fprintln(writer, ans[i])
	}
	writer.Flush()
}

func makeInts(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 113152
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> hito(N+1,0);
    for(int i=0; i<K; i++){
        int d;
        cin >> d;
        vector<int> A(d);
        for(int j=0; j<d; j++){
            cin >> A.at(j);
            hito.at(A.at(j))++;
        }
    }
    int sum=0;
    for(int i=1; i<=N; i++){
        if(hito.at(i)==0) sum++;
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

struct Rectangle{
  int x0 = 0;
  int y0 = 0;
  int x1 = 0;
  int y1 = 0;
  int area = 0;
};

struct Point{
  int x = 0;
  int y = 0;
  int a = 0;
};

void Area(Rectangle* rect){
  rect->area = (rect->x1 - rect->x0)>0 && (rect->y1 - rect->y0) > 0
    ? (rect->x1 - rect->x0)*(rect->y1 - rect->y0) : 0;
  cout << rect->area << endl;
}

void Paint(Rectangle* rect, Point* p){
  switch(p->a){
  case 1:
    if(rect->x0 >= p->x)
      break;
    else{
      rect->x0 = p->x;
      break;
    }
  case 2:
    if(rect->x1 <= p->x)
      break;
    else{
      rect->x1 = p->x;
      break;
    }
  case 3:
    if(rect->y0 >= p->y)
      break;
    else{
      rect->y0 = p->y;
      break;
    }
  case 4:
    if(rect->y1 <= p->y)
      break;
    else{
      rect->y1 = p->y;
      break;
    }
  }
}

int main()
{
  Rectangle rect;
  int N;
  cin >> rect.x1 >> rect.y1 >> N;

  Point p[N];

  for (int i = 0; i < N; ++i) {
    cin >> p[i].x >> p[i].y >> p[i].a;
  }

  for (int i = 0; i < N; ++i) {
    Paint(&rect, &p[i]);
  }
  Area(&rect);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<array>

using namespace std;

int n,x,m;
int l[10],r[10],s[10];
int ms=-1;
array<int,6> nl,ans;

void rec(int idx){
  if(idx<n){
    for(int i=0;i<=x;i++){
      nl[idx]=i;
      rec(idx+1);
    }
  }else{
    for(int i=0;i<m;i++){
      if(accumulate(begin(nl)+l[i]-1,begin(nl)+r[i],0)!=s[i])return;
    }
    int cs=accumulate(begin(nl),begin(nl)+n,0);
    if(cs>ms){
      ms=cs;
      ans=nl;
    }
  }
}

int main(){
  cin>>n>>x>>m;
  for(int i=0;i<m;i++){
    cin>>l[i]>>r[i]>>s[i];
  }
  rec(0);
  if(ms<0){
    cout<<-1<<endl;
  }else{
    for(int i=0;i<n;i++){
      cout<<ans[i]<<" \n"[i==n-1];
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;


int main()
{
	int n, m;
	cin >> n >> m;
	int min = 1;
	int max = n;
	for (int i = 0; i < m; i++) {
		int l, r;
		cin >> l >> r;
		if (min < l) min = l;
		if (max > r) max = r;
	}
	if (max - min + 1 < 0) {
		cout << 0 << endl;
	}
	else {
		cout << max - min + 1 << endl;
	}
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
for i in range(n):
    a[i]=a[i]-(i+1)
a=sorted(a)
if n%2==1:
    x=a[n//2]
else:
    x=(a[n//2]+a[n//2-1])//2
ans=0
for i in range(n):
    ans+=abs(a[i]-x)
print(ans)

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

using namespace std;

#define ll long long

void solve() {
	int n;
	cin >> n;
	int sum = 0;
	int a, b;
	while(n--) {
		cin >> a >> b;
		sum += b-a+1;
	}
	cout << sum << "\n";
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3580
/* ex3-3
   Sagzar1993  */


#include <stdio.h>

int main(void) {
    //表す整数と基数を定義
    int num;

    //入力を受け取る
    scanf("%d", &num);

    //numが各数字で割り切れ、かつその商が１から９の間であるとき、Yesを表示
    if(num % 1 == 0 && num / 1 <= 9){
        printf("Yes\n");
    }else if(num % 2 == 0 && num / 2 <= 9){
        printf("Yes\n");
    }else if(num % 3 == 0 && num / 3 <= 9){
        printf("Yes\n");
    }else if(num % 4 == 0 && num / 4 <= 9){
        printf("Yes\n");
    }else if(num % 5 == 0 && num / 5 <= 9){
        printf("Yes\n");
    }else if(num % 6 == 0 && num / 6 <= 9){
        printf("Yes\n");
    }else if(num % 7 == 0 && num / 7 <= 9){
        printf("Yes\n");
    }else if(num % 8 == 0 && num / 8 <= 9){
        printf("Yes\n");
    }else if(num % 9 == 0 && num / 9 <= 9){
        printf("Yes\n");
    }else{
        printf("No\n"); //どれにも当てはまらなかった場合はNoを表示
    }
    return 0;
}

Measured memory_bytes: 128
h = int(input())
tem = 1
while h/2 > 1:
    tem+=1
    h = h/2
result = 1
if h==2:
    for i in range(1,tem+1):
        result += 2**i
else:
    for i in range(1,tem):
        result += 2**i
print(result)


Measured memory_bytes: 3064
n1 = int(input())
n2 = list(map(int, input().split()))
if n1 == 1:
    print(0)
else:
    n3 = [n2[i] - n2[i+1] >= 0 for i in range(n1-1)]
    a1 = []
    a2 = 0
    for i in range(len(n3)):
        if n3[i]:
            a2 += 1
            if i == len(n3) - 1:
                a1.append(a2)
        else:
            a1.append(a2)
            a2 = 0
    print(max(a1))

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

typedef long long ll;

ll N, M;
vector<pair<ll, ll>> ab;

int main() {
  cin >> N >> M;
  ab.resize(N);
  int a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }

  
  sort(ab.begin(), ab.end());
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (ab[i].second <= M) {
      ans += ab[i].first * ab[i].second;
      M -= ab[i].second;
    } else {
      ans += ab[i].first * M;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:usize,
        a:[i64;n],
    }
    let ans = if is_pairwise_coprime(&a) {
        "pairwise coprime"
    } else if is_setwise_coprime(&a) {
        "setwise coprime"
    } else {
        "not coprime"
    };
    println!("{}", ans);
}

fn sheave(n: usize) -> Vec<i64> {
    let mut res = vec![0; n + 1];
    for i in 2..=n {
        if res[i] == 0 {
            for j in (1..).take_while(|&j| i * j <= n).map(|j| j * i) {
                if res[j] == 0 {
                    res[j] = i as i64;
                }
            }
        }
    }
    return res;
}

fn pf(mut x: i64, sheave: &Vec<i64>) -> BTreeSet<i64> {
    let mut res = BTreeSet::new();
    while x != 1 {
        let p = sheave[x as usize];
        res.insert(p);
        x /= p;
    }
    return res;
}

fn is_pairwise_coprime(a: &Vec<i64>) -> bool {
    let m = 1000000;
    let sheave = sheave(m);
    let mut used = vec![false; m];
    for &x in a.iter() {
        let pf = pf(x, &sheave);
        for p in pf {
            let p = p as usize;
            if used[p] {
                return false;
            } else {
                used[p] = true;
            }
        }
    }
    true
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn is_setwise_coprime(a: &Vec<i64>) -> bool {
    a.iter().fold(0, |acc, &x| gcd(acc, x)) == 1
}

Measured memory_bytes: 25552
#include <bits/stdc++.h>
#define SIZE 205

using namespace std;

string Input;
bool HaveC;

int main()
{
	cin>>Input;
    for(long long int i=0;i<=Input.length();i++)
    {
    	if(!HaveC&&Input[i]=='C')
    	{
    		HaveC=true;
		}
		if(HaveC&&Input[i]=='F')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;

    for(int i = 1; i <= N; i++){
        int sum = 0;
        int copy = i;
        for(int j = 0; j < 5; j++){
                sum += copy % 10;
                copy = copy / 10;
        }
        if( A <= sum && sum <= B){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

constexpr int max_size()
{
    return static_cast<int>(1e+2);
}

void print(int* a, int n, int i) {
    if (i == n - 1) {
        std::cout << a[i] << std::endl;
        return;
    }

    std::cout << a[i] << " ";
    return print(a, n, i + 1);
}

void print(int* a, int n) {
    print(a, n, 0);
    return;
}

void insert(int* a, int j)
{
    if (j == 0) {
        return;
    }

    if (a[j - 1] < a[j]) {
        return;
    }

    std::swap(a[j - 1], a[j]);
    return insert(a, j - 1);
}

void insertion_sort(int* a, int n, int i)
{
    if (i == n) {
        print(a, n);
        return;
    }

    print(a, n);
    insert(a, i);
    return insertion_sort(a, n, i + 1);
}

void insertion_sort(int* a, int n)
{
    insertion_sort(a, n, 1);
}

std::vector<int>
split(const std::string &s, const char delim) {
    std::vector<int> ret;
    std::string item;
    for (const char ch : s) {
        if (ch == delim) {
            if (!item.empty()) {
                ret.push_back(std::atoi(item.c_str()));
            }
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty()) {
        ret.push_back(std::atoi(item.c_str()));
    }
    return ret;
}

int main()
{
    int n;
    std::cin >> n;
    std::cin.ignore();  //ignore \n

    constexpr int N = max_size();
    std::string buf;
    getline(std::cin, buf);

    std::vector<int> a = split(buf, ' ');
    insertion_sort(&a[0], n);

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i=0;i<n;i++)cin >> d[i];
    sort(d,d+n);
    if(d[n/2-1]==d[n/2]){
        cout << 0 << endl;
        return 0;
    }
    else{
        cout << d[n/2]-d[n/2-1] << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

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

    return false;
}

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MAX_STR = 3000;

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

    vector<vector<int>> dp(MAX_STR + 1, vector<int>(MAX_STR + 1, 0));

    for (int i = 1; i < s.size() + 1; i++)
    {
        for (int j = 1; j < t.size() + 1; j++)
        {
            if (s[i - 1] == t[j - 1])
            {
                chmax(dp[i][j], dp[i - 1][j - 1] + 1);
            }
            else
            {
                chmax(dp[i][j], dp[i - 1][j]);
                chmax(dp[i][j], dp[i][j - 1]);
            }
        }
    }

    string res = "";
    /*
    for (int i = 1; i < s.size() + 1; i++)
    {
        if (dp[i][t.size()] > dp[i - 1][t.size()])
        {
            res += s[i - 1];
        }
    }
    */

    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i - 1][j])
        {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j - 1])
        {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else
        {
            res = s[i - 1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j;             // DP の遷移を遡る
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 38972
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll n;
    cin>>n;
    ll m=n-1;
    ll ans=0;
    for(ll i=2;i*i<=m;i++){
        if(m%i==0){
            if(i!=1) ans++;
            if(m/i!=i) ans++;
        }
    }
    ans++;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll x=n;
            while(x%i==0){
                x/=i;
            }
            if(x%i==1) ans++;
            if(i!=n/i){
                ll x=n;
                ll y=n/i;
                while(x%y==0){
                    x/=y;
                }
                if(x%y==1) ans++;
            }
        }
    }
    ans++;
    if(n!=2) cout<<ans<<endl;
    else cout<<1<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long i64;
inline int rd(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e7+5, P = 998244353;
int n, ans, pw[N]; i64 iv[N]; void fix(int &x) { x<P?0:x-=P; }
int main()
{
    n = rd(); pw[0] = iv[1] = 1, pw[1] = 2, ans = 3; 
    for(int i = 2; i <= n; ++i) ans = ans*3ll%P, iv[i] = P-(P/i)*iv[P%i]%P, fix(pw[i]=pw[i-1]<<1);
    ans = P-ans; for(int i = 0, m = n>>1, v = 1, w = 0; i <= m; ++i) 
        fix(w += (i64)v*pw[m-i]%P), fix(ans += (i64)v*w%P*pw[i+1]%P), v = v*iv[i+1]%P*(m-i)%P;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 120840
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>

using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
 
// constexpr int MOD = 1e9+7;
constexpr int Inf = 1e9;

struct Edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

int main(void){
    Cin(int, n, m, p);
    vc<Edge> e(m);
    For(i, m){
        Cin(int, a, b, c);
        e[i].from = a-1;
        e[i].to = b-1;
        e[i].cost = p-c;
    }
    vc<int> d(n, Inf);
    d[0] = 0;
    
    ll ha = Inf;
    For(i, Inf){
        For(j, m){
            if (d[e[j].to] > d[e[j].from] + e[j].cost){
                d[e[j].to] = d[e[j].from] + e[j].cost;
            }
        }
        if(i == n) ha = -d[n-1];
        if(i == 2*n){
            if(ha >= -d[n-1]){
                Cout(max(0ll, ha));
                return 0;
            }
            else{
                Cout(-1);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	int n, ans = 0, R = 0, L = 0, loc = 0;
	string s[100];
	for (;;) {
		ans = R = L = loc = 0;
		cin >> n;
		if (n == 0) return 0;
		for (int i = 0; i < n; i++) cin >> s[i];
		for (int i = 0; i < n; i++) {
			if (s[i] == "lu") L++;
			else if (s[i] == "ld") L--;
			else if (s[i] == "ru") R++;
			else if (s[i] == "rd") R--;
			if (L == R&&L != loc) {
				ans++;
				loc = L;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
# ABC 050: B – Contest with Drinks Easy
n = int(input())
t = [int(s) for s in input().split()]
m = int(input())

p = []
x = []

for i in range(m):
    tmp = [int(s) for s in input().split()]
    p.append(tmp[0] - 1)
    x.append(tmp[1])

for i in range(m):
    t2 = t[:]
    t2[p[i]] = x[i]
    print(sum(t2))

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

#define printLn(X) cout << X << endl
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(){
	set<int> st;
	int N;
	cin >> N;
	rep(i, N){
		int x;
		cin >> x;
		st.insert(x);
	}
	printLn(st.size());
	return 0;
}


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

int main()
{
    long long N;
    cin >> N;
    map<string, long long> A;
    while(N--)
    {
        string S;
        cin >> S;
        sort(S.begin(), S.end());
        A[S]++;
    }
    long long ans = 0;
    for(auto it : A)
    {
        long long n = it.second;
        if(n > 1)
            ans = ans + (n*(n-1))/2;
    }
    cout << ans << "\n";
}

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

int main() {
  
  int N=0;
  
  cin >> N;
  
  int quo = N / 2;
  double a = N - quo;
  double ans = a / N;
  
  if(N == 1) {
    
    cout << "1.0" << endl;
    
  } else if(N % 2 == 0) {
    
    cout << "0.5000000000" << endl;
    
  } else if(N % 2 != 0) {
    
    cout << ans << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll gcd(ll a,ll b){
  if(!b) return a;
  return gcd(b,a%b);
}
int main(){
    ll a,b;
    cin>>a>>b;
    ll c=gcd(a,b);
    set<int> A;
    for(int i=2;i<=sqrt(c);i++){
        while(c%i==0) A.insert(i),c=c/i;
    }
    if(c==1) cout<<A.size()+1;
    else cout<<A.size()+2;
}

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

void solve() {
    int S, W; cin >> S >> W;
    if (S <= W) puts("unsafe");
    else puts("safe");
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3644
use std::collections::HashMap;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    // [i32]
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

fn solve() {
    input! {
        n: u32,
        m: usize,
        keys: [(usize,[usize]);m]
    }

    let fullMask = (1 << n) - 1;

    let mut dp = vec![vec![std::usize::MAX; fullMask + 1]; m]; // 最小価格
    let mut masks = vec![0; m];
    for i in 0..m {
        let mut mask = 0;
        for j in 0..keys[i].1.len() {
            mask += 1 << (keys[i].1[j] - 1);
        }
        masks[i] = mask;

        dp[i][0] = 0;
    }

    for i in 0..(m - 1) {
        for j in 0..fullMask {
            if dp[i][j] == std::usize::MAX {
                continue;
            }
            dp[i + 1][j] = std::cmp::min(dp[i][j], dp[i + 1][j]);
            dp[i][j | masks[i]] = std::cmp::min(dp[i][j] + keys[i].0, dp[i][j | masks[i]]);
        }
    }

    let mut ans = std::usize::MAX;
    for i in 0..m {
        ans = std::cmp::min(ans, dp[i][fullMask]);
    }

    if ans == std::usize::MAX {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 45436
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

#define mid ((tl+tr)>>1)
const int maxn = 2e5+5;
vector<int>g[maxn],a(maxn),old(maxn),ans(maxn),t(maxn<<2),all;
int n;
void update(int rt,int tl,int tr,int pos,int new_val){
	if( tl == tr ){ t[rt] = new_val; return; }
	if( pos <= mid ) update(rt<<1,tl,mid,pos,new_val);
	else update(rt<<1|1,mid+1,tr,pos,new_val);
	t[rt]=max(t[rt<<1],t[rt<<1|1]);
}
int query(int rt,int tl,int tr,int l,int r){
	if( !l || !r || l > r ) return 0;
	if( tl == l && tr == r) return t[rt];
	return max( query(rt<<1,tl,mid,l,min(r,mid)) , query(rt<<1|1,mid+1,tr,max(mid+1,l),r) );
}

void dfs(int u,int p){
	old[u] = query(1,1,n,a[u],a[u]);
	update(1,1,n,a[u],query(1,1,n,1,a[u]-1)+1);
	ans[u] = query(1,1,n,1,n);
	//bug4(u,a[u],old[u],ans[u]);
	for(auto v:g[u]){
		if( v != p ){
			dfs(v,u);
		}
	}
	update(1,1,n,a[u],old[u]);
}
int32_t main(){
	IOS
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		all.push_back(a[i]);
	}
	for(int i=1;i<n;i++){
		int u,v;cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	sort(all.begin(),all.end());
	all.erase(unique(all.begin(),all.end()),all.end());
	for(int i=1;i<=n;i++){
		a[i] = lower_bound(all.begin(),all.end(),a[i]) - all.begin() + 1;
		//bug2(i,a[i]);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		cout << ans[i] <<" ";
	}
	cout<<endl;
	
	
}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

// 小数点以下桁数
// fixed << setprecision(i)

int gcd(int a,int b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応


int main()
{
  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	int n,m,a[55],b[55],t[55]={},i;

	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(i=0;i<m;i++){
		t[a[i]-1]++;
		t[b[i]-1]++;
	}
	for(i=0;i<n;i++)
		printf("%d\n",t[i]);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  llt x,y,tmp,ans = 0;
    cin >> x >> y;
    tmp = x;
    while(tmp <= y){
        tmp *= 2;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a[4],b[4],sum_a,sum_b;

cin>>a[0]>>a[1]>>a[2]>>a[3];
cin>>b[0]>>b[1]>>b[2]>>b[3];
sum_a=a[0]+a[1]+a[2]+a[3];
sum_b=b[0]+b[1]+b[2]+b[3];

if(sum_a>=sum_b){
cout<<sum_a<<endl;
}else{
cout<<sum_b<<endl;
}

return 0;
}

Measured memory_bytes: 1164
import java.io.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc, PrintWriter out) {
        long ai = sc.nextInt();
        long ao = sc.nextInt();
        long at = sc.nextInt();
        long aj = sc.nextInt();
        long al = sc.nextInt();
        long as = sc.nextInt();
        long az = sc.nextInt();

        long size = 0;

        size = (ai / 2 + aj / 2 + al / 2) * 2 + ao;
        if (ai > 0 && aj > 0 && al > 0) {
            size = Math.max(size, 3 + ((ai - 1) / 2 + (aj - 1) / 2 + (al - 1) / 2) * 2 + ao);
        }

        out.println(size);
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

Measured memory_bytes: 3620
from math import factorial as fac
from math import sqrt
from collections import deque
N = int(input())
X = []
for i in range(N):
    x,y = map(int,input().split())
    X.append((x,y))
ans = 0
Q = deque()
for i in range(N):
    Q.append((0,[i],X[i][0],X[i][1]))
while Q:
    S,L,x,y = Q.pop()
    if len(L)==N:
        ans += S
        continue
    for i in range(N):
        if not(i in L):
            h,w = X[i]
            Q.append((S+sqrt(pow(x-h,2)+pow(y-w,2)),L+[i],h,w))
print(ans/fac(N))

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    // 75 = 3 * 5 * 5でその約数は6個 -> 1*75, 3*25, 5*15
    // N!の約数のうち七五数はいくつあるかな
    // 100!までで,各素因数はいくつ出てくるかな
    int soinsuu[101][101]; //soinsuu[i][j]: i!の約数で素因数iはいくつあるか
    rep(i, 101) rep(j, 101) soinsuu[i][j] = 0;
    soinsuu[1][1] = 1;
    for(int i = 2; i <= 100; i++){
        int val = i;
        int divide = 2;
        int cnt = 0;
        while(val > 1){
            if(val % divide == 0){
                cnt++;
                val /= divide;
            }
            else{
                for(int j = i; j <= 100; j++){
                    soinsuu[j][divide] += cnt;
                }
                cnt = 0;
                divide++;
            }
        }
        if(cnt > 0){
            for(int j = i; j <= 100; j++){
                soinsuu[j][divide] += cnt;
            }
        }
    }
    /*
    for(int i = 1; i <= 100; i++){
        for(int j = 1; j <= 11; j++){
            printf("%3d", soinsuu[i][j]);
        }
        printf("\n");
    }
    */

    int N; cin >> N;
    //75 -> (1, 75), (3, 25), (5, 15), (3, 5, 5)
    //soinsuu[N][2]-soinsuu[N][N]で
    //2^74は約数?
    int ans;
    if(soinsuu[N][2] >= 74) ans = 1;
    else ans = 0;

    int over_24 = 0, over_2 = 0;
    for(int i = 2; i <= N; i++){
        if(soinsuu[N][i] >= 24){
            over_24++;
        }
        if(soinsuu[N][i] >= 2){
            over_2++;
        }
    }
    ans += over_24*(over_2-1);

    int over_14 = 0, over_4 = 0;
    for(int i = 2; i <= N; i++){
        if(soinsuu[N][i] >= 14){
            over_14++;
        }
        if(soinsuu[N][i] >= 4){
            over_4++;
        }
    }
    ans += over_14*(over_4-1);

    over_4 = 0; over_2 = 0;
    for(int i = 2; i <= N; i++){
        if(soinsuu[N][i] >= 4){
            over_4++;
        }
        if(soinsuu[N][i] >= 2){
            over_2++;
        }
    }
    ans += (over_4*(over_4-1)/2)*(over_2-2);
    cout << ans << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, arr[51];

bool check() {
    for (int i = 1; i < n; ++i) {
        if (arr[i] < arr[i-1]) {
            return false;
        }
    }
    return true;
}
int main() {
    //freopen("jumping.in", "r", stdin);
    IOS
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            swap(arr[i], arr[j]);
            if (check()) {
                cout << "YES" << endl;
                return 0;
            }
            swap(arr[i], arr[j]);
        }
    }
    cout << (check() ? "YES" : "NO") << endl;
    return 0;


}


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

int main() {
  long n,k;
  cin >> n>>k;
  
  long ans=1;
  rep(i,k){
    ans*=n-i;
  }
  rep(i,k){
    ans/=i+1;
  }
  
  cout<<n-k+1<<endl;  
}



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

int vis[3010][3010];

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

	int w, h;
	while(cin >> w >> h, w) {
		int n;
		cin >> n;
		int x1[1000], y1[1000], x2[1000], y2[1000];
		map<int, int> xm, ym;
		xm[0] = ym[0] = -1;
		xm[w - 1] = -1;
		ym[h - 1] = -1;
		for(int i = 0; i < n; i++) {
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
			x2[i]--, y2[i]--;
			for(int d = -1; d <= 1; d++) {
				if(0 <= x1[i] + d && x1[i] + d < w) xm[x1[i] + d] = -1;
				if(0 <= x2[i] + d && x2[i] + d < w) xm[x2[i] + d] = -1;
				if(0 <= y1[i] + d && y1[i] + d < h) ym[y1[i] + d] = -1;
				if(0 <= y2[i] + d && y2[i] + d < h) ym[y2[i] + d] = -1;
			}
		}

		int xc = 0, yc = 0;
		for(auto v : xm) {
			xm[v.first] = xc++;
		}
		for(auto v : ym) {
			ym[v.first] = yc++;
		}

		memset(vis, 0, sizeof vis);
		for(int i = 0; i < n; i++) {
			x1[i] = xm[x1[i]];
			x2[i] = xm[x2[i]];
			y1[i] = ym[y1[i]];
			y2[i] = ym[y2[i]];
			for(int y = y1[i]; y <= y2[i]; y++) {
				for(int x = x1[i]; x <= x2[i]; x++) {
					vis[y][x] = 1;
				}
			}
		}

		int ans = 0;
		for(int i = 0; i < yc; i++) {
			for(int j = 0; j < xc; j++) {
				if(vis[i][j]) continue;
				ans++;
				vis[i][j] = 1;
				queue<P> q;
				q.push({ j, i });
				int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
				while(q.size()) {
					int x = q.front().first, y = q.front().second;
					q.pop();
					for(int k = 0; k < 4; k++) {
						int nx = x + dx[k], ny = y + dy[k];
						if(0 <= nx && nx < xc && 0 <= ny && ny < yc && !vis[ny][nx]) {
							vis[ny][nx] = 1;
							q.push({ nx, ny });
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 38560
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        int test=in.nextInt();
        int ar[]=new int[test];
        int count=0;
        for (int i = 0; i <test; i++) {
            ar[i]=in.nextInt();
            if(i%2==0 && ar[i]%2!=0){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35752
#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()

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    deque<int> b;
    REP(i, n) {
        if (i % 2 == 0) b.push_back(a[i]);
        else b.push_front(a[i]);
    }
    if (n % 2 == 1) reverse(ALL(b));
    REP(i, n) cout << b[i] << " ";
    cout << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll a, b;
    cin >> a >> b;

    ll A = 0;
    for (ll i = ((a - 1) / 4) * 4; i <= a - 1; i++) A ^= i;
    ll B = 0;
    for (ll i = (b / 4) * 4; i <= b; i++) B ^= i;

    ll ans = A ^ B;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans= 0
tmp=0
sump=sum(p[0:k])
for i in range(n-k):
    sump=sump+p[i+k]-p[i]
    # print(i,tmp,p[i:i+k])
    if sump>tmp:
        # print(i,tmp)
        tmp = sump
        ans= i+1
anss=0
for j in p[ans:ans+k]:
    anss+=(j+1)/2


print(anss)

Measured memory_bytes: 71792
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 100005
#define oo 2000000007
#define EPS 1e-9

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

bool cmp(const ii &a, const ii &b) {
    return ((a.ff > b.ff) || (a.ff == b.ff && a.ss < b.ss));
}

int a, b;

int main () {
    scanf("%d%d", &a, &b);

    if ((ll)a*b <= 0) puts("Zero");
    else if (a > 0) puts("Positive");
    else if ((b-a)%2 == 0) puts("Negative");
    else puts("Positive");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()

int main(){
  ll a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n,p;
    cin>>n>>p;
    vector<int>ar(n);
    for(auto &i:ar)
        cin>>i;
    sort(ar.begin(),ar.end());
    int sum=0;
    for(int i=0;i<p;i++)
        sum+=ar[i];
    cout<<sum;
}
int32_t main()
{
    
    int t;
    t=1;
    while(t--)
        solve();
    
    
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
#include<set>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

int main(void)
{
  ll n;
  cin >> n;
  vector<ll> a(n+1, 0);
  for (int i = 2; i <= n; i++) {
    ll tmp;
    cin >> tmp;
    a[tmp]++;
  }

  for (int i = 1; i <= n; i++) {
    cout << a[i] << endl;
  }
}


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

#define int long long
#define ll long long
#define f1(i, a, b) for (int i = a; i < b; i++)
#define f2(i, a, b) for (int i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
#define ld long double

const int mod = 1000000007;
const ld PI = acosl(-1.0);
ll temp;

int primes[1000001];
int ins[1000001];
void sieve()
{
    for (int i = 0; i < 1000001; i++)
        primes[i] = i;
    for (int i = 2; i * i < 1000001; i++)
    {
        if (primes[i] == i)
        {
            for (int j = i * i; j < 1000001; j += i)
            {
                if (primes[j] == j)
                    primes[j] = i;
            }
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    f1(i, 0, n)
            cin >> a[i];
    sieve();
    int gcd = a[0];
    f1(i, 1, n)
    {
        gcd = __gcd(gcd, a[i]);
    }

    memset(ins, 0, sizeof ins);

    int pairco = true;
    for (int i = 0; i < n; i++)
    {
        temp = a[i];
        while (temp != 1)
        {
            ins[primes[temp]]++;
            int fact = primes[temp];
            while (temp % fact == 0 && fact != 1)
                temp /= fact;
        }
    }
    f1(i, 2, 1000001)
    {
        if (ins[i] > 1)
        {
            pairco = false;
            break;
        }
    }
    if (pairco)
        cout << "pairwise coprime" << endl;
    else if (gcd == 1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 27036
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String w = scanner.nextLine();
        if (w.length() % 2 == 1) {
            System.out.println("No");
            return;
        }

        char[] arr = new char[w.length()];
        for (int i = 0; i < w.length(); i++) {
            arr[i] = w.charAt(i);
        }
        Arrays.sort(arr);

        boolean yes = true;
        for (int i = 0; i < w.length(); i += 2) {
            if (arr[i] != arr[i+1]) {
                yes = false;
                break;
            }
        }
        if (yes) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22740
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    S = input_raw[0]
    new_S = S[:K - 1] + S[K - 1].lower() + S[K:]
    print new_S
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060