akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

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

double PI=3.141592653589793;


void solve(){
	int n,k;
	cin >> n >> k;
	vector<int> proc(n);
	forn(i,n) cin >> proc[i];
	forn(i,k){
		vector<int> nxt(n,0);
		forn(j,n){
			int l=max(0,j-proc[j]),r=j+proc[j]+1;
			if(r<n) nxt[r]--;
			if(l>=0) nxt[l]++;
		}
		forse(j,1,n) nxt[j]+=nxt[j-1];
		proc=nxt;
		bool chk=1;
		forn(i,n) chk&=(proc[i]==n);
		if(chk) break;
	}
	for(auto i:proc) cout << i << ' ';
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


Measured memory_bytes: 4972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int main(){
	string s; cin >> s;
	rep(i,s.size()-1){
		if (s[i] == s[i+1]){
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 764
import math

A, B, H, M = map(int, input().split())

omega_A = 360 / (12 * 60)  # deg/m
omega_B = 360 / 60  # deg/m

deg_A = omega_A * (H * 60 + M)
deg_B = omega_B * (H * 60 + M)

theta = abs(deg_A - deg_B)

c = A**2 + B**2 - 2 * A * B * math.cos(theta / 180 * math.pi)

print(math.sqrt(c))


Measured memory_bytes: 9500
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
m = [int(i) for i in list(str(n))]
l = len(str(n))
dp = [[0, 0] for _ in range(l)]
dp[0][0] = m[0] - 1
dp[0][1] = m[0]
for i in range(1, l):
    dp[i][0] = max(dp[i - 1][0] + 9, dp[i - 1][1] + m[i] - 1)
    dp[i][1] = dp[i - 1][1] + m[i]
print(max(dp[l - 1][0], dp[l - 1][1]))

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

using namespace std;

using ll = long long;

constexpr int LOG_MAXV = 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> v(n);
    ll all_xor = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        all_xor ^= v[i];
    }
    for (int i = 0; i < n; i++) {
        v[i] &= (all_xor ^ ((1LL << LOG_MAXV) - 1));
    }

    int rank = 0;
    for (int col = LOG_MAXV - 1; col >= 0; --col) {
        int pivot = -1;
        for (int row = rank; row < n; ++row) {
            if (v[row] & (1LL << col)) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(v[pivot], v[rank]);
        for (int row = 0; row < n; ++row) {
            if (row != rank && (v[row] & (1LL << col))) {
                v[row] ^= v[rank];
            }
        }
        ++rank;
    }
 
    ll red = 0;
    ll ans = all_xor;
    for (int i = 0; i < n; i++) {
        if (red < (red ^ v[i])) red ^= v[i];
        ans = max(ans, red * 2 + all_xor);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>

int main(void){
	int i,j,flag=0,b[11][11]={0};
	char c[11][11]={0};
	
	/*
	while(scanf("%c",&c[0][0])!=EOF){
		flag=0;
		for(i=1;i<8;i++)scanf("%c",&c[0][i]);
		getchar();
		for(i=1;i<8;i++){
			for(j=0;j<8;j++){
				scanf("%c",&c[i][j]);
			}
			getchar();
		}getchar();
		*/
	
	while(scanf("%s",c[0])!=EOF){
		flag=0;
		for(i=1;i<8;i++){
			scanf("%s",c[i]);
		}
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				b[i][j]=c[i][j]-'0';
			}
		}
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				if(b[i][j]==1){
					if(b[i+1][j]&&b[i][j+1]&&b[i+1][j+1]){
						puts("A");
						flag=1;
						break;
						break;
					}
					else if(b[i+1][j]&&b[i+2][j]&&b[i+3][j]){
						puts("B");
						flag=1;
						break;
						break;
					}
					else if(b[i][j+1]&&b[i][j+2]&&b[i][j+3]){
						puts("C");
						flag=1;
						break;
						break;
					}
					else if(b[i][j+1]&&b[i+1][j+1]&&b[i+1][j+2]){
						puts("E");
						flag=1;
						break;
						break;
					}
					else if(b[i+1][j]&&b[i+1][j+1]&&b[i+2][j+1]){
						puts("F");
						flag=1;
						break;
						break;
					}
					else if(b[i+1][j]&&b[i+1][j-1]&&b[i+2][j-1]){
						puts("D");
						flag=1;
						break;
						break;
					}
					else if(b[i][j+1]&&b[i+1][j-1]&&b[i+1][j]){
						puts("G");
						flag=1;
						break;
						break;
					}
				}
			}
			//if(flag)break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

#pragma endregion

const int N = 55;
int n, ans;

int gcd(int a, int b){
    if (b == 0) return a;
    return gcd(b, a%b);
}
pls give {
    AC;
    cin >> n;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            for (int k=1; k<=n; k++) {
                ans += gcd(i, gcd(j, k));
            }
        }
    }
    cout << ans << nl;
}

Measured memory_bytes: 3652
a, b = map(int, input().split())

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
n = gcd(a, b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

ans = set(prime_factorize(n))
print(len(ans)+1)

Measured memory_bytes: 3064
#include <iostream>
#include <memory>
#include <algorithm>
#include <numeric>
 
#define M 1000000000000000009

using namespace std;

static int64_t getInvMod(int64_t a, int64_t m)
{
    int64_t b, x, u, q, tmp;

    b = m; x = 1; u = 0;
    while (b > 0) {
	q = a / b;
	tmp = u; u = x - q * u; x = tmp;
	tmp = b; b = a - q * b; a = tmp;
    }

    return ( x < 0 ) ? m + x : x;
}

static int64_t getComb(int n, int r)
{
    if (n < r) {
	return 0;
    }
    
    __int128 ret;
    ret = 1;
    for (int i = n; i > n - r; i--) {
	ret = (ret * i) % M;
    }

    for (int i = r; i > 0; i--) {
	__int128 invi = getInvMod(i, M);
	ret = (ret * invi) % M;
	
    }

    return (int64_t) ret;
}


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

    int64_t v[n];
    for (int i = 0; i < n; i++) {
	cin >> v[i];
    }

    sort(v, v+n, greater<int64_t>());

    double ave = (double) accumulate(v, v+a, int64_t(0)) / a;

    cout.precision(20);
    cout << fixed << ave << endl;

    if (v[0] == v[a - 1]) {
	int count = a;
	for (int i = a; i < n; i++) {
	    if (v[i] == v[0]) {
		count++;
	    } else {
		break;
	    }
	}

	int64_t comb = 0;
	for (int i = a; i <= b; i++) {
	    comb += getComb(count, i);
	}
	cout << comb << endl;
    } else {
	int cn = 0;
	int cr = 0;

	for (int i = 0; i < n; i++) {
	    if (v[i] == v[a - 1]) {
		cn++;
		if (i <= a - 1) {
		    cr++;
		}
	    }
	}

	cout << getComb(cn, cr) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 504
N,K = (int(i) for i in input().split())

ans = 0

# i個選んだ時の数を足していく
for i in range(K,N+2):
  min_sum_num = i*(i-1)//2
  max_sum_num = N*i - (i*(i-1)//2)
  ans += max_sum_num - min_sum_num + 1


print(ans%(10**9+7))


Measured memory_bytes: 9172
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
int max(const void *a, const void *b){return *(int*)b - *(int*)a;}

int n,d;

int main(void)
{
    scanf("%d",&n);
    scanf("%d",&d);
    printf("%d\n", ((n-1)/(d*2+1))+1 );

    return 0;
}


Measured memory_bytes: 256
from math import ceil
D,G=map(int,input().split())
p,c=[0]*D,[0]*D
for i in range(D):
    p[i],c[i]=map(int,input().split())

m=0
mondai=[]
for i in range(2**D,2**(D+1)):
    s=(bin(i))[3:]
    a,b=0,0
    for j in range(D):
        if s[j]=='1':
            a,b=a+p[j],b+100*(j+1)*p[j]+c[j]
        else:
            m=j
    if G<=b:
        mondai.append(a)
    if G-p[m]*100*(m+1)<b<G:
        ad=ceil((G-b)/(100*(m+1)))
        mondai.append((a+ad))
print(min(mondai))

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

int n, m;
vector<vector<int>> s;
vector<int> p;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	s.resize(m);
	for(int i=0; i<m; ++i){
		int k;
		cin >> k;
		s[i].resize(k);
		for(auto &j:s[i]) cin >> j;
	}
	p.resize(m);
	for(auto &i:p) cin >> i;
	int ans = 0;
	for(int i=0; i<(1<<n); ++i){
		bool f = true;
		for(int j=0; j<m; ++j){
			int t = 0;
			for(size_t k=0; k<s[j].size(); ++k){
				if((i>>(s[j][k]-1))&1) ++t;
			}
			if(t % 2 != p[j] % 2){
				f = false;
				break;
			}
		}
		if(f) ++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 1000000000

long long min(long a, long b) {
    if (a < b)
        return a;
    return b;
}

long long max(long long int a, long long int b) {
    if (a > b)
        return a;
    return b;
}

int abs(int a){
    if (a < 0)
        return -1*a;
    return a;
}

long long int dp[100009];
const int INF = 1e9+1;

int main() {
    int n, W;
    int w, val;
    scanf("%d %d", &n, &W);

    for (int i=0; i <= 1e5; i++)
        dp[i] = INF;
    dp[0] = 0;

    for (int i=0; i < n; i++) {
        scanf("%d %d", &w, &val);

        for (int cur=1e5-val; cur >= 0; cur--) {
            dp[cur+val] = min(dp[cur+val], dp[cur]+w);
        }
    }

    long long ans = 0;
    for (int i=0; i <= 1e5; i++)
        if (dp[i] <= W)
            ans = max(ans, i);

    printf("%lld\n", ans);

    return 0;
}


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


void dfs(long node,vector<int> &visited,vector<long> graph[],long n,vector<long> &dp)
{
	if(visited[node]==1) return;

	visited[node] = 1;

	for(auto x:graph[node])
	{
		if(visited[x] == 0){	
			dfs(x,visited,graph,n,dp);	
		}
	dp[node] = max(dp[node],dp[x] + 1);
	}
	
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long n,m;
    cin>>n>>m;
    vector<long> graph[n+1];
    vector<int> visited(n+1,0);
    vector<long> dp(n+1,0);

    for(long i=0;i<m;i++)
    {
    	long u,v;
    	cin>>u>>v;
    	graph[u].push_back(v);
    }

    for(long i=1; i<=n;i++)
    {
    	if(visited[i]==0)
    	{
    		dfs(i,visited,graph,n,dp);
    	}
    }
    long max=-1;
    for(auto x:dp)
    {
    	if(max<x)
    		max=x;
    	//cout<<x<<" ";
    }
    cout<<max;

    return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;bool f = 1;
cin>>n;
while(n){
    int rmdr;
    rmdr = n%10;
    if(rmdr == 7)
        f = 0;
    n /=10;
}
if(f==0)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3584
import copy
N = int(input())
SP = [[] for _ in range(N)]
for i in range(N):
    SP[i] = list(input().split())
    SP[i][1] = int(SP[i][1])
    
unique = list(set(s[0] for s in SP))
unique.sort(reverse=True)
for i, uni in enumerate(unique):
    for j, S in enumerate(SP):
        if uni == S[0]:
            S[0] = i

copy_SP = copy.copy(SP)
SP.sort(reverse=True)
for i, c in enumerate(SP):
    for j, sp in enumerate(copy_SP):
        if c == sp:
            print(j+1)

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

int main(){
	int i,j,tmp,x;
	int tall[3] = {0};
	int num[10];

	for(i = 0 ; i < 10 ; i++){
		cin >> num[i];
		tmp = num[i];
		for(j = 0 ; j < 3 ; j++ ){
			if(tall[j] <= tmp){
				x = tall[j];
				tall[j] = tmp;
				tmp = x;

			}
		}
	}
	for( i = 0; i < 3 ; i++)
		cout << tall[i] << endl;
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T>
inline void remax(T& x, T y) { x = max(x, y); }

template<typename T>
inline void remin(T& x, T y) { x = min(x, y); }

// End of template code!
int main() 
{
    buff();
    int x;
    cin >> x;
    x -= 400;
    int k = x / 200;
    cout << 8 - k << '\n';
    return 0;
}





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



int main(){
    int K,S,count=0;
    cin>>K>>S;
    for(int x=0;x<K+1;x++){
        for(int y=x;y<K+1;y++){
            int z=S-x-y;
            if(z>K){
                continue;
            }
            if(z<y){
                break;
            }
            else if(x==y&&y==z){
                count++;
            }
            else if(x==y){
                count+=3;
            }
            else if(y==z){
                count+=3;
            }
            else if(z==x){
                count+=3;
            }
            else{
                count+=6;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
N = int(input())

ans = []
# KがNの約数ではないとき、割り算を適用しない
# つまり、あまりが1となるようなKを考える
# よって、N-1の約数を1以外カウント
i = 1
while i * i <= (N - 1):
    if (N - 1) % i == 0:
        ans.append(i)
        if i * i != (N - 1):
            ans.append((N - 1) // i)
    i += 1

# NがKの倍数のとき、つまりKがNの約数のとき
divisor = []
i = 1
while i * i <= N:
    if N % i == 0:
        divisor.append(i)
        if i * i != N:
            divisor.append(N // i)
    i += 1

# 約数のそれぞれに対し、実際に操作を行ってみる
for d in divisor:
    if d == 1:
        continue
    tmp_N = N
    while tmp_N % d == 0:
        tmp_N = tmp_N // d
    if tmp_N % d == 1:
        ans.append(d)

print(len(set(ans)) - 1)

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

ll mod_pow(ll x, ll p, ll M = MOD) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%M;
		x = x*x%M;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll M = MOD) {
	return mod_pow(a, M - 2, M);
}


int main() {
  int n, q;
  cin >> n >> q;
  vi a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vll dp(n, vl(n));
  rep (i, n) {
    rep (j, n) {
      if (i == j) continue;
      if (a[i] < a[j]) dp[i][j] = 1;
    }
  }
  ll half = mod_inverse(2);
  vll memo(n, vl(n));
  rep (aaa, q) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    rep (i, n) {
      if (i == u || i == v) continue;
      memo[i][u] = (dp[i][u] + dp[i][v]) % MOD * half % MOD;
      memo[u][i] = (dp[u][i] + dp[v][i]) % MOD * half % MOD;
      memo[i][v] = (dp[i][u] + dp[i][v]) % MOD * half % MOD;
      memo[v][i] = (dp[u][i] + dp[v][i]) % MOD * half % MOD;
    }
    memo[u][v] = memo[v][u] = (dp[u][v] + dp[v][u]) % MOD * half % MOD;
    rep (i, n) {
      if (i == u || i == v) continue;
      dp[i][u] = memo[i][u];
      dp[i][v] = memo[i][v];
      dp[u][i] = memo[u][i];
      dp[v][i] = memo[v][i];
    }
    dp[u][v] = dp[v][u] = memo[u][v];
  }
  ll ans = 0;
  ll po = mod_pow(2, q);
  rep (i, n) {
    for (int j = 0; j < i; j++) {
      ans += po * dp[i][j] % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 141184
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    lli n, m, k, u, v; cin >> n >> m >> k;
    map<lli, lli> cntu;
    map<lli, lli> cntv;
    set<ii> st;
    vector<vector<lli>> h(3e5 + 5);
    vector<vector<lli>> w(3e5 + 5);
    lli mxu = 0, mxv = 0;
    fore(i, 0, k) {
        cin >> u >> v;
        ++cntu[u];
        ++cntv[v];
        mxu = max(mxu, cntu[u]);
        mxv = max(mxv, cntv[v]);
        h[u].pb(v);
        w[v].pb(u);
    }
    vector<lli> candidatesU;
    vector<lli> candidatesV;
    for(auto it : cntu) if(it.s == mxu) candidatesU.pb(it.f);
    for(auto it : cntv) if(it.s == mxv) candidatesV.pb(it.f);
    bool b = false;
    vector<lli> cnt(3e5 + 5, 0);
    for(auto it : candidatesU) for(auto itt : h[it]) ++cnt[itt];
    for(auto it : candidatesV) if(cnt[it] != sz(candidatesU)) b = true;
    fill(all(cnt), 0);
    for(auto it : candidatesV) for(auto itt : w[it]) ++cnt[itt];
    for(auto it : candidatesU) if(cnt[it] != sz(candidatesV)) b = true;
    lli ans = mxu + mxv;
    if(!b) --ans;
    cout << ans << ENDL;
    return 0;
}


Measured memory_bytes: 81904
N,M = map(int,input().split())
ans = [-1]*N
flg = 0
 
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if ans[s] == -1 or ans[s] == c:
    ans[s] = c
  else:
    flg = 1
  
if flg == 0:
  if N == 1 and ans[0] == -1 or N == 1 and ans[0] == 0:
    print("0")
  elif ans[0] == 0:
    print("-1")
  else:
    if ans[0] == -1:
      ans[0] = 1
    for i in range(1,N):
      if ans[i] == -1:
        ans[i] = 0
    print(int("".join(map(str,ans))))
else:
  print("-1")

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

bool solve() {
  int N, Q;
  cin >> N >> Q;
  if (N == 0 && Q == 0) return false;
  vector<vector<int>> a(N);
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    a[i].resize(k);
    cin >> a[i];
    for (int d : a[i]) m[d]++;
  }
  pair<int, int> ans(-1, 0);
  for (auto p : m) {
    pair<int, int> a(p.second, -p.first);
    chmax(ans, a);
  }
  if (ans.first < Q)
    cout << 0 << endl;
  else
    cout << -ans.second << endl;
  return true;
}

signed main() {
  fastio();
  // solve();
  // int t; cin >> t; while(t--)solve();
  while (solve()) {}
  return 0;
}



Measured memory_bytes: 3096
import sys
N = int(input())
ls = list(map(int,input().split()))
for i in range(1,N):
  if ls[i]-ls[i-1]>=1:
    ls[i]-=1 
for i in range(1,N):
  if ls[i]-ls[i-1]>=0:
    continue
  else:
    print("No")
    sys.exit()
print("Yes")


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

int main(){
  int n,d;
  vector<vector<int> > v;
  vector<int> v_tmp;
  cin>>n>>d;
  for(int i=0; i<n;i++){
    for(int j=0;j<d;j++){
      int tmp;
      cin>>tmp;
      v_tmp.push_back(tmp);
    }
    v.push_back(v_tmp);
    v_tmp.clear();
  }
  int count=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int sum=0;
      for(int k=0;k<d;k++){
        sum+=(v.at(i).at(k)-v.at(j).at(k))*(v.at(i).at(k)-v.at(j).at(k));
      }
      if(ceil(sqrt(sum)) == floor(sqrt(sum))){
        count++;
      } 
    }
  }
  cout<<count<<endl;
}

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

int main(int argc, char *argv[])
{
    double x1, y1, x2, y2;
    
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
    printf("%lf", sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))));
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX 400030
struct FW{
    int t[MX],L;
    void ud(int x,int v){while(x<=L)t[x]=max(t[x],v),x+=x&-x;}
    int MAX(int x){int X=-INF;while(x)X=max(X,t[x]),x-=x&-x;return X;}
    void ini(int N){L=N,fill(t,t+N,-INF);}
}F;
map<int,int> T;
void rnm(int*A,int N){
    static int B[MX],L;
    memcpy(B,A,N<<2);
    sort(B,B+N),L=unique(B,B+N)-B;
    F(L)T[B[i]]=i+2;
    F(N)A[i]=T[A[i]];
}
#define M int(1e8+1)
void rt(int&a,int&b){swap(a,b),a=M-1-a;}
double q=2*M_PI*10/4,z,Z;
int u,v,U,V,N,B[MX],a;
ii A[MX];
double go(){
    F.ini(N+20),T.clear();
    while(u>U||v>V){
        rt(u,v),rt(U,V);
        F(N)rt(A[i].aa,A[i].bb);
    }
    F(N)B[i]=A[i].bb;
    B[N]=v,B[N+1]=V,B[N+2]=V-1,rnm(B,N+3);
    sort(A,A+N);
    F.ud(T[v],0);
    F(N){
        if(A[i].aa<u||A[i].aa>U||A[i].bb<v||A[i].bb>V)continue;
        int a=F.MAX(T[A[i].bb]);
        F.ud(T[A[i].bb],a+1);
    }
    a=F.MAX(T[V]),z=a*(q-20)+q;
    if(a<min(U-u+1,V-v+1))z=min(z,F.MAX(T[V])*(q-20));
    return 100.*(U-u+V-v)+z;
}
int main(void){
    scanf("%d%d%d%d%d",&u,&v,&U,&V,&N);
    F(N)scanf("%d%d",&A[i].aa,&A[i].bb);
//    Z=go();
//    swap(u,v),swap(U,V);
//    F(N)swap(A[i].aa,A[i].bb);
    printf("%.30lf\n",go());
    return 0;
}//WA - yet on a good way


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n,k; cin >> n >> k;
    vl v(n);
    rep(i,n)cin>>v[i];
    ll res = 0;
    for(int left = 0;left<=k;left++){
        for(int right = 0;right <= k-left;right++){
            if(left + right > n)continue;
            ll ttl = left + right;
            ll dif = k - ttl;
            vl tmp;
            rep(j,left)tmp.push_back(v[j]);
            rep(j,right)tmp.push_back(v[n-j-1]);
            sort(all(tmp));
            rep(j,min(dif,ttl)){
                if(tmp[j] < 0)tmp[j] = 0;
            }
            ll ans = accumulate(all(tmp),0LL);
            res = max(res,ans);
        }
    }
    out(res);
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 107;
const LD PI = acos ( -1.0 );

struct pT
{
	pT () : x ( 0 ), y ( 0 ) {}
	pT ( int _x, int _y ) : x ( _x ), y ( _y ) {}
	
	bool operator < ( const pT &a ) const
	{
		return ( x ^ a.x ) ? ( x < a.x ) : ( y < a.y );
	}
	
	pT operator + ( const pT &a ) const
	{
		return pT ( x + a.x, y + a.y );
	}
	
	pT operator - ( const pT &a ) const
	{
		return pT ( x - a.x, y - a.y );
	}
	
	LL operator * ( const pT &a ) const
	{
		return SC ( LL, x ) * a.x + SC ( LL, y ) * a.y;
	}
	
	LL operator ^ ( const pT &a ) const
	{
		return SC ( LL, x ) * a.y - SC ( LL, y ) * a.x;
	}
	
	LD len ()
	{
		return sqrt ( SC ( LL, x ) * x + SC ( LL, y ) * y );
	}
	
	int x, y;
};

int n;
int ord[MAXN];
pT pt[MAXN];
int stk[MAXN], top;
LD ans[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d%d", &pt[i].x, &pt[i].y );
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ) ord[i] = i;
	sort ( ord+1, ord+1+n, [] ( int x, int y ) { return pt[x] < pt[y]; } );
	sort ( pt+1, pt+1+n );
	
//	lpi ( i, 1, n ) cerr << ord[i] << " "; cerr << endl;
	
	top = 0;
	stk[top] = 1;
	lpi ( i, 2, n ){
		while ( top && ( ( ( pt[stk[top]] - pt[stk[top-1]] ) ^ ( pt[i] - pt[stk[top]] ) ) <= 0 ) ) --top;
		stk[++top] = i;
	}
	int nt = top;
	lpd ( i, n-1, 0 ){
		while ( top > nt && ( ( ( pt[stk[top]] - pt[stk[top-1]] ) ^ ( pt[i] - pt[stk[top]] ) ) <= 0 ) ) --top;
		stk[++top] = i;
	}
	if ( n == 1 ) stk[++top] = 1;
	
//	lpi ( i, 0, top ) cerr << ord[stk[i]] << " "; cerr << endl;
	
	stk[top+1] = stk[1];
	lpi ( i, 1, top ) ans[ord[stk[i]]] = acos ( min ( max ( ( ( pt[stk[i+1]] - pt[stk[i]] ) * ( pt[stk[i]] - pt[stk[i-1]] ) ) / ( ( pt[stk[i+1]] - pt[stk[i]] ).len () * ( pt[stk[i]] - pt[stk[i-1]] ).len () ), SC ( LD, -1 ) ), SC ( LD, 1 ) ) ) / ( 2 * PI );
	
	lpi ( i, 1, n ) cout << setprecision ( 13 ) << fixed << ans[i] << endl;
}

Measured memory_bytes: 512
import io.StdIn.readLine
object Main extends App {
  val Array(d, m) = readLine.split(" ").map(_.toInt)

  println(solve(d, m))

  def solve(d: Int, m: Int) = {
    if ((d - m).abs >= 2) 0
    else {
      val ans = factorial(d, 1) * factorial(m, 1) % 1000000007
      if (d == m) (2 * ans % 1000000007) else ans
    }
  }

  def factorial(n: Int, res: Long): Long = {
    if (n <= 0) -1
    else if (n == 1) res
    else {
      factorial(n - 1, res * n % 1000000007)
    }
  }
}


Measured memory_bytes: 25540
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
map<int, int> vis;
set<ll> s;
int main()
{
    MOAE;
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC" << endl;
    else if (s == "ARC")
        cout << "ABC" << endl;
    ok;
}

Measured memory_bytes: 3644
S = input()

L = len(S)
chk = False
ans1,ans2 = 0,0

# 連続する2文字が同じである
#   ならば3文字目が異なっていても過半数獲得
for i in range(1,L):
    if S[i]==S[i-1]:
        chk = True
        ans1,ans2 = i,i+1
        break

# 連続する3文字の1,3が同じ
# ならば3文字部分文字列において過半数獲得
if not chk:
    for i in range(2,L):
        if S[i]==S[i-2]:
            chk = True
            ans1,ans2 = i-1,i+1
            break

if chk:
    print(ans1,ans2)
else:
    print(-1,-1)



Measured memory_bytes: 3188
import sys
input=sys.stdin.readline

n=int(input())
p=[]
for _ in range(n):
    x,y,u=input().split()
    p.append((int(x),int(y),u))

ans=10**9
import bisect

D={}
L={}
for i in p:
    if i[2]=='D':
        if i[0] in D:
            D[i[0]].append(i[1])
        else:
            D[i[0]]=[i[1]]
    elif i[2]=='L':
        if i[1] in L:
            L[i[1]].append(i[0])
        else:
            L[i[1]]=[i[0]]
for i in D.values():
    i.sort()
for i in L.values():
    i.sort()

for i in p:
    if i[2]=='U':
        if i[0] in D:
            j=bisect.bisect(D[i[0]],i[1])
            if j==len(D[i[0]]):
                continue
            temp=(D[i[0]][j]-i[1])*5
            ans=min(ans,temp)
    elif i[2]=='R':
        if i[1] in L:
            j=bisect.bisect(L[i[1]],i[0])
            if j==len(L[i[1]]):
                continue
            temp=(L[i[1]][j]-i[0])*5
            ans=min(ans,temp)

U={}
L={}
D={}
R={}
for i in p:
    if i[2]=='U':
        x=i[0]+i[1]
        if x in U:
            U[x].append(i[0])
        else:
            U[x]=[i[0]]
    elif i[2]=='L':
        x=i[0]-i[1]
        if x in L:
            L[x].append(i[0])
        else:
            L[x]=[i[0]]
    elif i[2]=='D':
        x=i[0]+i[1]
        if x in D:
            D[x].append(i[0])
        else:
            D[x]=[i[0]]
    elif i[2]=='R':
        x=i[0]-i[1]
        if x in R:
            R[x].append(i[0])
        else:
            R[x]=[i[0]]
for i in U.values():
    i.sort()
for i in L.values():
    i.sort()
for i in D.values():
    i.sort()
for i in R.values():
    i.sort()

for i in p:
    if i[2]=='U':
        x=i[0]-i[1]
        if x in L:
            j=bisect.bisect(L[x],i[0])
            if j==len(L[x]):
                continue
            temp=(L[x][j]-i[0])*10
            ans=min(ans,temp)
    elif i[2]=='L':
        x=i[0]+i[1]
        if x in D:
            j=bisect.bisect(D[x],i[0])
            if j==0:
                continue
            temp=(-D[x][j-1]+i[0])*10
            ans=min(ans,temp)
    elif i[2]=='D':
        x=i[0]-i[1]
        if x in R:
            j=bisect.bisect(R[x],i[0])
            if j ==0:
                continue
            temp=(-R[x][j-1]+i[0])*10
            ans=min(ans,temp)
    elif i[2]=='R':
        x=i[0]+i[1]
        if x in U:
            j=bisect.bisect(U[x],i[0])
            if j == len(U[x]):
                continue
            temp=(U[x][j]-i[0])*10
            ans=min(ans,temp)

if ans==10**9:
    print('SAFE')
else:
    print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0, ans=0;
  string s;
  ll a,b,h;
  cin >> a >> b >> h >> m;
  m=60*h+m;
  double ad,bd;
  if(m>=720)  ad = 0.5*(m%720);
  else  ad = 0.5*m;

  if(m>=60)  bd = 6.0*(m%60);
  else  bd = 6.0*m;

  double sita = abs(ad-bd);
  double PI = 3.141592653589793;
  double rad = sita * PI / 180.0;
  double c= a*a+ b*b -2.0*a*b*cos(rad);
  c= pow(c,0.5);
  cout << fixed << setprecision(12) << c << endl;
}

Measured memory_bytes: 4328
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main(){
  int N,D,count=0;
  double sum;
  cin >> N >> D;
  vector<vector<int>> X(N,vector<int>(D));
  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++){
      sum=0;
      for(int k=0;k<D;k++){
        sum+=pow(X[i][k]-X[j][k],2);
      }
      if(ceil(sqrt(sum))==floor(sqrt(sum))){
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int sumN = getSum(n);
		int sumM = getSum(m);

		System.out.println(sumM+sumN);
	}

	private static int getSum(int k) {
		if (k==0 || k==1) {
			return 0;
		} else {
			return k*(k-1)/2;
		}
	}

}


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

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


int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];

    REP(i, N-1) A[i+1] += A[i];
    long long ans = 1e+18;
    REP(i, N-1){
        if(2*A[i] >= A.back()) ans = min(ans, 2*A[i]-A.back());
        if(2*A[i] <= A.back()) ans = min(ans, A.back()-2*A[i]);
    }
    cout << ans << endl;

    return 0;
}

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

#define DIR (0)
#define FIL (1)
struct F{
	string name;
	vector<F*> ch;
	int type;
	F(string name,int type) : name(name), type(type) {}
	F(){};
};

void ins(F* root,string s){
	assert(s[0] == '/' );
	string now = "";
	for(int i = 1 ; i < s.size() ; i++){
		if( s[i] == '/' ){
			//cout << now << endl;
			bool ok = false;
			for(int j = 0 ; j < root->ch.size() ; j++){
				if( root->ch[j]->name == now ){
					root = root->ch[j];
					root->type = DIR;
					ok = true;
					break;
				}
			}
			if(!ok){
				(root->ch).push_back(new F(now,DIR));
				root = (root->ch).back();
			}
			now = "";
		}else now += s[i];
	}
	assert( now != "" );
	(root->ch).push_back(new F(now,FIL));
}

F* get2(F* root_,string s){
	assert(s[0] == '/' );
	string now = "";
	vector<F*> rt;
	rt.push_back(root_);
	for(int i = 1 ; i < s.size() ; i++){
		if( s[i] == '/' ){
			F *root = rt.back();
			if( now == "." ){
				now = "";
				continue;
			}
			if( now == ".." ){
				if( rt.size() == 1 ) return NULL;
				rt.pop_back();
				now = "";
				continue;
			}
			bool ok = false;
			for(int j = 0 ; j < root->ch.size() ; j++){
				if( root->ch[j]->name == now && root->ch[j]->type == DIR){
					rt.push_back(root->ch[j]);
					ok = true;
					break;
				}
			}
			if(!ok){
				return NULL;
			}
			now = "";
		}else now += s[i];
	}
	
	if( now == "." ) now = "";
	if( now == ".." ){ rt.pop_back(); now = ""; }
	if( rt.size() == 0 ) return NULL;
	F *root = rt.back();
	if( now == "" ) {
		for(int j = 0 ; j < root->ch.size() ; j++){
			if( root->ch[j]->name == "index.html" && root->ch[j]->type == FIL){
				return root->ch[j];
			}
		}
		return NULL;
	}else{
		for(int j = 0 ; j < root->ch.size() ; j++){
			if( root->ch[j]->name == now ){
				if( root->ch[j]->type == DIR ){
						root = root->ch[j];
						for(int k = 0 ; k < root->ch.size() ; k++){
							if( root->ch[k]->name == "index.html" && root->ch[k]->type == FIL){
								return root->ch[k];
							}
						}
						return NULL;
				}else{
					return root->ch[j];
				}
			}
		}
		return NULL;
	}
}

int main(){
	int n,m;
	while( cin >> n >> m && (n||m) ){
		F *root = new F("",DIR);
		for(int i = 0 ; i < n ; i++){
			string s;
			cin >> s;
			ins(root,s);
		}
		for(int i = 0 ; i < m ; i++){
			string a,b;
			cin >> a >> b;
			F* A = get2(root,a);
			F* B = get2(root,b);
			if( A == NULL || B == NULL ) cout << "not found" << endl;
			else cout << (A==B?"yes":"no") << endl;
		}
		
		
		
		
	}
}

Measured memory_bytes: 1248
import sys
from math import cos, sin, pi

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, H, M = map(int, read().split())

H += M / 60

t1 = 2 * pi * H / 12
t2 = 2 * pi * H

z1 = A * complex(cos(t1), sin(t1))
z2 = B * complex(cos(t2), sin(t2))

print(abs(z1 - z2))

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  sort(all(A));

  int mod = 0;
  for (int i = 1; i < A.size(); i++) {
    if (A[i] == A[i-1]) mod++;
  }

  if (mod % 2 == 1) mod++;

  cout << N - mod << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int n;

void dfs(string s,char mx);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     n=nxt();
     dfs("",'a');
    

    return 0;   
}

void dfs(string s,char mx)
{
    if(s.length()==n)
    {
        printf("%s\n",s.c_str());
    }
    else
    {
        for(char c='a';c<=mx;c++)
        {
            dfs(s+c,((c==mx)?mx+1:mx));
        }
    }
}


 
 


Measured memory_bytes: 1536
# include <cstdio>
# include <iostream>
# include <cstring>
# include <string>
# include <cmath>
# include <algorithm>
# define R register int
 
using namespace std;
 
const int maxn=100005;
int n,k,p1,p2,equ;
int cnt,a[maxn],ans;
 
int ab (int x)
{
    if(x<0) return -x;
    return x;
}
 
int ask (int x,int y)
{
    if(x<0&&y<0) return -min(x,y);
    if(x>0&&y>0) return max(x,y);
    return ab(x)+ab(y)+min(ab(x),ab(y));
}
 
int main()
{
    scanf("%d%d",&n,&k);
    for (R i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        if(a[i]<0) equ=i;
    }
    p1=p2=equ;
    if(p2<k) p2=p1=k;
    cnt=1;
    while (cnt<k&&p1>1) p1--,cnt++;
    if(cnt==k) ans=ask(a[p1],a[p2]);
    while (p2<n)
    {
        p1++;
        p2++;
        ans=min(ask(a[p1],a[p2]),ans);
    }
    printf("%d",ans);
    return 0;
}

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

using namespace std;

int main() {
	int n, w;
	cin>>n>>w;
	int weight[n + 1];
	lli value[n + 1];
	for(int i = 1; i <= n; i++) cin>>weight[i]>>value[i];
	lli dp[n + 1][w + 1];
	for(int i = 0; i <= n; i++) fill(dp[i], dp[i] + w + 1, 0);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= w; j++)
			if(j < weight[i]) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i][j], max(dp[i - 1][j], value[i] + dp[i - 1][j - weight[i]]));
	cout<<dp[n][w];
	return 0;
}
	
	


Measured memory_bytes: 79104
def main():
  C, n = map(int, input().split())
  mp = [input() for _ in range(n)]
  diff_dic = {}

  def change(x, y):
    if (x, y) in diff_dic:
      diff_dic.pop((x, y))
    else:
      diff_dic[(x, y)] = True

  for y in range(n // 2):
    for x in range(n // 2):
      base = mp[y][x]
      if mp[y][n - 1 - x] != base:
        change(n - 1 - x, y)
      if mp[n - 1 - y][x] != base:
        change(x, n - 1 - y)
      if mp[n - 1 - y][n - 1 - x] != base:
        change(n - 1 - x, n - 1 - y)
  if n % 2:
    for x in range(n // 2):
      if mp[n // 2][x] != mp[n // 2][n - 1 - x]:
        chenge(n - 1 - x, n // 2)
    for y in range(n // 2):
      if mp[y][n // 2] != mp[n - 1 - y][n // 2]:
        change(n // 2, n - 1 - y)
  
  ans = 0
  if not diff_dic:
    ans += 1
  
  for _ in range(C - 1):
    d = int(input())
    for _ in range(d):
      r, c = map(int, input().split())
      r -= 1
      c -= 1
      if r < n // 2 and c < n // 2:
        change(c, n - 1 - r)
        change(n - 1 - c, r)
        change(n - 1 - c, n - 1 - r)
      elif n % 2 and r == n // 2 and c != n // 2:
        change(max(c, n - 1 - c), r)
      elif n % 2 and r != n // 2 and c == n // 2:
        change(c, max(r, n - 1 - r))
      else:
        change(c, r)
    if not diff_dic:
        ans += 1
  print(ans)
  
main()


Measured memory_bytes: 68824
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define ROR(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define F first
#define S second
#define sz size()
#define mp make_pair
#define p(x) cout<< x << " ";
#define pe(x) cout<< x << endl ;
typedef long long ll;
const ll N = 1e5 + 5;
#define M 1000000007

int main()
{
    FAST
    ll n,m,x;
    cin>>n>>m;
    ll a[n+1]={0};
    for(ll i=0;i<m;i++)
    {
        cin>>x;
        a[x]=-1;
    }
    a[0]=1;
    if(a[1]!=-1)
    a[1]=1;
    
    for(ll i=2;i<=n;i++)
    {
        ll t=0,t1=0;
        if(i-1>=0 && a[i-1]!=-1)
        t=a[i-1]%M;
        if(i-2>=0 && a[i-2]!=-1)
        t1=a[i-2]%M;
        if(a[i]!=-1)
        a[i]=(t+t1)%M;
        
    }
   
    cout<<a[n];
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if ((A==5&B==5&C==7)||(A==5&B==7&C==5)||(A==7&B==5&C==5))
    {
		printf("YES");
    }
    else
    {
		printf("NO");
    }
    
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,i,j ;
	cin >> n;
	bool valid = false;
	for (int i=1;i<=9;i++){
		for (int j=1 ;j<=9 ; j++){
			if (i*j== n){
				valid = true;
			}
		}
	}
	if (valid){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256