akhauriyash/Code-Regression huggingface dataset:
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_A
 */
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class Die
{
    enum fname {
        top, front, right, left, back, bottom,
    };

    vector<int> faces;
    map<fname, int> f2i;

    void
    turn_e() {
        int tmp = f2i[top];
        f2i[top] = f2i[left];
        f2i[left] = f2i[bottom];
        f2i[bottom] = f2i[right];
        f2i[right] = tmp;
    }

    void
    turn_n() {
        int tmp = f2i[top];
        f2i[top] = f2i[front];
        f2i[front] = f2i[bottom];
        f2i[bottom] = f2i[back];
        f2i[back] = tmp;
    }

    void
    turn_s() {
        int tmp = f2i[top];
        f2i[top] = f2i[back];
        f2i[back] = f2i[bottom];
        f2i[bottom] = f2i[front];
        f2i[front] = tmp;
    }

    void
    turn_w() {
        int tmp = f2i[top];
        f2i[top] = f2i[right];
        f2i[right] = f2i[bottom];
        f2i[bottom] = f2i[left];
        f2i[left] = tmp;
    }

public:
    Die()
    {
        faces.reserve(6);

        f2i.emplace(top, 0);
        f2i.emplace(front, 1);
        f2i.emplace(right, 2);
        f2i.emplace(left, 3);
        f2i.emplace(back, 4);
        f2i.emplace(bottom, 5);
    }

    ~Die()
    {
        faces.clear();
        f2i.clear();
    }

    void
    load_faces(const vector<int> v) {
        copy(v.begin(), v.begin() + 6, faces.begin());
    }

    void
    turn(const char c) {
        switch (c) {
          case 'N':
            turn_n();
            break;
          case 'E':
            turn_e();
            break;
          case 'S':
            turn_s();
            break;
          case 'W':
            turn_w();
            break;
        }
    }

    int Top()    { return faces[f2i[top]   ]; }
    int Front()  { return faces[f2i[front] ]; }
    int Right()  { return faces[f2i[right] ]; }
    int Left()   { return faces[f2i[left]  ]; }
    int Back()   { return faces[f2i[back]  ]; }
    int Bottom() { return faces[f2i[bottom]]; }
};

int
main()
{
    ios::sync_with_stdio(false);

    Die d;
    vector<int> v(6);
    for (int i = 0; i < 6; i++) {
        cin >> v[i]; cin.ignore();
    }
    d.load_faces(v);
    v.clear();

    string line;
    getline(cin, line);
    for (auto &it : line) {
        d.turn(it);
    }
    cout << d.Top() << endl;

    return 0;
}

Measured memory_bytes: 3176
signs=[[x;y;z] for x=[1,-1] for y=[1,-1] for z=[1,-1]]
sl = signs |> length
n,m=readline()|>split|>x->parse.(x)
points=[zeros(n) for _=1:sl]
for i=1:n
    xyz=readline()|>split|>x->parse.(x)
    for j=1:sl
        points[j][i] = xyz .* signs[j] |> sum
    end
end
maxs=fill(0,sl)
for i=1:(sl)
    maxs[i] = sort(points[i])[n-m+1:n] |> sum
end
print(maxs|>maximum)


Measured memory_bytes: 153224
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    int ans = 0;
    for(int i = 0; i < K; i++){
        ans += A.at(N - 1 - i);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int calc(int n, int k, const std::vector<int>& xs) {
  int ret = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (xs[i] < 0) {
      if (i - k + 1 >= 0) {
        ret = std::min(abs(xs[i - k + 1]), ret);
      }
      if (i + k - 1 < n) {
        ret = std::min(abs(xs[i]) + abs(xs[i + k - 1] - xs[i]), ret);
      }
    } else {
      if (i - k + 1 >= 0) {
        ret = std::min(abs(xs[i]) + abs(xs[i - k + 1] - xs[i]), ret);
      }
      if (i + k - 1 < n) {
        ret = std::min(abs(xs[i + k - 1]), ret);
      }
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, k;
  std::cin >> n >> k;
  std::vector<int> xs(n);
  for (auto& x : xs) {
    std::cin >> x;
  }
  std::cout << calc(n, k, xs) << std::endl;
  return 0;
}


Measured memory_bytes: 640
N = int(input())
A = [int(s) for s in input().split()]
mod = 10**9+7

wa = 0
wa_list = []
for i in range(N)[::-1]:
    if i == 0:
        break
    wa += A[i]
    wa_list.append(wa)

wa_list.reverse()
ans  = 0
for i in range(N-1):
    seki = A[i]*wa_list[i]
    ans += seki

print(ans % mod)

Measured memory_bytes: 31452
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int n,a[100010];
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<i){
			if(a[a[i]]==i)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    int v=randxor()%d;
    int w=randxor()%d;
    swap(ans1[v],ans1[w]);
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
void solve1(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    ans1[randxor()%d]=randxor()%26;
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=i%26;
    ans[i]=ans1[i];
  }
  while(clock()-ti<197.9*CLOCKS_PER_SEC/100){
    solve();
    solve1();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int H, W, N;
vec<int> a, b;
set<pii> s, black;

void make(int y, int x) {
  black.insert({y, x});
  for (int yi = -2; yi <= 0; yi++) {
    for (int xi = -2; xi <= 0; xi++) {
      int ny = y + yi, nx = x + xi;
      if (ny < 1 or ny > H-2 or nx < 1 or nx > W-2) continue;
      s.insert({ny, nx});
    }
  }
}

signed main() {
  cin >> H >> W >> N;
  a.resize(N);
  b.resize(N);
  rep (i, N) {
    cin >> a[i] >> b[i];
    make(a[i], b[i]);
  }

  vec<int> ans(10);
  ans[0] = (H-2) * (W - 2);
  for (auto p : s) {
    int y = p.first, x = p.second;
    // dbg2(y, x)

    int cnt = 0;
    for (int yi = 0; yi <= 2; yi++) {
      for (int xi = 0; xi <= 2; xi++) {
        int ny = y + yi, nx = x + xi;
        if (black.count({ny, nx})) {
          // dbg2(ny, nx)
          cnt++;
        }
      }
    }

    // dbg(cnt)
    // line()
    ans[cnt]++;
    if (cnt) ans[0]--;
  }

  for (int x : ans) {
    cout << x << endl;
  }

  return 0;
}

Measured memory_bytes: 64256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ggr getchar();getchar();return 0;
#define rep(i,q)for(int i=0;i<q;i++)
using namespace std;
signed main() {
	int n, m;
	cin >> n >> m;
	if (n >= 2 && m >= 2)cout << (n - 2)*(m - 2) << endl;
	else if (n == 1 && m == 1)cout << 1 << endl;
	else cout << max(n, m) - 2 << endl;
	ggr
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
numP = 1
numQ = 1
for i in range(N-1):
    cou = 1
    time = P[i]-1
    for j in range(1,N-i):
        cou = cou*j
    for j in range(0,i):
        if P[j]< P[i]:
            time -= 1
    numP += time*cou
for i in range(N-1):
    cou = 1
    time = Q[i]-1
    for j in range(1,N-i):
        cou = cou*j
    for j in range(0,i):
        if Q[j]< Q[i]:
            time -= 1
    numQ += time*cou
print(abs(numP-numQ))

Measured memory_bytes: 38384
def main():
    n,k = map(int,input().split())
    e = [[0]*(2*k) for i in range(2*k)]
    mod = 2*k
    for i in range(n):
        x,y,c = input().split()
        if c == "W":
            x = int(x)%mod
            y = (int(y)+k)%mod
        else:
            x = int(x)%mod
            y = int(y)%mod
        e[x][y] += 1

    for i in range(mod):
        for j in range(mod):
            if i != 0 and j != 0:
                e[i][j] -= e[i-1][j-1]
            if i != 0:
                e[i][j] += e[i-1][j]
            if j != 0:
                e[i][j] +=e[i][j-1]

    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            count = e[-1][-1]+2*e[i+k-1][j+k-1]-e[-1][j+k-1]-e[i+k-1][-1]
            if i != 0 and j != 0:
                count += 2*e[i-1][j-1]
            if i != 0:
                count += e[i-1][-1]-2*e[i-1][j+k-1]
            if j != 0:
                count += e[-1][j-1]-2*e[i+k-1][j-1]
            ans = max(ans,count,n-count)
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 79068
#include<bits/stdc++.h>
using namespace std;
#define MAXN	2005
#define P	924844033
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
long long dp[MAXN * 2][MAXN], fac[MAXN];
bool visited[MAXN * 2];
void update(long long &x, long long y) {
	x = (x + y) % P;
}
int main() {
	int n, k;
	read(n), read(k);
	int sum = 0;
	for (int i = 1; i <= k; i++) {
		int tmp = (n - i) / k;
		sum += tmp + 1;
		visited[sum] = true;
		sum += tmp + 1;
		visited[sum] = true;
	}
	for (int i = 0; i <= sum; i++)
		dp[i][0] = 1;
	for (int i = 2; i <= sum; i++)
	for (int j = 1; j <= n; j++) {
		if (!visited[i - 1]) update(dp[i][j], dp[i - 2][j - 1]);
		update(dp[i][j], dp[i - 1][j]);
	}
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % P;
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		long long tmp;
		if (i & 1) tmp = P - 1;
		else tmp = 1;
		ans += tmp * fac[n - i] % P * dp[sum][i];
		ans %= P;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 62976
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    ll a, b, x;
    cin >> a >> b >> x;
    cout << b / x + 1 - (a ? (a-1) / x + 1: 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int n;
	while(~getI(n)){
		map<string,int> cnt;
		map<string,int>::iterator itr;
		while(n--){
			char in[15];
			scanf("%s",in);
			itr=cnt.find(in);
			if(itr==cnt.end()) cnt[in]=1;
			else cnt[in]++;
		}
		VgetI(m);
		while(m--){
			char in[15];
			scanf("%s",in);
			itr=cnt.find(in);
			if(itr==cnt.end()) cnt[in]=-1;
			else cnt[in]--;
		}
		int ans=0;
		for(itr=cnt.begin();itr!=cnt.end();itr++) ans=max(ans,itr->second);
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;
const int MOD = 998244353;

int n, mx;
ll ans = 1, f[N];

ll bm(ll b, ll p, ll m) {
    ll rt = 1;
    for (; p; p >>= 1, b = b * b % m)
        if (p & 1) rt = rt * b % m;
    return rt;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int t; cin >> t;
        if (!t && i) return cout << "0\n", 0;
        mx = max(mx, t);
        ++f[t];
    }
    for (int i = 1; i <= mx; ++i) {
        if (!f[i - 1]) return cout << "0\n", 0;
        ans = ans * bm(f[i - 1], f[i], MOD) % MOD;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(); 
		int b = sc.nextInt(); 
		int cnt = 0;
		for(int i = a; i <= b; i++) {
			if(i/10000 == i%10 && i/1000 - (i/10000*10) == (i%100-i%10)/10) cnt++; 
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const vector<int> dx = {-1, +0, +0, +1, +0};
const vector<int> dy = {+0, +1, +0, +0, -1};

void fill(const int& y, const int& x, const int& h, const int& w, const vector<string>& s, vector<string>& t) {
    int cnt = 0;
    for (int i=0; i<5; i++) {
        int xi = x + dx[i];
        int yi = y + dy[i];
        if (xi < 0 || w <= xi) continue;
        if (yi < 0 || h <= yi) continue;
        if (s[yi][xi] == '#') cnt++;
    }

    if (cnt < 2) return;

    for (int i=0; i<5; i++) {
        int xi = x + dx[i];
        int yi = y + dy[i];
        if (xi < 0 || w <= xi) continue;
        if (yi < 0 || h <= yi) continue;
        if (s[yi][xi] == '#')
            t[yi][xi] = '#';
    }
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i=0; i<h; i++) cin >> s[i];

    vector<string> t(h, string(w,'.'));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (s[i][j] == '#') {
                fill(i,j,h,w,s,t);
            }
        }
    }

    bool ans = s == t;
    cout << (ans? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>

using namespace std;

#define int long long
 
signed main() {
 	int n, y; cin >> n >> y;
   	for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) {
   		int k = n-i-j;
   		if(i*10000 + j*5000 + k*1000 == y && i+j+k == n && k >= 0) cout << i << ' ' << j << ' ' << k, exit(0);
   	}
  	cout << "-1 -1 -1";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

map<string, int > M;

int main() {
  int n;
  S(n);
  while(n--) {
    string s;
    cin >> s;
    M[s]++;
  }
  printf("AC x %d\n",M["AC"]);
  printf("WA x %d\n",M["WA"]);
  printf("TLE x %d\n",M["TLE"]);
  printf("RE x %d\n",M["RE"]);
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
vector<int> adjlist[2005];
int dist[2005];
int a[2005], b[2005];
queue<int> q;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for (int i = 0; i < n-1; i++){
        scanf("%d%d",&a[i],&b[i]);
        adjlist[a[i]].push_back(b[i]);
        adjlist[b[i]].push_back(a[i]);
    }
    int ans = n;
    if (k & 1){
        for (int i = 0; i < n-1; i++){
            memset(dist,-1,sizeof(dist));
            dist[a[i]] = dist[b[i]] = 0;
            q.push(a[i]); q.push(b[i]);
            while (q.size()){
                int u = q.front(); q.pop();
                for (auto v : adjlist[u]){
                    if (dist[v] == -1){
                        dist[v] = dist[u]+1;
                        q.push(v);
                    }
                }
            }
            int ct = 0;
            for (int j = 1; j <= n; j++){
                ct += (dist[j]>k/2);
            }
            ans = min(ans,ct);
        }
    }
    else{
        for (int i = 1; i <= n; i++){
            memset(dist,-1,sizeof(dist));
            dist[i] = 0;
            q.push(i);
            while (q.size()){
                int u = q.front(); q.pop();
                for (auto v : adjlist[u]){
                    if (dist[v] == -1){
                        dist[v] = dist[u]+1;
                        q.push(v);
                    }
                }
            }
            int ct = 0;
            for (int j = 1; j <= n; j++){
                ct += (dist[j]>k/2);
            }
            ans = min(ans,ct);
        }
    }

    printf("%d ",ans);
}


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

int main() {
  string o, e;
  cin >> o >> e;
  for(int i=0; i<o.size()-1; i++){
    cout << o.at(i);
    cout << e.at(i);
  }
  cout << o.at(o.size() -1);
  if (o.size() == e.size()) cout << e.at(o.size() -1);
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  double t, x;
  cin >> t >> x;
  printf("%lf", t/x);
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//n ~ mの和
ll sigma(ll n, ll m)
{
  return ((n + m) * (m - n + 1) * 0.5);
}

void Main()
{
  str s; cin >> s;
  reverse(all(s));
  ll rui = 0;
  vll b(2019);
  ll ans = 0;
  ll h = 1;
  rep(i, s.size())
  {
    b[rui]++;
    rui += h * (s[i] - '0');
    rui %= 2019;
    ans += b[rui];
    h *= 10;
    h %= 2019;
  }
  fin(ans);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>
#include<math.h>

#define MAX 300000

int main(void){
  
  int i,j;
  char mstable[MAX];
  int ms[MAX];
  int n;

  for(i=0;i<MAX;i++){
    if(i%7 == 1 || i%7 == 6){
      mstable[i] = 1;
    }else{
      mstable[i] = 0;
    }
  }
  mstable[1] = 0;

  j = 6;
  while(j<MAX){
    for(i=2*j;i<MAX;i+=j)mstable[i] = 0;
    while(!mstable[++j]){
      if(j==MAX-1){
	j++;
	break;
      }
    }
  }

  j = 0;
  for(i=0;i<MAX;i++){
    if(mstable[i]){
      ms[j] = i;
      j++;
    }
  }
  
  while(1){
    scanf("%d",&n);
    if(n==1)break;

    printf("%d:",n);
    for(i=0;i<j;i++){
      if(n%ms[i]==0)printf(" %d",ms[i]);
    }
    putchar('\n');
  }

  return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp(a,b) make_pair(a, b)
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
ll X;
int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> X >> n;
    vector<ll> r(n);
    for (auto &x : r) cin >> x;
    r.push_back(1ll << 50);
    cin >> m;
    vector<pii> q(m);
    for (auto &x : q){
        cin >> x.first >> x.second;
    }
    int T = 0, i = 0, d = -1;
    ll minA = 0;
    ll maxA = X;
    ll curMin = 0;
    for (ll x : r) {
        while(i < q.size() && q[i].first <= x) {
            int t, a; tie(t, a) = q[i ++];
            a = (int)min(maxA, max(minA, (ll)a));
            ll ans = curMin + a - minA + (t - T) * d;
            cout << min(X, max(0ll, ans)) << endl;
        }
        curMin = curMin + (x - T) * d;
        minA += max(-curMin, 0ll);
        maxA = min(maxA, X + minA - curMin);
        if(maxA < minA) maxA = minA;
        curMin = min(X, max(0ll, curMin));
        T = x;
        d *= -1;
    }
    return 0;
}


Measured memory_bytes: 2800
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int t[110];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int m;
  cin >> m;

  int p[110], x[110];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }

  for (int i = 0; i < m; i++) {
    int ans = 0;
    for (int j = 0; j < n; j++) {
      if (j == (p[i]-1)) {
        ans += x[i];
      } else {
        ans += t[j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int main(){

	long N, M;
	vector<vector<long long> > P;

	cin >> N >> M;

	P = vector<vector<long long> >(N, vector<long long>(0, 0));
	long long p[M], y[M];

	for(long i = 0; i<M;i++){
		scanf("%lld %lld", &p[i], &y[i]);
		P[--p[i]].push_back(y[i]);
	}

	for(long i = 0; i < N ; i++){
		if(P[i].size() != 0) sort(P[i].begin(), P[i].end());
	}

	for(long i = 0; i<M; i++){
		auto itr = lower_bound(P[p[i]].begin(), P[p[i]].end(), y[i]);
		long idx = distance(P[p[i]].begin(), itr);
				printf("%06lld%06ld\n", p[i]+1, idx+1); 
	}

	return 0;
}


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

int main(){
  int n,k;
  vector<pair<int,int>> s;
  cin>>n>>k;

  int rev=0;
  s.push_back(make_pair(0,0));
  char a,b;
  cin>>a;
  if(a=='0')rev++;
  int l=1;
  for(int i=1; i<n; i++){
    cin>>b;
    if(a=='0' && b=='0')l++;
    if(a=='0' && b=='1'){
        s.push_back(make_pair(l,rev));
        l++;
    }
    if(a=='1' && b=='0'){
      s.push_back(make_pair(l,rev));
      l++;
      rev++;
    }
    if(a=='1' && b=='1')l++;
    a=b;
  }
  s.push_back(make_pair(l,rev));

  int m=s.size(), w=(k+1)*2-1, ans=0;

  if(s[1].second==0){
    if((k+1)*2>=m)ans=n;
    for(int i=0; i+w<m; i+=2)ans=max(ans, s[i+w].first-s[i].first);
    if(0<=m-w)ans=max(ans, s[m-1].first-s[m-w].first);
  }else{
    if((k+1)*2>m)ans=n;
    if(m>w-1)ans=max(ans, s[w-1].first);
    for(int i=1; i+w<m; i+=2)ans=max(ans, s[i+w].first-s[i].first);
    if(0<=m-w)ans=max(ans, s[m-1].first-s[m-w].first);  
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1400
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; ++i) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        System.out.println(solve(x, y));

        sc.close();
    }

    static int solve(int[] x, int[] y) {
        List<Edge> edges = new ArrayList<>();

        int[] xSortedIndices = IntStream.range(0, x.length).boxed().sorted((i1, i2) -> Integer.compare(x[i1], x[i2]))
                .mapToInt(a -> a).toArray();
        for (int i = 0; i < xSortedIndices.length - 1; ++i) {
            int v1 = xSortedIndices[i];
            int v2 = xSortedIndices[i + 1];

            edges.add(new Edge(v1, v2, x[v2] - x[v1]));
        }

        int[] ySortedIndices = IntStream.range(0, x.length).boxed().sorted((i1, i2) -> Integer.compare(y[i1], y[i2]))
                .mapToInt(a -> a).toArray();
        for (int i = 0; i < ySortedIndices.length - 1; ++i) {
            int v1 = ySortedIndices[i];
            int v2 = ySortedIndices[i + 1];

            edges.add(new Edge(v1, v2, y[v2] - y[v1]));
        }

        Collections.sort(edges, (e1, e2) -> Integer.compare(e1.distance, e2.distance));

        int[] parents = new int[x.length];
        Arrays.fill(parents, -1);

        int result = 0;
        for (Edge edge : edges) {
            int root1 = findRoot(parents, edge.v1);
            int root2 = findRoot(parents, edge.v2);
            if (root1 != root2) {
                result += edge.distance;
                parents[root2] = root1;
            }
        }

        return result;
    }

    static int findRoot(int[] parents, int v) {
        int root = v;
        while (parents[root] != -1) {
            root = parents[root];
        }

        int p = v;
        while (p != root) {
            int next = parents[p];
            parents[p] = root;

            p = next;
        }

        return root;
    }
}

class Edge {
    int v1;
    int v2;
    int distance;

    Edge(int v1, int v2, int distance) {
        this.v1 = v1;
        this.v2 = v2;
        this.distance = distance;
    }
}

Measured memory_bytes: 76476
from sys import stdin, stdout
from collections import defaultdict

def main():
    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))
    f = 1
    flag=0
    a = sorted(a)
    for i in range(n):
        f = f*a[i]
        if f>10**18:
            flag=1
            break
    if flag:
        print("-1")
    else:
        print(f)

main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, q, a[2525];
	cin>>n>>k>>q;
	REP(i, n){
		cin>>a[i];
	}
	int ans=MOD;
	REP(i, n){
		int mi=a[i];
		vi cand;
		int idx=0;
		while(idx<n){
			vi v;
			int cnt=0;
			for(;;){
				int tmp=a[idx++];
				if(tmp>=mi){
					v.push_back(tmp);
					++cnt;
				}
				if(tmp<mi || idx==n){
					if(cnt-k+1>0){
						sort(ALL(v));
						REP(j, cnt-k+1){
							cand.push_back(v[j]);
						}
					}
					break;
				}
			}
			// REP(cnt, n){
			// 	int tmp=a[idx++];
			// 	if(tmp>=mi){
			// 		v.push_back(tmp);
			// 	}
			// 	if(tmp<mi || idx==n){
			// 		if(cnt-k+1>0){
			// 			sort(ALL(v));
			// 			REP(j, cnt-k+1){
			// 				cand.push_back(v[j]);
			// 			}
			// 		}
			// 		break;
			// 	}
			// }
		}
		if(cand.size()>=q){
			sort(ALL(cand));
			CHMIN(ans, cand[q-1]-mi);
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
typedef vector<pair<ll,ll> > vpii;
typedef vector<ll> vi;
const ll INF=1e13+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)cin>>a[i];
}
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);}
bool isprime(ll n){
    if(n==1)return false;
    if(n==2 || n==3)return true;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}
//ll x[100001]={0};
ll a[100001]={0};
ll b[100001]={0};

//bool c[1000001]={0};
//vector<pair<ll,ll> > adj[100001];
//vector<ll> adj[200001];
//vpii edges;
//bool visited[200001]={0};
//bool color[200001]={0};
//ll dist[100001]={0};
ll binary_expon(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2)res=(res*a)%INF;
        a=(a*a)%INF;
        b/=2;
    }
    return res%INF;
}

void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)res*=i;
    return res;
}

double distance(ll x1,ll y1,ll x2,ll y2){
    return (sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

/*void tree_dfs(ll curr,ll prev){
    for(auto u:adj[curr]){
        if(u!=prev){
            tree_dfs(u,curr);
        }
    }
}*/

/*void dfs(ll x,ll y){
    if(x<0 || y<0 || x>=n || y>=m)return;
    //if(grid[x][y]!=color)return;
    if(visited[x][y] || Map[x][y]=='#'){
        //f=true;
        return;
    }
    visited[x][y]=true;
    Map[x][y]='#';
    //if(px!=(x+1) || py!=y)
        dfs(x+1,y);
    //if(px!=(x-1) || py!=y)
        dfs(x-1,y);
    //if(px!=(x) || py!=y+1)
        dfs(x,y+1);
    //if(px!=(x) || py!=y-1)
        dfs(x,y-1);
}*/

/*bool isVowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}*/
//ll grid[1001][1001]={0};
/*void dfs(ll s){
    if(visited[s])return;
    visited[s]=true;
    for(auto u:adj[s]){
        dfs(u);
    }
}*/
//set<pair<ll,ll> >edges;
/*vector<ll> z(string s) {
    ll n=s.length();
    vector<ll> z(n);
    ll x=0,y=0;
    for(ll i=1;i<n;i++) {
        z[i]=max(0ll,min(z[i-x],y-i+1));
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]){
            x = i; y = i+z[i]; z[i]++;
        }
     }
    return z;
}*/

ll dp[100001]={0};

void solve(){
    ll n;cin>>n;
    input(a,n);

    dp[0]=0;
    dp[1]=(ll)abs(a[1]-a[0]);

    for(ll i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }

    cout<<dp[n-1];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    //sieve(1000001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Measured memory_bytes: 5064
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;

    int sum = (n-1)*(n-2)/2;
    if(sum < k)
    {
        cout << "-1" << endl;
        return 0;
    }

    cout << n-1 + (sum-k) << endl;
    REP(i, n-1)
    {
        cout << 1 << " " << i+2 << endl;
    }
    int index = 2;
    int num = sum - k;
    while(num > 0)
    {
        FOR(j, index+1, n+1)
        {
            if(num <= 0) break;
            cout << index << " " << j << endl;
            num--;
        }
        index++;
    }
    //cout << n-1 + (sum-k) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    string s;
    cin >> s;

    bool f1 = true;
    bool f2 = true;
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D' ){
                f1 = false;
            }
        }
        else{
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D' ){
                f2 = false;
            }
        }
    }

    if(f1 && f2) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b,c,d;

int main(){
	cin>>a>>b>>c>>d;
	if(a!=c) cout<<1<<endl;
	else cout<<0<<endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
def input():return sys.stdin.readline().strip()

def main():
    H, W = map(int, input().split())
    
    field = "#" * (W+2)
    field += "#" + "##".join([input() for _ in range(H)]) + "#"
    field += "#" * (W+2)

    move = [-1, 1, -(W+2), W+2]
    cost = [0] * (H+2) * (W+2)

    def bfs(s):
        q = deque()
        enqueue = q.append
        dequeue = q.popleft
        cost[s] = 1
        enqueue(s)

        while q:
            now = dequeue()
            for dx in move:
                nv = now + dx
                if field[nv] != "#" and cost[nv] <= 0:
                    cost[nv] = cost[now] + 1
                    enqueue(nv)
        
    start = (W+2) + 1
    goal = H*(W+2) + W

    bfs(start)
    white = field.count(".")
    if cost[goal]:
        print(white - cost[goal])
    else:
        print(-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.close();

		System.out.println(Math.min(A, B) + Math.min(C, D));
	}
}

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

int main(){
  int A, B;
  cin >> A >> B;

  if (A == B){
    cout << "Draw" <<endl;
  }
  else if (A == 1)
  {
    cout << "Alice" << endl; 
  }
  else if (B == 1)
  {
    cout << "Bob" << endl;
  }
  else if (A > B)
  {
    cout << "Alice" << endl;
  }
  else
  {
    cout << "Bob" << endl;
  }
  
  
  
  
  
}

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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define debug(x) cout << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cout << a << " "; cout << endl;
#define debug3(x) rep(i, sizeof(x)) cout << x[i] << " "; cout << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
    return 0;
}



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

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

    int cnt = 0;
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == s[i + 1]) {
            if (s[i + 1] == '1') s[i + 1] = '0';
            else s[i + 1] = '1';
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
 
int H,W,R,C,a;
 
bool f[505][505][4];
bool used[505][505][2];
bool visited[505][505];
struct state{
  int y,x;
};
 
int main(){
  while(1){
    cin>>H>>W>>R>>C;
    memset( f , false , sizeof(f) );
    memset( used , false , sizeof(used) );
    memset( visited , false , sizeof(visited) );
 
    if(H==0&&W==0&&R==0&&C==0)break;
 
    for(int i=1;i<=W;i++){
      cin>>a;
      f[1][i][0]=a;
      f[0][i][2]=a;
    }
 
    for(int i=1;i<=H;i++){
      for(int j=0;j<=W;j++){
        cin>>a;
        f[i][j][1]=a;
        f[i][j+1][3]=a;
      }
      for(int j=1;j<=W;j++){
        cin>>a;
        f[i][j][2]=a;
        f[i+1][j][0]=a;
      }
    }
    queue< state > Q; 
    for(int y=1;y<=H;y++){
      Q.push((state){y,0});
      Q.push((state){y,W+1});
    }
    for(int x=1;x<=W;x++){
      Q.push((state){0,x});
      Q.push((state){H+1,x});
    }
 
 
    while(!Q.empty()){
      state s=Q.front();Q.pop();
 
      visited[s.y][s.x]=true;
 
      for(int i=0;i<4;i++){
        int ny=s.y+dy[i];
        int nx=s.x+dx[i];
        if(ny<0||nx<0)continue;
        if(ny>H||nx>W)continue;
        assert( f[s.y][s.x][i] == f[ny][nx][ (i+2)%4 ] );
        used[ny][nx][ f[s.y][s.x][i] ]=1;
        if(used[ny][nx][0]&&used[ny][nx][1]&&!visited[ny][nx]){
          visited[ny][nx]=true;
          Q.push((state){ny,nx});
        }
      }
    }
    bool ans=false;
    if(visited[R][C])ans=true;
    for(int i=0;i<4;i++){
      int y=R+dy[i];
      int x=C+dx[i];
      if( f[R][C][i] == 0 ){
        ans |= visited[y][x];
      }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 2980
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    vector<vector<ll>> c(3,vector<ll>(3));
    REP(i,3)REP(j,3)cin>>c[i][j];
    bool is=true;
    REP(i,2){
        REP(j,2){
            ll d1=c[i][j]-c[i][j+1], d2=c[i+1][j]-c[i+1][j+1];
            ll d3=c[i][j]-c[i+1][j], d4=c[i][j+1]-c[i+1][j+1];
            if(d1!=d2 || d3!=d4){
                is=false;
                break;
            }
        }
    }
    string ans;
    if(is){
        ans="Yes";
    }else{
        ans="No";
    }
    cout<<ans<<endl;
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end



int main(){
    int n;ll k; scanf("%d%lld",&n,&k);
    vector<ll> a(n),b(n);;
    rep(i,0,n)scanf("%lld",&a[i]);
    rep(i,0,n)scanf("%d",&b[i]);
    sort(ALL(a)); sort(ALL(b),greater<ll>());
    ll lb=-1,rb=1e13;
    while(rb-lb>1){
        ll mid=(lb+rb)/2;
        ll need=0;
        rep(i,0,n)need+=max(0LL,a[i]-(mid/b[i]));
        if(need>k)lb=mid; else rb=mid;
    }
    printf("%lld\n",rb);
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<char> vc;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define F(ii,a,n) for(ii=a;ii<n;ii++)
#define read(array,n) for(ll i=0;i<n;i++) cin>>array[i];
#define inf 1000000007;
// function to transform string to lowercase --> transform(s.begin(),s.end(),s.begin(),::tolower)
//(a + b ) % m = (a % m + b % m ) %m
//(a - b ) % m = ( ((//(//(a - b ) % m = ( (a % m - b % m ) + m ) %m
// a % m - b % m ) + m ) %m
//(a * b ) % m = (a % m * b % m ) %m
//(a / b ) % m = (a % m * inv(b) ) %m where inv(b) = pow(b,m,m-2)



ll power(ll i,ll j){
	ll prod=1;
	while(j>0){
		if(j&1){
			prod=prod*i;
		}
		j=j>>1;
		i=i*i;
	}
	return prod;
}
void solve(){
	ll i,j,n,k;
	string s="";
	cin>>n;
	while(n>0){
		ll rem=n%26;
		if(rem==0){
			s+="z";
			n=(n/26)-1;
		}
		else{
			s+=(char)('a'+rem-1);
			n=n/26;
		}
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	
}
int main(){
	// freopen("filename.txt","r",stdin);
	solve();
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
void fast()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}
int main()
{
    fast();
    long long n,m,sum=0,x;
    cin>>n>>m;
    for(int i=0;i<m;i++){cin>>x;sum+=x;}
    cout<<max(n-sum,(long long)-1);
    return 0;
}


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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    bool flag = false;
    rep (i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            flag = true;
        }
    }

    if (flag) {
        ll ans = 0;
        rep (i, n) {
            ans += abs(a[i]);
        }
        cout << ans << endl;
        exit(0);
    }
    sort(all(a));
    int idx = 0;
    ll ans = 0;
    while (idx + 1 < n) {
        ll p = a[idx];
        ll q = a[idx + 1];
        if (p < 0 && q < 0) {
            ans += -(p + q);
        } else if (p < 0) {
            ans += abs(p + q);
        } else {
                ans += p + q;
        }
        idx += 2;

    }
    if (n % 2 == 1) {
        ans += a[n - 1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024