akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	

	int tempNum = 0;
	char tempRank;
	int existCard[4][13] = { 0 };

	char rankList[4] = { 'S', 'H', 'C', 'D' };

	// 0 = スペードが'S'、 1 = ハートが'H'、2 =クラブが'C'、3 = ダイヤが'D'
	int n;
	scanf("%d", &n);

	int i = 0;
	for (; i <= n; i++) {
		scanf("%c %d\n", &tempRank, &tempNum);
		if (tempRank == 'S') {
			existCard[0][tempNum - 1] = 1;
		}
		else if (tempRank == 'H') {
			existCard[1][tempNum - 1] = 1;
		}
		else if (tempRank == 'C') {
			existCard[2][tempNum - 1] = 1;
		}
		else if (tempRank == 'D') {
			existCard[3][tempNum - 1] = 1;
		}
	}

	int j = 0;
	for (; j < 4; j++) {
		for (i = 0; i < 13; i++) {
			if (existCard[j][i] == 0) {
				printf("%c %d\n", rankList[j], i + 1);
			}
		}
	}


	return 0;
}


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

int main() {
  int A, B, answer;
  cin >> A >> B;
  if (A >= 13) {
    answer = B;
  }
  else if (A <= 5) {
    answer = 0;
  }
  else {
    answer = B/2;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int num[3];
	cin>>num[0]>>num[1]>>num[2];
	sort(num,num+3);
	cout<<num[2]*10+num[1]+num[0];
	return 0;
}

Measured memory_bytes: 764
void main() {
	auto N = rs;
	auto S = N.map!(a => a.to!int - '0').sum;
	if(N.to!int%S==0) "Yes".writeln;
	else "No".writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define MAX_N 100000000
#define INF 100000000000000

int main(){
  long long n,m,temp;
  cin >> n >> m;
  temp = m;
  list<long long> p;
  long long ans = 1;
  for(int i=1;i<100000;i++){
    if(m%i == 0){
      p.push_front(i);
      p.push_front(m/i);
    }
  }

  for(auto it=p.begin();it!=p.end();it++){
    long long d;
    d = *it;
    if(temp/d >= n){
      ans = max(ans,d);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
import math
x = x2 - x1
y = y2 - y1
theta3 = math.pi/4
x3 = round(math.sqrt(2) * (x*math.cos(theta3) - y*math.sin(theta3)))
y3 = round(math.sqrt(2) * (x*math.sin(theta3) + y*math.cos(theta3)))
theta4 = math.pi/2
x4 = round(x*math.cos(theta4) - y*math.sin(theta4))
y4 = round(x*math.sin(theta4) + y*math.cos(theta4))

print(x3+x1,y3+y1,x4+x1,y4+y1)

Measured memory_bytes: 3064
import java.util.Scanner;
	public class Main{
	public static void main(String[] args) {
	try (Scanner sc = new Scanner(System.in)) {
	int w = sc.nextInt();
	int n = sc.nextInt();
	int[] values = new int[w];
	for (int i = 0; i < values.length; i++) {
	values[i] = i + 1;
	}
	for (int i = 0; i < n; i++) {
	String str = sc.next();
	String[] ab = str.split(",");
	int a = Integer.parseInt(ab[0]) - 1;
	int b = Integer.parseInt(ab[1]) - 1;
	int value=values[a];
	values[a]=values[b];
	values[b]=value;
	}
	for(int i=0;i<values.length;++i)
	{
		System.out.println(values[i]);
	}
	}
	}
}


Measured memory_bytes: 26032
#include <cstdio>
#include <ctype.h>

using namespace std;

int main(void){
	int sum = 0, val;
	char c;
	while((c = getchar()) != EOF){
		if(isdigit(c)){
			val = c - '0';
			while(isdigit(c = getchar())){
				val = val * 10 + c - '0';
			}
			sum += val;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 932
import sys
input = sys.stdin.readline  #文字列では使わない
A,B,C = map(int, input().split())
K = int(input())
count =0
while A >=B:
    B *=2
    count +=1

while B >=C:
    C *=2
    count +=1

if A < B < C and count <=K:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9132
from collections import deque

INF = float("inf")

H, W = map(int, input().split())
S = [input() for _ in range(H)]

dp = [[INF] * W for _ in range(H)]
dp[0][0] = int(S[0][0] == "#")

Q = deque([(dp[0][0], 0, 0)])
while Q:
    cur, i, j = Q.popleft()
    for ni, nj in [(i + 1, j), (i, j + 1)]:
        if H <= ni or W <= nj:
            continue

        c = int(S[i][j] != S[ni][nj])
        if dp[ni][nj] > cur + c:
            dp[ni][nj] = cur + c
            Q.append((cur + c, ni, nj))

print((dp[H - 1][W - 1] + 1) // 2)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    vector<int> num(3);
    cin >> num[0] >> num[1] >> num[2];
    int ans = 0;
    while(num[0] != num[1] || num[1] != num[2] || num[2] != num[0]){
        sort(num.begin(),num.end());
        num[0]++;
        sort(num.begin(),num.end());
        num[0]++;
        ans++;
    }
    cout << ans << endl;
}

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

public class Main {

    static final long MOD = 1000_000_007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        Arrays.sort(a);
        if (n % 2 == 1 && a[0] != 0) {
            System.out.println(0);
            return;
        }

        int now = n % 2 + 1;
        int i = n % 2;
        while (i < n) {
            if (a[i] == a[i + 1] && a[i] == now) {
                i += 2;
                now += 2;
                continue;
            } else {
                System.out.println(0);
                return;
            }
        }

        long ans = 1;
        for (int j = 0; j < n / 2; j++) {
            ans = modmul(ans, 2, MOD);
        }

        System.out.println(ans);
    }

    static long modmul(long a, long b, long mod) {
        return (a * b) % mod;
    }
}

Measured memory_bytes: 48756
#include <cstdio>
#include <stack>
using namespace std;
struct Stone {
	bool color;
	int num;
	Stone(bool _col,int _num) {color=_col,num=_num;}
};
int main() {
	int n;
	while(scanf("%d",&n),n) {
		stack<Stone> stone;
		bool c;
		scanf("%d",&c);
		stone.push(Stone(c,1));
		for(int i=1;i<n;i++) {
			bool c;
			scanf("%d",&c);
			Stone S(stone.top()); stone.pop();
			if((i&1)==0) {
				if(S.color^c) {
					stone.push(S);
					stone.push(Stone(c,1));
				}else {
					S.num++;
					stone.push(S);
				}
			}else {
				if(S.color^c) {
					if(stone.size()) {
						Stone _S(stone.top()); stone.pop();
						stone.push(Stone(c,S.num+_S.num+1));
					}else {
						stone.push(Stone(c,S.num+1));
					}
				}else {
					S.num++;
					stone.push(S);
				}
			}
		}
		int sum=0;
		while(stone.size()) {
			Stone S(stone.top()); stone.pop();
			if(!S.color) sum+=S.num;
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 1036
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 6666;

char s[MAX];
int w[MAX];
string f[MAX];
string g[MAX];
int h[MAX];
int bio[MAX];
int cookie;

int main(void) {
  int N;
  scanf("%d", &N);
  scanf("%s", s);

  vector<int> a, b;
  REP(i, 2 * N) {
    if (s[i] == 'a') {
      w[i] = a.size();
      a.push_back(i);
    } else {
      w[i] = b.size();
      b.push_back(i);
    }
  }

  REP(i, 2 * N) {
    if (s[i] == 'b' && a[w[i]] > i) {
      cookie++;

      int e = i, j = i;
      while (j <= e) {
        if (s[j] == 'b' && a[w[j]] > j) {
          if (a[w[j]] > j) {
            bio[a[w[j]]] = cookie;
            e = max(e, a[w[j]]);
          }
          g[i].push_back(s[j]);
        } else if (bio[j] == cookie) {
          g[i].push_back(s[j]);
        }
        j++;
      }
      h[i] = e;
    }
  }

  f[N] = "";
  for (int i = 2 * N - 1; i >= 0; --i) {
    f[i] = f[i + 1];
    if (s[i] == 'a') {
      if (b[w[i]] > i) {
        f[i] = max(f[i], "ab" + f[b[w[i]] + 1]);
      }
    } else {
      if (a[w[i]] > i) {
        f[i] = max(f[i], g[i] + f[h[i] + 1]);
      }
    }
  }

  puts(f[0].c_str());
  return 0;
}


Measured memory_bytes: 16384
S = input()
if S[0]==S[1]==S[2]==S[3]:
    print("No")
elif (S[0]==S[1] and S[2]==S[3]) or (S[0]==S[2] and S[1]==S[3]) or (S[0]==S[3] and S[1]==S[2]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
from itertools import accumulate
N = int(input())
t = [0]*2 + list(map(int, input().split())) + [0]
v = [0] + list(map(int, input().split())) + [0]
N += 3

at = list(accumulate(t))
T = at[-1]

s = [0]*(2*T+1)

minvs = []
for i in range(2*T+1):
    t = i*0.5
    minv = 10**10
    for j in range(N-1):
        if t < at[j]:
            tmpv = v[j] + (at[j]-t)
        elif at[j] <= t and t <= at[j+1]:
            tmpv = v[j]
        else:
            tmpv = v[j] + (t-at[j+1])
        minv = min(minv, tmpv)
    minvs.append(minv)
ans = 0.0
for i in range(2*T):
    ans += (minvs[i]+minvs[i+1])*0.25
print(ans)


Measured memory_bytes: 45788
def f(x, y, z):
    return x*x + y*y + z*z + x*y + y*z + z*x

n = int(input())

cnt = {}
for x in range(1, 101):
    for y in range(1, 101):
        if(f(x, y, 1) > n): break
        for z in range(1, 101):
            if(f(x, y, z) > n): break
            
            val = f(x, y, z)

            if(cnt.get(val) is None): cnt[val] = 1
            else: cnt[val] += 1

for i in range(1, n+1):
    if(cnt.get(i) is None): print(0)
    else: print(cnt[i])

Measured memory_bytes: 9820
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  int h, w, K;
  cin >> h >> w >> K;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  
  int ans = INF;

  rep(div, 1<<(h - 1)) {
    vector<int> id(h);
    int g = 0;
    rep(i, h) {
      id[i] = g;
      if(div>>i&1) ++g;
    }
    ++g;

    vector<vector<int>> c(g, vector<int>(w));
    rep(i, h)rep(j, w) c[id[i]][j] += s[i][j] - '0';
    int cnt = g - 1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i, g) now[i] += c[i][j];
      rep(i, g) if(now[i] > K) return false;
      return true;
    };
    
    rep(j, w) {
      if(!add(j)) {
        cnt++;
        now = vector<int>(g);
        if(!add(j)) {
          cnt = INF;
          break;
        }
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

const int INF = 1e9;

signed main() {
    int n,m;
    cin >> n >> m;

    int a[m+1];
    int dp[22][50050];
    rep(i,22) rep(j,50050) dp[i][j] = INF;
    for(int i = 1; i <= m; i++) cin >> a[i];

    dp[0][0] = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 0; j <= n; j++){
            if(j - a[i] >= 0){
                dp[i][j] = min(dp[i-1][j - a[i]] + 1, dp[i][j - a[i]] + 1);
            }
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
        }
    }
    cout << dp[m][n] << endl;
}



Measured memory_bytes: 11716
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

#define INF 100000

int main() {
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int vecX = x2 - x1, vecY = y2 - y1;
    int x3 = x2 - vecY, y3 = y2 + vecX, x4 = x3 - vecX, y4 = y3 - vecY;

    cout << x3 << " " << y3 <<" " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
//-------------------
int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    ll x,k,d; cin >> x >> k >> d;
    if(x < 0) x = -x;
    if(x/d >= k) cout << x - k*d << endl;
    else {
        ll res = k-x/d;
        if(res%2==0) {
            cout << x - d * (x/d) << endl;
        } else {
            cout << abs(x - d * (x/d) -d ) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i <= s.length() - t.length(); i++) {
            char[] v = s.substring(i, i + t.length()).toCharArray();
            int a = 0;
            for (int j = 0; j < v.length; j++) {
                if (t.charAt(j) != v[j]) {
                    a++;
                }
            }
            ans = Math.min(a, ans);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 37244
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
f = True
l = [a, b, c, d, e]
for m in range (0, 5):
    for n in range(m, 5):
        if l[n] - l[m] > k:
            f = False

if f == False:
    print (":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
using namespace std;
using ll = long long int;

struct Elem {
    int gold, silver, bronze;
    Elem() {}
    Elem(int a, int b, int c) : gold(a), silver(b), bronze(c) {}
    bool operator<(const Elem &e) const {
        int valL = gold - silver;
        int valR = e.gold - e.silver;
        return valL > valR;
    }
};

int main() {
    int X, Y, Z; cin >> X >> Y >> Z;
    int S = X + Y + Z;
    vector<Elem> people;
    for(int i=0; i<S; i++) {
        int A, B, C; cin >> A >> B >> C;
        people.emplace_back(A, B, C);
    }
    sort(people.begin(), people.end());

    /*
    for(auto x : people) {
        fprintf(stderr, "elem: gold = %d, silver = %d, bronze = %d\n", x.gold, x.silver, x.bronze);
    }
    */

    // priority_queue にのせるやつ
    auto compL = [](Elem e1, Elem e2) {
        int valL = e1.gold - e1.bronze;
        int valR = e2.gold - e2.bronze;
        return valL > valR;
    };

    auto compR = [](Elem e1, Elem e2) {
        int valL = e1.silver - e1.bronze;
        int valR = e2.silver - e2.bronze;
        return valL > valR;
    };

    priority_queue<Elem, vector<Elem>, decltype(compL)> queL(compL);
    priority_queue<Elem, vector<Elem>, decltype(compR)> queR(compR);

    // 左から (金の枚数) - (銀の枚数) 降順に並んでいる
    // sumGoldL と sumSilverR は、queue に入っている要素に対する合計
    // sumBronzeL と sumBronzeR は、queue に入っていない要素に対する合計
    ll sumGoldL = 0, sumSilverR = 0, sumBronzeL = 0, sumBronzeR = 0;
    for(int i=0; i<S; i++) {
        if(i < X) {
            queL.push(people[i]);
            sumGoldL   += people[i].gold;
        }
        if(i >= X+Z) {
            queR.push(people[i]);
            sumSilverR += people[i].silver;
        }
    }

    vector<ll> cand(S);
    for(int i=X; i<X+Z+1; i++) {
        // fprintf(stderr, "cand[%d:L] = %lld\n", i, sumGoldL + sumBronzeL);
        cand[i] += sumGoldL + sumBronzeL;
        // i 番目の要素を L に追加
        queL.push(people[i]);
        sumGoldL += people[i].gold;
        while(queL.size() > X) {
            Elem e = queL.top(); queL.pop();
            sumGoldL   -= e.gold;
            sumBronzeL += e.bronze;
        }
    }

    for(int i=X+Z-1; i>=X-1; i--) {
        // fprintf(stderr, "cand[%d:R] = %lld\n", i+1, sumSilverR + sumBronzeR);
        cand[i+1] += sumSilverR + sumBronzeR;
        // i 番目の要素を R に追加
        queR.push(people[i]);
        sumSilverR += people[i].silver;
        while(queR.size() > Y) {
            Elem e = queR.top(); queR.pop();
            sumSilverR -= e.silver;
            sumBronzeR += e.bronze;
        }
    }

    cout << *max_element(cand.begin(), cand.end()) << endl;
    return 0;
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  bool a =false;
  rep(i,n){
    rep(j,n){
      int cost = 4*i+7*j;
      if(cost==n) a=true;
    }
  }
  if(a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector <ll> a(n+1), dp[3];
	for (int i=0; i<=2; i++) {
		dp[i].resize(n+1);
		for (int j=1; j<=n; j++) {
			dp[i][j] = -1e18;
		}
	}
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}
	for (int i=1; i<=n; i++) {
		for (int j=0; j<=2; j++) {
			if (i-j-2 < 1) continue;
			for (int k=0; k<=2-j; k++) {
				dp[j+k][i] = max(dp[j+k][i], dp[k][i-j-2]+a[i]);
			}
		}
		if (i <= 3) {
			dp[max(0, i-2)][i] = a[i];
		}
	}
	ll ans;
	if ((n&1)) {
		ans = max(max(max(dp[1][n], dp[2][n]), max(dp[0][n-1], dp[1][n-1])), dp[0][n-2]);
	} else {
		ans = max(dp[1][n], max(dp[0][n], dp[0][n-1]));
	}
	cout << ans;
	return 0;
}


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


long long int min(long long int a, long long int b){
  return a < b ? a : b;
}


long long int calc(const vector<int>& a, int sig,
                   long long int sum = 0,
                   long long int ope = 0,
                   size_t index = 0){
  if(index == a.size()){ return ope; }
  
  sum += a[index];
  
  // プラスに押しあげるフェイズの場合
  if(sig == 1 && sum < 1){
    ope += 1 - sum;
    sum = 1;
  }
  // マイナスに引きさげるフェイズの場合
  else if(sig == -1 && sum > -1){
    ope += sum + 1;
    sum = -1;
  }
  
  return calc(a, sig * (-1), sum, ope, index + 1);
}


int main(void){
  int n;
  cin >> n;

  vector<int> a(n);
  for(int i = 0; i < n; i++){ cin >> a[i]; }
  
  cout << min(calc(a, 1), calc(a, -1)) << endl;
  
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {

	void submit() {
		String s = "" + (nextLong() + 1);
		int ans = 0;
		int pref = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != '0') {
				int cur = pref + s.charAt(i) - '1' + (s.length() - 1 - i) * 9;
				ans = Math.max(ans, cur);
			}
			pref += s.charAt(i) - '0';
		}
		out.println(ans);
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 21332
def main():
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    f=sorted(list(map(int,input().split())),reverse=True)
    def b_search(a,b,value,lim):
        med=(a+b)//2
        if a==b:return a
        elif lim=="upper":
            if a+1==b:
                if value(b):return b
                else:return a
            elif value(med):return b_search(med,b,value,lim)
            else:return b_search(a,med-1,value,lim)
        else:
            if a+1==b:
                if value(a):return a
                else:return b
            elif value(med):return b_search(a,med,value,lim)
            else:return b_search(med+1,b,value,lim)

    def count(val):
        cnt=0
        for i in range(n):
            cnt+=max(a[i]-val//f[i],0)
        if cnt>k:
            return False
        else:
            return True
    
    print(b_search(0,10**12+10,count,"lower"))
    
main()

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

using namespace std;

typedef long long ll;

const int N = 42;

ll dp[N][N][N];
int n;
char s[N][N];

ll solve(int l, int p, int r) {
  if (l == p && p == r) return 1;
  if (dp[l][p][r] != -1) return dp[l][p][r];
  ll &res = dp[l][p][r];
  res = 0;
  for (int a = l; a < p; a++) {
    for (int b = r; b > p; b--) {
      for (int x = l; x <= a; x++) {
        for (int y = r; y >= b; y--) if (s[x][y] == '1') {
          res += solve(l, x, a) * solve(b, y, r) * solve(a + 1, p, b - 1);
        }
      }
    }
  }
  return res;
}

int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= 2 * n; i++) scanf("%s", s[i] + 1);
  ll ans = 0;
  for (int i = 2; i <= 2 * n; i++) {
    if (s[1][i] == '1') {
      ans += solve(2, i, 2 * n);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
ll inf = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans;

  if(k % 2 == 0) {
    ans = a - b;
  } else {
    ans = b - a;
  }
  if(abs(ans) <= inf) {
    cout << ans << endl;
  } else {
    cout << "Unfair" << endl;
  }
  return 0;
}

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

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int x;
    int a;
    cin >> x >> a;
    if (x < a) { cout << "0" << endl; }
    else { cout << "10" << endl; }

    return 0;
}


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

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

    int n;
    cin >> n;

    vector<int> m;
    m.reserve(n);

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

        auto it = upper_bound(m.begin(), m.end(), a, greater<>());
        if (it == m.end()) m.push_back(a); else *it = a;
    }

    cout << m.size() << endl;

    return 0;
}

Measured memory_bytes: 640
from sys import stdin
#from pprint import pprint
input = stdin.readline

N, M, Q = map(int, input().split())

count = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
    l, r = map(int, input().split())
    count[l][r] += 1
# pprint(count)

accum = [[0]*(N+1) for _ in range(N+1)]
for i in range(N+1):
    accum[i][0] = count[i][0]
    for j in range(1, N+1):
        accum[i][j] = accum[i][j-1] + count[i][j]
for i in range(1, N+1):
    for j in range(N+1):
        accum[i][j] = accum[i-1][j] + accum[i][j]
# pprint(accum)

test = [[0]*(N+1) for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, N+1):
        test[i][j] = accum[j][j] - accum[i-1][j] - \
            accum[j][i-1] + accum[i-1][i-1]
# pprint(test)


for _ in range(Q):
    p, q = map(int, input().split())
    ans = accum[q][q] - accum[p-1][q] - accum[q][p-1] + accum[p-1][p-1]
    print(ans)


Measured memory_bytes: 25048
#include <stdio.h>
int main(void){
   int a,b;
   char op;
   
   
   while(1){
   scanf("%d %c %d", &a, &op, &b);
   if( op == '?')break;
   
   if ( op == '+' )
    printf("%d\n",(a+b));
    else if ( op == '-' )
    printf("%d\n",(a-b));
    else if ( op == '*' )
    printf("%d\n",a*b);
    else if ( op == '/' )
    printf("%d\n",a/b);
} 

return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));

typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
int main(){
    ll n,a,b;
    std::cin >> n>>a>>b;
    std::cout << max(0ll,(b*(n-1)+a)-(a*(n-1)+b)+1ll) << std::endl;
}


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

int main(){
    int S, W;
    cin >> S >> W;

    if(W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
  
int W,H,x,y,r;
 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if(x-r >= 0 && x+r <= W){
   if(y-r >= 0 && y+r <= H){
     printf("Yes\n");
   }else{
     printf("No\n");
   };
 }else{
   printf("No\n");
 }
 return 0;
}
     

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n,m;
  cin>>n;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  cin>>m;
  vector<string>t(m);
  rep(i,m)cin>>t[i];
  int ans=0;
  rep(i,n){
    int score=0;
    rep(j,n){
      if(s[i]==s[j])score++;
    }
    rep(j,m){
      if(s[i]==t[j])score--;
    }
    ans=max(score,ans);
  }
  cout<<ans<<endl;
}


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

int n,c;
int t[10][10];
bool vis[10][10],flag;
int dy[] = {0,1,1,0,-1,-1}, dx[] = {1,1,0,-1,-1,0};

int dfs(int y,int x,int col){
  if(vis[y][x])return 0;
  if(t[y][x] != col){
    if(t[y][x] == 0)flag = true;
    return 0;
  }
  vis[y][x] = true;

  int res = 1;
  rep(i,6){
    int ty = y+dy[i], tx = x+dx[i];
    if(ty<0 || tx<0 || ty>=n || tx>ty)continue;
    res += dfs(ty,tx,col);
  }
  return res;
}

int solve(){
  int res = 0;
  rep(i,n)rep(j,i+1)vis[i][j] = false;

  int cnt = 0;
  rep(i,n)rep(j,i+1){
    if(!vis[i][j] && t[i][j]){
      cnt++;
      flag = false;
      int tmp = dfs(i,j,t[i][j]);
      if(!flag){
	if(t[i][j] == c)res -= tmp;
	else res += tmp;
      }
    }
  }
  return res;
}

int main(){
  while(cin >> n >> c,n||c){
    bool f = false;
    rep(i,n)rep(j,i+1){
      cin >> t[i][j];
      if(!t[i][j])f = true;
    }

    if(!f){
      cout << 0 << endl;
      continue;
    }

    int ans = -100000;
    rep(i,n)rep(j,i+1){
      if(!t[i][j]){
	t[i][j] = c;
	ans = max(ans,solve());
	t[i][j] = 0;
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
def chekend(mc):
    for m in mc:
        if not all(m):
            return False
    return True


def solve(n):
    mc = [ [ 0 for j in xrange(n) ] for i in xrange(n)]
    px = n/2
    py = n/2 + 1
    cnt = 1
    mc[py][px] = cnt
    px += 1
    py += 1
    cnt += 1
    while True:
        if chekend(mc): break
        if px >= n: px = 0; continue
        if px < 0: px = n-1; continue
        if py >= n: py = 0; continue
        if mc[py][px]: px -= 1; py += 1; continue
        mc[py][px] = cnt
        cnt += 1
        px += 1
        py += 1

    for m in mc:
        line = ""
        for l in m:
            line += "%4d"%(l)
        print line
while True:
    n = input()
    if n == 0:
        break
    solve(n)

Measured memory_bytes: 4268
a,b,c,d,e = map(int, input().split())

if a ==0:
    print(1)
    exit()
elif b ==0:
    print(2)
    exit()
elif c ==0:
    print(3)
    exit()
elif d ==0:
    print(4)
    exit()
else:
    print(5)

Measured memory_bytes: 9116
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i <= ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i >= ll(b); --i)
#define loop while(true)
#define asort(array, size) std::sort(array, array + size)
#define cauto const auto&
#define bit(n) (1LL << (n))

int main()
{
    string N;
    cin >> N;
    int n = 0;
    for (const auto c : N) {
        n += (c - '0');
    }
    if (n % 9) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>
#include <map>
#include <utility>
#include <numeric>
#include <set>
#include <map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define _USE_MATH_DEFINES

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

const ll INF = 999999999;
const ll atcoder = 1000000007;
const int dx[4] = { 1 , 0 , -1 ,0 };
const int dy[4] = { 0 , 1 , 0 , -1 };

int kaijo(int n) {
	if (n == 1) return 1;
	return kaijo(n - 1)*n;
}

int main() {

	int dist[210][210];
	int n, m, R,a;
	int r[10];
	int ans = INF;

	for (int i = 0; i < 210; i++) {
		for (int j = 0; j < 210; j++) {
			dist[i][j] = INF;
		}
	}

	cin >> n >> m >> R;

	for (int i = 0; i < R; i++)cin >> r[i];

	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		dist[a][b] = c;
		dist[b][a] = c;
	}

	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	a = kaijo(R);
	sort(r, r + R);
		
	do {
		int s = 0;
		for (int i = 0; i < R - 1; i++) {
			s += dist[r[i]][r[i + 1]];
		}
		ans = min(s, ans);
	} while (next_permutation(r, r + R));

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 384
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def is_square_number(a, b):
    x = a * (10 ** len(str(b))) + b
    if((x ** 0.5).is_integer()): return True
    else: return False

def main():
    a, b = list(map(int, input().split()))
    if is_square_number(a, b):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    try:
        assert is_square_number(1, 21) == True
        assert is_square_number(100, 100) == False
        assert is_square_number(12, 10) == False
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;
int n, a[1000010];
struct node {
    int id;
    long long point;
} node[1<<22];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int count = 0;
	for (int a = 0; a <= A; ++a) {
		for (int b = 0; b <= B; ++b) {
			for (int c = 0; c <= C; ++c) {
				int total = 500 * a + 100 * b + 50 * c;
				if (total == X) ++count;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SORT(i) sort((i).begin(), (i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
 
int main(){
    int X, A, B;
    cin >> X >> A >> B;
    X -= A;
    cout << X % B << "\n";

    return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,M = LI()
    print("Yes" if N==M else "No")

main()



Measured memory_bytes: 26136
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
signed main() {
	int n, d; cin >> n >> d;
	int x[50][50], ans=0;
	for (int i = 0; i < n; i++)for (int j = 0; j < d; j++)cin >> x[i][j];
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			double sum = 0;
			for (int k = 0; k < d; k++)sum += pow(x[i][k] - x[j][k], 2);
			sum = sqrt(sum);
			if (sum == (double)(int)sum)ans++;
		}
	}
	cout << ans << endl;
}

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

int main() {
    int n, a;
    cin >> n >> a;

    if (n % 500 <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << 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<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

vector<vector<ll>> ql;
ll n, m, q, a, b, c, d;
ll ans = 0;

void calscore(vector<ll> x){
	ll ansl = 0;
	REP(i,q) if (x[ql[i][1]-1]-x[ql[i][0]-1]==ql[i][2]) ansl+=ql[i][3];
	//cout << ansl << endl;
	ans = max(ans,ansl);
}

void dfs(vector<ll> x){
	if (x.size()==n){
		//REP(i,x.size()) cout << x[i] << " ";
		//cout << endl;
		calscore(x);
		return;
	}
	x.pb(x.back());
	while (x.back()<=m){
		dfs(x);
		x.back()++;
	}
	return;
}

int main(){
	cin >> n >> m >> q;
	REP(i,q){
		cin >> a >> b >> c >> d;
		ql.pb({a,b,c,d});
	}
	dfs({1});
	cout << ans << endl;
}

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

int main(){
	string S, K;
	int count = 0;
	bool flag = true;
	cin >> S >> K;

	int *array = new int[S.size()];
	for(int i=0; i<S.size(); i++){
		array[i] = S[i] - '0';
		if(array[i] == 1 && flag){
			count++;
		}else{
			flag = false;
		}
	}

	if(K.size() <= 3){
		int num = stoi(K);
		if(num <= count){
			cout << 1;
			delete[] array;
			return 0;
		}
	}
	cout << array[count];

	delete[] array;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> dat[1000000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			int r,s,t,u,v,w,x,y,z;
			scanf("%d%d%d%d%d%d%d%d%d",&r,&s,&t,&u,&v,&w,&x,&y,&z);
			int q=(s+u+w+y)*60+t+v+x+z;
			dat[i]=make_pair(q,r);
		}
		std::sort(dat,dat+a);
		printf("%d\n%d\n%d\n",dat[0].second,dat[1].second,dat[a-2].second);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s;
	cin >> s;
	int a,b,c,d;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';
	if(a+b+c+d==7)cout<<s[0]<<'+'<<s[1]<<'+'<<s[2]<<'+'<<s[3];
	else if(a+b+c-d==7)cout<<s[0]<<'+'<<s[1]<<'+'<<s[2]<<'-'<<s[3];
	else if(a+b-c+d==7)cout<<s[0]<<'+'<<s[1]<<'-'<<s[2]<<'+'<<s[3];
	else if(a+b-c-d==7)cout<<s[0]<<'+'<<s[1]<<'-'<<s[2]<<'-'<<s[3];
	else if(a-b+c+d==7)cout<<s[0]<<'-'<<s[1]<<'+'<<s[2]<<'+'<<s[3];
	else if(a-b+c-d==7)cout<<s[0]<<'-'<<s[1]<<'+'<<s[2]<<'-'<<s[3];
	else if(a-b-c+d==7)cout<<s[0]<<'-'<<s[1]<<'-'<<s[2]<<'+'<<s[3];
	else cout<<s[0]<<'-'<<s[1]<<'-'<<s[2]<<'-'<<s[3];
	cout<<"=7"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define alpha_size 26

int nC2(int n){
  return n * (n - 1) / 2;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
    
    int n, m;
    cin >> n >> m;
    int even = nC2(n);
    int odd = nC2(m);
    cout << even + odd << endl;
}



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

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

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let n = int();
    const MOD: i64 = 1000000007;

    let mut a = 1;
    for k in 1..(n + 1) {
        a = a * k % MOD
    }
    println!("{}", a)
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
  int machi[4] = {};
  int a[3];
  int b[3];
  int i;
  char *ans ="YES";
  for (i=0;i<3;i++)
  {
    scanf("%d %d",&a[i],&b[i]); 
  }
  for (i=0;i<3;i++)
  {
    machi[a[i]-1]++;
    machi[b[i]-1]++;
  }
  for (i=0;i<4;i++)
  {
    if ( machi[i] >= 3 ){
      ans = "NO";
      break;
    }
  }
  printf ("%s\n",ans);
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int64_t sum=0;
	unordered_map<int,int>a;
	for(int i=0;i<n;++i){
		int A; cin>>A;
		++a[A];
		sum+=A;
	}
	int q; cin>>q;
	for(int i=0;i<q;++i){
		int b,c; cin>>b>>c;
		sum-=1L*c*a[c];
		a[c]+=a[b];
		sum+=1L*c*a[c];
		sum-=1L*b*a[b];
		a.erase(b);
		cout<<sum<<"\n"s;
	}
}

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

int main(){
  string S;
  cin>>S;
  vector<string> data{"dream","dreamer","erase","eraser"};
  
  string a;
  bool b=true;
  reverse(S.begin(),S.end());
  for(int i=0;i<4;i++){
   reverse(data[i].begin(),data[i].end()); 
  }
  bool handan=true;
  for(int j=0;j<S.size();){
    int a=j;
	for(int i=0;i<4;i++){
       if(S.substr(j,data[i].size())==data[i]){
         //cout<<"data="<<data[i]<<" j="<<j<<endl;
         j+=data[i].size();
         //cout<<"data="<<data[i]<<" j="<<j<<endl;
       }
    }
    if(j==a){
      //cout<<"j,a="<<j<<a<<endl;
      handan=false;
      break;
    }
  }
  
  if(handan==true){
   cout<<"YES"<<endl; 
  }else{
   cout<<"NO"<<endl; 
  }


}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int N;
long long C;

int main() {
    cin >> N >> C;
    vector<int> v(N);
    vector<long long> x(N), cal(N);
    vector<long long> clock(N), clock_turn(N);
    cin >> x[0] >> v[0];
    cal[0] = v[0];
    clock[0] = max(v[0] - x[0], 0ll);
    clock_turn[0] = max(0ll, v[0] - 2 * x[0]);
    for (int i = 1; i < N; i++) {
        cin >> x[i] >> v[i];
        cal[i] = cal[i - 1] + v[i];
        clock[i] = max(clock[i - 1], cal[i] - x[i]);
        clock_turn[i] = max(clock_turn[i - 1], cal[i] - x[i] * 2);
    }
  
    //反時計回りでも計算
    vector<long long> anti(N), anti_turn(N);
    cal[0] = v[N - 1];
    anti[N - 1] = max(v[N - 1] - C + x[N - 1], 0ll);
    anti_turn[N - 1] = max(0ll, v[N - 1] - 2 * (C - x[N - 1]));
    for (int i = 1; i < N; i++) {
        cal[i] = cal[i - 1] + v[N - i - 1];
        anti[N - i - 1] = max(anti[N - i], cal[i] - C + x[N - i - 1]);
        anti_turn[N - i - 1] = max(anti_turn[N - i], cal[i] - (C - x[N - i - 1]) * 2);
    }
    
      long long ans = max(clock[N - 1], anti[0]);
    for (int i = 0; i < N - 1; i++) {
        long long tmp = max(clock_turn[i] + anti[i + 1], clock[i] + anti_turn[i + 1]);
 	    ans = max(tmp, ans);
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int> > minpq;

int main() {
    while (true) {    
        int n, m, t, p;
        cin >> n >> m >> t >> p;
        if (n == 0) break;
        int yoko[32], tate[32];
        fill(yoko, yoko + n, 1);
        fill(tate, tate + m, 1);

        for (int i=0; i<t; i++) {
            int d, c;
            cin >> d >> c;
            int buf[32] = {0};
            if (d == 1) {
                for (int j = 0; j < n; j++) {
                    if (c + j < n) buf[j] += yoko[c + j];
                    if (c - 1 - j >= 0) buf[j] += yoko[c - 1 - j];
                }
                copy(buf, buf + n, yoko);
                n = max(c, n - c);
            } else {
                for (int j = 0; j < m; j++) {
                    if (c + j < m) buf[j] += tate[c + j];
                    if (c - 1 - j >= 0) buf[j] += tate[c - 1 - j];
                }
                copy(buf, buf + m, tate);
                m = max(c, m - c);
            }
        }
        int x[p], y[p];
        for (int i = 0; i < p; i++) {
            cin >> x[i] >> y[i];
        }

        for (int i=0; i<p; i++) {
            cout << yoko[x[i]] * tate[y[i]] << '\n';
        }
    }
    return 0;
}


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

using namespace std;
typedef long long ll;


int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
    ll ans = 0 ;
    int tot = 0;
    for(int i=a;i>=1;i--){
    	ans += 1;
    	tot++;
    	if(tot==d){
    		cout<<ans<<endl;
    		return 0;
		}
	}
    for(int i=b;i>=1;i--){
    	tot++;
    	if(tot==d){
    		cout<<ans<<endl;
    		return 0;
		}
	}
	for(int i=c;i>=1;i--){
    	ans -= 1;
    	tot++;
    	if(tot==d){
    		cout<<ans<<endl;
    		return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 3628
import sys
import itertools


class UnionFindTree:
    def __init__(self, n: int) -> None:
        self.par = list(range(n))
        self.rank = [0] * n

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


def resolve(in_):
    N, M = map(int, next(in_).split())
    tree = UnionFindTree(N + 1)
    AB = (map(int, line.split()) for line in itertools.islice(in_, M))
    for a, b in AB:
        tree.unite(a, b)
    
    ans = len(frozenset(tree.find(x) for x in range(1, N + 1))) - 1
    return ans


def main():
    ans = resolve(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21656