akhauriyash/Code-Regression huggingface dataset:
n=int(input())
alpha=[chr(i) for i in range(97, 97+26)]
d={i:[{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}] for i in alpha}
ans=0
for _ in range(n):
    s=input()
    if s not in d[s[0]][len(s)-1]:
        d[s[0]][len(s)-1]|={s}
        ans+=1
print(ans)

Measured memory_bytes: 29132
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


S = read()[:-1]

flg1, flg2 = False, False

first = int(S[:2])
last = int(S[2:])

# print(first, last)
if 0 < first < 13:
    flg1 = True

if 0 < last < 13:
    flg2 = True

if flg1 and flg2:
    print('AMBIGUOUS')

if flg1 and not flg2:
    print('MMYY')

if flg2 and not flg1:
    print('YYMM')

if not flg2 and not flg1:
    print('NA')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  string s;
  cin >> s;
  
  if(s.at(0) == 'S'){
    cout << "Cloudy" << endl;
  }
  else if(s.at(0) == 'C'){
    cout << "Rainy" << endl;
  }
  else{
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <tuple>
#include <map>
#include <cmath>
#include <numeric>
#include <utility>
#include <sstream>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef pair<ll, ll> Pl;
typedef tuple<ll, ll, ll> Tl;

ll d[18];
ll dd[18];
ll f[18];
void init() {
	f[0] = 1;
	for (int i = 1; i < 18; i++) {
		f[i] = f[i-1]*10;
	}
	d[0] = 0;
	for (int i = 1; i < 18; i++) {
		ll u = f[i];
		d[i] = (u-1)-(u-1)/3-(u-1)/5+(u-1)/15;
		for (int j = 0; j < i; j++) {
			d[i] -= d[j];
		}
	}
	dd[0] = 0;
	for (int i = 1; i < 18; i++) {
		dd[i] = dd[i-1];
		dd[i] += d[i]*i;
	}
	for (int i = 1; i < 18; i++) {
		dd[i] += ((f[i]-1)/3+(f[i]-1)/5)*4;
	//	cout << dd[i] << endl;
	}
}

ll solve(ll md) {
	int nn = 0;
	while (f[nn] <= md) nn++;
	nn--;
	ll r = dd[nn];
	ll s1 = (md-1)/3+(md-1)/5;
	s1 -= (f[nn]-1)/3+(f[nn]-1)/5;
	r += s1*4;
	r += (md-f[nn]-s1+(md-1)/15-(f[nn]-1)/15)*(nn+1);
	return r;
}

//int main() {
string so(ll s) {
	s--;
	init();
	ll l = 1, r = 1e17;
	while (r - l > 1) {
		ll md = (l+r)/2;
		if (solve(md) <= s) {
			l = md;
		} else {
			r = md;
		}
	}
	ll u = s-solve(l);
	string res;
	for (ll i = l; i < l+100; i++) {
		bool f = false;
		if (!(i%3)) {
			f = true;
			res += "Fizz";
		}
		if (!(i%5)) {
			f = true;
			res += "Buzz";
		}
		if (!f) {
			stringstream ss;string t;ss << i;ss >> t;
			res += t;
		}
	}
	return res.substr(u, 20);
}

int main() {
	ll s;
	cin >> s;
	cout << so(s) << endl;
}

Measured memory_bytes: 1228
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 int N;
 int tmp_h,max_h;
 int res=0;
 vector<int> h;
 scanf("%d",&N);
 for(int i=0;i<N;i++){
   scanf("%d",&tmp_h);
   h.push_back(tmp_h);
 }

  max_h=*max_element(h.begin(),h.end());
//  printf("%d\n",max_h);
  for(int i=0;i<max_h;i++){
/*    printf("%d>>",res);
	for(int j:h)
      printf("%d ",j);
    printf("\n");*/
    if(h[0]>0)
      res++;
    for(int j=0;j<N-1;j++){
      if(h[j]==0 && h[j+1]>0)
        res++;
      if(h[j]>0)
        h[j]--;
    }
    if(h[N-1]>0)
      h[N-1]--;
  }
  printf("%d\n",res);

 h.clear();
 return 0;
}

Measured memory_bytes: 256
S = input()
S = S.split()
N = int(S[0])
K = int(S[1])
h = [int(input()) for i in range(N)]
h.sort()
ans = 10**9 + 1
for i in range(N - K + 1):
    tmp = h[i + K - 1] - h[i]
    if(tmp < ans):
        ans = tmp
print(ans)


Measured memory_bytes: 7384
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

using namespace std;

int main(){
	
	int N, M;
	cin >> N >> M;
	
	double L[50], a[50], b[50];
	double cost[50][50];
	
	for(int i = 0; i < N; i++){
		cin >> L[i] >> a[i] >> b[i];
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			double dL = (L[i] - L[j]);
			double da = (a[i] - a[j]);
			double db = (b[i] - b[j]);
			cost[i][j] = dL * dL + da * da + db * db;
		}
	}
	
	double DP[(1 << N)] = {};
	double ans = 0;
	
	for(int i = 0; i < (1 << N); i++){
		DP[i] = 0;
		int cnt = 0;
		for(int j = 0; j < N; j++){
			if(i & (1 << j)){
				int hoge = i - (1 << j);
				DP[i] = DP[hoge];
				for(int k = j; k < N; k++){
					if(hoge & (1 << k)){
						DP[i] += cost[j][k];
					}
				}
				break;
			}
		}
		for(int j = 0; j < N; j++){
			if(i & (1 << j)){
				cnt++;
			}
		}
		if(cnt == M){
			ans = max(ans, DP[i]);
		}
	}
	
	printf("%.10f\n", ans);
	
	return 0;
}


Measured memory_bytes: 11496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		String s = scan.next();
		if(a >= 3200) {
			System.out.println(s);
		}else if(a <3200) {
			System.out.println("red");
		}
	}
}

Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long N = n;
		int m = sc.nextInt();
		UnionFind uf = new UnionFind(n);
		int[][] ab = new int[2][m];
		for (int i = 0; i < m; i++) {
			ab[0][i] = Integer.parseInt(sc.next())-1;
			ab[1][i] = Integer.parseInt(sc.next())-1;
		}
		StringBuilder sb = new StringBuilder();
		long[] answer = new long[m];
		long ans = N*(N-1)/2;
		//sb.insert(0,"\n");
		//sb.insert(0, ans);
		answer[m-1] = ans;
		for (int i = m-1; i >= 1; i--) {
			if(!uf.same(ab[0][i], ab[1][i])) {
				ans -= (long)uf.amount(ab[0][i])*(long)uf.amount(ab[1][i]);
			}
			uf.unite(ab[0][i], ab[1][i]);
			//sb.insert(0,"\n");
			//sb.insert(0, ans);
			answer[i-1] = ans;
		}
		for (int i = 0; i < m; i++) {
			sb.append(answer[i]);
			sb.append("\n");
		}
		System.out.println(new String(sb));
		sc.close();
	}
	public static class UnionFind {

		int par[]; int rank[]; int size[]; int count;

		public UnionFind(int n) {
			this.par = new int[n];
			this.rank = new int[n];
			this.size = new int[n];
			this.count = n;
			for(int i = 0; i < n; i++) {
				par[i] = i; rank[i] = 0; size[i] = 1;
			}
		}

		int find(int x) {//xの属する集合の根を探す
			if(par[x] == x) return x;
			else return par[x] = find(par[x]);
		}

		void unite(int x, int y) {//x,yの集合を合併
			x = find(x);
			y = find(y);
			if(x == y) return ;
			if(rank[x] < rank[y]) {
				par[x] = y;
				size[y] += size[x];
			}else {
				par[y] = x;
				size[x] += size[y];
				if(rank[x] == rank[y]) {
					rank[x]++;
				}
			}
			count--;
		}

		boolean same(int x, int y) {//x,yが同じ集合に属するか
			return find(x) == find(y);
		}

		int amount(int x) {//xの属する集合の要素数
			return size[par[x]];
		}

		int count() {//集合の数
			return count;
		}
	}
}

Measured memory_bytes: 63836
import sys
input = sys.stdin.readline

class SegmentTree():
    def __init__(self,arr,func=min,ie=2**63):
        self.n = 2**(len(arr)-1).bit_length()
        self.ie = ie
        self.func = func
        self.tree = [ie for _ in range(2*self.n)]
        for i in range(len(arr)):
            self.tree[self.n+i-1] = arr[i]
        for i in range(self.n-1)[::-1]:
            self.tree[i] = func(self.tree[2*i+1],self.tree[2*i+2])
    def update(self,index,x):
        index += self.n-1
        self.tree[index] = x
        while index>0:
            index = (index-1)//2
            self.tree[index] = self.func(self.tree[2*index+1],self.tree[2*index+2])
    def query(self,left,right): #開区間！
        if right <= left:
            return self.ie
        left += self.n-1
        right += self.n-2
        res = self.ie
        while right-left > 1:
            if left & 1 == 0:
                res = self.func(res,self.tree[left])
            if right & 1 == 1:
                res = self.func(res,self.tree[right])
                right -= 1
            left = left//2
            right = (right-1)//2
        if left == right:
            res = self.func(res,self.tree[left])
        else:
            res = self.func(self.func(res,self.tree[left]),self.tree[right])
        return res

N,Q = map(int,input().split())
A = [0 for _ in range(N)]

st = SegmentTree(A,lambda x,y:x+y,0)
ans = []

for _ in range(Q):
    com,x,y = map(int,input().split())
    if com == 0:
        st.update(x-1,st.query(x-1,x)+y)
    else:
        ans.append(st.query(x-1,y))

print(*ans,sep='\n')


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

void main_()
{
    ll N;
    cin >> N;

    vector<bitset<10>> Fs(N);
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < 10; j++) {
            ll F;
            cin >> F;
            Fs[i].set(j, F);
        }
    }

    vector<vector<ll>> Ps(N, vector<ll>(11));
    for (ll i = 0; i < N; i++) {
        copy_n(istream_iterator<ll>(cin), 11, begin(Ps[i]));
    }

    ll ans = -(1e9 + 7);
    for (ll i = 1; i < (1 << 10); i++) {
        bitset<10> open_bs(i);
        ll venefit = 0;
        for (ll j = 0; j < N; j++) {
            ll c = (Fs[j] & open_bs).count();
            venefit += Ps[j][c];
        }
        ans = max(ans, venefit);
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	string S = res();
	string T = "keyence";
	int c = 0;
	for(int i=0;i<7;i++){
		if(S[i] == T[i]){
			c++;
		}
		else{
			break;
		}
	}
	for(int i=0;i<7;i++){
		if(S[S.length()-1-i] == T[T.length()-1-i]){
			c++;
		}
		else{
			break;
		}
	}
	if(c >= 7){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int n; cin >> n;
    ll x; cin >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    _rep(i, 1, n){
        if(a[i - 1] > x){
            ans += a[i - 1] - x;
            ans += a[i];
            a[i] = 0;
        }else if(a[i - 1] + a[i] > x){
            ans += (a[i - 1] + a[i] - x);
            a[i] = x - a[i - 1];
        }
    }
    cout << ans << endl;
}

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

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

    string S;
    int Q;
    cin >> S >> Q;
    bool reverseFlg = false;

    for(int i = 0; i < Q; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            reverseFlg = !reverseFlg;
        } else {
            int f;
            string c;
            cin >> f >> c;
            if(f == 1 ) {
                if(reverseFlg == false) {
                    S.insert(0, c);
                }else {
                    S.append(c);
                }
            } else {
                if(reverseFlg == false){
                    S.append(c);
                }
                else{
                    S.insert(0, c);
                }
            }
        }
    }
    if(reverseFlg) {
        std::reverse(S.begin(), S.end());
    }
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 912
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M; int K; cin >> K;
    bool data[N][M];
    F0R(i, N) F0R(j, M) {
        char C; cin >> C; data[i][j] = C == '1';
    }
 
    int ans = N*M+1;
    F0R(mask, (1 << (N-1))) {
        vi comps;
        comps.pb(0);
        F0R(i, N-1) {
            if (mask & (1 << i)) comps.pb(i+1);
        }
        comps.pb(N);
        int cur = sz(comps) - 2;
        int sum[sz(comps) - 1]; F0R(i, sz(comps) - 1) sum[i] = 0;
        F0R(j, M) {
            int add[sz(comps) - 1]; F0R(i, sz(comps) - 1) add[i] = 0;
            F0R(c, sz(comps) - 1) {
                FOR(i, comps[c], comps[c+1]) {
                    if (data[i][j]) add[c]++;
                }
            }
            F0R(i, sz(comps) - 1) {
                if (add[i] > K) goto bad;
            }
            F0R(i, sz(comps) - 1) {
                if (add[i]+sum[i] > K) {
                    F0R(c, sz(comps) - 1) {
                        sum[c] = 0;
                    }
                    cur++;
                    goto done;
                }
            }
 
            done:
            ;
            F0R(i, sz(comps) - 1) sum[i] += add[i];
        }
        ans = min(ans, cur);
        bad:
        ;
    }
 
    cout << ans << endl;
	
	return 0;
}

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

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

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

int solve(int a, int k){
    while(a%k && a >= k){
        int d = (a+k-1)/k;
        int to = a/k*k;
        a = to-((to-a)%d+d)%d;
    }
    return a/k;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a, k;
        cin >> a >> k;
        ans ^= solve(a, k);
    }
    puts(ans ? "Takahashi" : "Aoki");
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
NPM = [[0] * 3 for _ in range(M)]
for i in range(M):
    p, m = map(int, input().split())
    NPM[i][0] = i
    NPM[i][1] = p
    NPM[i][2] = m

NPM.sort(key = lambda x:(x[2]))

##print(NPM)
city_num = [0] * N
ans_list = [""] * M
for i in range(M):
    city_num[NPM[i][1]-1] += 1

    ans_list[NPM[i][0]] = "{:0>6}{:0>6}".format(NPM[i][1], city_num[NPM[i][1]-1])

for i in range(M):
    print(ans_list[i])

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

int main(){
    int n, tot;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    tot = 0;
    rep(i,n){
        tot += a[i];
    }
    int mn;
    if(((float)tot/(float)n - tot/n) >=0.5)mn = tot/n +1;
    else mn = tot/n;
    int rel = 0;
    rep(i,n){
        rel += pow((a[i] - mn),2);
    }
    cout << rel << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n, a[110];
int main() {
  cin >> n;
  for (int i=0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  int counter = 0;
  for (int i=0; i < n; ++i) {
    if (a[i] != a[i-1]) ++counter;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int x = 0;
  int ans = 0;
  rep(i, N) {
    if (S[i] == 'I')
      x++;
    else
      x--;
    chmax(ans, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import heapq

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
A=input_array()
sortA=sorted(A,reverse=True) #降順にソート

ans=0
q=[]
heapq.heappush(q,-sortA[0])

for i in range(1,n):
	tmp=heapq.heappop(q)
	tmp*=-1
	ans+=tmp
	heapq.heappush(q,-sortA[i])
	heapq.heappush(q,-sortA[i])
print(ans)

Measured memory_bytes: 31728
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  cout<<min(A,B)+min(C,D)<<endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;

int n, k;
string s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s >> k >> s;
	s[--k] += ('a' - 'A');
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)
 
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
 
int dp[2005][2];
 
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n, Z, W;
    cin >> n >> Z >> W;
    VI V(n+1);
    FOR(i, 1, n) {
        cin >> V[i];
    }
    if (n == 1) {
        cout << abs(V[1] - W) << endl;
    } else if (n == 2) {
        cout << max(abs(V[n] - W), abs(V[n] - V[n - 1])) << endl;
    } else {
        dp[n - 1][0] = abs(V[n] - V[n - 1]);
        dp[n - 1][1] = dp[n - 1][0];
        int mn = dp[n - 1][0];
        int mx = dp[n - 1][0];
        int ans = dp[n - 1][0];
        // dp[n - 2][1] = max(abs(V[n] - V[n - 2]), dp[n - 1][0]);
        for (int i = n - 2; i >= 1; i--) {
            // int mx = 0;
            // for (int j = i + 1; j <= n - 1; j++) {
            //     mx = max(mx, dp[j][0]);
            // }
            dp[i][1] = max(mx, abs(V[n] - V[i]));
            mx = max(dp[i][1], mx);
            // int mn = INT_MAX;
            // for (int j = i + 1; j <= n - 1; j++) {
                // mn = min(mn, dp[j][1]);
            // }
            dp[i][0] = min(mn, abs(V[n] - V[i]));
            mn = min(mn, dp[i][0]);
            ans = max(ans, dp[i][0]);
        }
        // for (int i = 1; i < n; i++) {
        //     cout << dp[i][0] <<" "<<  dp[i][1] << endl;
        // }
        // int ans = 0;
        // for (int i = 1; i < n; i++) {
        //     ans = max(ans, dp[i][0]);
        // }
        cout << max(abs(V[n] - W), ans) << endl;
    }
}

Measured memory_bytes: 256
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int n, m;

int main() {
  init_ios();
  cin >> n >> m;
  cout<<n*(n-1)/2+m*(m-1)/2<<"\n";
}

Measured memory_bytes: 892
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think('ASSA'), 'Yes')

    def test_2(self):
        self.assertEqual(think('STOP'), 'No')

    def test_3(self):
        self.assertEqual(think('FFEE'), 'Yes')

    def test_4(self):
        self.assertEqual(think('FREE'), 'No')


def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    length_of_string = 4
    return read_line(n=length_of_string)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    for i in range(len(s)):
        if s.count(s[i]) == 2:
            continue
        else:
            return 'No'
    return 'Yes'


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  double w,h,x,y;
  cin>>w>>h>>x>>y;
  cout<<w*h/2<<" ";
  if(w/2==x&&h/2==y){
    cout<<1;
  }else{
    cout<<0;
  }
}

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

int main(){
  vector<string> s(3);
  rep(i,3) cin >> s[i];
  vector<int> index(3,0);
  int temp = 0;
  
  while(1){
    temp = s[temp][index[temp]++] - 'a';
    if(index[temp] >= s[temp].size()){
      cout << char('A' + temp) << endl;
      break;
    }
    
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;


struct UnionFind {
    vector<int> parent;
    UnionFind (int n) : parent(n) {
        for(int i = 0; i < n; i++) parent[i] = i;
    }
 
    int root (int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }
 
    void unite (int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
    }
 
    bool same_root(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    
    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        UnionFind tree(n);
        for (int j = 0; j < m; j++)
        {
            if (i==j) continue;
            tree.unite(a[j], b[j]);
        }
        if (!tree.same_root(a[i], b[i])) ans++;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 5005;

int a[maxn],n,m;
bool L[maxn][maxn],R[maxn][maxn];

int main() {
//  freopen("in.cpp","r",stdin);
  cin>>n>>m;
  for(int i=1; i<=n; i++)cin>>a[i];
  L[0][0]=1;
  for(int i=0; i<n; i++)
    for(int j=0; j<=m; j++) {
      if(!L[i][j])continue;
      L[i+1][j]=1;
      int nj=min(j+a[i+1],m);
      L[i+1][nj]=1;
    }
  R[n+1][0]=1;
  for(int i=n+1; i>1; i--)
    for(int j=0; j<=m; j++) {
      if(!R[i][j])continue;
      R[i-1][j]=1;
      int nj=min(j+a[i-1],m);
      R[i-1][nj]=1;
    }
  int ret=0;
  for(int i=1; i<=n; i++) {
    int mx = 0,r=-1;
    bool sign=0;
    for(int j=m-1;j>=0;j--){
      if(!R[i+1][j])continue;
      while(r+1+j<m){
        if(L[i-1][r+1])mx=r+1;
        r++;
      }
      if(mx!=-1&&mx+j<m&&mx+j+a[i]>=m){
        sign=1;
        break;
      }
    }
    if(sign)ret++;
  }
  cout<<n-ret<<endl;
  return 0;
}


Measured memory_bytes: 49152
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;
void TxtRead(){
    freopen("sleepy.in","r", stdin);
    freopen("sleepy.out","w", stdout);
}
void TheTime(){
    ios_base::sync_with_stdio(false);
	cin.tie();
}
const int N = 405;
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793116;

int n;
ll sum[N], dp[N][N];

int main()
{
    //TxtRead();
    TheTime();
		
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		ll a;
		scanf("%lld", &a);
		sum[i]=sum[i-1]+a;
	}
	
  	memset(dp, '?', sizeof(dp));
	for(int l=n; l>=1; l--){
		for(int r=l; r<=n; r++){
			if(l==r) dp[l][r]=0;
			else for(int i=l; i<r; i++){
				dp[l][r]=min(dp[l][r], dp[l][i]+dp[i+1][r]
										  +sum[r]-sum[l-1]);
			}
		}
	}
  
	printf("%lld", dp[1][n]);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ld n , d;
vector<vector<ld>> x(n,vector<ld>(d));

int main(){
    ll n ; cin >> n;
    ll left = 0, right = 1000000;
    ll center = (left+right)/2;
    while(right - left != 1){
        if(center*(center+1)>=2*n){
            right = center;
        }else{
            left = center;
        }
        center = (left+right)/2;
    }
    for(int i=1;i<=right;i++){
        if(i == right*(right+1)/2 - n) continue;
        cout << i << endl;
    }
    return 0;
}

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

int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+') {
        cout << a + b << endl;
    }
    else {
        cout << a - b << endl;
    }
}


Measured memory_bytes: 3600
class dice:
    def __init__(self,label):
        self.label = {i+1: l for i,l in enumerate(label)}
    def roll(self,op):
        l = self.label
        if   op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
        elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
        elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
        elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
    def yaw(self,op):
        l = self.label
        if   op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
        elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
    def get_label(self,i=0):
        if 1 <= i <= 6:
            return self.label[i]
        else:
            return [self.label[x] for x in range(1,7)] 

def cmp_dice(d0,d1):
    dc = dice(d0.get_label())
    d1_l = d1.get_label()
    result=False
    if set(dc.get_label())==set(d1_l):
        for i in range(6):
            for _ in range(4):
                if dc.get_label()==d1_l:
                    result=True
                    break
                dc.yaw('CW')
            if dc.get_label()==d1_l:
                break
            if i < 4:
                dc.roll('E')
            if i >= 3:
                dc.roll('N')
            if i >= 4:
                dc.roll('N')
    return result

if __name__ == '__main__':
    import itertools
    d_grp={}
    for _ in range(int(input())):
        d = dice(list(map(int, input().split())))
        d_set = tuple(set(d.get_label()))
        if d_set in d_grp:
            d_grp[d_set].append(d)
        else:
            d_grp[d_set]=[d]
    result='Yes'
    for d_list in d_grp.values():
        for dx, dy in itertools.combinations(d_list,2):
            if cmp_dice(dx,dy):
                result='No'
                break
    print(result)

Measured memory_bytes: 7948
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
gcd = lambda a:functools.reduce(fractions.gcd,a)

def solution():
    N,X = input_ints()
    Xs = input_ints()

    diffs = [abs(X-int(x)) for x in Xs]
    ans = gcd(diffs)
    print(ans)

if __name__ == '__main__':
    solution()

Measured memory_bytes: 16304
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,k,ans,len,b[N],tree[N*4],lazy[N*4];
char s[N];
struct node{
	int x,y;
}a[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
bool cmp(node a,node b)
{
	return a.x<b.x;
}
void pushdown(int nod,int l,int r)
{
	int mid=(l+r)/2;
	tree[nod*2]+=(mid-l+1)*lazy[nod];
	tree[nod*2+1]+=(r-mid)*lazy[nod];
	lazy[nod*2]+=lazy[nod];
	lazy[nod*2+1]+=lazy[nod];
	lazy[nod]=0;	
}
void change(int nod,int l,int r,int L,int R,int val)
{
	if(l==L&&r==R)
	{
		tree[nod]+=(r-l+1)*val;
		lazy[nod]+=val;
		return;
	}
	pushdown(nod,l,r);
	int mid=(l+r)/2;
	if(R<=mid)change(nod*2,l,mid,L,R,val);
	else if(L>mid)change(nod*2+1,mid+1,r,L,R,val);
	else{
		change(nod*2,l,mid,L,mid,val);
		change(nod*2+1,mid+1,r,mid+1,R,val);
	}
}
int find(int nod,int l,int r,int x)
{
	if(l==r)return tree[nod];
	pushdown(nod,l,r);
	int mid=(l+r)/2;
	if(x<=mid)return find(nod*2,l,mid,x);
	else return find(nod*2+1,mid+1,r,x);
}
signed main()
{
	n=read();m=read();k=read();
	for(int i=1;i<=n;i++)
	{
		a[i].x=read();
		b[++len]=a[i].x;
		b[++len]=a[i].x+m;
		b[++len]=a[i].x+m+m;
		a[i].y=read();
		a[i].y=a[i].y/k+(a[i].y%k>0);
	}
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+len+1);
	len=unique(b+1,b+len+1)-b-1;
	for(int i=1;i<=n;i++)
		a[i].x=lower_bound(b+1,b+len+1,a[i].x)-b;
	for(int i=1;i<=n;i++)
	{
		if(find(1,1,len,a[i].x)>=a[i].y)continue;
		int xu=a[i].y-find(1,1,len,a[i].x);
		int x=b[a[i].x]+m,y=x+m;
		x=lower_bound(b+1,b+len+1,x)-b;
		y=lower_bound(b+1,b+len+1,y)-b;
		ans+=xu;
		change(1,1,len,a[i].x,y,xu);
	}
	cout<<ans;
	return 0;
}

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

int main() {
    int n, k, q;
    scanf("%d %d %d", &n, &k, &q);
    vector<int> change(n+5, 0);
    for (int i=0; i<q; i++) {
        int a;
        scanf("%d", &a);
        change[1]--;
        change[a]++;
        change[a+1]--;
        change[n+1]++; 
    }
    for (int i=1; i<=n+1; i++) {
        change[i] += change[i-1];
    }
    vector<int> init(n+5, k);

    for (int i=1; i<=n; i++) {
        init[i] = init[i] + change[i];
    }
    for (int i=1; i<=n; i++) {
        // printf ("%d ", init[i]);
        if (init[i]<=0) {
            printf("No\n");
        } else {
            printf("Yes\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(){
  long m,n,cnt=0,i,j;
  scanf("%ld %ld",&n,&m);
  if(m==2||n==2) cnt=0;
  else if(m==1&&n==1) cnt=1;
  else if(m==1||n==1) cnt=m*n-2;
  else cnt=m*n-(m+n-2)*2;
  printf("%ld\n",cnt);
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
public class Main{
  static ArrayList<Integer> primes = new ArrayList<Integer>();
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
     sieve(3161);
      PrintWriter out = new PrintWriter(System.out);
      int n = Integer.parseInt(st.nextToken());
      long ans = 1;
     div = new int[n+1];
     div[1] = 1;
     for(int i = 2; i <= n; i++)
       ans += solve(i);
     out.println(ans);
      out.close();
   }
  static void sieve(int n){
    boolean prime[] = new boolean[n+1];
    for(int i = 0; i < n; i++)
      prime[i] = true;
    for(int p = 2; p*p <= n; p++){
      if(prime[p]){
        for(int i = p*p; i <= n; i+= p)
          prime[i] = false;
      }
    }
    for(int i = 2; i <= n; i++){
      if(prime[i])
        primes.add(i);
    }
  }
  static int[] div;
  static long solve(int n){
    int p = 0;
    for(int prime:primes){
      if(n%prime == 0){
        p = prime;
      	break;
      }
    }
    if(p == 0){
      div[n] = 2;
      return (long)2*n;
    }
    else{
      int help = n/p;
      if(help%p == 0)
        div[n] = 2*div[help] - div[help/p];
      else
        div[n] = 2*div[help];
      return (long)div[n]*n;
    }
  }
}

Measured memory_bytes: 74316
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
  cin>>n>>k;
  int vis[n]={0};
  for(i=0;i<k;i++)
  {
   cin>>j;
    for(int x=0;x<j;x++)
    {
     	int p;
      	cin>>p;
      	vis[p-1]++;
    }
  }
  ll c=0;
  for(i=0;i<n;i++)
  {
    if(vis[i]==0)
	c++;
  }	
  cout<<c;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3652
n = int(input())
_A = list(map(int, input().split()))
ans = 1000
A = [_A[0]]
B = []

for i in range(n-1):
  if (_A[i] != _A[i + 1]):
    A.append(_A[i+1])

flag = 0
if(len(A) < 2):
  print(ans)
  exit()
for i in range(len(A)-1):
  if (flag == 0 and A[i] < A[i + 1]):
    flag = 1
    B.append(A[i])
  elif (flag == 1 and A[i] > A[i + 1]):
    flag = 0
    B.append(A[i])
if((A[-1] > A[-2] and flag == 1) or (A[-1] < A[-2] and flag == 0)):
  B.append(A[-1])
if(len(B) < 2):
  print(ans)
  exit()
if(B[-1] < B[-2]):
  B.pop(-1)

stock = 0
for i,b in enumerate(B):
  if(i % 2 == 0):
    stock = ans // b
    ans = ans % b
  else:
    ans = ans + stock * b
    stock = 0

print(ans)

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int> > mat(n, vector<int>(m));
  vector<int> vec(m);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> mat.at(i).at(j);
    }
  }
  
  for(int i = 0; i < m; i++){
    cin >> vec.at(i);
  }

  for(int i = 0; i < n; i++){
    int sum = 0;
    for(int j = 0; j < m; j++){
      sum += mat.at(i).at(j) * vec.at(j);
    }

    cout << sum << endl;
  }
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i = 0; i<n; i++) cin>>a[i];
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	int res = 0;
	for(int i = 0; i<n ; i++){
		if(i%2==0) res+=a[i];
		else res-=a[i];
		}
	cout<<res;
	return 0;
	}


Measured memory_bytes: 256
require 'matrix'

N, D = gets.split.map(&:to_i)

x = N.times.map { gets.split.map(&:to_i) }

ans = 0

N.times do |i|
  N.times do |j|
    next unless i <  j
    d = ( Vector.elements(x[i]) - Vector.elements(x[j]) )
    t = d.map{ |i|  i**2 }.inject(:+)
    ans += 1 if 0 == t - (Math.sqrt(t).floor ) ** 2
  end
end

puts ans

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename L, typename R>
ostream& operator<<(ostream& out, const pair<L, R>& p) {
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}

template <typename L, typename R>
istream& operator>>(istream& in, pair<L, R>& p) {
    in >> p.first >> p.second;
    return in;
}

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;     \
    cin >> name;
#define VL(name, num) \
    vl name(num);     \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

int main() { cin.sync_with_stdio(0);
    LL(A); LL(B);
    cout << A*B << endl;
}  // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0 && w==0)    break;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if((i+j)%2) cout<<".";
                else    cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

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

	ll H, W;

	cin >> H >> W;
	if (H != 1 && W != 1) cout << ((H * W) + 1) / 2 << "\n";
	else cout << "1\n";

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	g := make([][]bool, n)
	for i := 0; i < n; i++ {
		g[i] = make([]bool, n)
	}
	var a, b int
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		a--
		b--
		g[a][b], g[b][a] = true, true
	}

	res := solve(n, g)
	fmt.Println(res)
}

func solve(n int, g [][]bool) int {
	visited := make([]bool, n)

	var dfs func(a int) int
	dfs = func(a int) int {
		ok := true
		for _, v := range visited {
			if !v {
				ok = false
				break
			}
		}
		if ok {
			return 1
		}

		c := 0
		for b := 0; b < n; b++ {
			if g[a][b] && !visited[b] {
				visited[b] = true
				c += dfs(b)
				visited[b] = false
			}
		}

		return c
	}

	visited[0] = true
	return dfs(0)
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


int H, W;
int h, w;

int main()
{
	scanf("%d%d", &H, &W);
	scanf("%d%d", &h, &w);
	
	int rh, rw;
	rh = H - h;
	rw = W - w;
	int area = rh * rw;
	printf("%d\n", area);
	
	return 0;
}



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

int main()
{
    int N, M;
    while (true)
    {
      cin >> N >> M;
      if (N == 0 && M == 0)
      {
        break;
      }
      vector<int> C(M);
      vector<int> X(N);
      for (int i = 0; i < M; ++i)
      {
        cin >> C.at(i);
      }
      for (int i = 0; i < N; ++i)
      {
        cin >> X.at(i);
      }

      vector<vector<int>> dp(N + 1, vector<int>(256, INF));
      dp.at(0).at(128) = 0;
      for (int i = 0; i < N; ++i)
      {
        for (int j = 0; j < 256; ++j)
        {
          if (dp.at(i).at(j) == INF)
          {
            continue;
          }
          int dp_ij = dp.at(i).at(j);
          for (int k = 0; k < M; ++k)
          {
            int next_j = max(0, min(j + C.at(k), 255));
            dp.at(i + 1).at(next_j) = min(dp.at(i + 1).at(next_j), dp.at(i).at(j) + int(pow(X.at(i) - next_j, 2.0)));
          }
        }
      }
      int ans = INF;
      for (int i = 0; i < 256; ++i)
      {
        if (dp.at(N).at(i) == INF)
        {
          continue;
        }
        ans = min(dp.at(N).at(i), ans);
      }
      cout << ans << endl;
    }
}



Measured memory_bytes: 23808
#include<iostream>
using namespace std;
int main(){

	int a[4][3][10];
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 10; k++){
				a[i][j][k] = 0;
			}
		}
	}
			int n;
			cin >> n;
			for (int l = 0; l < n; l++){
				int b, f, r, v;
				cin >> b >> f >> r >> v;
				a[b-1][f-1][r-1] += v;
			}
			for (int i = 0; i < 4; i++){
				for (int j = 0; j < 3; j++){
					for (int k = 0; k < 10; k++){
						cout <<" "<< a[i][j][k];
					}
					cout << endl;
				}
		if(i!=3)		cout << "####################" << endl;
			}
		}


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

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String r = br.readLine();
            String[] in = r.split(" ");
            int a = Integer.parseInt(in[0]);
            int b = Integer.parseInt(in[1]);
            String ans = a == b ? "a == b" : a > b ? "a > b" : "a < b";
            System.out.println(ans);
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24228
N = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in range(1,N+1)]
count = 0
for i in range(N):
  if p[i] == q[i]:
    continue
  else:
    count += 1
if count <= 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
use std::cmp;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::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();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let (n, t) = get!(i64, i64);
    let mut ans: i64 = 10000;
    for _ in 0..n {
        let (c, ti) = get!(i64, i64);
        if ti <= t && c < ans {
            ans = c;
        }
    }
    if ans < 10000 {
        println!("{}", ans);
    } else {
        println!("TLE");
    }
}


Measured memory_bytes: 4352
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 +f(N-1, X-2-a[N-1])

print(f(N, X))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <queue>

using namespace std;

int main() {
    long long int N, M;
    cin >> N >> M;
    vector<vector<pair<int, long long int> > > E(N+1);
    vector<long long int> in_num(N+1, 0);
    for(int m=0; m<M; m++) {
        int l, r;
        long long int d;
        cin >> l >> r >> d;
        E[l].push_back(make_pair(r, d));
        in_num[r]++;
    }
    
    map<int, long long int> mp;
    queue<int> que;
    for(int n=1; n<=N; n++) {
        if(in_num[n]==(long long int)0) {
            mp[n] = (long long int)0;
            que.push(n);
        }
    }

    bool flag=true;
    while(!que.empty()) {
        int cur=que.front(); que.pop();
        for(int i=0; i<E[cur].size(); i++) {
            if(mp.count(E[cur][i].first)) {
                if(mp[E[cur][i].first]!=mp[cur]+E[cur][i].second) {
                    flag=false;
                    break;
                }
            } else {
                mp[E[cur][i].first] = mp[cur]+E[cur][i].second;
                que.push(E[cur][i].first);
            }
        }
        if(!flag) break;
    }
    
    
    if(flag && mp.size()==N) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



    return 0;
    
}

Measured memory_bytes: 14720