akhauriyash/Code-Regression huggingface dataset:
import itertools as it

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

cnt = 0
for i in it.permutations([i for i in range(1, n + 1)], n):
    cnt += 1
    if list(i) == p:
        a = cnt
    if list(i) == q:
        b = cnt
        
print(abs(a-b))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Verified: AOJ-DSL1A, AGC002D
class UFSet {
 private:
  vector<int> ranks;
  vector<int> prevs;
  vector<int> sizes;

 public:
  UFSet(int n) : ranks(n), prevs(n), sizes(n) {
    for (int i = 0; i < n; i++) prevs[i] = i;
    for (int i = 0; i < n; i++) sizes[i] = 1;
  }

  // Returns an ID of a set which x belongs to.
  int Find(int x) {
    if (x != prevs[x]) prevs[x] = Find(prevs[x]);
    return prevs[x];
  }

  // Merges a set which x blongs to and a set which y belongs to.
  void Union(int x, int y) {
    int x_root = Find(x);
    int y_root = Find(y);
    if (ranks[x_root] > ranks[y_root]) {
      prevs[y_root] = prevs[x_root];
      sizes[x_root] += sizes[y_root];
    } else if (ranks[x_root] < ranks[y_root]) {
      prevs[x_root] = prevs[y_root];
      sizes[y_root] += sizes[x_root];
    } else if (prevs[x_root] != prevs[y_root]) {
      prevs[y_root] = prevs[x_root];
      ranks[x_root]++;
      sizes[x_root] += sizes[y_root];
    }
  }

  // Returns a size of a set which x belongs to.
  int Size(int x) {
    return sizes[Find(x)];
  }
};

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

  int n;
  cin >> n;
  vector<tuple<int, int>> ps(n);
  vector<int> original_xs(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    ps[i] = {x, y};
    original_xs[i] = x;
  }
  sort(ps.begin(), ps.end(), [](const auto& p1, const auto& p2) {
    return get<1>(p1) > get<1>(p2);
  });

  UFSet uf_set(n);
  set<int> s;

  for (const auto [x, y] : ps) {
    if (s.empty()) {
      s.insert(x);
    } else if (*s.rbegin() < x) {
      s.insert(x);
    } else {
      vector<int> remove_vector;
      for (auto it = s.rbegin(); it != s.rend(); it++) {
        if (*it > x) {
          if (it != s.rbegin()) remove_vector.push_back(*it);
        } else {
          break;
        }
      }
      for (int rx: remove_vector) {
        // cout << rx << " " << *s.rbegin() << endl;
        uf_set.Union(rx, *s.rbegin());
        s.erase(rx);
      }
      uf_set.Union(x, *s.rbegin());
    }

    // DUMP
    // for (int sx : s) {
    //   cout << sx << " ";
    // }
    // cout << endl;
  }

  for (int i = 0; i < n; i++) {
    cout << uf_set.Size(original_xs[i]) << "\n";
  }
}

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

int main(){
  int d,t,s;
  cin >> d >> t >> s;
  if(t*s >= d)cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int s_sum = 0;
    priority_queue<int, vector<int>, greater<int> > s_not_10mul;
    rep(i, n) {
        int s;
        cin >> s;
        s_sum += s;
        if (s % 10 != 0) s_not_10mul.push(s);
    }

    if (s_sum % 10 == 0) {
        if (s_not_10mul.size() == 0) {
            cout << 0 << endl;
        } else {
            cout << s_sum - s_not_10mul.top() << endl;
        }
    } else {
        cout << s_sum << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int
main()
{
      int a, b, x, sum;
      char z[10];
      
      while(scanf("%d %d", &a, &b) != EOF)
      {
         sum = a+b;
         sprintf(z, "%d", sum);
         x = strlen(z);
         printf("%d\n", x);                         
      }

return 0;
}

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

using namespace std;
int input(){
    int res = 0; char c = ' ';
    while (c < '0') c = getchar();
    while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
    return res;
}
const int N = 301;

int a[N][N], s[N], c[N];
char d[N];
int main(){
    int n = input(), m = input(), ans = 1e9;
    for (int i = 0; i < n; ++ i)
        for (int j = 0; j < m; ++ j)
            a[i][j] = input() - 1;
    for (int i = 0; i < m; ++ i){
        for (int j = 0; j < n; ++ j){
            while (d[a[j][s[j]]]) ++ s[j];
            ++ c[a[j][s[j]]];
        }
        int idx, mx = -1;
        for (int j = 0; j < m; c[j] = 0, ++ j)
            if (c[j] > mx)
                mx = c[idx = j];
        d[idx] = 1;
        ans = min(ans, mx);
    }
    cout << ans;
}


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


D = ini()
C = inl()
assert len(C) == 26
S = [None] * D
for i in range(D):
    S[i] = inl()
    assert len(S[i]) == 26
T = [ini() - 1 for _ in range(D)]
changes = []
M = ini()
for i in range(M):
    d, q = inm()
    d -= 1
    q -= 1
    changes.append((d, q))
# changes.sort()


def main():
    last = [[-1] * (D + 1) for _ in range(26)]
    score = 0
    for d in range(D):
        ct = T[d]
        score += S[d][ct]
        for i in range(26):
            last[i][d + 1] = last[i][d]
        last[ct][d + 1] = d
        for i in range(26):
            score -= C[i] * (d - last[i][d + 1])

    for d, after in changes:
        before = T[d]
        if before == after:
            continue
        score -= S[d][before]
        score += S[d][after]
        lb = last[before][d]
        la = last[after][d]
        da = db = 0
        for x in range(d, D):
            if x > d and T[x] == before:
                break
            last[before][x + 1] = lb
            db += 1
        score -= C[before] * (d - lb) * db
        for x in range(d, D):
            if T[x] == after:
                break
            last[after][x + 1] = d
            da += 1
        score += C[after] * (d - la) * da
        T[d] = after
        print(score)


main()


Measured memory_bytes: 17260
#include<bits/stdc++.h>
#define N 100010
using namespace std;
struct no{
    int to, cost;
};
int n;
vector<no> G[N];//邻接表
int d[N];
bool used[N];
void bfs(int s){
    queue<int> q;
    fill(d, d+N, 0);
    fill(used, used+N, false);
    d[s] = 0;
    q.push(s);
    while(!q.empty()){
        int t = q.front(); q.pop();
        used[t] = true;
        for(int i = 0; i < G[t].size(); i++){
            int v = G[t][i].to;
            if(!used[v]){
                d[v] = d[t] + G[t][i].cost;
                q.push(v);
            }
        }
    }
}
void solve(){
    bfs(0);
    int maxi = 0, maxv = 0;
    for(int i = 1; i < n; i++){
        if(d[i] > maxv){
            maxv = d[i];
            maxi = i;
        }
    }

    bfs(maxi);
    maxv = 0;
    for(int i = 0; i < n; i++) if(d[i] > maxv) maxv = d[i];
    printf("%d\n", maxv);
}
int main() {
    scanf("%d", &n);
    for(int i = 0; i < n-1; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    solve();
    return 0;
}


Measured memory_bytes: 10000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
  ll a,ans;
  cin >> a;
  ans = a / 500 * 1000;
  ans += (a%500/5) * 5;
  cout << ans << endl;
}


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

void solve(vector<string>& ret, int N, int i_step = 0, string s = "a", int c_max = 0){
    if(i_step == N-1){
        ret.push_back(s);
        return;
    }

    for(int i=0; i<=(c_max + 1); i++){
        char c = 'a' + i;
        if(i == c_max + 1){
            solve(ret, N, i_step+1, s + c, c_max + 1);
        }else{
            solve(ret, N, i_step+1, s + c, c_max);
        }
    }
}

int main()
{
    int N;
    cin >> N;
    vector<string> ret;
    solve(ret, N);
    for(auto s : ret){
        cout << s <<endl;
    }

    return 0;
}

Measured memory_bytes: 7796
#include <stdio.h>
int main(void)
{
  int x,n,i,j,k,z;
  
  while(1){
  scanf("%d %d",&n,&x);
  if(n==0&&x==0){
     break;
    }    
    z=0;
    for(i=1;i<=n-2;i++){
      for(j=i+1;j<=n-1;j++){
        for(k=j+1;k<=n;k++){
          if(i+j+k==x){
            z++;
          }
        }
      }
    }
  printf("%d\n",z);
  }
  return 0;
}

Measured memory_bytes: 1748
# -*- coding:utf-8 -*-

class Shop():
    def __init__(self, yen, num):
        self.yen = yen  # ドリンクの単価
        self.num = num  # 販売している個数


def solve():
    N, M = list(map(int, input().split(" ")))
    A, B = [], []
    shops = []
    for i in range(N):
        a, b = list(map(int, input().split(" ")))
        A.append(a)
        B.append(b)
        shops.append(Shop(a, b))
    
    shops = sorted(shops, key=lambda x: x.yen)

    ans = 0
    rest_count = M
    for i in range(N):
        if rest_count <= shops[i].num:
            ans += shops[i].yen * rest_count
            break
        ans += shops[i].yen * shops[i].num
        rest_count -= shops[i].num
    
    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 36916
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv)
{
	int n;
	scanf("%d", &n);
	if (n == 1 * 1)
	{
		puts("Yes");
	}
	else if (n == 1 * 2 || n == 2 * 2)
	{
		puts("Yes");
	}
	else if (n == 1 * 3 || n == 2 * 3 || n == 3 * 3)
	{
		puts("Yes");
	}
	else if (n == 1 * 4 || n == 2 * 4 || n == 3 * 4 || n == 4 * 4)
	{
		puts("Yes");
	}
	else if (n == 1 * 5 || n == 2 * 5 || n == 3 * 5 || n == 4 * 5 || n == 5 * 5)
	{
		puts("Yes");
	}
	else if (n == 1 * 6 || n == 2 * 6 || n == 3 * 6 || n == 4 * 6 || n == 5 * 6 || n == 6 * 6)
	{
		puts("Yes");
	}
	else if (n == 1 * 7 || n == 2 * 7 || n == 3 * 7 || n == 4 * 7 || n == 5 * 7 || n == 6 * 7 || n == 7 * 7)
	{
		puts("Yes");
	}
	else if (n == 1 * 8 || n == 2 * 8 || n == 3 * 8 || n == 4 * 8 || n == 5 * 8 || n == 6 * 8 || n == 7 * 8 || n == 8 * 8)
	{
		puts("Yes");
	}
	else if (n == 1 * 9 || n == 2 * 9 || n == 3 * 9 || n == 4 * 9 || n == 5 * 9 || n == 6 * 9 || n == 7 * 9 || n == 8 * 9 || n == 9 * 9)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n, m; cin >> n >> m;
    long long ans = n * m - 4;
    ans -= 2 * (n - 2) + 2 * (m - 2);
    cout << abs(ans) << endl;
    return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())

p = 0.
for i in range(1, min(n+1, k)):
    count = 0
    while(i < k):
        i *= 2
        count += 1
    p += (0.5)**count
p *= 1/n

if n >= k:
    p += (n - k + 1)/n
print(p)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N,M,X,Y,l;
	cin >> N >> M >> X >> Y;
	vector<int> x(N+1,0);
	vector<int> y(M+1,0);
	for (int i = 0;i < N;i++){
		cin >> l;
		x[i] = l;
	}
	x[N] = X;
	for (int i = 0;i < M;i++){
		cin >> l;
		y[i] = l;
	}
	y[M] = Y;
	sort(ALL(x));
	sort(ALL(y));
	if (x[N] < y[0]){
		cout << "No War" <<endl;
	}
	else{
		cout << "War" <<endl;
	}

	return 0;
}

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

vector<P>E[200000];
ll d[200000];
int par[20][200000];

struct LCA{
public:
	vector<vector<int> > g;
	const int MAX_LOG = 22;
	vector<vector<int> > lcc;
	vector<int> dep;
	void init2(){
		int n = g.size();
		for (int i = 0; i + 1 < MAX_LOG; i++){
			for (int j = 0; j < n; j++){
				if (lcc[i][j] == -1){
					lcc[i + 1][j] = -1;
					continue;
				}
				lcc[i + 1][j] = lcc[i][lcc[i][j]];
			}
		}
	}
	int lca(int a, int b){
		if (dep[a] < dep[b]){
			swap(a, b);
		}
		for (int i = 0; i < MAX_LOG; i++){
			if (((dep[a] - dep[b]) >> i) & 1){
				a = lcc[i][a];
			}
		}
		if (a == b){
			return a;
		}
		for (int i = MAX_LOG - 1; i >= 0; i--){
			if (lcc[i][a] != lcc[i][b]){
				a = lcc[i][a];
				b = lcc[i][b];
			}
		}
		return lcc[0][a];
	}
	inline void dfs(int b, int pr = -1, int d = 0){
		for (auto &i : g[b]){
			if (i == pr)continue;
			dfs(i, b, d + 1);
		}
		dep[b] = d;
		lcc[0][b] = pr;
	}
	void init(vector<vector<int> > &tree, int root = 0){
		g = tree;
		lcc.resize(MAX_LOG, vector<int>(g.size(), 0));
		dep.resize(g.size());
		dfs(root);
		init2();
	}
};
void dfs(int v,int p,ll d1){
	d[v]=d1;par[0][v]=p;
	for(P u:E[v]){
		if(u.second!=p)dfs(u.second,v,d1+u.first);
	}
}
LCA G;
ll dist(int x,int y){
	return d[x]+d[y]-d[G.lca(x,y)]*2;
}
int main(){
	int n;scanf("%d",&n);
	vector<vector<int>>F(n);
	rep(i,n-1){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		E[a].push_back(P(c,b));E[b].push_back(P(c,a));
		F[a].push_back(b);F[b].push_back(a);
	}
	G.init(F);
	dfs(0,-1,0);
	int q,k;scanf("%d%d",&q,&k);k--;
	rep(i,q){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		printf("%lld\n",dist(x,k)+dist(k,y));
	}
}

Measured memory_bytes: 37496
#include<stdio.h>
int train[100]={},idx=0,num;
void pop(){
	idx--;
	printf("%d\n",train[idx]);
}
void push(){
	train[idx]=num;
	idx++;
}
int main(){
	while(scanf("%d",&num)!=EOF){
		if(num==0)	pop();
		else		push();
	}
	return 0;
}
 

Measured memory_bytes: 1744
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N; cin>>N;
    bool answer=false;
    rep(i,30) {
        rep(j,30) {
            if(i*4+j*7==N) answer=true;
        }
    }
    if(answer) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = [' '] * h
for i in range(h):
    a[i] = input()
    
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            col[j] = True
            
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end = '')
        print()

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

struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INf = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
//#define int ll

signed main(){
    char a[3],b[3];
    bool rullonz = true;
    scanf("%s %s",&a,&b);
    for(int i=0;i<3;i++){
        if(a[i]!=b[2-i]) rullonz = false;
    }
    if(rullonz) puts("YES");
    else puts("NO");
    return 0;
}

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

using namespace std;

typedef long long ll;

string s;
ll N;
vector<char> v[4];

char inv(char c){
    if(c == 'S') return 'W';
    return 'S';
}

int main(){
    cin >> N;
    cin >> s;
    v[0].push_back('S');
    v[0].push_back('S');
    v[1].push_back('S');
    v[1].push_back('W');
    v[2].push_back('W');
    v[2].push_back('S');
    v[3].push_back('W');
    v[3].push_back('W');
    for(int i=0;i<4;i++){
        for(int j=2;j<N;j++){
            if(s[j-1] == 'o'){
                if(v[i][j-1] == 'S'){
                    v[i].push_back(v[i][j-2]);
                }else{
                    v[i].push_back(inv(v[i][j-2]));
                }
            }else{
                if(v[i][j-1] == 'S'){
                    v[i].push_back(inv(v[i][j-2]));
                }else{
                    v[i].push_back(v[i][j-2]);
                }
            }
        }
        if(s[0] == 'o'){
            if(v[i][0] == 'S'){
                if(v[i][1] != v[i][N-1]) continue;
            }else{
                if(v[i][1] == v[i][N-1]) continue;
            }
        }else{
            if(v[i][0] == 'S'){
                if(v[i][1] == v[i][N-1]) continue;
            }else{
                if(v[i][1] != v[i][N-1]) continue;
            }
        }
        if(s[N-1] == 'o'){
            if(v[i][N-1] == 'S'){
                if(v[i][0] != v[i][N-2]) continue;
            }else{
                if(v[i][0] == v[i][N-2]) continue;
            }
        }else{
            if(v[i][N-1] == 'S'){
                if(v[i][0] == v[i][N-2]) continue;
            }else{
                if(v[i][0] != v[i][N-2]) continue;
            }
        }
        for(int j=0;j<N;j++){
            cout << v[i][j];
        }
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,a;
map<int,int> mp;
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a;
        mp[a-1]++;
        mp[a]++;
        mp[a+1]++;
    }
    int mx = 0;
    for(int i = -1; i < 100002; i++){
        mx = max(mx,mp[i]);
    }
    cout << mx << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using graph = vector<vector<int>>;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    const int MOD = 2019;
    int k[n]={0};
    rep(i,n) k[i] = s[i] - '0';
    int cum[n+1]={0};
    int amari2019[n+1]={1};
    rep1(i,n){
        amari2019[i] = amari2019[i-1]*10 % MOD;
    }
    rep(i,n){
        cum[n-i-1] = (k[n-1-i]*amari2019[i] + cum[n-i]) % MOD;
    }
    sort(cum,cum+n+1);
    ll ans = 0;
    vector<ll> count(2019,0);
    rep(i,n+1) count[cum[i]]++;
    rep(i,2019){
        ans += count[i]*(count[i]-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

#define MAX_N 2000005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r);
  ans = (ans * finv[r]) % mod;
  return ans;
}
ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  make();
  int n, m, k; cin >> n >> m >> k;
  ll ans = 0;
  for(int i=0; i<=k; i++) {
    (ans += comb(n-1, i) * m % mod * modpow(m-1, n-1-i) % mod) %= mod;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 50524
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String [] input = sc.nextLine().split(" ");
			int a = Integer.parseInt(input[0]);
			int b = Integer.parseInt(input[2]);
			int result = 0;
			
			switch(input[1]) {
			case "+":
				result = a + b;
				break;
			case "-":
				result = a - b;
				break;
			case "*":
				result = a * b;
				break;
			case "/":
				result = a / b;
				break;
			}
			
			if (input[1].equals("?")) {
				break;
			}
			
			System.out.println(result);
		}
	}
}



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

int main()
{
 long long A[4444],p,i;
 cin>>p;
 A[0]=100;
 for(i=1;i<4444;i++)
 {
     A[i]=A[i-1]+(0.01*A[i-1]);
     if(A[i]>=p)
     {cout<<i<<endl;
       return 0;
      }
}

}


Measured memory_bytes: 3644
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n + 1)
        self.rank=[0] * (n + 1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y

            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def size(self, x):
        return -self.parents[self.find(x)]

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

uf = UnionFind(N)
ans = 0

for m in range(M):
    A, B = map(int, input().split())
    uf.union(A, B)

for n in range(1, N+1):
    ans = max(ans, uf.size(n))

print(ans)

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

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

struct Ren{
	int a;
	int b;

	bool operator<(const Ren& right) const{
		return a == right.a ? b < right.b : a > right.a;
	}
};

int main()
{
	int K, T;
	cin >> K >> T;
	vector<Ren> A(T);

	rep(i, T)
	{
		cin >> A[i].a;
		A[i].b = i;
	}

	int ans = 0;
	int pre = -1;

	if (T == 1)
	{
		cout << K - 1 << endl;
		return 0;
	}
	rep(i, K)
	{
		sort(A.begin(), A.end());
		if (pre != A[0].b)
		{
			A[0].a--;
			pre = A[0].b;
		}
		else if(A[1].a == 0){
			ans++;
		}
		else{
			A[1].a--;
			pre = A[1].b;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int s;cin>>s;
  	vector<long long int> a(1000010,0);
  	int m=1;
  	a[s]++;
  	while(true){
    	if(s%2==0){
        	s/=2;        
        }else{
        	s=3*s+1;
        }
      	if(a[s]==1){
        	cout<<m+1<<endl;
          	return 0;
        }
      	a[s]++;m++;
    }
}

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

void solve()
{
	int n,m,k;
	cin >> n >> m >> k;
	int a[n], b[m];
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<m; i++) cin >> b[i];
	
	int count = 0;
	int i = 0;
	int sum = 0;
	int maxCount = 0;
	while(i<n){
		if(sum + a[i] <= k) {
			sum += a[i];
			i++;
			count++;
		}
		else break;
	}
	
	int j =0;
	while(j<m){
		if(sum + b[j] <= k){
			sum += b[j];
			j++;
			count++;
		}
		else break;
	}
	maxCount = count;
	
	while(j<m){
		if(i==0) break;
		if(i>=1) {
			sum -= a[i-1];
			i--;
			count--;
		}
		while(j<m){
			if(sum + b[j] <= k){
				sum += b[j];
				j++;
				count++;
				maxCount = max(maxCount, count);
			}
			else break;
		}
	}
	
	cout << maxCount << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t;
	t = 1;
	while(t--){
		solve();		
	}
	return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;
constexpr i64 MAX = 500500;

i64 fac[MAX], inv[MAX], finv[MAX];
void CombInit() {
    fac[0] = inv[0] = finv[0] = 1;
    fac[1] = inv[1] = finv[1] = 1;
    for (int i = 2; i < MAX; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

i64 P(int n, int k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * finv[n - k] % MOD;
}

i64 C(int n, int k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return (fac[n] * finv[n - k] % MOD) * finv[k] % MOD;
}

int main() {
	i64 n, m; cin >> n >> m;
    CombInit();
	i64 a = P(m, n);

    i64 b = P(m, n);
    rep(i, 1, n + 1) {
        if (i & 1) {
            b += (MOD - C(n, i) * P(m - i, n - i) % MOD) % MOD;
        }
        else {
            b += C(n, i) * P(m - i, n - i) % MOD;
        }
        b %= MOD;
    }
    cout << a * b % MOD;

	return 0;
}

Measured memory_bytes: 15368
#include<bits/stdc++.h>
 
int main()
{
    long long n,k,r,s,p;
    std::cin >> n >> k >> r >> s >> p;
    std::map<char,long long> map;
    map['r'] = p;
    map['s'] = r;
    map['p'] = s;
    map['q'] = 0;
    std::string t;
    std::cin >> t;
    std::string ans;
    for(long long i = 0; i < k; i++){
        ans.push_back(t[i]);
    }
    for(long long i = k; i < n; i++){
        if(ans[i - k] != t[i])ans.push_back(t[i]);
        else ans.push_back('q');
    }
    long long sum = 0;
    for(long long i = 0; i < n; i++)sum += map[ans[i]];
    std::cout << sum << std::endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,L,ans=0,min=1000;
    cin >> N >> L;

    int j = 0;
    for(int i = 0;i < N;i++){
        if(abs(L + (i+1) - 1) < min){
            min = abs(L + (i+1) - 1);
            j = i;
        }
    }

    for(int i = 0;i < N;i++){
        if(i != j)
            ans += L + (i+1) -1;
    }

    cout << ans << endl;
    
} 

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    for (int i = 0; i < v.size(); ++i)
      os << v[i] << " ";
    os << '\n';
  }
  return os;
}

signed main() {
    string str;
    cin >> str;
    if(str.back() != 's')
        str+="s";
    else
        str+="es";
    cout << str;
}

Measured memory_bytes: 3596
N, L = map(int, input().split())
aji = [L+i for i in range(N)]

choice = abs(aji[0])
m_i = 0
for i, score in enumerate(aji):
    if choice >= abs(score):
        choice = abs(score)
        m_i = i
ans = sum(aji) - aji[m_i]
print(ans)


Measured memory_bytes: 38384
#include <map>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int as[200000+10];
int bs[200000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &as[i]);
  }
  REP(i, n) {
    scanf("%d", &bs[i]);
  }

  int res = 0;
  REP(d, 29) {
    // cerr << "> " << d << endl;
    int mask = (1 << d) - 1;
    int target = 1 << d;
    vector<int> tas[2];
    vector<int> tbs[2];
    REP(i, n) {
      tas[as[i] & target ? 1 : 0].push_back(as[i] & mask);
      tbs[bs[i] & target ? 1 : 0].push_back(bs[i] & mask);
    }
    REP(i, 2) {
      sort(tas[i].begin(), tas[i].end());
      sort(tbs[i].begin(), tbs[i].end());
    }
    ll cur00 = 0;
    ll cur01 = 0;
    ll cur10 = 0;
    ll cur11 = 0;
    {
      // (0,0)carryあり
      int ib0 = (int)tbs[0].size() - 1;
      // (0,1)carryなし
      int ib1 = (int)tbs[1].size() - 1;;
      REP(ia, tas[0].size()) {
        while(ib0 >= 0 && tas[0][ia] + tbs[0][ib0] >= target) {
          --ib0;
        }
        cur00 += (int)tbs[0].size()-1 - ib0;
        while(ib1 >= 0 && tas[0][ia] + tbs[1][ib1] >= target) {
          --ib1;
        }
        cur01 += ib1+1;
      }
    }
    {
      // (1,1)carryあり
      int ib1 = (int)tbs[1].size() - 1;
      // (1,0)carryなし
      int ib0 = (int)tbs[0].size() - 1;
      REP(ia, tas[1].size()) {
        while(ib1 >= 0 && tas[1][ia] + tbs[1][ib1] >= target) {
          --ib1;
        }
        cur11 += (int)tbs[1].size()-1 - ib1;
        while(ib0 >= 0 && tas[1][ia] + tbs[0][ib0] >= target) {
          --ib0;
        }
        cur10 += ib0+1;
      }
    }

    if((cur00+cur01+cur10+cur11) % 2 == 1) {
      res |= 1 << d;
    }
  }
  printf("%d\n", res);

  return 0;
}


Measured memory_bytes: 4584
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*pow(x,m-1))%p
p = 10**9+7
N = (2*10**6)//3
A = [1 for _ in range(N+1)]
for i in range(2,N+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(N+1)]
B[N] = pow(A[N],p-2)
for i in range(N-1,1,-1):
    B[i] = ((i+1)*B[i+1])%p
X,Y = map(int,input().split())
if (X+Y)%3==0 and (X+Y)//3<=X<=2*(X+Y)//3:
    n = (X+Y)//3
    ans = (A[n]*B[X-n])%p
    ans = (ans*B[2*n-X])%p
    print(ans)
else:
    print(0)

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

bool is_month(string s) {
	if(
		s=="01"||
		s=="02"||
		s=="03"||
		s=="04"||
		s=="05"||
		s=="06"||
		s=="07"||
		s=="08"||
		s=="09"||
		s=="10"||
		s=="11"||
		s=="12"
	) {
		return true;
	}
	return false;
}

int main() {
	string s;
	cin >> s;
	bool a = is_month(s.substr(0,2));
	bool b = is_month(s.substr(2,2));
	if(a&&b) cout << "AMBIGUOUS" << endl;
	if(!a&&b) cout << "YYMM" << endl;
	if(a&&!b) cout << "MMYY" << endl;
	if(!a&&!b) cout << "NA" << endl;
	return 0;
}


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

vector<int> G[MAX_V];

void input_graph(int E){
    int s,t;
    REP(i,E){
        cin>>s>>t;s--;t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }
}

int main(){
  int V,E,ans=0;cin>>V>>E;
  vector<int> h(V,0);
  REP(i,V) cin>>h.at(i);
  input_graph(E);

  REP(i,V){
      bool f=1;
      for(int j=0;j<G[i].size();j++){
          if(h.at(i)<=h.at(G[i].at(j))) f=0;
      }
      if(f) ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 8804
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define poi 500000
#define inf 0x3f3f3f3f
using namespace std;
inline int re()
{
	char c=(char)getchar();
	int x=0,k=1;
	while(c<'0'||c>'9')
	{if(c=='-')k=-1;c=(char)getchar();}
	while(c>='0'&&c<='9')
	{x=(x<<1)+(x<<3)+c-'0';c=(char)getchar();}
	return k<0?-x:x;
}
void wr(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) wr(x/10);
	putchar(x%10+'0');
}
int main()
{
	int n=re(),ans=0;
	for(int i=1;i<=n;i++)
	if(re()&1) ans=1;
	if(ans) printf("first");
	else printf("second");
	return 0;
}
/*

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
#pragma GCC optimize("Ofast")

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M, L;
  cin >> N >> M >> L;
  vector<vector<pll>> connection(N);
  for (ll i = 0; i < M; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    a -= 1;b -= 1;
    if (c <= L) {
      connection.at(a).push_back({b, c});
      connection.at(b).push_back({a, c});
    }
  }
  ll Q;
  cin >> Q;
  vector<vector<ll>> shortest_path(N, vector<ll>(N, INF));
  for (ll s = 0; s < N; ++s) {
    set<pll> st;//fuel, index
    st.insert({0, s});
    shortest_path.at(s).at(s) = 0;
    while (!st.empty()) {
      ll f = (*st.begin()).first, now = (*st.begin()).second;
      st.erase(st.begin());
      if (f > shortest_path.at(s).at(now)) {
        continue;
      }
      for (ll i = 0; i < connection.at(now).size(); ++i) {
        ll next = connection.at(now).at(i).first, c = connection.at(now).at(i).second;
        ll cost;
        if (f % L + c > L) {
          cost = (f / L * L + L) + c;
        }
        else {
          cost = f + c;
        }
        if (shortest_path.at(s).at(next) <= cost) {
          continue;
        }
        shortest_path.at(s).at(next) = cost;
        st.insert({cost, next});
      }
    }
  }
  for (ll i = 0; i < Q; ++i) {
    ll s, t;
    cin >> s >> t;
    s -= 1;t -= 1;
    if (shortest_path.at(s).at(t) == INF) {
      cout << -1 << "\n";
    }
    else {
      cout << (shortest_path.at(s).at(t) - 1) / L << "\n";
    }
  }
}


Measured memory_bytes: 8520
n = int(input())
a = list(map(int, input().split()))
x1 = x2 = x4 = 0
for i in a:
    cnt = 0
    while i % 2 < 1:
        i //= 2
        cnt += 1
    if cnt > 1:
        x4 += 1
    elif cnt > 0:
        x2 += 1
    else:
        x1 += 1
if x1 < 1:
    print('Yes')
elif x2 < 1:
    if n // 2 <= x4:
        print('Yes')
    else:
        print('No')
else:
    if (x1 + x4 + 1) // 2 <= x4:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 14252
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	H = getlist()
	ans = [1] * N
	for i in range(M):
		A, B = getlist()
		if H[A - 1] > H[B - 1]:
			ans[B - 1] = 0
		elif H[A - 1] < H[B - 1]:
			ans[A - 1] = 0
		else:
			ans[A - 1] = 0
			ans[B - 1] = 0

	print(sum(ans))



if __name__ == '__main__':
	main()

Measured memory_bytes: 83840
#include <iostream>

int main() {
  int n, a, b;
  std::cin >> n >> a >> b;

  int ans { 0 };
  for(int i = 1; i <= n; ++i) {
    int val { i };
    int acc { 0 };
    do {
      acc += (val % 10);
      val /= 10;
    } while(val != 0);
    ans += (a <= acc && acc <= b ? i : 0); 
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,a,b,ab_cnt=0,b_cnt=0;
    string s;
    cin >> n >> a >> b >> s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='a'){
            if(ab_cnt<a+b){
                cout <<"Yes\n";
                ab_cnt++; 
            }else cout << "No\n";
        }else if(s[i]=='b'){
            if(ab_cnt<a+b&&b_cnt<b){
                cout <<"Yes\n";
                ab_cnt++; 
                b_cnt++;
            }else cout << "No\n";
        }else{
            cout << "No\n";
        }
    }
}

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

int main(){
  int n,t;
  cin >> n >> t;
  int amin = 1e9;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    t -= a;
    amin = min(amin, a);
  }
  cout << n +t/amin << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(void){
  string s;
  cin >> s;
  int len = s.length();
  if(s[len-1] == 's'){
    s += "es";
  }
  else{
    s += "s";
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<bitset>
#include<deque>
#include<iterator>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include <cmath>
#include<vector>
using namespace std;
#define pb push_back
#define pf push_front
#define M 1000000007
#define ll long long int
int main()
 {
 	 
     double n;
     cin>>n;
     double ans;
    ans=2*3.14159265358979323846*n;
    printf("%.20lf",ans);
     return 0;
 }


Measured memory_bytes: 3784
import java.util.Scanner;
class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int x , y , z,c;
    x = sc.nextInt();
    y = sc.nextInt();
    z = sc.nextInt();
    c = x;
    x = y;
    y = c;

    c = x;
    x = z;
    z = c;
    System.out.println(x+" "+y+ " "+z);

  }
}


Measured memory_bytes: 23764
// AtCoder Beginner Contest 159 A.cpp

#include <iostream>
#include <vector>

using namespace std;

int nCr(int n, int r) {
	if (n == 0 || n == 1)
		return 0;
	if (n == r)
		return 1;
	int re = 1;
	for (int i = 0; i < r; i++, n--) {
		re *= n;
	}
	for (int i = 0; i < r; i++) {
		re /= (r - i);
	}
	return re;
}

int main()
{
	int n, m, answer = 0;
	cin >> n >> m;
	answer = nCr(n, 2) + nCr(m, 2);
	cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
#include <numeric>
#include <cmath>
#include <bitset>
#include <stack>
#include <algorithm>
#define llc (long long)
#define pm %1000000007
#define ldc (long double)
using namespace std;


int main(){
	int n;
	int cer=0;
	cin>>n;getchar();
	char a[1000][3];
	for(int i = 0;i < n;i ++){
		a[i][0]=getchar();
	}getchar();
	for(int i = 0;i < n;i ++){
		a[i][1]=getchar();
	}getchar();
	for(int i = 0;i < n;i ++){
		a[i][2]=getchar();
	}
	for(int i = 0;i < n;i ++){
		if(a[i][0]==a[i][1]&&a[i][1]==a[i][2]){

		}else if(a[i][0]==a[i][1]||a[i][1]==a[i][2]||a[i][0]==a[i][2]){
			cer++;
		}else{
			cer+=2;
		}
	}
	printf("%d\n", cer);
}

Measured memory_bytes: 256
N = int(input())
p = 10**9+7
T = [0]*(1001)
for m in range(2,N+1):
    pf={}
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    for key in pf.keys():
        T[key] += pf[key]
out = 1
for i in range(1001):
    out = out*(T[i]+1)%p
print(out)

Measured memory_bytes: 72336
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int V, E, Bit[16], DP[15][32768], ans = 1e9;
bool visited[32768];
vector <Pii> Graph[15];

int Solve(int start){
  fill((int*)DP, (int*)(DP + V), 1e9);
  fill((bool*)visited, (bool*)(visited + Bit[V] - 1), false);

  queue <int> que; que.push(0);
  visited[0] = true; DP[start][0] = 0;

  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < V; i++){
      if (DP[i][Q] == 1e9) continue;

      for (int j = 0; j < Graph[i].size(); j++){
        int node = Graph[i][j].fi, cost = Graph[i][j].se;
        int flag = Bit[node] & Q;
        if (flag > 0) continue;
        int next = Q + Bit[node];
        if (visited[next] == false){
          que.push(next); visited[next] = true;
        }
        DP[node][next] = min(DP[node][next], DP[i][Q] + cost);
      }
    }
  }
  ans = min(ans, DP[start][Bit[V] - 1]);
  return 0;
}

int main(){
  Bit[0] = 1;
  for (int i = 1; i < 16; i++) Bit[i] = Bit[i - 1] * 2;
  scanf("%d%d", &V, &E);
  for (int i = 0; i < E; i++){
    int S, T, D; scanf("%d%d%d", &S, &T, &D);
    Graph[S].push_back(mp(T, D));
  }


  Solve(0);
  if (ans == 1e9) ans = -1;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 5216
# include <iostream>
# include <algorithm>
# include <vector>
# include <functional>
# include <string>
using namespace std;

int main() {
	string s;

	cin >> s;

	cout << s[0];
	cout << s.size()-2;
	cout << s[s.size() - 1] << endl;
	

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		// input
		int num = scan.nextInt();
		int[] color = new int[9];
		for(int i = 0; i < num; i++){
			int temp = scan.nextInt() / 400;
			if(temp < 8 && color[temp] == 0){
				color[temp] += 1;
			} else if(temp >= 8) {
				color[8] += 1;
			}
		}
		
		// search
		int count = 0;
		for(int i = 0; i < 8; i++){
			count += color[i];
		}
		
		// answer
		if(count == 0){
			System.out.println("1 " + color[8]);
		} else {
			System.out.println(count + " " + (count + color[8]));
		}
		
	}
}

Measured memory_bytes: 23892
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

int main() {
  int A, B; cin >> A >> B;
  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 1;
  int cur = A;
  while (cur < B) {
    cur += A - 1;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=210;
    int cost[10][10];
    int H,W;
    int A[MAXN][MAXN];
    int dist[10][10];
    void floyed(){
        memcpy(dist,cost,sizeof(cost));
        for(int k=0;k<10;k++){
            for(int u=0;u<10;u++){
                for(int v=0;v<10;v++){
                    if(dist[u][v]>dist[u][k]+dist[k][v])
                    dist[u][v]=dist[u][k]+dist[k][v];
                }
            }
        }
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>H>>W;
        for(int r=0;r<10;r++){
            for(int c=0;c<10;c++){
                cin>>cost[r][c];
            }
        }
        floyed();
        int ans=0;
        for(int r=1;r<=H;r++){
            for(int c=1;c<=W;c++){
                int t;
                cin>>t;
                if(t!=-1)
                ans+=dist[t][1];
            }
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
int a,r,sum=0;
cin>>a;
int temp=a;
while(temp!=0)
{
	r=temp%10;
	sum=(sum*10)+r;
	temp=temp/10;
	
}
if(a==sum)    
printf("Yes ");    
else    
printf("No");   

return 0;  
}

Measured memory_bytes: 3692