akhauriyash/Code-Regression huggingface dataset:
use std::collections::{BTreeMap, BinaryHeap};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner(s.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();

    let mut edges = vec![vec![]; n];
    for _ in 0..m {
        let l: usize = sc.read::<usize>() - 1;
        let r: usize = sc.read::<usize>() - 1;
        let c: i64 = sc.read();
        edges[l].push((r, c));
    }

    //    eprintln!("{:?}", edges);
    let mut heap = BinaryHeap::new();
    heap.push((0, 0));
    for cur in 0..n {
        while let Some((c, v)) = heap.pop() {
            let z = (-v) as usize;
            if z >= cur {
                heap.push((c, v));
                break;
            }
        }
        if let Some(&(cost, v)) = heap.peek() {
            let v = (-v) as usize;
            let cur_cost = -cost;
            if v == n - 1 {
                println!("{}", cur_cost);
                return;
            }
            for &(next, cost) in edges[cur].iter() {
                let next_cost = cost + cur_cost;
                heap.push((-next_cost, -(next as i64)));
            }
        } else {
            println!("-1");
            return;
        }

        //        eprintln!("{:?}", heap);
    }
}

pub struct Scanner<R>(R);

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 14588
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		MDT = new int[16][16];
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 16; j++) {
				MDT[i][j] = Math.abs(i / 4 - j / 4) + Math.abs(i % 4 - j % 4);
			}
		}
		int[] a = new int[16];
		int zero = -1;
		for (int i = 0; i < 16; i++) {
			a[i] = scanner.nextInt();
			if (a[i] == 0)
				zero = i;
		}
		int md = getMD(a);
		Puzzle in = new Puzzle(a, zero, md);

		for (limit = in.md; limit <= 45; limit++) {
			puzzle = in.clone();
			if (dfs(0, -100)) {
				System.out.println(limit);
				break;
			}
		}

	}

	Puzzle puzzle;

	private boolean dfs(int depth, int s) {
		if (puzzle.md == 0)
			return true;
		if (puzzle.md + depth > limit)
			return false;

		int y = puzzle.zero / 4;
		int x = puzzle.zero % 4;
		for (int r = 0; r < 4; r++) {

			int ny = y + move[r][0];
			int nx = x + move[r][1];
			if (ny < 0 || 4 <= ny || nx < 0 || 4 <= nx)
				continue;
			if (Math.max(s, r) - Math.min(s, r) == 2)
				continue;
			int nz = ny * 4 + nx;
			Puzzle p = puzzle.clone();
			
			puzzle.md -= MDT[nz][puzzle.map[nz] - 1];
			puzzle.md += MDT[puzzle.zero][p.map[nz] - 1];
			swap(puzzle.map, puzzle.zero, nz);
			puzzle.zero = nz;
			if (dfs(depth + 1, r))
				return true;
			puzzle = p;

		}
		return false;

	}

	int limit;

	private void swap(int[] tmpMap, int zero, int nz) {
		int tmp = tmpMap[zero];
		tmpMap[zero] = tmpMap[nz];
		tmpMap[nz] = tmp;
	}

	int[][] move = { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };

	private int getMD(int[] a) {
		int sum = 0;
		for (int i = 0; i < 16; i++) {
			if (a[i] == 0)
				continue;
			sum += MDT[i][a[i] - 1];
		}
		return sum;
	}

	int[][] MDT;

	class Puzzle implements Cloneable {
		int[] map;
		int zero;
		int md;

		public Puzzle(int[] map, int zero, int md) {
			super();
			this.map = map;
			this.zero = zero;
			this.md = md;
		}

		@Override
		public Puzzle clone() {
			try {
				Puzzle clonePuzzle = (Puzzle) super.clone();
				clonePuzzle.map = Arrays.copyOf(this.map, 16);
				return clonePuzzle;
			} catch (CloneNotSupportedException e) {
				throw new InternalError();
			}
		}

		@Override
		public String toString() {
			return "Puzzle [map=" + Arrays.toString(map) + ", zero=" + zero
					+ ", md=" + md + "]";
		}

	}
}

Measured memory_bytes: 281040
from operator import itemgetter
N = input()
t = []
for i in range(N):
	s,p = raw_input().split()
	p2 = int(p)
	t.append([s,p2,i+1])
t2 = sorted(t,key = itemgetter(1), reverse = True)
t3 = sorted(t2,key = itemgetter(0))
for c in t3:
	print(c[2])

Measured memory_bytes: 2692
N = int(input())
S = ['0'] * N
for i in range(N):
    S[i] = input()
import collections
c = collections.Counter(S)
li = list(c.values())
ca = list(c.keys())
li.sort()
max = li[-1]
lia = []
for i in ca:
    if c[i] == max:
        lia.append(i)
lia.sort()
n = len(lia)
for i in range(n):
    print(lia[i])

Measured memory_bytes: 36452
def sumd(n):
    r=0
    while n:
        r+=n%10
        n=n//10
    return r

n,a,b=map(int,input().split())
counter=0
for i in range(n+1):
    r=sumd(i)
    # print(r)
    if r>=a and r<=b:
        counter+=i
print(counter)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int n;
	cin >> n;
	for (int a = 1;a <= 9;++a) {
		for (int b = 1;b <= 9;++b) {
			if (a * b == n) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  if(S==U){
    cout<<A-1<<" "<<B<<endl;
  }
  else{
    cout<<A<<" "<<B-1<<endl;
  }
}
  

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,cost=0;
	scanf("%d %d",&a,&b);
	if(a <= 5)
		cost = 0;
	if(a >= 6 && a <= 12)
		cost = b/2;
	if(a > 12)
		cost = b;
	printf("%d\n",cost);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String res = "Yes";
        
        if(N % 2 == 1){
            res = "No";
        }else{
            for(int i = 0;i < N / 2;i++){
                if(S.charAt(i) != S.charAt(N/2+i)){
                    res = "No";
                }
            }
            
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 22352
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <utility>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  int A[100001];
  REP(i,100001) A[i] = 0;
  REP(i,N){
    int num;
    cin >> num;
    A[num]+= 1;
  }
  int valid = 0;
  int even = 0;
  REP(i,100001){
    if(A[i] != 0){
      valid ++;
      if(A[i] % 2 == 0) even++;
    }
  }
  if(even % 2 == 0){
    cout << valid << endl;
  }else{
    cout << (valid - 1) << endl;
  }

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<string>> c(h, vector<string>(w));
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            c.at(i).at(j) = s[j];
        }
    }

    // 白と黒の総数
    int black_sum = 0;
    int white_sum = 0;

    rep(i, h) {
        rep(j, w) {
            // 黒
            if (c.at(i).at(j) == "#")
                black_sum += 1;
        }
    }
    white_sum += h * w - black_sum;

    int ans = 0;

    // 行と列の選び方は2^6 * 2^6通りある
    for (int bit_i = 0; bit_i < (1 << h); bit_i++) {
        for (int bit_j = 0; bit_j < (1 << w); bit_j++) {
            // 黒の数
            int count = 0;

            // 全てのi行j列目の要素について考える
            rep(column, h) {
                rep(row, w) {
                    // 片方でもbitが立っているなら含めない
                    if ((bit_i & (1 << column)) && (bit_j & (1 << row))) {
                        // 黒なら追加
                        if (c.at(column).at(row) == "#") {
                            count++;
                        }
                    }
                }
            }

            // 黒の数がkと等しければok
            if (count == k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
    char S[4][4];
    int i,j;
  
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        scanf("%c",&S[i][j]);
      }
    }
  
    printf("%c%c%c\n",S[0][0],S[1][1],S[2][2]);
  
    return 0;
}

Measured memory_bytes: 128
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 1;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n;
int t, q;

int main () {
    cin >> q;
    while(q--){
        llong a, b;
        cin >> a >> b;
        llong sq = sqrt(a * b);
        llong k = sq;
        if(sq * sq == a * b){
            sq --;
        }
        llong ans = sq * 2;
        if(sq != 0){
            if((a * b - 1) / sq == sq){
                ans--;
            }
        }
        if(a <= sq){
            ans--;
        }if(b <= sq){
            ans--;
        }
        cout << ans << nl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


union x_t
{
	long x[3];
	char y[12];
	bool operator<(const x_t&rhs) const
	{
		if(x[0]!=rhs.x[0]) return x[0]<rhs.x[0];
		if(x[1]!=rhs.x[1]) return x[1]<rhs.x[1];
		return x[2]<rhs.x[2];
	}
};

int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		x_t t;
		map<x_t,int> m;
		for(int i=0;i<n;i++)
		{
			scanf("%10s", t.y);
			sort(&t.y[0], &t.y[10]);

			auto it=m.find(t);
			if(it!=m.end())
			{
				it->second++;
			}
			else
			{
				m[t]=1;
			}
		}

		ll ans=0;
		for(auto&mm:m)
		{
//printf("[%s] %d\n", mm.first.y, mm.second);
			int x=mm.second;
			ans+=(ll)x*(x-1)/2;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ll long long
using namespace std;
int main()
{
    int l;
    cin>>l;
    double sum=(l*1.0/3)*(l*1.0/3)*(l*1.0/3);//*(l/3)*(l/3);
    printf("%.12f",sum);
    return 0;
}


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

const int N = 1e5 + 10;

vector <int> tr[N];
int a[N];
int ans, k;

int dfs(int x, int fa){
	int rec = -1;
	for (int i = 0; i < tr[x].size(); i++){
		if (tr[x][i] == fa) continue;
		rec = max(rec, dfs(tr[x][i], x));
	}
	rec++;
	if (x != 1 && rec == k - 1 && fa != 1){
		ans++;
		return -1;
	}
	return rec;
}

int main(){
	int n;
	scanf("%d %d",&n,&k);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	if (a[1] != 1) ans = 1;
	else ans = 0;
	for (int i = 2; i <= n; i++){
		tr[i].push_back(a[i]);
		tr[a[i]].push_back(i);
	}
	dfs(1, 0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12416
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int A[n];
    rep(i,n)cin>>A[i];
    int ans =0 ;
    rep(i,n-2){
        if((A[i]<A[i+1])!=(A[i+1]>A[i+2]))++ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Yes "Yes"
#define YES "YES"
#define No "No"
#define NO "NO"


const ll mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = x * p.x % mod; return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  friend mint operator+(const int &c,const mint &p) { return mint(c) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  friend mint operator-(const int &c,const mint &p) { return mint(c) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  friend mint operator*(const int &c,const mint &p) { return mint(c) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  friend mint operator/(const int &c,const mint &p) { return mint(c) /= p; }
  bool operator==(const mint &p) const { return x == p.x; }
  friend bool operator==(const int &c,const mint &p) { return mint(c) == p; }
  bool operator!=(const mint &p) const { return x != p.x; }
  friend bool operator!=(const int &c, const mint &p) { return mint(c) != p; }
  mint inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return mint(u);
  }
  mint pow(ll n) const {
    mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os,const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is,mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};


int main() {
  int N;
  cin >> N;
  vec<vec<mint>> dp(N,vec<mint>(3,0));
  dp[0][1] = 2;
  dp[0][2] = 8;
  rep1(i,N-1) {
    dp[i][0] = dp[i-1][0]*10 + dp[i-1][1];
    dp[i][1] = dp[i-1][1]*9 + dp[i-1][2]*2;
    dp[i][2] = dp[i-1][2]*8;
  }
  print(dp[N-1][0]);
  return 0;
}

Measured memory_bytes: 57812
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define vec1(V,T,a) vector<T> V (a)
#define vec2(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define vec3(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

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"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
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...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

  int N,M;
  cin >> N >> M;

  vec1(x,int,M);

  REP(i,M) cin >> x[i];

  if (N >= M) {
    cout << 0 << endl; return 0;
  }

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

  ll sum = 0;
  vec1(sub,int,M-1);
  REP(i,M-1) {
    sub[i] = x[i+1] - x[i];
    sum += sub[i];
  }
  sort(sub.begin(),sub.end(), greater<int>());
  REP(i,N-1) sum -= sub[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1001001001;
using namespace std;
vector<int> g[100005];
map<pair<int, int>, int> c;
int cc = 0;
void dfs(int n, int p, int pc) {
    int ref = 1;
    for(auto i: g[n]) {
        if (i == p) continue;
        if (ref == pc) ref++;
        c[make_pair(n, i)] = ref;
        c[make_pair(i, n)] = ref;
        dfs(i, n, ref);
        ref++;
    }
    chmax(cc, ref-1);
}

int main(){
    int N;
    cin >> N;
    int a[N], b[N];
    rep(i, N-1) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    dfs(0, -1, 0);
    cout << cc << endl;
    rep(i, N-1){
        cout << c[make_pair(a[i], b[i])] << endl;
    }

}

Measured memory_bytes: 20480
s = input()

N = 0
W = 0
S = 0
E = 0

for i in s:
    if i == "N":
        N += 1
    elif i == "W":
        W += 1
    elif i == "S":
        S += 1
    elif i == "E":
        E += 1

if (N == 0 and S > 0) or (N > 0 and S == 0) or (W > 0 and E == 0) or (W == 0 and E > 0):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	int n;
  int a[SIZE];
	//入力
  cin >> n;
  rep(i,n) cin >> a[i];

	//定数
	long long count_1=0,count_2=0;
	long long sum = 0;
	int sign = 1;

  //odds>0
	rep(i,n){
		sum +=a[i];
		if(sum * sign <=0){
			count_1 += abs(sum)+1;//正になるまで加算
			sum = sign;
		}
		sign *=(-1);
	}
	//even>0
	sign = -1;
	sum = 0;
	rep(i,n){
		sum +=a[i];
		if(sum * sign <=0){
			count_2 += abs(sum)+1;//正になるまで加算
			sum = sign;
		}
		sign *=(-1);
	}


	cout << min(count_1,count_2) << endl;

	return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3

S = input()
T = input()
ret = 10**9
for i in range(len(S)-len(T)+1):
    s = S[i:i+len(T)]
    c = 0
    for j in range(len(s)):
        if s[j] != T[j]:
            c += 1
    ret = min(c, ret)

print(ret)



Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,p;
	cin>>a>>p;
	cout<<(a*3+p)/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int D = 1000000007;
const int MAX_N = 100000;
const int MAX_M = MAX_N - 1;

int main() {
    // input
    int N, M, a[MAX_M];
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> a[i];

    // initialize DP table
    long long dp[MAX_N + 1];
    for (int i = 0; i <= N; i++) dp[i] = 0;

    // initial condition
    dp[0] = 1;

    int j = 0;
    for (int i = 1; i <= N; i++) {
        if (i == a[j]) {
            dp[i] = 0;
            j++;
            continue;
        }
        dp[i] += dp[i - 1];
        if (i > 1) dp[i] += dp[i - 2];
        dp[i] %= D;
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1408
from itertools import accumulate
N, M = map(int, input().split())

A = [[0 for _ in range(N + 1)]]
for i in range(N):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    A.append(rows)
B = [[0 for _ in range(M + 1)]]
for i in range(M):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    B.append(rows)
# print(A)
# print(B)
ans = False
for i in range(1, N - M + 2):
    for j in range(1, N + 2 - M):
        is_exist = True
        # print('=======', i, j)
        for k in range(1, M + 1):
            for l in range(1, M + 1):
                # print(k, l, B[k][l], A[i + k - 1][j + l - 1], A[i - 1][j], A[i][j - 1])
                if B[k][l] != (A[i + k - 1][j + l - 1] - A[i - 1][j]):
                    is_exist = False
        if is_exist:
            ans = is_exist
if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9284
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, A, B, C, D;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> A >> B >> C >> D;
    bool flag = false;
    int x = abs(A - B);
    N--;
    int l = -D * N, r = -C * N;
    for (int i = 0; i < N + 1; i++) {
        if (l <= x && x <= r)
            flag = true;
        l += C + D;
        r += C + D;
    }
    YES(flag);

    solve();
    return 0;
}


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

int main(){
    ll q, c, x, y;
    multiset<ll> s;
    cin >> q;
    for(ll i = 0; i < q; i++){
        cin >> c >> x;
        if (c == 0){
            s.insert(x);
            cout << s.size() << endl;
        }else if(c == 1){
            cout << s.count(x) << endl;
        }else if(c == 2){
            auto j = s.find(x);
            if(j != s.end()){
                s.erase(x);
            }
        }else{
            cin >> y;
            auto b = s.lower_bound(x);
            auto e = s.upper_bound(y);
            if(b != e){
                for(auto j = b; j != e; j++){
                    cout << *j << endl;
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 12280
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
using namespace std;
using Graph = vector<vector<int>>;
using Int = long long;

int main() {
  string a,b;cin>>a>>b;
  int c = stoi(a + b);
  bool ans = false;
  repi(i,c) if (i*i==c) ans = true;
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int MAX_N=1<<20;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d});
}

Measured memory_bytes: 3648
using System;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int result = n;
            if(n % 2 == 0)
            {
                n /= 2;
                result /= 2;
                while (n % 2 == 0)
                {
                    n /= 2;
                }
            }
            for(int i = 3; i * i <= n; i += 2)
            {
                if (n % i == 0)
                {
                    n /= i;
                    result -= result/i;
                    while(n % i == 0)
                    {
                        n /= i;
                    }
                }
            }
            if(n>1) result -= result/ n;
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 9136
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

#define LL unsigned long long int

LL A,B;

LL ans = 0;

LL xorsum(LL x){//0~xまで(x含む)の数について、全部xorをとる
	LL ret = 0;
	for(int i=63;i>=1;i--){
		if((x>>i)&0x1){
			ret += ((x%(1ll<<i)+1)%2)*(1ll<<i);
		}
	}
	ret = ret ^ (x%4==1 || x%4==2);
	return ret;
}

void solve(){
	ans = xorsum(A)^xorsum(B)^A;
}
 
int main(){
	cin >> A >> B;
 
	solve();
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
<?php
  list($h,$w) = explode(" ", trim(fgets(STDIN)));
  list($ch,$cw) = explode(" ", trim(fgets(STDIN)));
  list($dh,$dw) = explode(" ", trim(fgets(STDIN)));
  $s = [];
  for($i=0;$i<$h;$i++){
    list($s[]) = explode(" ", trim(fgets(STDIN)));
  }
/*
  $h=1000;
  $w=1000;
  $ch=1;
  $cw=1;
  $dh=1000;
  $dw=1000;
  $s=[];
  for($i=0;$i<1000;$i++){
    $s[$i]=[];
    for($j=0;$j<1000;$j++){
//      if(($i==0&&$j==0) || ($i==999&&$j==999)){
        $s[$i][$j]=".";        
//      } else{
//        $s[$i][$j]="#";
//      }
    }
  }
*/  
//exit;

  $comp=[];
  $comp2=[];
  $math=[];
  for($i=0;$i<$h;$i++){
    $comp[]=array_fill(0,$w,false);
    $comp2[]=array_fill(0,$w,false);
    $math[]=array_fill(0,$w,PHP_INT_MAX);
  }
  $q=new SplQueue();
  $q->enqueue([$ch-1,$cw-1]);
  $q2=new SplQueue();
  $math[$ch-1][$cw-1]=0;
  $sa1=[0,1,-1,0];
  $sa2=[1,0,0,-1];
  while($q->count() > 0){
    $tg=$q->dequeue();
//    echo "q:".$tg[0]." ".$tg[1].PHP_EOL;
    for($i=0;$i<4;$i++){
      $x=$tg[0]+$sa1[$i];
      $y=$tg[1]+$sa2[$i];
      if(isset($s[$x][$y]) && $s[$x][$y]!='#'){
        if($math[$x][$y]>$math[$tg[0]][$tg[1]]){
          $math[$x][$y]=$math[$tg[0]][$tg[1]];
          $q->enqueue([$x,$y]);
          $comp[$x][$y]=true;
          $comp2[$x][$y]=true;
        }
      }
    }
    for($i=-2;$i<=2;$i++){
      for($j=-2;$j<=2;$j++){
        if(!isset($s[$tg[0]+$i][$tg[1]+$j])){
          continue;
        }
        if($s[$tg[0]+$i][$tg[1]+$j]=='#'){
          continue;
        }
        if($math[$tg[0]+$i][$tg[1]+$j]>$math[$tg[0]][$tg[1]]+1){
          $math[$tg[0]+$i][$tg[1]+$j]=$math[$tg[0]][$tg[1]]+1;
          if(!$comp[$tg[0]+$i][$tg[1]+$j] && !$comp2[$tg[0]+$i][$tg[1]+$j]){
            $q2->enqueue([$tg[0]+$i,$tg[1]+$j]);
            $comp2[$tg[0]+$i][$tg[1]+$j]=true;
          }
        }
      }
    }
    if($q->count() === 0){
      if($math[$dh-1][$dw-1]!==PHP_INT_MAX){
        echo $math[$dh-1][$dw-1];
        exit;
      }
      while($q2->count() > 0){
        list($x,$y)=$q2->dequeue();
//        echo $x." ".$y.PHP_EOL;
        if($comp[$x][$y]){
          continue;
        }
        $q->enqueue([$x,$y]);
      }
    }
//    var_dump($math);
//    exit;
  }
 
  if($math[$dh-1][$dw-1]==PHP_INT_MAX) echo "-1";
  else echo $math[$dh-1][$dw-1];


Measured memory_bytes: 117856
/* https://atcoder.jp/contests/abc135/submissions/6790748 (hemispherium) */
#include <stdio.h>

#define N 50

int main() {
	static int pp[N];
	int n, i, cnt;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &pp[i]);
	cnt = 0;
	for (i = 0; i < n; i++)
		if (pp[i] != i + 1)
			cnt++;
	printf(cnt <= 2 ? "YES\n" : "NO\n");
	return 0;
}


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

using namespace std;
const int _max = 2e6 + 10;
const int mod = 1e9 + 7;
typedef unsigned long long ll;

int main(){
    int n;
    cin>>n;
    int count=0;
    for(int i=1;i<=n;i++){
        int shu;
        cin>>shu;
        if(shu%2==1&&i%2==1){
            count++;
        }
    }
    cout<<count;
    return 0;
}

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

#define mod 10007

int main(void){
    int N,M,A=0;
    scanf("%d %d",&N,&M);
    int x;
    for (int i=0; i<M; i++) {
        scanf("%d",&x);
        A+=x;
    }
    if (N<A) {
        printf("-1\n");
        return 0;
    }
    else{
        printf("%d\n",N-A);
        return 0;
    }
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main() {
  
int b,c,N;
 string S;
 cin >> N >> S;
  
if(N % 2 == 0 ){
  string X;
 for(int i =0; i < N/2; i++){
  string b;
  b = S.at(i);
  X = X + b;
 }
  string Y;
 for(int i =N/2; i < N; i++){
  string c;
  c = S.at(i);
  Y = Y + c;
 }
 if(X==Y){
    cout << "Yes" << endl;
 }
 else{
    cout << "No" << endl;
 }
 } 
  if(N%2 == 1 ){
   cout << "No" << endl;
  }
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 100010
#define inf 1<<29
#define linf 1e18
#define eps (1e-10)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int n,t,ans=0,sum=0;
int T[MAX]={};

int main()
{
  cin>>n>>t;
  FOR(i,0,n){
    int l,r;
    cin>>l>>r;
    T[l]++;
    T[r]--;
  }
  FOR(i,0,t+1){
    sum+=T[i];
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 3456
#include <iostream> 

#include <stdio.h>
using namespace std; 
typedef long ll;

 int main(){

    int length;
    ll arr[200000];
    ll res[200000]={0};
    ll temp = 0;
    ll m = 2147483647;
    scanf("%d",&length);
   	for(int i=0;i<length;++i){
   		scanf("%ld",&arr[i]);
   	}
   	res[0] = arr[0];
    for(int i=1;i<length;++i){
    	res[i] += res[i-1] + arr[i];
    }
    for(int i=1;i<length;++i){
    	temp = abs(res[length-1]-res[i-1]*2);
    	m = min(temp,m);
    }
    printf("%ld\n", m);


 	return 0;
 }


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main() {
    int n;
    cin>>n;
    vector<string> s(2);
//    rep(i,2) cin>>s[i];
    vector<int> nums(n), d(2);
    vector<vector<int>> x(2, vector<int>(n));
    rep(i,2){
        rep(j,n){
            cin>>x[i][j];
        }
    }
    rep(i,n) nums[i]=i+1;
    int c=0;
    do {
        rep(i,2){
            bool b=true;
            rep(j,n){
                b&=nums[j]==x[i][j];
            }
            if(b) d[i]=c;
        }
        c++;
    } while (next_permutation(nums.begin(), nums.end()));
    cout<<abs(d[0]-d[1])<<endl;
    return 0;
}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#K, X = map(int, input().split())
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

T = list(itertools.permutations(range(1,N+1)))
#print (T)

pk = 0
qk = 0

for i in range(len(T)) :
  
  cntP = 0
  cntQ = 0
  for j in range(N) :
    if T[i][j] == P[j] :
      cntP += 1
    if T[i][j] == Q[j] :
      cntQ += 1
  
  if cntP == N :
    pk = i+1
  if cntQ == N :
    qk = i+1

#print (str(pk))
#print (str(qk))
print (abs(pk-qk))

Measured memory_bytes: 48368
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntVec n
  let s = V.sum as

  v <- VM.new (10^5 + 1)
  VM.set v (0::Int)

  forM_ [0..(n-1)] $ \i -> do
    let a = as V.! i
    t <- VM.read v a
    VM.write v a (t+1)

  let solve j s | j == 0 = return ()
                | otherwise = do
                    [b, c] <- getIntList
                    m <- VM.read v b
                    let s' = s + m * (c - b)
                    print s'
                    VM.write v b 0
                    t <- VM.read v c
                    VM.write v c (t+m)
                    solve (j-1) s'

  q <- getInt
  solve q s

Measured memory_bytes: 8244
#include <iostream>

using namespace std;

int main(){
    long long  x ;
    long long  m = 100.0;
    long long  y = 0;
    cin >> x;


    while(m < x){
        //m = m * 1.01;
        m += m / 100;
        y ++;
    }
    cout << y << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>

#define NUM 11000

int main(){
	int result,tmp;
	char buf[20],op;
	bool firstFLG = true;

	while(scanf("%s",buf)!=EOF){

		if(buf[0] == '='){
			printf("%d\n",result);
		}else{

			if(buf[1] == '\0' && (buf[0] == '*' || buf[0] == '-' || buf[0] == '+' || buf[0] == '/')){
				op = buf[0];
			}else{
				tmp = 0;
				if(buf[0] == '-'){
					for(int i = 1; buf[i] != '\0'; i++){
						tmp = 10*tmp + (buf[i]-'0');
					}
					tmp = -1*tmp;
				}else{
					for(int i = 0; buf[i] != '\0'; i++){
						tmp = 10*tmp + (buf[i]-'0');
					}
				}

				if(firstFLG){
					result = tmp;
					firstFLG = false;
				}else{
					switch(op){
					case '-':
						result -= tmp;
						break;
					case '+':
						result += tmp;
						break;
					case '*':
						result *= tmp;
						break;
					case '/':
						result /= tmp;
						break;

					}
				}

			}
		}
	}

	return 0;
}

Measured memory_bytes: 2700
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;
	auto X = RD;
	
	long ans;
	foreach (i; 0..A+1)
	{
		foreach (j; 0..B+1)
		{
			foreach (k; 0..C+1)
			{
				if (i * 500 + j * 100 + k * 50 == X)
					++ans;
			}
		}
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
def main():
    h, w = map(int, input().split())
    alp = [0]*26
    for _ in range(h):
        s = input()
        for c in s:
            p = ord(c) - ord("a")
            alp[p] += 1
    f = True
    cnt_1, cnt_2, cnt_4 = 0, 0, 0
    if h%2 == 1 and w%2 == 1:
        cnt_1 = 1
        cnt_2 = w-1 + h-1
        cnt_4 = (w-1)*(h-1)
    elif h%2 == 1 and w%2 == 0:
        cnt_2 = w
        cnt_4 = w*(h-1)
    elif h%2 == 0 and w%2 == 1:
        cnt_2 = h
        cnt_4 = (w-1)*h
    else:
        cnt_4 = w*h
    for i in range(26):
        while cnt_4 > 0 and alp[i]>=4:
            alp[i] -= 4
            cnt_4 -= 4
    if cnt_4 > 0:
        f = False
    for i in range(26):
        while cnt_2 > 0 and alp[i]>=2:
            alp[i] -= 2
            cnt_2 -= 2
    if cnt_2 > 0:
        f = False
    for i in range(26):
        while cnt_1 > 0 and alp[i]>=1:
            alp[i] -= 1
            cnt_1 -= 1
    if cnt_1 > 0:
        f = False
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 9296
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	int K,S,ans=0;
	cin>>K>>S;
	for(int i=0;i<=K;i++){
		for(int j=0;j<=K;j++){
			if(S-i-j>=0&&S-i-j<=K){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

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

	vector<int> input(3);
	for (int i = 0; i < 3; i++){
		cin >> input[i];
	}
	sort(input.begin(), input.end());
	for (int i = 0; i < 3; i++){
		cout << input[i];
		if (i < 2){
			cout << " ";
		}
	}
	cout << "\n";
	return 0;
}


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


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

    string s;
    cin >> s;
    if (s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<vector<int>> cnt(10, vector<int>(10, 0));
  for (int i = 1; i <= N; ++i) {
    string x = to_string(i);
    int a = x[0] - '0';
    int b = i % 10;
    ++cnt[a][b];
  }
  
  int ans = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;
unsigned long long int dp[102][22];

void solve()
{
	int n;
	cin >> n;
	vector<int> Vec(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> Vec[i];
	}
	memset(dp, 0, sizeof(dp));
	dp[1][Vec[0]] = 1;
	for(int i = 1; i < n - 1; ++i)
	{
		for(int j = 0; j < 21; ++j)
		{
			if(dp[i][j] > 0)
			{
				int plus = j + Vec[i];
				int minus = j - Vec[i];
				if(0 <= plus && plus < 21)
				{
					dp[i + 1][plus] += dp[i][j];
				}
				if(0 <= minus && minus < 21)
				{
					dp[i + 1][minus] += dp[i][j];
				}
			}
		}
	}
	cout << dp[n -1][Vec[n - 1]] << endl;
}

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

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define ll      long long

void solve() {
        int n;
        cin >> n;
        vector<int> cnt(101010, 0);
        for (int i = 0; i < n; i ++) {
                int a;
                cin >> a;
                if (a > 0) cnt[a - 1] ++;
                cnt[a] ++;
                cnt[a + 1] ++;
        }
        int ans = -1;
        for (int i = 0; i < 101010; i ++) ans = max(ans, cnt[i]);
        cout << ans << endl;
        return;
}

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

        //int T;
        //freopen("a.in", "r", stdin);
        //cin >> T;
        //while (T --) solve();
        
        solve();
        return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
#include<climits>

using namespace std;

#define lld long long int
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);	cout.tie(0);

/* 											CODE:-									*/
														


void IMPLEMENT_CODE(){
	
	lld n, k;
	cin>>n>>k;
	lld h[n];
	for(lld i=0; i<n; i++)	cin>>h[i];

	lld dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(lld i=2; i<n; i++){
		dp[i] = INT_MAX;
		for(int j=1; j<=k && i-j>=0; j++){
			dp[i] = min(dp[i-j] + abs(h[i]-h[i-j]), dp[i]);
			//cout<<dp[i]<<" ";
		}
		//cout<<endl;
		//cout<<dp[i]<<" ";
	}
	cout<<dp[n-1]<<endl;
}



int main(){
	
	FASTIO;

	IMPLEMENT_CODE();

	return 0;

}


Measured memory_bytes: 5136
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int inp;
    for(int a=0; a<5; a++){
      inp=scan.nextInt();
      if(inp==0){
        System.out.println(a+1);
      } 
    }
  }
}


Measured memory_bytes: 35652
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()

        val wa = IntArray(N)
        val ac = BooleanArray(N)
        repeat(M) {
            val p = sc.next().toInt() - 1
            val S = sc.next()
            if (!ac[p] && S == "WA") wa[p]++
            if (S == "AC") ac[p] = true
        }
        for (i in 0 until N) if (!ac[i]) wa[i] = 0
        pw.println("${ac.count { it }} ${wa.sum()}")
    }
}


Measured memory_bytes: 43572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll n,d;cin>>n>>d;
    vector<vector<long>> x(10,vector<long>(10));
    For(i,10){
        For(j,10){
            x.at(i).at(j)=0;
        }
    }    
    For(i,n){
        For(j,d){
            cin>>x.at(i).at(j);
        }
    }
    ll ans=0;
    For(i,n){
        for(long j=i+1;j<n;j++){
            ll dist=0;
            For(k,d){
                dist +=(x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
            }
            For(k,400){
                if(k*k==dist){
                    ans++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256