akhauriyash/Code-Regression huggingface dataset:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
        
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n,m = inpl()
uf = UnionFind(n)
for _ in range(m):
    a,b = inpl()
    uf.union(a-1,b-1)
res = 0
for i in range(n):
    res = max(res, uf.size(i))
print(res)

Measured memory_bytes: 84552
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  vector<ll> L;
  cin >> N;
  ll maxl = 0;
  ll sum = 0;
  REP(i, N) {
    ll l;
    cin >> l;
    L.push_back(l);
    if (maxl < l)
      maxl = l;
    sum += l;
  }
  if (sum - maxl > maxl)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

n = int(input())
s_di = dict()

for i in range(n):
    t = input()
    if t not in s_di:
        s_di[t] = 1
    else:
        s_di[t] += 1

s_di = sorted(tuple(s_di.items()))
s_di = sorted(s_di, key=lambda s: s[1])
# print(s_di)

n_max = s_di[-1][1]

for s in s_di:
    if s[1] == n_max:
        print(s[0])


Measured memory_bytes: 43996
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
int n,k;
int dp[100100];
int main(){
	string str;
	cin>>str;
	int gs=0;
	int n=str.size();
	for(int i=0;i<str.size();i++){
		if(str[i]=='g')gs++;
	}
	cout<<gs-((n+1)/2)<<endl;
}

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

int main()
{
	int n; cin >> n;
	
	vector<int> x(n); for (int i = 0; i < n; i++) cin >> x[i];
	
	vector<int> y(n);
	y = x;
	sort(y.begin(), y.end());

	int leftIndex = (n - 1 - 1) / 2;
	int rightIndex = (n -1 + 1) / 2;

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

		if (x[i] <= y[leftIndex]) {
			cout << y[rightIndex] << endl;
		}
		else if (y[rightIndex] <= x[i]) {
			cout << y[leftIndex] << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main() {
    ll N, M;
    cin >> N >> M;
    char A[50][50];
    char B[50][50];

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

    for(int i = 0; i < M; i++){
        for(int j = 0; j < M; j++){
            cin >> B[i][j];
        }
    }
    ll cnt = 0;
    bool flag = false;
    for(int i = 0; i < N ; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < M; k++){
                for(int l = 0; l < M; l++){
                    if(A[i + k][j + l] == B[k][l]){
                        cnt++;
                        if(cnt == M * M){
                            flag = true;
                        }
                    }
                    else{
                        cnt = 0;
                    }                    
                }
            }
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

long long int a[110],n,sum=0,minimum=100000;
int main()
{
     std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>n;
     a[0]=100000;
     for(int i=1;i<n;i++){
        cin>>a[i];
        minimum=min(a[i],a[i-1]);
        sum=sum+minimum;
        minimum=100000;
        if(i==(n-1)){
            sum=sum+a[i];
        }
     }
     if(n<2){
     sum=sum+a[1];
     }
     cout<<sum<<endl;

     return 0;
}



Measured memory_bytes: 256
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
l=sorted([int(i) for i in input().split()])
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        m=bisect_left(l,l[i]+l[j])
        ans+=m-j-1
        #print(m)
print(ans)

Measured memory_bytes: 3188
def resolve():
    mod = 10 ** 9 + 7
    s = int(input())
    dp = [0] * (s + 1)
    dp[s] = 1
    for i in range(s, 2, -1):
        dp[i] %= mod
        for j in range(3, i + 1):
            dp[i - j] += dp[i]
    print(dp[0] % mod)


if __name__ == '__main__':
    resolve()


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

int main()
{
    int n, k, i, j;
    cin>>n>>k;
    vector<int> h(n);
    for(i=0;i<n;i++) {
        cin>>h[i];
    }
    vector<int> dp(n, -1);
    dp[0]=0;
    for(i=0;i<n;i++) {
        for(j=i+1;j<=i+k;j++) {
            if(j>=n) {
                break;
            }
            if(dp[j]==-1) {
                dp[j] = dp[i] + abs(h[j]-h[i]);
            }
            else {
                dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 4024
use std::io::*;
use std::str::FromStr;
 
fn abc(s: &str) -> String {
    //dream dreamer erase eraser
    let s = s.replace("eraser", "")
        .replace("erase", "")
        .replace("dreamer", "")
        .replace("dream", "");
 
    if s == "" {
        return "YES".to_string();
    } else {
        return "NO".to_string();
    }
}
 
fn main() {
    //assert_eq!(abc(9, 45_000), vec![4, 0, 5]);
    //assert_eq!(abc(20, 196_000), vec![-1, -1, -1]);
    //assert_eq!(abc(1_000, 1_234_000), vec![2, 54, 944]);
    //assert_eq!(abc(2_000, 20_000_000), vec![2_000, 0, 0]);
 
    let s: String = read();
 
    let result = abc(&s);
 
    println!("{}", result);
}
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    int ans = n;
    rep(i, n) a[i] = 0;
    int m, p;
    rep(i, k)
    {
        cin >> m;
        rep(j, m)
        {
            cin >> p;
            if (a[p - 1] == 0)
            {
                ans--;
            }
            a[p - 1]++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  string s;
  while (getline(cin, s)) {
    vector<string> ans;

    int b;
    bool cut = false;
    for (unsigned int i = 0; i < s.size(); ++i) {
      if (!cut) {
	if (s[i] != ' ' && s[i] != '.' && s[i] != ',') {
	  b = i;
	  cut = true;
	}
      } else {
	if (s[i] == ' ' || s[i] == '.' || s[i] == ',') {
	  string t = s.substr(b, i-b);
	  if (3 <= t.size() && t.size() <= 6)
	    ans.push_back(t);
	  cut = false;
	}
      }
    }

    if (cut) {
      string t = s.substr(b);
      if (3 <= t.size() && t.size() <= 6)
	ans.push_back(t);
    }

    for (int i = 0; i < static_cast<int>(ans.size())-1; ++i)
      cout << ans[i] << " ";
    if (!ans.empty())
      cout << ans[ans.size()-1] << endl;
    else
      cout << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    string sentence;
    cin >> sentence;
    int num_command;
    cin >> num_command;
    string command;
    string replace_string;
    int a,b;
    for(int i = 0;i < num_command;i++){
        cin >> command;
        if(command == "print"){
            cin >> a >> b;
            cout << sentence.substr(a,b-a+1) << "\n";
        }else if(command == "replace"){
            cin >> a >> b >> replace_string;
            sentence.replace(a,b-a+1,replace_string);
        }else if(command == "reverse"){
            cin >> a >> b;
            reverse(sentence.begin()+a,sentence.begin()+b+1);
        }
    }

    
    return 0;
}




Measured memory_bytes: 3200
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int P;
    cin >> P;
    cout << P / 500 * 500 << endl;

    return 0;
}



Measured memory_bytes: 3200
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        for (int i = 0; i < s.Length; i++)
        {
            if (t.Equals(s))
            {
                Console.WriteLine("Yes");
                return;
            }
            else
            {
                s = s.Substring(s.Length - 1, 1) + s.Substring(0, s.Length - 1);
            }
        }
        Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int str_s1[4000 + 10][30];
int str_s2[4000 + 10][30];

char str1[4000 + 10];
char str2[4000 + 10];

unsigned long long lists[16 * 1000000 + 10];

void solve() {
	scanf("%s", str1 + 1);
	scanf("%s", str2 + 1);
	
	int len_1 = strlen(str1 + 1);
	int len_2 = strlen(str2 + 1);
	memset(str_s1, 0, sizeof(str_s1));
	memset(str_s2, 0, sizeof(str_s2));
	
	int maxLen = min(len_1, len_2);
	
	for(int i = 1; i <= len_1; i++) {
		str_s1[i][str1[i] - 'a'] = 1;
		for(int j = 0; j < 26; j++) {
			str_s1[i][j] += str_s1[i - 1][j];
		}
	}
	
	
	for(int i = 1; i <= len_2; i++) {
		str_s2[i][str2[i] - 'a'] = 1;
		for(int j = 0; j < 26; j++) {
			str_s2[i][j] += str_s2[i - 1][j];
		}
	}
	int index = 0;
	for(int l = 1; l <= len_1; l++) {
		for(int r = l; r <= len_1; r++) {
			unsigned long long num = 2333;
			for(int j = 0; j < 26; j++) {
				num += (num  << 11) + str_s1[r][j] - str_s1[l - 1][j];
			}
			//cerr << num << endl;
			lists[index++] = num;
		}
	}
	
	sort(lists, lists + index);
	
	int ans = 0;
	int flag = 0;
	for(int l = maxLen; l && !flag; l--) {
		for(int i = 1; i + l - 1 <= len_2 && !flag; i++) {
			unsigned long long num = 2333;
			for(int j = 0; j < 26 && !flag; j++) {
				num += (num << 11) + str_s2[i + l - 1][j] - str_s2[i - 1][j];
			}
			unsigned long long * it = lower_bound(lists, lists + index, num);
			if(*it == num) {
				ans = l;
				flag = 1;
			}
				
		}
	}
	printf("%d\n", ans);
	
	
}
int main(int argc, char *argv[]) {
	//freopen("data.txt", "r", stdin);
	solve();
}

Measured memory_bytes: 66748
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

const int N = (int)1e5;

priority_queue<int> dat;

int main(){
    while(!dat.empty()) dat.pop();

    int n,m; scanf("%d %d", &n, &m);
    for (int i=1; i<=n; i++) {
        int a; scanf("%d", &a);
        dat.push(a);
    }

    for (int i=1; i<=m; i++) {
        int a = dat.top(); dat.pop();
        dat.push(a/2);
    }

    ll res = 0;
    while (!dat.empty()) {
        res += dat.top();
        dat.pop();
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 892
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
diff = [0]*(M-1)
for i in range(M-1):
    diff[i] = X[i+1]-X[i]

diff.sort()
if N>=M:
    ans = 0
else:
    ans = sum(diff[:M-N])
print(ans)

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

using namespace std;

typedef long long ll;
const int MAX = 1e5 + 6;
int prefg[MAX], sufg[MAX];
int ara[MAX];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

    for(int i=1; i<=n; i++) cin >> ara[i];

    prefg[1] = ara[1];
    sufg[n] = ara[n];

    for(int i=2; i<=n; i++){
        prefg[i] = __gcd(ara[i], prefg[i-1]);
    }

    for(int i=n-1; i>=1; i--){
        sufg[i] = __gcd(ara[i], sufg[i+1]);
    }

    int ans = max(sufg[2], prefg[n-1]);

    for(int i=2; i<n; i++){
        ans = max(ans, __gcd(prefg[i-1], sufg[i+1]));
    }

    cout << ans;



}

Measured memory_bytes: 1408
list = list(input())

a, b, c, d = map(int, list)


def plus(items, key):
    if(key == 1):
        return items[0] + items[1]
    else:
        return items[0] - items[1]


def numToOp(num):
    return "+" if num == 1 else "-"


ans = 0
opList = [1, 1, 1]
i = 0
while ans != 7:
    aPlusB = plus([a, b], opList[0])
    aPlusBPlusC = plus([aPlusB, c], opList[1])
    ans = plus([aPlusBPlusC, d], opList[2])
    # print(f"{i}回目：ans == {ans}, opList == {opList}")

    if ans != 7 and i <= 4:
        opList[i % 3] *= -1
        i += 1
    elif ans != 7 and i == 5:
        opList = [1, -1, 1]
        i += 1
    elif ans != 7 and i == 6:
        opList = [-1, 1, -1]
        i += 1

# print(opList)

print(
    f"{a}{numToOp(opList[0])}{b}{numToOp(opList[1])}{c}{numToOp(opList[2])}{d}=7")


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> str;
    long long ans = 0;
    for(i = 0;i < str.length();i++){
        if(str[i] == '?'){
            str[i] = 'D';
        }
    }
    cout << str << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int mina = 100001, minb = 100001, minm = 200001, A, B, M, x, y, c, m;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  rep(i, A)
  {
    cin >> a[i];
    mina = min(mina, a[i]);
  }
  rep(i, B)
  {
    cin >> b[i];
    minb = min(minb, b[i]);
  }
  rep(i, M)
  {
    cin >> x >> y >> c;
    m = a[x - 1] + b[y - 1] - c;
    minm = min(minm, m);
  }
  cout << min(mina + minb, minm);
}

Measured memory_bytes: 1024
from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
#print(L)
ans = 0
for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        ans += bisect_left(L, a + L[j])  - j - 1
        #print(ans, end=",")
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>

using namespace std;

#define IDX_TRUMP_DESIGN 0
#define IDX_TRUMP_NUMBER 1


//トランプ型
typedef struct {
	char design;
	int number;
} trump_t;

//トランプの要素を交換
void Swap(trump_t &t1, trump_t &t2)
{
	trump_t t_tmp;

	t_tmp = t1;
	t1 = t2;
	t2 = t_tmp;
}

void out_card_info(trump_t *t, int n)
{
	for(int i = 0; i < n-1; i++)
	{
		cout << t[i].design << t[i].number << " ";
	}
	cout << t[n-1].design << t[n-1].number << endl;
}

//バブルソート
void BubbleSort(trump_t *t, int n)
{
	for(int i = 0; i < n; i++)
	{
		for(int j = n-1; j >= i+1; j--)
		{
			if(t[j].number < t[j-1].number)
			{
				Swap(t[j], t[j-1]);
			}
		}
	}
}

//選択ソート
void SelectionSort(trump_t *t, int n)
{
	int minj;

	for(int i = 0; i < n; i++)
	{
		minj = i;
		for(int j = i; j < n; j++)
		{
			if(t[j].number < t[minj].number)
			{
				minj = j;
			}
		}
		Swap(t[i], t[minj]);
	}
}

//安定か判定
bool judgeStable(trump_t *original, trump_t *sorted, int n)
{
	int i, j, k, l;
	for(i = 0; i < n; i++)
	{
		for(j = i+1; j < n; j++)
		{
			for(k = 0; k < n; k++)
			{
				for(l = k+1; l < n; l++)
				{
					//カード内に同じ数字があった場合
					if( original[i].number == original[j].number )
					{
						if( ( original[i].design == sorted[l].design ) &&
							( original[i].number == sorted[l].number ) &&
							( original[j].design == sorted[k].design ) &&
							( original[j].number == sorted[k].number ) )
						{
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}

void output_stable_msg(bool isStable)
{
	if(isStable)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
}

int main(void)
{
	bool isStable;
	int card_num;
	string card_info;
	trump_t* trump;
	trump_t* sorted_bubble;
	trump_t* sorted_selection;

	//カードの枚数
	cin >> card_num;
	trump = new trump_t[card_num];
	sorted_bubble = new trump_t[card_num];
	sorted_selection = new trump_t[card_num];

	for(int i = 0; i < card_num; i++)
	{
		cin >> card_info;
		trump[i].design = card_info[IDX_TRUMP_DESIGN];
		trump[i].number = card_info[IDX_TRUMP_NUMBER] - 0x30;

		sorted_bubble[i].design = trump[i].design;
		sorted_bubble[i].number = trump[i].number;
		sorted_selection[i].design = trump[i].design;
		sorted_selection[i].number = trump[i].number;
	}

	//バブルソート
	BubbleSort(&sorted_bubble[0], card_num);
	isStable = judgeStable(&trump[0], &sorted_bubble[0], card_num);
	out_card_info(&sorted_bubble[0], card_num);
	output_stable_msg(isStable);

	//選択ソート
	SelectionSort(&sorted_selection[0], card_num);
	isStable = judgeStable(&trump[0], &sorted_selection[0], card_num);
	out_card_info(&sorted_selection[0], card_num);
	output_stable_msg(isStable);

	delete trump;
	delete sorted_bubble;
	delete sorted_selection;
	return 0;
}



Measured memory_bytes: 3132
#include<iostream>
using namespace std;
long long n,a[1001001],suma,sumb,ret,j;
int main()
{
	cin>>n;
	for(long long i=1;i<=n;i++)
		cin>>a[i];
	for(long long i=1;i<=n;i++)
	{
		while(j+1<=n&&(suma^a[j+1])==(sumb+a[j+1]))
		{
			j++;
			suma^=a[j];
			sumb+=a[j];
		}
		ret+=j-i+1;
		suma^=a[i];
		sumb-=a[i];
	}
	cout<<ret;
 	return 0;
}

Measured memory_bytes: 1792
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)


int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


int GCD(int a,int b){
  int r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


int LCM(int a,int b){
  int c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  bool flag=true;
  vector<vector<int>> c(3,vector<int>(3));
  rep(i,3) rep(j,3) cin>>c[i][j];
  if(c[0][1]-c[0][0]==c[1][1]-c[1][0] && c[1][1]-c[1][0]==c[2][1]-c[2][0] && c[0][2]-c[0][1]==c[1][2]-c[1][1] && c[1][2]-c[1][1]==c[2][2]-c[2][1]){
  }else{
    flag=false;
  }
  
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  
}

Measured memory_bytes: 256
MOD = int(1e9) + 7

N, M = map(int, input().split())
a = [True]*(N+1)

for _ in range(1, M+1):
    n = int(input())
    a[n] = False

##
dp = [0]*(N+1)
dp[0] = 1
for i in range(1, N+1):
    if a[i]:
        if i == 1:
            dp[i] = dp[i-1]
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[-1])


Measured memory_bytes: 7668
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int x, n;
	cin >> x >> n;

	vi p = vi(n);
	REP(i, n) {
		cin >> p[i];
	}
	sort(All(p));

	int idx=-1;
	REP(i, n) {
		//cout << p[i] << endl;
		if (p[i] == x) {
			idx = i;
			break;
		}
	}
	if (idx == -1) {
		cout << x << endl;
		return 0;
	}
	//*
	REPS(i, n + 1) {
		if (idx - i < 0 || p[idx - i] != x - i) {
			cout << x - i << endl;
			return 0;
		}

		if (idx + i >= n || p[idx + i] != x + i) {
			cout << x + i << endl;
			return 0;
		}
	}//*/
}

Measured memory_bytes: 3652
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

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

    char path[h+1][w+1];

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin>>path[i][j];
        }
    }

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


    if(path[1][1] == '#'){
        cout<<0<<endl;
        return 0;
    }

    dp[1][1] = 1;

    for(int j=2; j <= w; j++){
        if(path[1][j] == '.'){
            dp[1][j] = dp[1][j-1];
        }
    }

    for(int i=2; i<=h; i++){
        if(path[i][1] == '.'){
            dp[i][1] = dp[i-1][1];
        }
    }

    for(int i=2; i<=h; i++){
        for(int j=2; j<=w; j++){
            if(path[i][j] == '.'){
                dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
            }
        }
    }

    cout<<dp[h][w]<<endl;

    return 0;
}


Measured memory_bytes: 8208
#include <stdio.h>
#define MAX 10000
#define NIL -1

typedef struct{
  int parent,left,right;
} Node;

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u == NIL) return ;
  D[u] = d;
  setDepth(T[u].left,d + 1);
  setDepth(T[u].right,d + 1);
}

int setHeight(int u){
  int h1 = 0,h2 = 0;
  if(T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  int deg = 0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  if(T[u].parent == NIL) printf("root\n");
  else if(T[u].left == NIL && T[u].right == NIL) printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i,v,l,r,root = 0;
  scanf("%d",&n);
  for(i = 0;i < n;i++) T[i].parent = NIL;
  for(i = 0;i < n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  for(i = 0;i < n;i++){
    if(T[i].parent == NIL) root = i;
  }
  setDepth(root,0);
  setHeight(root);
  for(i = 0;i < n;i++) print(i);
  return 0;
}

Measured memory_bytes: 624
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int MAX=-1;
    int sum=0;
    
    for(int i=0;i<N;i++){
      int tmp=sc.nextInt();
      sum+=tmp;
      if(MAX<tmp){
        MAX=tmp;
      }
    }
    
    sum-=MAX;
    
    if(sum<=MAX){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 22996
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        long[] C = new long[N];

        for (int i=0; i<N; i++) {
            A[i] = reader.nextLong();
            B[i] = reader.nextLong();
            C[i] = reader.nextLong();
        }

        // dp[i][j] : max happiness when do i at jth day
        long[][] dp = new long[3][N+1];
        for (int i=0; i<N; i++) {
            dp[0][i+1] = Math.max(dp[1][i]+A[i], dp[2][i]+A[i]);
            dp[1][i+1] = Math.max(dp[0][i]+B[i], dp[2][i]+B[i]);
            dp[2][i+1] = Math.max(dp[0][i]+C[i], dp[1][i]+C[i]);
        }

        System.out.println(Math.max(Math.max(dp[0][N], dp[1][N]), dp[2][N]));
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



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

int main() {

     int height, width;
    char cell[101][101];

   
    int cell_row[101] = {0};
    int cell_col[101] = {0};
    


    scanf("%d %d", &height, &width);
    
    
    // for (int i = 0; i < height; i++)
    // {
    //     cell_row[i] = 0;
    // }
    // for (int j = 0; j < width; j++)
    // {
    //     cell_col[j] = 0;
    // }
    

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
           
            scanf(" %c", &cell[i][j]);

            
            if (cell[i][j] == '#')
            {
                cell_row[i] = 1;
                cell_col[j] = 1;
            }
        } 
    }
    for (int i = 0; i < height; i++)
    {
        if (cell_row[i] == 1 )
        {
            for (int j = 0; j < width; j++)
            {
                if (cell_col[j] == 1)
                {
                    printf("%c", cell[i][j]);
                }
            }
            printf("\n");
        }
    }


    return 0;
}



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

Measured memory_bytes: 600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int inf = 2e18;
struct Sol{
  int a,b,c,d;
  map<int,int> res;
  
  int licz(int n){
    auto xxx = res.find(n);
    if(xxx != res.end())return xxx->SE;
    int &ak = res[n];
    if(__int128(n) * d < __int128(inf)){
      ak = n * d;
    }else{
      ak = inf;
    }
    mini(ak, licz(n/2) + a + (n % 2) * d);
    mini(ak, licz(n/2+1) + a + (2 - n % 2) * d);
    mini(ak, licz(n/3) + b + (n % 3) * d);
    mini(ak, licz(n/3+1) + b + (3 - n % 3) * d);
    mini(ak, licz(n/5) + c + (n % 5) * d);
    mini(ak, licz(n/5+1) + c + (5 - n % 5) * d);
    return ak;
  }
  
  void run(){
    res[0] = 0;
    int n;
    cin >> n >> a >> b >> c >> d;
    cout << licz(n) << "\n";
  }
};

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int t;
  cin >> t;
  while(t--){
    Sol sol;
    sol.run();
  }
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;




int32_t main()
{
    
   
    crap;
    string s;
    cin>>s;
    int rev = 0;
    int q; cin>>q;
    deque<char> dq;
    for(int i=0;i<s.length();i++){
      dq.push_back(s[i]);
    }
    string s1="";
    while(q--){
      int query; cin>>query;
      if(query==1) rev = (rev+1)%2;
      else {
        int z; char c;
        cin>>z>>c;
        --z;
      //  s1="";
        if(rev) z= (z+1)%2;
        if(z==0){
          dq.push_front(c);
        }
        else{
          dq.push_back(c);
        }
      //  s=s1;
       // cout<<s1<<endl;
      }
    }
    string ans="";
    if(rev){
      while(!dq.empty()){
        ans+= dq.back();
        dq.pop_back();
      }
    }
    else{
      while(!dq.empty()){
        ans+= dq.front();
        dq.pop_front();
      }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1368
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

ll dp[55][55][2500];
ll n,a;
vector<ll>x;


int main(){
	memset(dp,0,sizeof(dp));
	cin>>n>>a;
	x.resize(n);
	rep(i,n)cin>>x[i];
	dp[0][0][0]=1;
	ll ans=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			for(int k=0;k<=2500;++k){
			dp[i+1][j+1][k+x[i]]+=dp[i][j][k];//選んだパターン
			dp[i+1][j][k]+=dp[i][j][k];//選ばなかったパターン
			}
		}
	}
	for(int j=1;j<=n;++j)ans+=dp[n][j][a*j];
	cout<<ans<<endl;
}

Measured memory_bytes: 59264
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, a, b;
    cin >> n >> a >> b;
    li d = abs(b - a);

    li ans;
    if (d % 2 == 0) {
        ans = d / 2;
    } else {
        li c1 = min(min(a - 1, b - 1), min(n - a, n - b));
        ans = c1 + 1 + (d - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        ans += B[A[i] - 1]
        if i > 0 and A[i - 1] + 1 == A[i]:
            ans += C[A[i - 1] - 1]

    print(ans)


sol()

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define MAXN 5005
#define LL long long
using namespace std;

const int C = 2500;
int N,A;
int x[MAXN];
LL dp[MAXN], temp[MAXN];

int main(){
	
	cin>>N>>A;
	
	dp[C] = 1;
	
	for(int i=1,x;i<=N;i++){
		cin>>x;
		x -= A;
		memcpy(temp, dp, sizeof(dp));
		
		for(int j=0;j<=2*C;j++){
			if(j+x>=0 && j+x<=2*C) temp[j] += dp[j+x];
		}
		memcpy(dp, temp, sizeof(temp));
	}
	
	cout<<dp[C] - 1<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#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 <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


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

	int h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) cout << 1 << endl;
	else cout << (h*w + 1) / 2 << endl;
}

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

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

    int n;
    cin >> n;
    int i = 0;
    int counter = 0;
    while (i <= n) {
        if (i % 2 != 0) {
            counter++;
        }
        i++;
    }
    double result = (double)counter / n;
    cout << result;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val, int MAX_LEN = 100001>
void permutate(vector<Val> &arr, const vector<int> &perm) {
    static Val temp[MAX_LEN];
    assert(arr.size() == perm.size());
    for(size_t i = 0; i < arr.size(); i++) {
        temp[i] = arr[perm[i]];
    }
    copy(temp, temp + (int)arr.size(), arr.begin());
}

int n, x[100001], m, a[100001];
ll k, ans[100001];

void solve() {
    vi dx(n - 1);
    rep(i, n-1) {
        dx[i] = x[i + 1] - x[i];
    }

    vi pw2(n - 1), tmp(n - 1);
    iota(all(pw2), 0);

    rep(i, m) swap(pw2[a[i]-2], pw2[a[i] - 1]);

    for(; k > 0; k >>= 1, permutate(pw2, pw2)) {
        if(k & 1)permutate(dx, pw2);
    }

    ans[0] = x[0];
    rep(i, n - 1)
        ans[i + 1] = ans[i] + dx[i];
    rep(i, n)printf("%lld\n", ans[i]);
}

int main(){
    while(cin >> n) {
        rep(i, n)scanf("%d", &x[i]);
        cin >> m >> k;
        rep(i, m)scanf("%d", &a[i]);
        solve();
    }
}

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

const ll mod = 1e9+7;

ll Pow(ll x, ll n){
  if(n == 0) return 1;
  if(n % 2 == 0) return Pow(x*x % mod,n/2);
  else return x * Pow(x,n-1) % mod;
}

int main(){
  ll n, k;
  cin >> n >> k;
  cout << Pow(k,n) << endl;
  return 0;
}



Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  ll tot=0;
  string s;
  cin>>s;
  vector<int>v(s.size()+1,0);
  rep(i,0,s.size()-1)
  {
    if(s[i]=='<'){
      v[i+1]=v[i]+1;
      
    }
    else{
      int cnt=0;
      for(int j=i;j<s.size();j++)
      {
        if(s[j]=='>') cnt++;
        else break;
      }
      while(cnt)
      {
        v[i]=max(v[i],cnt);
        cnt--;
        i++;
      }
      i--;
    }
  }
    for (auto x:v)
      tot+=x;
   
    cout<<tot;
  
    return 0;

  
  
}

Measured memory_bytes: 2820
N,T = map(int, input().split())
ct = [list(map(int, input().split())) for i in range(N)]
ct_sort = sorted(ct, key=lambda x: x[1])

cost_limit_list = []

for i in ct_sort:
    if i[1]<=T:
        cost_limit_list.append(i)
    else:
        break
if len(cost_limit_list) == 0:
    print('TLE')
else:
    cost_limit_list = sorted(cost_limit_list, key=lambda x: x[0])
    print(cost_limit_list[0][0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    int n=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            if(a[i][j]=='#'){n++;}
        }
    }
    if(h+w-1==n){
        cout<<"Possible"<<endl;}
else{cout<<"Impossible"<<endl;}
        return 0;
   
      
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let stdin = &mut stdin;
    let n: usize = read(stdin).unwrap();
    if n == 1 {
        println!("{}", 0);
        return;
    }
    let mut p = vec![0; n + 1];
    for i in 1..n + 1 {
        let pi: usize = read(stdin).unwrap();
        p[pi] = i;
    }
    // ここからpのなかでの連続増加列の長さをもとめる
    let mut count = 1;
    let mut len = 0;
    for i in 2..n + 1 {
        let i = i as usize;
        if p[i - 1] < p[i] {
            count = count + 1;
        } else {
            len = max(len, count);
            count = 1;
        }
    }
    len = max(len, count);
    let ans = n - len;
    println!("{}", ans);
}


Measured memory_bytes: 6396