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

int main(){
    bool cards[4][14];
    int n, rank;
    char suit;
    
    for ( int s = 0; s < 4; s++)
    for( int r = 1; r <= 13; r++)
    cards[s][r] = 0 ;
    
    cin >> n;
    for ( int  i = 0; i < n; i++){
        cin >> suit >> rank;
    if ( suit == 'S' ) cards[0][rank] = 1;
    if ( suit == 'H' ) cards[1][rank] = 1;
    if ( suit == 'C' ) cards[2][rank] = 1;
    if ( suit == 'D' ) cards[3][rank] = 1;
    }
    
    for ( int s = 0; s < 4; s++){
        for ( int r = 1; r <= 13; r++){
            if ( cards[s][r] ) continue;
            if ( s == 0 ) suit = 'S';
            if ( s == 1 ) suit = 'H';
            if ( s == 2 ) suit = 'C';
            if ( s == 3 ) suit = 'D';
            cout << suit << " " << r << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3044
H, W = map(int, input().split())
S_list = []
for _ in range(H):
    S_list.append(input())

for i in range(H):
    S_list[i] = ',' + S_list[i] + ','

U_list = [',' * (W + 2)]
S_newlist = U_list + S_list + U_list

pre_result = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S_newlist[i][j] == '#':
            pre_result.append('#')
        else:
            num = S_newlist[i][j - 1: j + 2].count('#') + \
                  S_newlist[i - 1][j - 1: j + 2].count('#') + \
                  S_newlist[i + 1][j - 1: j + 2].count('#')
            pre_result.append(str(num))

comb_result = ''
for s in pre_result:
    comb_result += s

result = [comb_result[n: n + W] for n in range(0, len(comb_result), W)]

ans = '\n'.join(result)
print(ans)


Measured memory_bytes: 3188
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)

int tekitou(int a){
	return (a%2==0)? a/2:(a-1)/2 ;
}

int main (){
	int NN;
	cin >> NN;
	int temp=-1;
	int now=-1;
	int count=0;
	int ans = 0;
	rep(i,NN){
		cin >> temp;
		if(temp != now){
			now = temp;
			ans += tekitou(count+1);
			count = 0 ;
		}
		else {
			count ++;
		}
	}
	ans += tekitou(count+1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
n,m=map(int,input().split())
query=[]
for i in range(m):
    a,b=map(int,input().split())
    query.append([a,b])
query.sort(key=lambda x:x[1])

tekyo=-1
kazu=0
for i in range(m):
    a,b=query[i][0],query[i][1]
    if tekyo<a: #キレてない
        tekyo=b-1
        kazu+=1
print(kazu)

Measured memory_bytes: 21824
/*
	##############################
	#  Author: Pratyush Gaurav   #
	#  College: NIT ROURKELA     #
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)
#define mem(a,b)memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()

#define endl '\n'

const long long INF = 2000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

void solve()
{
    lli a,b,c,d;
    cin >> a >> b >> c >> d;
    lli ans = min(a,b) + min(c,d);
    cout << ans ;
}
int main()
{
	opt;
	lli t = 1;
	while(t--)
	    solve();
	return 0;
}










Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;




void solve() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	int tmp = 1;
	rep(i, n) {
		if (a[i] == tmp)tmp++;
	}
	if (tmp == 1) {
		cout << -1 << endl;
	}
	else {
		cout<<n - (tmp - 1) << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(4);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 1024
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

Q, A, B, C = map(int, readline().split())
N = A + B + C
S = read().split()

S = tuple(0 if s == b'BC' else 1 if s == b'AC' else 2 for s in S)

def solve_1(N, A, B, C, S):
    nums = [A, B, C]
    for s in S:
        if nums[s] == N:
            raise Exception
        i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
        if nums[i] < nums[j]:
            i, j = j, i
        yield j
        nums[j] += 1
        nums[i] -= 1

def solve_2(N, A, B, C, S):
    nums = [A, B, C]
    s = S[0]
    # 初手で死亡
    if nums[s] == N:
        raise Exception
    # あとはできる。きわどいときは 2 手読み
    S = S + (0, )
    for s, t in zip(S, S[1:]):
        i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
        if (nums[i], nums[j]) != (1, 1):
            if nums[i] < nums[j]:
                i, j = j, i
        elif s != t:
            i, j = t, 3 - s - t
        yield j
        nums[j] += 1
        nums[i] -= 1

def large(N, A, B, C, S):
    nums = [A, B, C]
    for s in S:
        if nums[s] == N:
            raise Exception
        i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
        if nums[i] < nums[j]:
            i, j = j, i
        yield j
        nums[j] += 1
        nums[i] -= 1

f = solve_1 if N == 1 else solve_2 if N == 2 else large

try:
    cmds = list(f(N, A, B, C, S))
    print('Yes')
    answer = ('ABC' [i] for i in cmds)
    print('\n'.join(answer))
except Exception:
    print('No')



Measured memory_bytes: 15912
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e6+10,mod=1e9+7;
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
int dp[maxn],sum;
int main(){
	int n=read(),m=read(),d=read();
	int fac=1,coef=0;
	REP(i,1,n){
		fac=(ll)i*fac%mod;
		coef=(coef+fac)%mod;
	}
	sum=dp[0]=fac;
	REP(i,1,m){
		if(i-d>0) sum=(sum+mod-dp[i-d-1])%mod;
		dp[i]=(ll)sum*coef%mod;
		if(i==m) break;
		sum=(sum+dp[i])%mod;
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 4096
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
//    int x=sc.nextInt();
//    int a=sc.nextInt();
//    int b=sc.nextInt();
    int z=0;
    for(int i=0;i<4;i++){
      if(s.charAt(i)=='+'){
        z++;
      }else{
        z--;
      }
    }
    System.out.println(z);
  }
}

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

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

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

    if (s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import bisect 
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
count=0
while True:
    a.sort(reverse=True)
    a0=a[0]//2
    for i in range(n):
        a[i]=a[i]//2
        count+=1
        if count==m:
            print(sum(a))
            exit()
        if i==n-1:break
        if a[i+1]<a0:
            break






Measured memory_bytes: 14480
#include <bits/stdc++.h>
#include <vector>
using namespace std;
 
int main()
{
  int n, d;
  int ans = 0;
  vector<int> v;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> d;
    v.push_back(d);
  }
  for(int i = 0; i < n; i++){
    ans += v[i] - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
int par[100000];
int ans[100000];
vector<pi> edge[100000];

void dfs (int v) {
    int cnt = 1;
    int ex = 0;
    rep(i,edge[v].size()) {
        if (edge[v][i].first == par[v]) {
            ex = ans[edge[v][i].second];
            continue;
        }
        par[edge[v][i].first] = v;
    }
    rep(i,edge[v].size()) {
        if (edge[v][i].first == par[v]) {
            continue;
        }
        if (cnt == ex) cnt++;
        ans[edge[v][i].second] = cnt++;
    }
    rep(i,edge[v].size()) {
        if (edge[v][i].first == par[v]) {
            continue;
        }
        dfs(edge[v][i].first);
    }

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        edge[a].push_back(pi(b,i));
        edge[b].push_back(pi(a,i));
    }
    memset(par, -1, sizeof(par));
    dfs(0);
    cout << *max_element(ans, ans+N-1) << endl;
    rep(i,N-1) {
        cout << ans[i] << endl;
    }
}

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

typedef long long int LL;

int main(void)
{
	LL n, k;
	LL come_T[100000];

	LL burning_T;

	LL i;

	scanf("%lld %lld",&n,&k);

	burning_T = n;

	for (i = 0; i < n; i++)
	{
		scanf("%lld", &come_T[i]);
	}

	LL use_k = n;
	LL poket_T;
	LL T[100000];
	LL cnt = 0;

	for (i = 0; i < n - 1; i++)
	{
		T[i] = come_T[i + 1] - come_T[i] - 1;
	}

	sort(T, T + (n - 1) );

	for (i = 0; i < n - k; i++)
	{
		//printf("i= %lld T=%lld\n",i, T[i]);

		burning_T += T[i];
	}

	printf("%lld\n", burning_T);

	return 0;
}


Measured memory_bytes: 4820
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	for (int i = k; i < n; i++) {
		if (a[i - k] < a[i]) cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 3988
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, a, b, c, d) = get!(i64, i64, i64, i64, i64);

    let b = (b - a).abs();

    let n = n - 1;
    for i in 0..n + 1 {
        let l = i * c - (n - i) * c;

        if l - (n - i) * (d - c) <= b && b <= l + i * (d - c) {
            println!("YES");
            return;
        }
    }
    println!("NO");
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define dump(x) cout << (x) << endl;
typedef int64_t Int;
Int mod = 1e9+7;

int main() {
  Int a, b;
  cin >> a >> b;
  Int k;
  cin >> k;
  while (k > 0) {
    b += a / 2;
    a /= 2;
    k--;
    if (k == 0) break;
    a += b / 2;
    b /= 2;
    k--;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int n, m;
  cin >> n >> m;
  vecint a(m), b(m);
  REP(i,m)cin >> a[i] >> b[i];
  map<int, int> from1, toN;
  REP(i,m){
    if(a[i] == 1){
      from1[b[i]]++;
    }else if(b[i] == 1){
      from1[a[i]]++;
    }
  }
  REP(i,m){
    if(from1.count(a[i]) == 1){
      toN[b[i]]++;
    }else if(from1.count(b[i]) == 1){
      toN[a[i]]++;
    }
  }
  cout << ((toN[n] == 1)?"POSSIBLE":"IMPOSSIBLE") << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;

int main(){
    int m, n, i, total=0;
    cin>>n>>m;
    vector<int> arr(n);

    REP(i, 0, n){
        cin>>arr[i];
        total += arr[i];
    }

    sort(all(arr));

    int cnt=0;
    REP(i, 0, n){
        if(arr[i]*4*m >= total)
            cnt++;
    }

    if(cnt>=m)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}














Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ')
                    .Select(elem => int.Parse(elem))
                    .OrderBy(elem => elem)
                    .ToArray();
        Console.WriteLine(a[n - 1] - a[0]);
    }
}


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

int main()
{
  string str;

  while (1){
    getline(cin, str);
    if (str[0] == '0') break;

    int sum = 0;
    int cnt = 0;

    for (int i = 0; i < str.size(); i++){
      if (str[i] == '1' && '0' <= str[i + 1] && str[i + 1] <= '3'){
        sum += 10;
        i++;
        continue;
      }
      if (str[i] == '1') cnt++;
      if (str[i] != ' ') sum += (str[i] - '0');
    }


    while(cnt--){
      if (sum + 10 <= 21){
        sum += 10;
      }
    }
   if (sum > 21){
      sum = 0;
    }

   cout << sum << endl;
  }
}

Measured memory_bytes: 1176
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


A, B, C, D = map(int, input().split(' '))
lcm_cd = lcm(C, D)


def count_target(n):
    c_multiples = n // C
    d_multiples = n // D
    cd_multiples = n // lcm_cd
    return n - c_multiples - d_multiples + cd_multiples


count2a = count_target(A - 1)
count2b = count_target(B)

print(count2b - count2a)


Measured memory_bytes: 5048
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数＋１が答え

from fractions import gcd
from math import floor

def main():
  a, b = map(int, input().split())
  fac = facto(gcd(a,b))
  print(len(fac))  
  
def facto(n):
  fac = [1]
  max_n = floor(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  
  for cursor in two_and_odds(max_n):
    if n == 1: break
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    fac.append(n)
  return fac

def two_and_odds(max_n):
  yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()


Measured memory_bytes: 118248
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>
using namespace std;
using i64 = int64_t;
template<class T, class F = std::plus<T>>
struct Fenwick {
    int n;
    vector<T> c;
    F f;
    T init;
    Fenwick(int n, F f = plus<T>(), T init = T())
        : n(n), c(n + 1, init), f(f), init(init) {}
    
    T sum(int i) const {
        T x = init;
        while (i > 0) {
            x = f(x, c[i]);
            i -= i & -i;
        }
        return x;
    }
    void add(int i, T x) {
        while (i <= n) {
            c[i] = f(c[i], x);
            i += i & -i;
        }
    }
};
i64 n, m;
vector<vector<pair<int, int>>> ss;
int main() {
    cin >> n >> m;
    ss.resize(m + 1);
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        ss[r - l + 1].emplace_back(l, r);
    }
    int rest = n;
    Fenwick<int> fen(m + 1);
    for (int d = 1; d <= m; ++d) {
        for (auto p : ss[d]) {
            int l, r;
            tie(l, r) = p;
            fen.add(l, 1);
            fen.add(r + 1, -1);
        }
        rest -= ss[d].size();
        int ans = rest;
        for (int i = 0; i <= m; i += d) {
            ans += fen.sum(i);
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 9856
from math import sqrt, floor
N = int(input())
t = 0
p = 0
for k in range(floor(sqrt(2*N))-2,floor(sqrt(2*N))+2):
    if ((k-1)*k)/2 <= N < (k*(k+1))/2:
        t = k
        p = (k*(k+1))//2 - N
        break

for k in range(1,t+1):
    if k!=p:
        print(k)

Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i,j,p)   for(int i=j; i<p; i++)
#define frr(i,j,p)  for(int i=j; i>=p; i--)
#define PI          3.14159265358979323846
#define pb          push_back
#define pbk         pop_back()
#define mkp         make_pair
#define print(m)    std::cout << std::fixed << std::setprecision(11) << m <<endl;
#define ff          first
#define ss          second
#define mod         1000000007
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())

lli knap(lli tot, lli w[], lli v[], lli n) {
    lli k[tot+1][n+1];
    fr(i,0,tot+1) {
        fr(j,0,n+1) {
            if(i==0 || j==0) k[i][j]=0;
            else if(w[j-1]<=i) {
                k[i][j]=max(k[i][j-1], v[j-1]+k[i-w[j-1]][j-1]);
            }
            else k[i][j]=k[i][j-1];
        }
    }
    return k[tot][n];
}
int main() {
	lli n,tot;  cin>>n>>tot;
	lli w[n],v[n];
	fr(i,0,n) cin>>w[i]>>v[i];
    cout<<knap(tot,w,v,n);
	return 0;
}

Measured memory_bytes: 82440
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int d, t, s; cin >> d >> t >> s;
  if (d <= t * s) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define NIL -1
using namespace std;
const int MAX=30;
int n,D[MAX],H[MAX];
struct Node{
    int p,l,r;//parent,left,right
    Node(int p=NIL){this->p=p;}
}T[MAX];
void setDepth(int cur,int dep){
    D[cur]=dep;
    if(T[cur].l!=NIL) setDepth(T[cur].l,dep+1);
    if(T[cur].r!=NIL) setDepth(T[cur].r,dep+1);
}
int setHeight(int cur){
    int hl=0,hr=0;
    if(T[cur].l!=NIL) hl=setHeight(T[cur].l)+1;
    if(T[cur].r!=NIL) hr=setHeight(T[cur].r)+1;
    return H[cur]=max(hl,hr);
}
int getSibling(int cur){
    if(T[cur].p==NIL) return NIL;
    if(T[T[cur].p].l!=cur&&T[T[cur].p].l!=NIL) return T[T[cur].p].l;
    if(T[T[cur].p].r!=cur&&T[T[cur].p].r!=NIL) return T[T[cur].p].r;
    return NIL;
}
int getDegree(int cur){
    int deg=0;
    if(T[cur].l!=NIL) deg++;
    if(T[cur].r!=NIL) deg++;
    return deg;
}
void print(int cur){
    cout<<"node "<<cur<<": parent = "<<T[cur].p<<", sibling = "<<getSibling(cur)<<", degree = ";
    cout<<getDegree(cur)<<", depth = "<<D[cur]<<", height = "<<H[cur]<<", ";
    if(T[cur].p==NIL) cout<<"root\n";
    else if(T[cur].l==NIL&&T[cur].r==NIL) cout<<"leaf\n";
    else cout<<"internal node\n";
}
int main()
{
    int id,left,right;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>id>>left>>right;
        T[id].l=left;
        T[id].r=right;
        if(left!=NIL) T[left].p=id;
        if(right!=NIL) T[right].p=id;
    }
    int root;
    for(int i=0;i<n;i++) if(T[i].p==NIL){root=i;break;}
    setDepth(root,0);
    setHeight(root);
    for(int i=0;i<n;i++) print(i);
}



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


int main()
{
    int n;
    cin >> n;
    int nod[n+1] = {0};
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j=i;j<n+1;j+=i){
            nod[j]++;
        }
    }
    for(int i = 1; i <= n; i++) ans+= (long long)i*nod[i];

    cout << ans;
    
    return 0;
}

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

using namespace std;

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

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

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] >= static_cast<double>(sum) / (4 * m)) count++;
    }

    cout << (count >= m ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char c;
    cin >> c;
    if (c == 'a'  || c== 'e'  || c== 'i'  || c== 'o'  ||c == 'u'){
        cout << "vowel";
    }
    else {cout << "consonant";}


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    bitset<100*100+100> dp;
    dp[0]=true;
    rep(i,n){
        cin>>a;
        dp|=dp<<a;
    }
    ans=LINF;
    rrep(i,1,100*100+100){
        if(i%10==0)continue;
        if(dp[i])ans=i;
    }
    if(ans==LINF)Cout(0);
    else Cout(ans);
    return 0;
}


Measured memory_bytes: 256
n,m,x,y = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
z1 = max(A)+1
z2 = min(B)
for i in range(x+1,y+1):
    if z1 <= i <= z2:
        print("No War")
        break
else:
    print("War")

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  int p;
  int max_p = 0;
  int ans = 0;
  REP(i, N) {
    cin >> p;
    ans += p;
    max_p = max(max_p, p);
  }

  ans -= max_p / 2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;


int main(void){

	double d;
	while( scanf("%lf",&d) != EOF ) {
		double a[10];
		a[0] = d;
		for( int i = 1; i < 10; i++ ) {
			if( i % 2 == 0 ) a[i] = a[i-1] / 3.0;
			else a[i] = a[i-1] * 2.0;
		}
		double sum = 0.0;
		for( int i = 0; i < 10; i++ )
			sum += a[i];
		printf("%.8lf\n",sum);
	}

    return 0;
}

Measured memory_bytes: 1236
//*Here I go out to sea again
//*The sunshine fills my hair
//*And dreams hang in the air

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[26]={0};
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
      a[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
      if(a[i]%2!=0){
        cout<<"No"<<"\n";
        return 0;
      }
    }
    cout<<"Yes"<<"\n";

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	int ans = 0;
	for(int i=0; i<N; i++){
		while(A[i]%2==0){
			A[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a <= b) {
        if (a*-1 == b) ans = 1;
        else if (a < 0 && b > 0) ans = abs(a+b)+1;
        else ans = b-a;
    } else {
        if (a >= 0 && b <= 0) {
            ans = abs(a+b)+1;
        } else {
            ans = abs(a-b)+2;
        }
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m;
vector<int> con[100111],rcon[100111];
bool vis[100111];
int col[100111];
vector<int> v[100111];
int f[100111];
int cnt[4],dtot;
bool tmp;
bool dfs(int x,int t)
{
//	cerr<<"dfs:"<<x<<" "<<t<<endl;
	if(con[x].size()>0&&rcon[x].size()>0)tmp=1;
	dtot+=con[x].size();
	col[x]=t;cnt[t]++;
	bool ret=1;
	for(int i=0;i<con[x].size();i++)
	{
		int u=con[x][i];
		if(!col[u])
		{
			col[u]=t%3+1;
			ret&=dfs(u,t%3+1);
		}
		if(col[u]!=t%3+1)ret=0;
	}
	int nt=(t+1)%3+1;
	for(int i=0;i<rcon[x].size();i++)
	{
		int u=rcon[x][i];
		if(!col[u])
		{
			col[u]=nt;
			ret&=dfs(u,nt);
		}
		if(col[u]!=nt)ret=0;
	}
	return ret;
}
int main()
{
	getii(n,m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		getii(x,y);
		con[x].PB(y);
		rcon[y].PB(x);
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		if(col[i])continue;
		cnt[1]=cnt[2]=cnt[3]=0;
		tmp=0;dtot=0;
		if(dfs(i,1))
		{
			if(tmp)ans+=1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[3]+1ll*cnt[3]*cnt[1];
			else ans+=dtot;
		}
		else
		{
//			cerr<<"false"<<endl;
			ll tot=cnt[1]+cnt[2]+cnt[3];
			ans+=tot*tot;
		}
//		cerr<<cnt[1]<<" "<<cnt[2]<<" "<<cnt[3]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


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

void update_dpk12(int k, vector<vector<int>> & dp, const vector<int> & As){
    int m1, m2;
    if (As[0] > As[k]){
        m1 = As[0];
        m2 = As[k];
        dp[k][1] = 0;
        dp[k][2] = k;
    }else{
        m1 = As[k];
        m2 = As[0];
        dp[k][1] = k;
        dp[k][2] = 0;
    }
    for (int mask = 1; mask < k; mask <<= 1) {
        if ((mask & k) == 0) continue;
        int s = k ^mask;
        if (As[dp[s][1]] > m1) {
            dp[k][2] = dp[k][1];
            dp[k][1] = dp[s][1];
            m2 = m1;
            m1 = As[dp[s][1]];
        }else if (As[dp[s][1]] == m1){
            if (dp[s][1] != dp[k][1]){
                dp[k][2] = dp[s][1];
                m2 = m1;
            }
        }else if (As[dp[s][1]] > m2){
            dp[k][2] = dp[s][1];
            m2 = As[dp[s][1]];
        }
        if (s > 0 and As[dp[s][2]] > m2 ){
            dp[k][2] = dp[s][2];
            m2 = As[dp[s][2]];
        }
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    const int L = (1 << N);
    vector<int> As(L);
    for (auto & a : As) cin >> a;

    vector<vector<int>> dp(L,{-1,-1,-1});
    // dp[k][0]  k 以下の i or j についての、Ai + Aj の最大値
    // dp[k][1]  k の bit列 のサブセット i について、Aiが最大となるときの i
    // dp[k][2]　k の bit列 のサブセット i について、Aiが２番目に大きい値となるときの i

    dp[0][0] = -1;
    dp[0][1] = 0;
    dp[0][2] = -1;
    dp[1][0] = As[0] + As[1];
    dp[1][1] = (As[0] > As[1]) ? 0 : 1;
    dp[1][2] = 1 - dp[1][1];
    cout << dp[1][0] << '\n';

    for (int k = 2; k < L; ++k){
        update_dpk12(k, dp, As);
        dp[k][0] = max(dp[k - 1][0], As[dp[k][1]] + As[dp[k][2]]);
        cout << dp[k][0] << '\n';
    }

    return 0;
}

Measured memory_bytes: 18432
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

#define MAX_N 160005

int par[MAX_N]; // 親の番号
int depth[MAX_N];

// n要素で初期化
void init(int n){
  for(int i=0; i<n; i++){
    par[i] = i;
    depth[i] = 0;
  }
}
// 木の根を求める
int root(int x){
  if(par[x] == x){ // 根
    return x;
  } else {
    return par[x] = root(par[x]); // 経路圧縮
  }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
  return root(x) == root(y);
}

// xとyの属する集合を併合
void unite(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y) return;

  if(depth[x] < depth[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if(depth[x] == depth[y])
      depth[x]++;
  }
}

bool M[405][405];
void sub(int i1, int j1, int i2, int j2, int W) {
  if(M[i1][j1] xor M[i2][j2]) {
    unite(i1*W+j1, i2*W+j2);
  }
}

int main(){
  int H, W;
  cin >> H >> W;
  for(int i=0; i<H; i++) {
    string S;
    cin >> S;
    for(int j=0; j<W; j++) {
      if(S[j] == '.') // white
	M[i][j] = true;
      else // black
	M[i][j] = false;
    }
  }
  init(H*W);
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      bool self = M[i][j];
      // if(i != 0)
      // 	sub(i, j, i-1, j, W);
      if(i != H-1)
	sub(i, j, i+1, j, W);
      // if(j != 0)
      // 	sub(i, j, i, j-1, W);
      if(j != W-1)
	sub(i, j, i, j+1, W);
    }
  }
  vector<ll> white(H*W, 0);
  vector<ll> black(H*W, 0);
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if(M[i][j]) { // white
	white[root(i*W+j)]++;
      } else { // black
	black[root(i*W+j)]++;
      }
    }
  }
  ll ans = 0;
  for(int i=0; i<H*W; i++)
    ans += white[i] * black[i];
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    long long A_list[200010];
    long long sum[200010];
    map<long long, long long> m;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A_list[i];
    }
    sum[0] = A_list[0];
    for(int i=1; i<N; i++){
        sum[i] = A_list[i] + sum[i-1];
    }
    for(int i=0; i<N; i++){
        long long a = sum[i];
        if(m.find(a) == m.end()){
            m[a] = 1;
        }else{
            m[a]++;
        }
    }
    long long x = 0;
    for(auto itr = m.begin(); itr != m.end(); itr++){
        long long n = itr->second;
        if(itr->first == 0){
            x += (n+1)*n/2;
        }else{
            x += n*(n-1)/2;
        }
    }
    cout << x;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;cin >> n;
  vector<long long> a(n);
  for (int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  long long count=1;
  for (int i=0;i<n;i++) {
    if (count!=-1) {
      if (a[i]==0) count=0;
	  else if (count<=1000000000000000000/a[i]) count*=a[i];
	  else count=-1;
	}
  }
  cout << count << endl;
}


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

int main()
{
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1&f==-1&r==-1)break;
        if(m==-1|f==-1){
            cout<<"F"<<endl;
        }else if(m+f>=80){
            cout<<"A"<<endl;
        }else if(m+f>=65){
            cout<<"B"<<endl;
        }else if(m+f>=50|(m+f>=30&r>=50)){
            cout<<"C"<<endl;
        }else if(m+f>=30){
            cout<<"D"<<endl;
        }else cout<<"F"<<endl;
    }
}


Measured memory_bytes: 3116
#include <stdio.h>

int main(void){
  int A, B, K, cnt=0;
  int i;
  scanf("%d %d %d", &A, &B, &K);
  for(i=100;i>0;i--){
    if(A%i==0 && B%i==0) cnt++;
    if(cnt==K) break;
  }
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
count = 0
0.step(N-1) do |i|
  min = i
  i.step(N-1) do |j|
    min = j if A[min] > A[j]
  end
  count += 1 if i != min
  A[i], A[min] = A[min], A[i]
end
puts A.join ' '
puts count


Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  ll H, W; cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = (H / 2) * (W / 2) * 2;

  if (H % 2) {
    ans += W / 2;
  }
  if (W % 2) {
    ans += H / 2;
  }
  if ((H % 2 == 1) && (W % 2 == 1)) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = (int(x) for x in input().split())
s = input()
t = list(reversed(s))

ANS = []
i = 0
while i < n:
    for j in reversed(range(1, m+1)):
        if i+j > n:
            continue
        else:
            if t[i+j] == "1":
                continue
            else:
                ANS.append(j)
                i += j
                break
    else:
        print(-1)
        exit()

print(*reversed(ANS))

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

const int N = 4005, M = 1e9+7;
int C[N][N];

int dp[N][N];
int st[N][N], en[N][N];

void pre() {
    for (int i=0; i<N; i++) C[i][0] = C[0][i] = 1;
    for (int i=1; i<N; i++)
        for (int j=1; j<N; j++)
            C[i][j] = (C[i-1][j] + C[i][j-1])%M;
}

int main() {
    pre();
    long long ans = 0;

    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        int x, y;
        cin>>x>>y;
        ans = (ans  + M - C[x+x][y+y])%M;

        st[N/2-x][N/2-y] ++;
        en[N/2+x][N/2+y] ++;
    }

    for (int i=1; i<N; i++) {
        for (int j=1; j<N; j++) {
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] + st[i][j])%M;
            ans = (ans + 1LL * en[i][j] * dp[i][j])%M;
        }
    }

    ans = (ans%M+M)%M;
    if (ans%2)  ans +=M;
    cout<<ans/2<<endl;
}






Measured memory_bytes: 175468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
bool check(int n, double len, double vx, double vy, vector<double> &p, vector<double> &h) {
  bool ok = true;
  for(int k=0;k<(n);++k) {
    double now = p[k];
    while(now > eps) now -= len;
    now += len;
    ok &= - (now * now / (2 * vx * vx)) + (vy / vx) * now >= h[k];
  }
  return ok;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; double d, b; cin >> d >> n >> b;
  vector<double> p(n), h(n);
  for(int i=0;i<(n);++i) {
    cin >> p[i] >> h[i];
  }
  double ans = INF;
  for(int i=0;i<(b+1);++i) {
    double len = d / (i+1);
    double l = 0, r = INF;
    for(int j=0;j<(500);++j) {
      double vy = (l + r) / 2.0;
      double vx = len / (2 * vy);
      bool ok = check(n, len, vx, vy, p, h);
      if(ok) r = vy;
      else l = vy;
    }
    r = INF;
    for(int j=0;j<(500);++j) {
      double vy1 = (2*l + r) / 3.0;
      double vx1 = len / (2 * vy1);
      double vy2 = (l + 2*r) / 3.0;
      double vx2 = len / (2 * vy2);
      if(vx1 + vy1 < vx2 + vy2) {
        r = vy2;
      } else {
        l = vy1;
      }
    }
    chmin(ans, sqrt(l * l + (len / (2 * l)) * (len / (2 * l))));
  }
  cout << ans << endl;
}



Measured memory_bytes: 3312
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
const ll MOD  = (ll)(1e9+7);
vll fact(3000000, 0);
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%MOD;
       base=(base*base)%MOD;
       exp/=2;
    }
    return res%MOD;
}
ll modadd(ll x, ll y) {
  return(x%MOD + y%MOD)%MOD;
}
ll modmul(ll x, ll y) {
  return (x%MOD * y%MOD)%MOD;
}
void f() {
  fact[0] = 1;
  fact[1] = 1;
  for(ll i = 2; i < 3000000 ; i++) fact[i] = modmul(i, fact[i-1]);
}
ll ncr(ll x, ll y) {
  if(y > x) return 0;
  ll ans = fact[x];
  ll denom = modmul(fact[y], fact[x - y]);
  denom = fast_exp(denom, MOD-2);
  ans = modmul(ans, denom);
  return ans;
}

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll x, y;
  cin >> x >> y;
  ll tot = x + y;
  if(tot%3) {
    cout << 0 << endl;
    return 0;
  }
  f();
  tot/=3;
  ll firch = x - tot;
  if(firch == 0) {
    cout << 1;
    return 0;
  }
  if(firch < 0) {
    cout << 0;
    return 0;
  }
  cout << ncr(tot, firch);
  return 0;
} //good night.

Measured memory_bytes: 23680
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_D&lang=jp
  * Structured Program II - Matrix Multiplication
  */
object Main {
  type Matrix[T] = Seq[Seq[T]]

  def main(args: Array[String]): Unit = {
    val Array(n, m, l) = io.StdIn.readLine().split(" ").map(_.toInt)
    val matrixA = readMatrix(n)
    val matrixB = readMatrix(m)
    val result = mulplyMatrices(matrixA, matrixB)
    result.foreach(row => println(row.mkString(" ")))
  }

  def readMatrix(rows: Int): Matrix[Int] = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(rows).map(_.split(" ").map(_.toInt).toSeq).toList
  }

  def swapDim(matrix: Matrix[Int]): Matrix[Int] = {
    val width = matrix.head.length
    (0 until width).map(column => matrix.map(_ (column)))
  }

  // element type is Long
  def mulplyMatrices(matrixA: Matrix[Int], matrixB: Matrix[Int]): Matrix[Long] = {
    val swappedB = swapDim(matrixB)
    matrixA.map(elemA => swappedB.map(elemB => (elemA zip elemB).foldLeft(0L)((acc, x) => acc + x._1 * x._2)))
  }
}

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

int main()
{
  ll n;
  map<string,ll>mp;
  cin>>n;
  vector<string>a(n);
  for(ll i=0;i<n;i++) cin>>a[i];
  for(ll i=0;i<n;i++)
	mp[a[i]]++;
  ll max=LONG_LONG_MIN;
  for(auto it=mp.begin();it!=mp.end();it++)
  {
    if(it->second > max)
      max=it->second;
  }
  for(auto it=mp.begin();it!=mp.end();it++)
  {
    if(it->second == max)
      cout<<it->first<<"\n";
  }
  return 0;
}

Measured memory_bytes: 26752
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while b > 0:
        a,b = b,a%b
    return a

def solve():
    n = int(input())
    a = int(input())
    for _ in range(n-1):
        b = int(input())
        a = a*b//gcd(a,b)
    return a

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 9;
ll n,m,a,b,ans=0;
bool e[N][N];
bool did[N];

bool allgo(){
	bool ok=true;
	FOR(i,1,n+1){
		if(did[i]==false)ok=false;
	}
	return ok;
}

void dfs(ll s){
	did[s]=true;
	FOR(i,1,n+1){
		if(did[i]==false&&e[s][i]==true){
			did[i]=true;
			if(allgo()){
				ans++;
			}
			dfs(i);
		}
	}
	did[s]=false;
}

int main(){
	cin>>n>>m;
	FOR(i,0,m){
		cin>>a>>b;
		e[a][b]=e[b][a]=true;
	}
	FOR(j,0,n+1)did[j]=false;
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
   string S;
   cin >> S;
   int s = stoi(S);
   int k = s % 100;
   int l = s / 100;
   if(s == 0)cout << "NA" << endl; 
   else if(k == 0 && l >= 13)cout << "NA" << endl;
   else if(13 <= s && s <= 99)cout << "NA" << endl;
   else if(13 <= k && k <= 99 && 13 <= l && l <= 99)cout << "NA" << endl;
   else if(1 <= s && s <= 12)cout << "YYMM" << endl;
   else if(1 <= l && l <= 12 && 1 <= k && k <= 12)cout << "AMBIGUOUS" << endl;
   else if(l >= 13)cout << "YYMM" << endl;
   else cout << "MMYY" << endl;
  }



Measured memory_bytes: 256
s=input()
t=input()
seen=set()
for i in range(len(s)):
  if s[i] not in seen:
    for j in range(i,len(t)):
      if s[i]==s[j]:
        if t[i]!=t[j]:
          print("No")
          exit(0)
      else:
        if t[i]==t[j]:
          print("No")
          exit(0)
    seen.add(s[i])
else:
  print("Yes")

Measured memory_bytes: 3632