akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long i,j,n,a[100001],s,sum,m[100001];
int main(){
    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i];
    for(i=1;i<=n;i++) s+=a[i];
    m[1]=a[1];
    for(i=2;i<=n;i++) m[i]=m[i-2]+a[i];
    for(i=1;i<=n;i++){
        sum=0;
        if(i%2==1){
            sum+=m[max(i-2,(long long)0)];
            sum+=m[n-1]-m[i-1];
        }
        else{
            sum+=m[i-2];
            sum+=m[n]-m[i-1];
        }
        sum*=2;

        cout<<s-sum<<" ";
    }
}


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

int main()
{
	string num;
	cin >> num;
	if (num.length() == 2){
		cout << num << endl;
	}
	else
	{
		for (int i = 2; i >= 0; --i)
		{
			cout << num[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
cnt=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i]!=L[j] and L[i]!=L[k] and L[j]!=L[k]:
                if L[i]+L[j]>L[k]:
                    cnt+=1
print(cnt)

Measured memory_bytes: 9196
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int[] g = new int[n];
    for (int i=0;i<n;i++){
      g[i] = scan.nextInt();
    }
    Arrays.sort(g);
    if (g.length % 2 != 0){
      System.out.println(0);
    }
    else{
      int t = g.length;
      t = (int) t/2;
      System.out.println(g[t] - g[t-1]);
    }
  }
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;

    ll a = h2*60+m2 - h1*60-m1;
    cout<<a-k<<endl;


    return 0;

}

Measured memory_bytes: 3624
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double lb;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

int a;

int main() {
    cin >> a;
    for(register int i = 1; i <= 9; i++) {
        for(register int j = 1; j <= 9; j++) {
            if(i * j == a) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void
solver(int m1, int m2)
{
    if (m1==m2) {
        printf("0\n");
        return;
    }
    printf("1\n");
}

int
main(int argc, char *argv[])
{
    int m1, m2, d1, d2;

    scanf("%d%d", &m1, &d1);
    scanf("%d%d", &m2, &d2);
    solver(m1, m2);

    return 0;
}

Measured memory_bytes: 128
def main():
    o = input()
    e = input()

    if len(o) == len(e):
        pw = [o[i]+e[i] for i in range(len(o))]
    else:
        pw = [o[i]+e[i] for i in range(len(e))]
        pw.append(o[-1])

    print("".join(pw))


if __name__ == "__main__":

    main()


Measured memory_bytes: 3060
<?php

$a = trim(fgets(STDIN));

$list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];

foreach($list as $k => $c) {
    if ($c === $a) {
        echo $list[$k+1];
        exit();
    }
}


Measured memory_bytes: 4728
n = int(raw_input())
a = [raw_input() for i in xrange(n)]

if len(set(a)) != n:
	print "No"
	exit(0)

for i in xrange(1, n):
	if a[i - 1][-1] != a[i][0]:
		print "No"
		exit(0)

print "Yes"


Measured memory_bytes: 2568
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()

	switch n % 10 {
	case 3:
		fmt.Println("bon")
	case 0, 1, 6, 8:
		fmt.Println("pon")
	default:
		fmt.Println("hon")
	}
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int N,K;
    cin >> N >> K;

    int h[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    //sort
    sort(h,h+N);

    int result=1000000000;
    for(int i=K-1;i<N;i++){
        int local = h[i] - h[i-K+1];
        if(local<result)result=local;
    }
    cout << result << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        int A,B;
        string S;

        cin >> A >> B;
        cin >> S;

        if(S[A]!='-'){
                cout << "No" << endl;
                return 0;
        }

        for(int i=0; i<(A+B+1); i++){
                if(i==A)continue;
                if(!(isdigit(static_cast<unsigned char>(S[i])))){
                        cout << "No" << endl;
                        return 0;
                }
        }

        cout << "Yes" << endl;
        return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>
#include <iterator>


using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 

 
int V,E;

struct edge {
	int dst;
	int cost;
	edge(int dst, int cost) {
		this->dst = dst; this->cost = cost;
	}

};

typedef vector<edge> edges;
vector<edges> G;

int dist[100005];
int k;

void solve(int v) {

	fill(dist, dist + k, INF);
	dist[v] = 0;
	deque<P> q;
	
	q.push_front(P(v,0));
	while (q.size()) {
		P p = q.front(); q.pop_front();
		int v = p.first;
		if (dist[v] < p.second)
			continue;
		dist[v] =  p.second;
		FORI(0,G[v].size()) {
			edge e = G[v][i];
			if (dist[e.dst] > dist[v] + e.cost) {
				dist[e.dst] = dist[v] + e.cost;
				if(e.cost==0)
					q.push_front(make_pair(e.dst ,dist[e.dst] ));
				else
					q.push_back(make_pair(e.dst , dist[e.dst] ));
			}
		}
	}
	cout << dist[0] + 1 << endl;
}

int main() {
	cin >> k;
	G.resize(k);
	FORI(0, k) {
		G[i].push_back(edge((i + 1)%k, 1));
		G[i].push_back(edge((i*10)%k, 0));
	}
	solve(1);
	return 0;
}


Measured memory_bytes: 6528
//   PIGMEISTER™   //

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

#define ll long long
#define ull unsigned long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);i++)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);i--)
#define mi map<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define pi pair<ll,ll>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod (ll)1000000007
//#define mod (ll)998244353
#define MAX 200005
ll powah(ll, ll);

int main()
{
    jaldi;
    
    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y;

    return 0;
}

ll powah(ll x, ll y) { 
    ll res = 1; x = x % mod;
    while (y > 0) { 
        if (y & 1) res = (res*x) % mod; 
        y = y>>1; x = (x*x) % mod; 
    } 
    return res; 
}

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

int main(void) {
  int n;
  cin >> n;
  vector<vector<int>> a(1001,vector<int>(1001,0)); //素因数分解
  int i,j,tmp; 
  a[1][1]=1;
  for(i=2;i<=n;i++) {
    tmp=i;
    for(j=2;j<=i;j++) {
      if(tmp%j==0) {
        tmp/=j;
        a[i][j]++;
        rep(k,i+1) {a[i][k] += a[tmp][k];}
        break;
      }
    }
  }
  vector<int> sum(n+1,0);
  rep(i,n+1) {
    rep(j,n+1) {
      sum[i] += a[j][i];
    }
  }
  //rep(i,n+1) cout << sum[i] << endl;
  ll ans=1;
  rep2(i,2,n+1) {
    ans *= (sum[i]+1);
    ans%= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7520
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,l,q;
ll x[500005],y[500005],z[500005];
ll dp[3000005],res[3000005];
char s[500005];
bool flag,dame;

ll  fact[400005];
ll rfact[400005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<400000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll ncr(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

int main(){
	cin >> a >> b >> c >> k;
	for(i=0;i<a;i++)cin >> x[i];
	for(i=0;i<b;i++)cin >> y[i];
	for(i=0;i<c;i++)cin >> z[i];
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			dp[num++] = x[i] + y[j];
		}
	}
	num = 0;
	sort(dp,dp+a*b);
	reverse(dp,dp+a*b);
	for(i=0;i<c;i++){
		for(j=0;j<k;j++){
			res[num++] = z[i] + dp[j];
		}
	}
	sort(res,res+c*k);
	reverse(res,res+c*k);
	for(i=0;i<k;i++){
		p(res[i]);
	}


	return 0;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string S;
signed main() {
    cin >> N >> S;
    if (N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
}


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

int main(){
  int n;
  cin >> n;
  n = n%10;
  if(n==2 or n==4 or n==5 or n==7 or n==9){
    cout << "hon" << endl;
  }else if(n==0 or n==1 or n==6 or n==8){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
} 

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  int i = 0;
  int p = 0;
  int w = 0;
  int g = 0;
  int y = 0;
  while (i < N) {
    string col;
    cin>>col;
    if (col == "P") {
      p++;
    }
    else if (col == "W") {
      w++;
    }
    else if (col == "G") {
      g++;
    }
    else {
      y++;
    }
    i++;
  }
  if (p > 0 && w > 0 && g > 0 && y > 0) {
    cout<<"Four"<<endl;
  }
  else {
    cout<<"Three"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    int ans = x / __gcd(x, y) * y;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;cin>>n;
  vector<vector<int> > v(3, vector<int>(n));
  for(int i=0;i<n;i++){
    int a;cin>>a;
    for(int j=0;j<3;j++){
      //v[j][i] = a +(j-1);
      int num = a + (j-1);
      if(num>=0){
        v[j][i] = num;
      }else{
        v[j][i] = 100001;
      }
    }
  }
  vector<int> ans(100000);
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      ans[v[j][i]]++;
    }
  }
  sort(ans.begin(),ans.end(),greater<int>());
  //reverse(ans.begin(),ans.end());
  cout<<ans[0]<<endl;

}

Measured memory_bytes: 1792
let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.sort (-) a;

  let dp = Array.make k false in
  let rec loop l r =
    if l >= r then r else
    let m = (l+r) / 2 in
    let x = a.(m) in
    Array.fill dp 0 k false; dp.(0) <- true;

    a |> Array.iteri (fun i v -> 
      if i = m then () else
      for j = k-1 downto v do
        dp.(j) <- dp.(j) || dp.(j-v)
      done);

    Array.init (min k x) (fun i -> dp.(k-1-i))
    |> Array.fold_left (||) false
    |> fun b -> if b then loop l m else loop (m+1) r
  in

  loop 0 n |> Printf.printf "%d\n"


Measured memory_bytes: 4096
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int W, H,a,b;
	scanf("%d%d%d%d", &W, &H, &a, &b);
	W -= a;
	H -= b;
	printf("%d", W * H);
	return 0;

}


Measured memory_bytes: 256
//coded by dsingh_24
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
    ll a,b;
    cin>>a>>b;
    cout<<(a-1)*(b-1);
	return 0;
}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  for(int i = 0; i * 10000 <= Y; ++i) {
    for(int j = 0; j * 5000 <= Y; ++j) {
      int k = N - i - j;
      if(k < 0) {
        continue;
      }
      if(i * 10000 + j * 5000 + k * 1000 == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
pl=1
visit=[-1]*n
visit[0]=0
loop=0
q=True
v=True
cnt=0

while q:
    cnt+=1
    pl=a[pl-1]
    if visit[pl-1]!=-1:
        loop=visit[pl-1]
        break
    visit[pl-1]=cnt
    if cnt==k:
        print(pl)
        v=not v
        break
    if cnt==10**7:
        q=not q
if v:
    loop_len=cnt-loop
    q=True
    k=(k-loop)%loop_len
    cnt=0
    if k==0:
        print(pl)
    else:
        while q:
            cnt+=1
            pl=a[pl-1]
            if cnt==k:
                print(pl)
                break
            if cnt==10**7:
                q=not q

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

int main(){
  int n;
  cin >> n;
  if(n == 100000){
    cout << 9+900+90000 << endl;
  }else if(n >= 10000){
    cout << 9+900+(n-9999) << endl;
  }else if(n >= 1000){
    cout << 9+900 << endl;
  }else if(n >= 100){
    cout << 9+(n-99) << endl;
  }else if(n >= 10){
    cout << 9 << endl;
  }else{
    cout << n << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        int a[] = {1, 100, 10000};
        int D;
        int N;
        Scanner sc = new Scanner(System.in);

        D = sc.nextInt();
        N = sc.nextInt();

        if (N == 100) {
            System.out.println(a[D] * 101);
        } else {
            System.out.println(a[D] * N);
        }
    }
}


Measured memory_bytes: 23764
/*
CODED BY               
**************
DARSHAN JAIN
darshanjain31
**************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define MOD 1000000007
 
int main()
{ 
	ll a,b,c,d,s;
	cin>>a>>b>>c>>d>>s;
	ll start=a*60+b;
	ll end=c*60+d;
	cout<<(end-start)-s<<endl;
}

Measured memory_bytes: 3636
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e9+7 ;
ll fact(ll x, ll y){
    ll f=1,i=1;
    while(i<=y){
        f=( (f%M) * (x%M) )%M;
        i++;
    }
    return f;
}
int main()
{
   ll n,ans=0;
   cin>>n;
   ans =fact(10,n)- ( 2*fact(9,n))%M +fact(8,n) ;
   ans= (ans+M)%M;

   cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3648
function Main(input) {
  const arr = input.trim().split('\n')[1].split(' ');
  let count = 1;
  let flg = true;
  let trend;

  for (let i = 0; i < arr.length - 1; i++) {
    const diff = arr[i] - arr[i + 1];
    let curr;

    if (diff === 0) continue;
    if (diff > 0) curr = 0;
    if (diff < 0) curr = 1;
    if (flg) {
      trend = curr;
      flg = false;
      continue;
    }

    if (curr === trend) {
      continue;
    } else {
      flg = true;
      trend = curr;
      count += 1;
    }
  }

  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;

ll N, M;
vector<vector<ll>> Adj;

bool solve() {
  for (ll u : Adj[0])
    for (ll v : Adj[u])
      if (v == N - 1) return true;
  return false;
}
int main() {
  cin >> N >> M;
  Adj.resize(N);
  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    Adj[a].push_back(b);
    Adj[b].push_back(a);
  }
  cout << (solve() ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 12776
n=int(input())
a=[int(i) for i in input().split()]
c2=0
c4=0
c=0
for i in a:
    if i%4==0:
        c4+=1
    elif i%2==0:
        c2+=1
    else:
        c+=1

if c==0 or c+c2-1<=c4 or c<=c4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
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;}



signed main(){
	int N;
	cin>>N;
	vector<int> a(N); for(auto& e:a)cin >> e;
	double t = 0.0;
	REP(i,N){
		t += 1.0/a[i];
	}
	printf("%.10lf\n",1.0/t);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, W;
	static int[][] info;
	static int[] weight, value;
	static int count = 1;
	static int[][]dp;
	public static void main(String[] args) {
		while(read()){
			int res = solve();
			System.out.println(res);
			count++;
		}
	}
	static boolean read(){
		W = sc.nextInt();
		if(W == 0)
			return false;
		N = sc.nextInt();
		info = new int[2][N];
		weight = new int[N];
		value = new int[N];
		dp = new int[N+1][W+1];
		String line;
		String [] devide = new String[2];
		for(int i = 0; i < N; i++){
			line = sc.next();
			devide = line.split(",");
			info[0][i] = Integer.parseInt(devide[0]);
			value[i] = Integer.parseInt(devide[0]);
			info[1][i] = Integer.parseInt(devide[1]);
			weight[i] = Integer.parseInt(devide[1]);
		}
		return true;
	}
	static int solve(){
		for(int i = 0; i <= N-1; i++){
			for(int j = 0; j <= W; j++){
				if(weight[i] > j){
					dp[i+1][j] = dp[i][j];
				}else{
					dp[i+1][j] = Math.max(dp[i][j], dp[i][j - weight[i]] + value[i]);
				}
			}
		}
		int ans = dp[N][W];
		System.out.println("Case " + count + ":");
		System.out.println(ans);
		int bestValue = dp[N][W];
		int index = 0;
		for(int j = 0; j <= W; j++ ){
			if(bestValue == dp[N][j]){
				index = j;
				break;
			}
		}
		return index;
	}
}

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

int main() {
    int K;
    string S;
    cin >> K >> S;
    if ((int)S.length() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
}


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

typedef long long ll;
const ll MOD = ll(1e9) + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(1223);
  int N;
  cin >> N;
  vector<int> like(N);
  for(int& a : like) {
    cin >> a;
    --a;
  }
  int res=0;
  for(int i=0;i<N;++i){
    if (like[i] < i && like[like[i]] == i) {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
};

Measured memory_bytes: 640
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

typedef long double real;
const real inf = 1e20;

struct point {
	int x, y;
};

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


vector<real> dist;
// ret1: true if arg e < calculated e
// ret2: expected s-g value if e is correct
pair<bool, real> is_lower(const real e, const vector<vector<char> >& f,
	const point& s, const point& g, const vector<point>& spring)
{
	const int w = f[0].size(), h = f.size();

	dist.resize(w * h);
	fill(dist.begin(), dist.end(), inf);

	queue<pair<point, real> > q;

	q.push(make_pair(g, 0));

	while(!q.empty()) {

		const auto vd = q.front();
		const auto v = vd.first;
		const auto d = vd.second;
		q.pop();
		const int idx = v.x * w + v.y;

		if(dist[idx] < inf)
			continue;
		dist[idx] = d;

		for(int dir = 0; dir < 4; ++dir) {
			const int nx = v.x + dx[dir], ny = v.y + dy[dir];
			const point vvv = {nx, ny};
			if(nx < 0 || nx >= h || ny < 0 || ny >= w)
				continue;
			char c = f[nx][ny];
			if(c == '#' || c == '*')
				continue;
			q.push(make_pair(vvv, d + 1));
		}
	}

	for(auto sp : spring)
		q.push(make_pair(sp, e));

	while(!q.empty()) {
		const auto vd = q.front();
		const auto v = vd.first;
		const auto d = vd.second;
		q.pop();
		const int idx = v.x * w + v.y;

		if(dist[idx] <= d)
			continue;
		dist[idx] = d;

		for(int dir = 0; dir < 4; ++dir) {
			const int nx = v.x + dx[dir], ny = v.y + dy[dir];
			const point vvv = {nx, ny};
			if(nx < 0 || nx >= h || ny < 0 || ny >= w)
				continue;
			char c = f[nx][ny];
			if(c == '#' || c == '*')
				continue;
			q.push(make_pair(vvv, d + 1));
		}
	}

	real total = 0;
	int count = 0;

	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {

			char c = f[i][j];
			const int idx = i * w + j;

			if(c == '#' || c == 'g' || c == '*')
				continue;

			total += dist[idx];
			count += 1;
		}
	}

	bool ok = e < total / count;
	real ans = dist[s.x * w + s.y];

	return make_pair(ok, ans);
}


int main()
{
	int w, h;
	vector<vector<char> > f;

	scanf("%d%d", &w, &h);
	f.resize(h);
	for(int i = 0; i < h; ++i) {
		char buf[1024];
		scanf("%s", buf);
		for(int j = 0; buf[j] != '\0'; ++j)
			f[i].push_back(buf[j]);
	}

	vector<point> spring;
	point s, g;

	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {

			char c = f[i][j];
			if(c == 's')
				s = {i, j};
			else if(c == 'g')
				g = {i, j};
			else if(c == '*')
				spring.push_back({i, j});
		}
	}

	real lb = 0, ub = inf / 2;
	real ans = 0;
	const int max_step = 200;

	for(int step = 0; step < max_step; ++step) {

		real mid = (lb + ub) / 2;

		auto ret = is_lower(mid, f, s, g, spring);
		if(ret.first)
			lb = mid;
		else
			ub = mid;
		ans = ret.second;
	}

	printf("%.20Lf\n", ans);

	return 0;
}

Measured memory_bytes: 7720
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

i=0
sb=0
while i<m:
    sb+=b[i]
    i+=1
    if sb>k:
        i-=1
        sb-=b[i]
        break

ans=i
j=0
sa=0
while j<n:
    sa+=a[j]
    while sa+sb>k:
        if i>0:
            sb-=b[i-1]
            i-=1
        else:
            print(ans)
            exit()
    j+=1
    ans=max(ans,i+j)

print(ans)

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

int main(){
  string S;cin>>S;
  int mod=2019;
  vector<int> T(S.size()+1);
  vector<int> C(2019,0);
  T[S.size()]=0;
  vector<int> ruimod(200001,0);
  ruimod[0]=1;
  for(int i=1;i<200001;i++){
    ruimod[i]=(ruimod[i-1]*10)%mod;
  }
  for(int i=S.size()-1;i>=0;i--){
    T[i]=(T[i+1]+(S[i]-'0')*ruimod[S.size()-i-1])%mod;
  }
  for(int i=0;i<=S.size();i++){
    C[T[i]]++;
  }
  int cnt=0;
  for(int i=0;i<2019;i++){
    if(C[i]>=2)cnt+=(C[i]*(C[i]-1))/2;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 5132
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    LL n, a, b;
    cin >> n >> a >> b;
    LL l = a + b + a * ( n - 2 );
    LL r = a + b + b * ( n - 2 );
    cout << max( (LL)0, r - l + 1 ) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int sum1=0,sum2=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')sum1++;
        else sum2++;
    }
    int ans=min(sum1,sum2);
    cout<<ans*2<<endl;
}


Measured memory_bytes: 512
local read = io.read

local n, m = read("n", "n")

if n >= m then
	print(0)
	os.exit()
end

local x_t = {}
for i = 1, m do
	x_t[i] = read("n")
end
table.sort(x_t)
local distance_t = {}
for i = 1, m - 1 do
	distance_t[i] = x_t[i + 1] - x_t[i]
end
table.sort(distance_t, function(x, y) return x > y end)
local out = x_t[#x_t] - x_t[1]
for i = 1, n - 1 do
	out = out - distance_t[i]
end

print(out)


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

using namespace std;

int n, m, X;

int c[15];

int a[15][15];

int Sum[15];

int Ans = 2e9;

void dfs(int x, int C)
{
	if (x > n)
	 {
	 	for (int i = 1 ; i <= m ; ++ i)
	 	 if (Sum[i] < X)
	 	  return;
	 	Ans = min(Ans, C);
	 	return;
	 }
	for (int i = 1 ; i <= m ; ++ i)
	 Sum[i] += a[x][i];
	dfs(x + 1, C + c[x] );
	for (int i = 1 ; i <= m ; ++ i)
	 Sum[i] -= a[x][i];
	dfs(x + 1, C);
	return;
}

int main()
{
	scanf("%d%d%d", &n, &m, &X);
	for (int i = 1 ; i <= n ; ++ i)
	 {
	 	scanf("%d", &c[i] );
	 	for (int j = 1 ; j <= m ; ++ j)
	 	 scanf("%d", &a[i][j] );
	 }
	dfs(1, 0);
	printf("%d\n", Ans == 2e9 ? -1 : Ans);
	return 0;
}

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

#define ll                   long long int
#define MOD                  1000000007
#define fast()               ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define loop(i,a,b)          for(ll i=(ll)a;i<(ll)b;i++)
#define pool(i,a,b)          for(ll i=(ll)a;i>=(ll)b;i--)
#define pb                   push_back
#define vi                   vector<ll>
#define test()               ll t; cin>>t; while(t--)
#define endl                 "\n"
#define param                greater<ll>()
#define ff                   first
#define ss                   second
#define all(v)               v.begin(),v.end()
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define sor(vec) sort(vec.begin(),vec.end());

using namespace std;

const int N = 1e5+10;
#define MAX  100000000000000000;
// const int MOD = 998244353;

ll fast_exp(ll x,ll n){ll ans=1;while(n){if(n&1)ans*=x;n=n>>1;x=x*x;}return ans;}
ll mod_exp(ll x, ll y,ll p){ll res = 1;x = x % p;while(y>0){if(y&1)res = (res*x) % p;y = y>>1;x=(x*x)%p;}return res;}


//  vector < ll > vec(N);

// ll fib[N];

ll dp[N];


int main()
{
    
    fast()
    
    
    ll t;
    // cin>>t;
    t=1;
    
    while(t--)
    {
        ll a,b,c,i,n,k,p,j,d,m;
        
        string s;
        
        cin>>n;
        
        vector<ll>vec(n+1);
      
        for(i=1;i<=n;i++)
        {
          cin>>vec[i];
        }
        
        
        
        
        dp[1]=0;
        dp[2]=abs(vec[2]-vec[1]);
    
        
        for(i=3;i<=n;i++)
        {
            dp[i]=min( dp[i-1]+abs(vec[i]-vec[i-1]) , abs(vec[i]-vec[i-2])+dp[i-2]);
        }
        
        cout<<dp[n]<<endl;
    
        
        
        // string ans=vec[0];
        
       
   


      
    }
   
   
   
   
    return 0;
}


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

using namespace std;

int dp1[2][32010], dp2[2][32010], *DP1[2] = {(dp1[0]+16005),(dp1[1]+16005)}, *DP2[2] = {(dp2[0]+16005),(dp2[1]+16005)};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	int x, y, c = 0, cur = 0, t = 0;
	vector<int> xmoves, ymoves;
	cin >> s;
	cin >> x >> y;
	s += 'T';
	for (int i = 0; i < s.size(); ++i){
		t++;
		if (s[i] == 'F'){
			cur++;
			t--;
		}
		else if (cur){
			if (!c){
				if (t == 1){
					x -= cur;
				}
				else xmoves.push_back(cur);
				cur = 0;
				c = 1;
			}
			else{
				ymoves.push_back(cur);
				cur = 0;
				c = 0;
			}
		}
		else{
			c = 1 - c;
		}
	}
	DP1[0][0] = 1;
	for (int i = 1; i <= xmoves.size(); ++i){
		for (int j = -8000; j <= 8000; ++j){
			DP1[i&1][j] = (DP1[(i-1)&1][j-xmoves[i-1]] | DP1[(i-1)&1][j+xmoves[i-1]]);
		}
	}
	DP2[0][0] = 1;
	for (int i = 1; i <= ymoves.size(); ++i){
		for (int j = -8000; j <= 8000; ++j){
			DP2[i&1][j] = (DP2[(i-1)&1][j-ymoves[i-1]] | DP2[(i-1)&1][j+ymoves[i-1]]);
		}
	}
	if (DP1[((int)xmoves.size())&1][x] && DP2[((int)ymoves.size())&1][y]){
		cout << "Yes\n";
	}
	else cout << "No\n";
	cout << flush;
	//for (int i = 0; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}
}

Measured memory_bytes: 512
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, m = MI()
    l, r = MI()
    for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
    ans = max(0, r-l+1)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) std::sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 998244353;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}



void Main()
{
    int n;cin>>n;
    int len = 1e6+10;

    VVL minus(len);
    VPLL plus;
    VPLL minus2;

    REP(i,n){
        string s;cin>>s;
        int r=0;
        int l=0;
        REP(j,SIZE(s)){
            if(s[j] == ')'){
                if(l>0){
                    l--;
                }
                else{
                    r++;
                }
            }
            else{
                l++;
            }
        }
        //cerr<<s<<" "<<l<<" "<<r<<endl;
        if(l-r>=0){
            plus.PB(MP(r,l-r));

        }
        else{
            minus[len+(l-r)].PB(r);
            minus2.PB(MP(l,r));
        }
    }
    SORT_ASC(plus);
    SORT_DESC(minus2);
    /*
    REP(i,len){
        SORT_ASC(minus[i]);
        
    }
    */

    LL x=0;
    REP(i,SIZE(plus)){
        if(x<plus[i].first){
            std::cout<<"No"<<endl;
            return;
        }
        x+=plus[i].second;

    }
    REP(i,SIZE(minus2)){
        if(x<minus2[i].second){
            std::cout<<"No"<<endl;
            return;
        }
        x+=minus2[i].first-minus2[i].second;

    }
    /*
    PER(i,len){
        int t=i-len;
        PER(j,SIZE(minus[i])){
            if(x<minus[i][j]){
                std::cout<<"No"<<endl;
                return;
            }
            x+=t;
        }
    }
    */

    if(x==0){
        std::cout<<"Yes"<<endl;
    }
    else{
        std::cout<<"No"<<endl;
    }


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	std::cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 49988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testAtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] t = new int[n];
            string[] str = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                t[i] = int.Parse(str[i]);
            }
            int m = int.Parse(Console.ReadLine());
            int[] p = new int[m];
            int[] x = new int[m];
            string[] mtemp;
            for (int i = 0; i < m; i++)
            {
                mtemp = Console.ReadLine().Split();
                p[i] = int.Parse(mtemp[0]);
                x[i] = int.Parse(mtemp[1]);
                //
            }
            var ans = 0;
            for (int i = 0; i < n; i++)
            {
                ans += t[i];
            }
            for (int i = 0; i < m; i++) {
                var temp = (t[p[i]-1] - x[i]);
                if (t[p[i]-1] > x[i])
                {
                    Console.WriteLine(ans - temp);
                }
                else if (t[p[i]-1] < x[i]) Console.WriteLine(ans + Math.Abs(temp));
                else Console.WriteLine(ans);
                
            }
            

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 2776
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    S = input(str)
    th = (len(S) - 1) // 2
    a = S
    b = S[:th]
    c = S[th+1:]
    yesno(a == a[::-1]
          and b == b[::-1]
          and c == c[::-1])


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
#define MOD 1000000007

int high_digit(int x)
{
  while (x / 10 > 0)
  {
    x = x / 10;
  }
  return x % 10;
}

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

  ll n;
  cin >> n;
  ll x[10][10];

  for (auto i = 0; i < 10; i++)
  {
    for (auto j = 0; j < 10; j++)
    {
      x[i][j] = 0;
    }
  }

  for (ll i = 1; i <= n; i++)
  {
    ll low = i % 10;
    ll high = high_digit(i);
    auto p = make_pair(low, high);
    x[low][high]++;
  }

  ll ans = 0;
  for (ll i = 0; i < 10; i++)
  {
    for (ll j = 0; j < 10; j++)
    {
      ans += x[i][j] * x[j][i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<int> size;
    
  UnionFind(int N) : par(N), rank(N), size(N) {
    for (int i = 0; i < N; i++) {
      par[i]  = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }
  
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    
    if (rank[rx] < rank[ry]) {
      par[rx] = ry;
      size[ry] = size[ry] + size[rx];
    }
    else if (rank[rx] > rank[ry]) {
      par[ry] = rx;
      size[rx] = size[rx] + size[ry];
    }
    else {
      par[ry] = rx;
      size[rx] = size[rx] + size[ry];
      rank[rx]++;
    }
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  
  int get_size(int x) {
    int rx = find(x);
    return size[rx];
  }
  
};

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

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

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

  UnionFind uf = UnionFind(N);
  int x, y;
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    x--; y--;
    uf.unite(x, y);
  }

  map<int, vector<int> > mp; // root, i
  for (int i = 0; i < N; i++) {
    int rt = uf.find(i);
    mp[rt].push_back(i);
  }

  int ans = 0;  
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    vector<int> v = itr->second;
    set<int> st;
    for(int i = 0; i < v.size(); i++) {
      st.insert(v[i]);
      st.insert(p[ v[i] ]);
    }
    ans += v.size()*2 - st.size();
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12800
#include<cstdio>
#include<queue>
#include<cstring>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;

int n,m,l;
class edge{
public:
	int t,d,e;
	edge(){}
	edge(int it,int id,int ie){
		t=it;
		d=id;
		e=ie;
	}
};

class data{
public:
	int v,l,cost;
	data(){}
	data(int iv,int il,int icost){
		v=iv;
		l=il;
		cost=icost;
	}

	bool operator<(const data &d1)const{
		return d1.cost<cost;
	}
};
vector<edge> G[101];
int dp[101][101];
int dijk(){
	priority_queue<data> que;
	memset(dp,-1,sizeof(dp));
	dp[1][l]=0;
	que.push(data(1,l,0));
	while(que.size()){
		data q=que.top();
		que.pop();
		if(dp[q.v][q.l]<q.cost)continue;
		if(q.v==n)return q.cost;
		dp[q.v][q.l]=q.cost;
		for(int i=0;i<G[q.v].size();i++){
			edge e=G[q.v][i];
			if(e.d<=q.l){
				if(dp[e.t][q.l-e.d]>q.cost || dp[e.t][q.l-e.d]==-1){
					dp[e.t][q.l-e.d]=q.cost;
					que.push(data(e.t,q.l-e.d,q.cost));
				}
			}
			if(dp[e.t][q.l]>q.cost+e.e || dp[e.t][q.l]==-1){
				dp[e.t][q.l]=q.cost+e.e;
				que.push(data(e.t,q.l,q.cost+e.e));
			}
		}
	}
}

int main(void){
	while(1){
		scanf("%d %d %d",&n,&m,&l);
		if(n+m+l==0)break;
		for(int i=1;i<=n;i++)G[i].clear();
		for(int i=0;i<m;i++){
			int a,b,d,e;
			scanf("%d %d %d %d",&a,&b,&d,&e);
			G[a].push_back(edge(b,d,e));
			G[b].push_back(edge(a,d,e));
		}
		printf("%d\n",dijk());
	}
	return 0;
}

Measured memory_bytes: 1324
# C - Alchemist
N = int(input())
v = list(map(int, input().split()))

new_v = sorted(v)

for i in range(N-1):
    if i == 0 :
        a = (new_v[i]+new_v[i+1])/2
    else:
        a = (a + new_v[i+1])/2
print(a)

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

int n;
int X1[2000], Y1[2000], X2[2000], Y2[2000];
bool fld[4000][4000];
int compress(int*X1, int*X2,vector<int>&X) {
	rep(i, n) {
		X.push_back(X1[i]);
		X.push_back(X2[i]);
	}
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	rep(i, n) {
		X1[i] = lower_bound(X.begin(), X.end(), X1[i]) - X.begin();
		X2[i] = lower_bound(X.begin(), X.end(), X2[i]) - X.begin();
	}
	return X.size();
}
int main() {
	scanf("%d", &n);
	rep(i, n)scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
	vector<int>a, b;
	int w = compress(X1, X2, a), h = compress(Y1, Y2, b);
	rep(i, n) {
		for (int j = X1[i]; j < X2[i]; j++)
			for (int k = Y1[i]; k < Y2[i]; k++)fld[j][k] = true;
	}
	ll ans = 0;
	rep(i, w - 1)rep(j, h - 1) {
		if (fld[i][j])ans += ((ll)a[i + 1] - a[i])*(b[j + 1] - b[j]);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 18992
///Comentary AC

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
int main(){ 
   int x1,x2,y1,y2;
   cin >> x1 >> y1 >> x2 >> y2;
   int dx = x2 - x1, dy = y2 - y1;
   int x = x2, y = y2;
   for (int i=0;i<2;i++){
      swap(dx,dy);
      dx = - dx;
      x += dx;
      y += dy;
      cout << x << " " << y;
      if (i==0) cout << " ";
   }

   cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int x,a,b;
    scanf("%d" "%d" "%d",&x,&a,&b);
	
		
		if(x < b-a){
			printf("dangerous");
			printf("\n");
		}else if(x >= b-a && b-a > 0){
			printf("safe");
			printf("\n");						
		}else if(b-a <= 0){
			printf("delicious");
			printf("\n");
		}

	return 0;
}    


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

int main(){

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

    int a[1001], n, sum = 0, mx = INT_MIN;
    cin >> n;
    for(int i = 0 ;i < n; ++i){
        cin >> a[i];
        sum += a[i];
        mx = max(mx, a[i]);
    }
    cout << (mx < sum - mx ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256