akhauriyash/Code-Regression huggingface dataset:
from scipy.misc import comb 
from collections import defaultdict, deque, Counter
import sys
#from scipy.special import comb
import heapq
import math

input = sys.stdin.readline

sys.setrecursionlimit(10000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N, A, B = [int(a) for a in input().split()]
    V = sorted([int(a) for a in input().split()], reverse=True)

    s = sum(V[:A]) / A
    target = V[A - 1]
    if target == V[0]:
        co = V.count(target)
        t = sum(
            comb(co, c, exact=True)
            for c in range(A, min(B, co) + 1)
        )
        print(s)
        print(t)
        return

    c1 = V[:A].count(target)
    c2 = V.count(target)
    t = comb(c2, c1, exact=True)
    print(s)
    print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13360
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef char keytype;

int gcd(int a, int b){ return (a % b) ? gcd(b, a % b) : b;}
int lcm(int a, int b){ return (a / gcd(a, b)) * b;}

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

const int inf = 1012345678;
int main(){
    int a, b;

    scanf("%d %d", &a, &b);

    int cnt = 0;
    for(int i = a; i <= b; ++i){
        if((i / 1000) == ((i % 10) * 10) + (i % 100) / 10){
            cnt++;
        }
    }

    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>
#include<math.h>
int main()
{
    int m,n,s,v,i,j,a[100002][2],p,q,b[100002],c[100002];
    while(~scanf("%d",&n))
    {
        v=1;
        for(i=0; i<n; i++)
            scanf("%d %d %d",&b[i],&a[i][0],&a[i][1]);
        p=0;
        q=0;
        for(i=0;i<n;i++)
        {
            if(i==0)
                c[i]=b[i];
            else
                c[i]=b[i]-b[i-1];
        }
        for(i=0; i<n; i++)
        {
            s=abs(a[i][0]-p)+abs(a[i][1]-q);
            if(s>c[i]||(c[i]-s)%2!=0)
            {
                v=0;
                break;
            }
            p=a[i][0];
            q=a[i][1];
        }
        if(v==1)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

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

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

Measured memory_bytes: 3588
N, M = map(int, input().split())
A = list(map(int, input().split()))

check = ((1 / (4 * M)) * sum(A))
x = 0
for item in A:
    if item < check:
        x += 1

ans = N - x

if ans >= M :
    print('Yes')
else:
  	print('No')

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

ll souwa(ll x){
  ll sum = 0;
  sum = x*(x+1)/2;
  return sum;
}


int main(){
  ll ans,count,n = 0;
  cin >> n;
  ans = souwa(n) - souwa(n/3)*3 - souwa(n/5)*5 + souwa(n/15)*15;
  cout << ans << endl;
}

Measured memory_bytes: 3604
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,m,ord[10];
bool con[111][111];
int main()
{
	get2(n,m);
	for(int i=1;i<=n;i++)ord[i]=i;
	for(int i=1,u,v;i<=m;i++)
	{
		get2(u,v);
		con[u][v]=con[v][u]=1;
	}
	int ans=0;
	do
	{
		bool ok=1;
		for(int i=1;i<n&&ok;i++)ok&=con[ord[i]][ord[i+1]];
		if(ok)ans++;
	}while(next_permutation(ord+2,ord+n+1));
	printendl(ans);
	return 0;
}

Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a, b) for (ll i = a; i < b; ++i)
#define rrrep(i, a, b) for (ll i = a; i >= b; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;

    string ans;
    while (N != 0) {
        ll r = N % -2;
        if (r == 0) {
            ans += '0';
        } else {
            ans += '1';
            N -= 1;
        }
        N /= -2;
    }
    reverse(all(ans));
    if (ans == "") ans = "0";
    cout << ans << endl;
}


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

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    int s[m];
    int c[m];
    int ans=0;
    int f[n];
    int p=0;
    int f2=0;
    for(int i=0; i<n; i++){
        f[i]=0;
    }
    for(int i=0; i<m; i++){
        scanf("%d %d",&s[i],&c[i]);
        f2=0;
        if(s[i]==1&&c[i]==0&&n>1){
            p=1;
        }
        for(int j=0; j<i; j++){
            if(s[j]==s[i]&&c[j]==c[i]){
                f2=1;
            }
            if(s[j]==s[i]&&c[j]!=c[i]){
                p=1;
            }
        }
        if(f2==0){
            ans+=c[i]*pow(10,n-s[i]);
        }
    }
    
    if(ans<pow(10,n-1)&&n>1){
        ans+=pow(10,n-1);
    }
    if(p==1){
        printf("-1\n");
    }
    else{
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int total;
    total=n*800;
    int d=n/15;
    int k=d*200;
    int ans=total-k;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
long long arr[10000];
int main()
{
	long long n,i,j,ans,l,r,mid,flag;
	ans=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
	for(i=0;i<n;i++)
	{
		for(j=n-1;j>i+1;j--)
		{
			flag=0;
			l=i+1;
			r=j-1;
			while(l<=r)
			{
				mid=(l+r)/2;
				//cout<<arr[mid]<<endl;
				if(arr[i]+arr[mid]<=arr[j])
				{
					if (arr[i]+arr[mid+1]>arr[j])
					{
						mid=mid+1;
						flag=1;
						break;
					}
					else
					{
						l=mid+1;
					}
				}
				else
				{
					if(mid==r)
					{
						flag=1;
					}
					r=mid-1;
				}
			}
			if ((j-mid)>0 && arr[mid]+arr[i]>arr[j])
			{
				ans+=(j-mid);
			}
			//cout<<ans<<endl;
		}
	}
	cout<<ans<<endl;
}

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

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

    std::unordered_map<int, int> m;
    m.reserve(N);
    int a;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        ++m[a];
    }

    int ret = 0;
    const int size = static_cast<int>(m.size());
    if (size > K) {
        std::vector<int> v;
        v.reserve(size);
        for (const auto& i_pair : m) {
            v.push_back(i_pair.second);
        }
        std::sort(v.begin(), v.end());

        const int num = size - K;
        for (int i = 0; i < num; ++i) {
            ret += v[i];
        }
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 8832
H,W=map(int,input().split())
G=[ ]

for i in range(H):
  G.append(list(input()))
  
L=[[0]*W for i in range(H)]
R=[[0]*W for i in range(H)]
U=[[0]*W for i in range(H)]
D=[[0]*W for i in range(H)]

for i in range(H):
  for j in range(W):
    k=-i-1
    l=-j-1
    if G[i][j]=="#":
      L[i][j]=0
      U[i][j]=0
    else:
      if j==0:
        L[i][j]=1
        U[i][j]=U[i-1][j]+1
      elif i==0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1
        
    if G[k][l]=="#":
      R[k][l]=0
      D[k][l]=0
    else:
      if k==-1:
        R[k][l]=1
        D[k][l]=D[k+1][l]+1
      elif i==0:
        R[k][l]=R[k][l+1]+1
        D[k][l]=1
      else:
        R[k][l]=R[k][l+1]+1
        D[k][l]=D[k+1][l]+1
ans=0
for i in range(H):
  for j in range(W):
    #print(L[i][j],R[i][j],U[i][j],D[i][j])
    ans=max(R[i][j]+L[i][j]+U[i][j]+D[i][j]-3,ans)
print(ans)

Measured memory_bytes: 309128
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [map(int,input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
ans = [True for _ in range(n)]
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        ans[b[i]-1] = False
    elif h[a[i]-1] == h[b[i]-1]:
        ans[a[i]-1] = False
        ans[b[i]-1] = False
    else:
        ans[a[i]-1] = False
answer = sum(ans)
print(answer)


Measured memory_bytes: 123548
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    vector<ll> buka(N, 0);
    rep(i, N - 1)
    {
        ll a;
        cin >> a;
        --a;
        A[i + 1] = a;
        ++buka[a];
    }
    rep(i, N)
    {
        cout << buka[i] << endl;
    }
    //
    //
    return 0;
}

Measured memory_bytes: 5984
#include<stdio.h>
#include<string.h>
struct Card{
	char suit;
	int value;
};

void bubble(struct Card b[], int n);
void selection(struct Card s[], int n);
	
int main(void){
	int n,v, i, j;
	struct Card a[100], b[100], c[100];
	int aa, bb;
	int d[100];
	char s[10];
	char change[10];
	int stable=1;
	
	
	scanf("%d", &n);
	for(i = 0;i<n;i++){
		scanf("%s",s);
		//strcpy(b[i].suit, a[i].suit);
		
		a[i].suit =b[i].suit=c[i].suit= s[0];
		a[i].value =b[i].value =c[i].value = s[1]-'0';
	}
	
		
	bubble(b, n);
	
	

	
	for(i = 0;i<n-1;i++){
		
		printf("%c%d ", b[i].suit, b[i].value);
	}
	printf("%c%d\n", b[n-1].suit, b[n-1].value);

	
		printf("Stable\n");
	
	
	selection(c, n);
	stable =1;
	for(i = 0;i<n;i++){
		
			if(b[i].value != c[i].value || b[i].suit != c[i].suit ){
			stable =0;

		}
		
		
	}
	
	
	for(i = 0;i<n-1;i++){
		
		printf("%c%d ", c[i].suit, c[i].value);
	}
	printf("%c%d\n", c[i].suit, c[i].value);
	
	
	if(stable == 1){
		printf("Stable\n");
	}
	else {printf("Not stable\n");}
	
	//printf("%c %d\n", b[n-1].suit, b[i].value);
	
	return 0;
	
}




void bubble(struct Card b[], int n){
	int i, j, x;
	char y;
	for(i = 0;i<n;i++){
		for(j = n-1;j>i;j--){
			if(b[j].value<b[j-1].value){
				x = b[j-1].value;
				y = b[j-1].suit;
				b[j-1].value = b[j].value;
				b[j-1].suit = b[j].suit;
				b[j].value = x;
				b[j].suit = y;
				
				
			}
		}
	}
	
}


void selection(struct Card s[], int n){
	int i, j, min, x;
	char y;
	for(i = 0;i<n;i++){
		min =i;
		for(j =i;j<n;j++){
			if(s[min].value > s[j].value){
				min =j;
			}
		}
		if(min != i){
		x = s[i].value;
		y = s[i].suit;
		s[i].value = s[min].value;
		s[i].suit = s[min].suit;
		s[min].value = x;
		s[min].suit = y;
		}
	}
}




Measured memory_bytes: 2032
from bisect import bisect_left, bisect_right, insort_left, insort_right

import numpy as np

import itertools

import math 
from collections import defaultdict as dd
def main():
    n = int(input())
    A = []
    for k in range(n):
        A.append(int(input()))

    A =  sorted(A)

    count = 0
    val = 0
    for a in A:
        if a > val:
            count += 1
            val = a

    print (count)

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()


Measured memory_bytes: 12676
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < (i##_MACRO); i++)
#define RANGE(i, a, b) for(int i = (a); i < (b); i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int h, w, k;
	scanf("%d %d %d", &h, &w, &k);
	VI2D cake(h, VI(w, 0));
	getchar();
	REP(i, h) {
		REP(j, w) {
			char c;
			c = getchar();
			if(c == '#') {
				cake[i][j] = 1;
			}
		}
		getchar();
	}
	VI2D result(h, VI(w, 0));

	int s = 0;
	REP(i, h) {
		bool empty = true;
		REP(j, w) {
			if(cake[i][j] == 1) {
				s++;
				if(empty) {
					empty = false;
					REP(x, j) { result[i][x] = s; }
				}
			}
			if(!empty) {
				result[i][j] = s;
			}
		}
	}

	REP(i, h) {
		bool empty = true;
		REP(j, w) {
			if(result[i][j] != 0) {
				empty = false;
				break;
			}
		}
		if(empty && i != 0) {
			REP(j, w) { result[i][j] = result[i - 1][j]; }
		}
	}

	for(int i = h - 1; i >= 0; i--) {
		bool empty = true;
		REP(j, w) {
			if(result[i][j] != 0) {
				empty = false;
				break;
			}
		}
		if(empty && i != h - 1) {
			REP(j, w) { result[i][j] = result[i + 1][j]; }
		}
	}

	REP(i, h) {
		REP(j, w) { printf("%d ", result[i][j]); }
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h> 
#define ll long long int
#define push_back pb

using namespace std; 

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

    for(int i=0;i<s.length();i++) {
        char t = s[i] + n;
        if(t > 90) t-=26;
        cout<<t;
    }
    cout<<endl;
}

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

const int mod = 1000000007;
int dp[1100][1100] = {0};

int main() 
{
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i,h) cin >> a[i];

    dp[0][0] = 1;
    rep(i,h)rep(j,w) {
        if (i>0 && a[i-1][j] == '.') dp[i][j] += dp[i-1][j];
        if (j>0 && a[i][j-1] == '.') dp[i][j] += dp[i][j-1];
        dp[i][j] %= mod;
    }
    cout << dp[h-1][w-1] << endl;

    return 0;
}


Measured memory_bytes: 5632
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
tmp=(n+1)//2*(n-2)
# print(tmp)
if n%2==0:
    print(n*(n-2)//2)
else:
    print(((n-1)*(n-3))//2+n-1)
for i in range(n):
    for j in range(i+1,n):
        if (i+1)+(j+1)!=n+(n+1)%2:
            print(i+1,j+1)

Measured memory_bytes: 42736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
int main()
{
   ll a,ans;
   scanf("%lld",&a);
   ans=a+a*a+a*a*a;
   printf("%lld\n",ans);
}

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL N;
	cin >> N;

	int count = 0;
	int side = 0;
	int left = 0;
	int right = 0;

	REP(i, N) {
		string str;
		cin >> str;

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

		if (str[0] == 'B' && str[str.size() - 1] == 'A') {
			++side;
		}
		else if (str[0] == 'B') {
			++left;
		}
		else if (str[str.size() - 1] == 'A') {
			++right;
		}
	}

	if (side > 1) {
		count += side - 1;
		side = 1;
	}

	int ls = min(side, left);
	count += ls;
	side -= ls;

	int rs = min(side, right);
	count += rs;
	side -= rs;

	int lrPair = min(left, right);
	count += lrPair;
	left -= lrPair;
	right -= lrPair;

	/*if (side > 0 && max(left, right) > 0) {
		++count;
	}*/

	//int ls = min(side, left);
	//count += ls;
	//side -= ls;

	//int rs = min(side, right);
	//count += rs;
	//side -= rs;


	cout << count << endl;

	return 0;
}


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

char grid[310][310];
int ans[310][310];

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<P> p;
  int tmp=0;
  rep(i,h)rep(j,w){
    cin>>grid[i][j];
    ans[i][j]=0;
    if(grid[i][j]=='#'){
      tmp++;
      p.push_back(make_pair(i,j));
      ans[i][j]=tmp;
    }
  }
  //x
  for(auto x : p){
    int nx,ny;
    tie(nx,ny)=x;
    int now=ans[nx][ny];
    while(true){
      nx++;
      if(nx<0 || nx>=h || grid[nx][ny]=='#') break;
      ans[nx][ny]=now;
    }
  }
  for(auto x : p){
    int nx,ny;
    tie(nx,ny)=x;
    int now=ans[nx][ny];
    while(true){
      nx--;
      if(nx<0 || nx>=h || grid[nx][ny]=='#') break;
      ans[nx][ny]=now;
    }
  }
  //y
  rep(hi,h)rep(wi,w){
    if(ans[hi][wi]!=0){
      int nx=hi, ny=wi;
      int now=ans[nx][ny];
      while(true){
        ny++;
        if(ny<0 || ny>=w || ans[nx][ny]!=0) break;
        ans[nx][ny]=now;
      }
    }
  }
  rep(hi,h)rep(wi,w){
    if(ans[hi][wi]!=0){
      int nx=hi, ny=wi;
      int now=ans[nx][ny];
      while(true){
        ny--;
        if(ny<0 || ny>=w || ans[nx][ny]!=0) break;
        ans[nx][ny]=now;
      }
    }
  }
  //answer
  rep(i,h){
    rep(j,w){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
}


Measured memory_bytes: 4756
#include<stdio.h>

int main()
{
  char s[100];
  int N;
  scanf("%d",&N);
  scanf("%s",s);

  int alpha[1000];
  int i,j,k,count=0,count_max=0;;

  for(i=1;i<N;i++){
    count=0;
    for(j=0;j<1000;j++){ // alpha[j]を初期化
      alpha[j]=0;
    }

    for(j=i;j<N;j++){ //後半(iから)
      for(k=0;k<i;k++){ //前半(iまで)
        if(s[j]==s[k] && alpha[s[j]]==0){
          count++;
          alpha[s[j]] = 1; //alpha[s[j]]が既出であればcountを増やさないようにする
        }
      }
    }
    if(count>=count_max){ // 分ける場所(i)を変えて最大のものを記録する
      count_max=count;
    }
  }

  printf("%d\n",count_max);

  return 0;
}

Measured memory_bytes: 128
def partition(A,p,r):
    x=int(A[r])
    i=p-1
    for j in range(p,r):
        if int(A[j])<=x:
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

n=int(input())
A=[str(i) for i in input().split()]
q=partition(A,0,n-1)
print(' '.join(A[:q]) , '['+A[q]+']',' '.join(A[q+1:]))


Measured memory_bytes: 13268
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n=int(input())
print(l[n-1])

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

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

int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
while(1){
c-=b;
if(c<=0){
  cout<<"Yes";
  break;
}
a-=d;
if(a<=0){
  cout<<"No";
  break;
}

}




  return 0;
}


Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int A,B,M;
int a[1<<17],b[1<<17];
main()
{
	cin>>A>>B>>M;
	int ans;
	for(int i=0;i<A;i++)cin>>a[i];
	for(int i=0;i<B;i++)cin>>b[i];
	for(int i=0;i<M;i++)
	{
		int x,y,c;cin>>x>>y>>c;
		x--,y--;
		int t=a[x]+b[y]-c;
		if(i==0||ans>t)ans=t;
	}
	int ma=a[0],mb=b[0];
	for(int i=0;i<A;i++)if(ma>a[i])ma=a[i];
	for(int i=0;i<B;i++)if(mb>b[i])mb=b[i];
	if(ans>ma+mb)ans=ma+mb;
	cout<<ans<<endl;
}


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

int N;
int A[100], B[100], C[100];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N-1; i++) cin >> C[i];
    
    int ans = 0;
    int pre = -1;
    for (int i = 0; i < N; i++) {
        ans += B[A[i] - 1];
        if (pre + 1 == A[i]) ans += C[pre - 1]; 
        pre = A[i];
    }

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


Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

string ban;

bool judge(int start, int end) {
    for(int i = start; i + 1 < end; i++){
        if(ban[i] == '#' && ban[i + 1] == '#') return false;
    }
    return true;
}

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

    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    cin >> ban;
    ban = '#' + ban + '#';

    if(!judge(a, c) || !judge(b, d)) {
        cout << "No" << endl;
        return 0;
    }

    if(c > d) {
        int flg = 0;
        for(int i = b; i <= d; i++) {
            if(ban[i - 1] == '.' && ban[i] == '.' && ban[i + 1] == '.'){
                flg = 1;
            }
        }
        if(!flg) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 720
import java.util.Scanner;

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

		String str;
		int sq = 0, hi = 0;
		
		int a, b, c;
		
		while(scan.hasNext()){
			str = scan.next();
			String[] num = str.split(",", 0);
			
			a = Integer.parseInt(num[0]);
			b = Integer.parseInt(num[1]);
			c = Integer.parseInt(num[2]);
			
			if(a*a + b*b == c*c)sq++;
			else if(a == b)hi++;
		}
		System.out.println(sq);
		System.out.println(hi);
	}
}

Measured memory_bytes: 26076
#include<stdio.h>

int main(void)

{
    int a,b;
    int menseki;
    int nagasa;
    scanf("%d %d",&a,&b);
    menseki=a*b;
    nagasa=2*a+2*b;
    printf("%d %d\n",menseki,nagasa);
    return 0;
}

Measured memory_bytes: 596
from collections import defaultdict, deque

int1 = lambda x: int(x) - 1


def topological_sort(N, G):
    outs = defaultdict(list)
    ins = defaultdict(int)
    for v1, v2 in G:
        outs[v1].append(v2)
        ins[v2] += 1

    q = deque(v1 for v1 in range(N) if ins[v1] == 0)
    while q:
        v1 = q.popleft()
        yield v1
        for v2 in outs[v1]:
            ins[v2] -= 1
            if ins[v2] == 0:
                q.append(v2)


N, M = map(int, input().split())
G = [tuple(map(int1, input().split())) for _ in range(M)]
dp = [-1] * (N + 1)  # dp[N]は親がいないときの処理用

parents = [[N] for _ in range(N)]
for v1, v2 in G:
    parents[v2].append(v1)
for x in topological_sort(N, G):
    dp[x] = max(dp[p] for p in parents[x]) + 1
print(max(dp))


Measured memory_bytes: 56860
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int> p(a),q(b),r(c);
    for(int i=0;i<a;i++)cin>>p[i];
    for(int i=0;i<b;i++)cin>>q[i];
    for(int i=0;i<c;i++)cin>>r[i];
    sort(All(p),greater<int>());
    sort(All(q),greater<int>());
    priority_queue<int> Q,R;
    int res=0;
    for(int i=0;i<x;i++)Q.push(-p[i]);
    for(int i=0;i<y;i++)Q.push(-q[i]);
    for(auto it:r)R.push(it);
    while(true){
        int now=-Q.top();
        int x=R.top();
        if(x>now){
            R.pop();
            Q.pop();
            Q.push(-x);
            if(R.empty())break;
        }else{
            break;
        }
    }
    while(!Q.empty()){
        res-=Q.top();
        Q.pop();
    }
    cout<<res<<endl;
    
}

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

#define rep(i, u) for (int i = 0; i < u; i++)
double pi = 3.14159265359;

int main() {
  double r;
  cin >> r;
  cout << fixed << setprecision(6) << pi * r * r << ' ' << 2 * pi * r << endl;
  return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,k;
    cin>>a>>b>>k;
    if((a+b)<=k)
    {
        cout<<0<<' '<<0;
        return 0;
    }
    if(a>=k)
    {
        cout<<(a-k)<<' '<<b;
    }
    else
    {
        cout<<0<<' '<<a+b-k;
    }
    return 0;
}



Measured memory_bytes: 3616
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
//#define int long long
using namespace std;
char s[200000+5];
int len,n,cnt=1,r,w;
int main()
{
	cin>>n;
	cin>>s+1;
	len=strlen(s+1);
	int i=len;
	for(int i=2;i<=len;i++)
	{
		if(s[i]!=s[i-1])
		{
			cnt=0;break;
		}
	}
	if(cnt)
	{
		printf("0");return 0;
	}
	for(int i=1;i<=len;i++)
	{
		if(s[i]=='W')w++;
		else r++;
	}
	for(int i=1;i<=n;i++)
	{
		if(i<=r)
		{
			if(s[i]!='R')cnt++;
		}
		else
		{
			if(s[i]!='W')cnt++;
		}
	}
	printf("%d",cnt/2);
}

Measured memory_bytes: 3920
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

const int64_t M = 1'000'000'007;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);

    int n;
    cin >> n;
    int a[21];
    for(int i=0;i<n;i++){
        a[i] = 0;
        for(int j=0;j<n;j++){
            int x;
            cin >> x;
            a[i] |= x<<j;
        }
    }

    static uint32_t dp[1<<21][22];
    for(int j=0;j<=n;j++){
        for(uint ptn=0;ptn<(1<<n);ptn++){
            if(j == 0){
                dp[ptn][j] = 1;
                continue;
            }
            dp[ptn][j] = 0;
            uint mask = ptn & a[j-1];
            mask |= 1<<n;
            for(uint k=(mask & -mask);k<(1<<n);k=(mask & -mask)){
                dp[ptn][j] += dp[ptn & ~k][j-1];
                dp[ptn][j] %= M;
                mask &= ~k;
            }
        }
    }

    cout << dp[(1<<n)-1][n] << endl;
    
    return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  if (b % a == 0) cout << a + b << endl;
  else cout << b - a << endl;
}


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

int main() {

    int a, b, x, ans;
    
    while (cin >> a >> b) {
        x = a + b;
        ans = 0;
        
        while (x > 0) {
            ans++;
            x /= 10;
           
        }
         cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
      
        int result = b - a;
        if (b % a == 0) result = a + b;
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35712
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
using namespace std;

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

	while (n)
	{
		int t = n % 10;
		if (t == 7)
		{
			cout << "Yes";
			return 0;
		}
		n /= 10;
	}
	cout << "No";
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, m; ll k;
    cin >> n >> m >> k;
    ll a[n+1], b[m+1];
    a[0] = b[0] = 0;
    for (int i=0, ai; i<n; i++) {
        cin >> ai;
        a[i+1] = a[i] + ai;
    }
    for (int i=0, bi; i<m; i++) {
        cin >> bi;
        b[i+1] = b[i] + bi;
    }
    int ans = 0;
    for (int i=0; i<=n; i++) {
        ll left = k - a[i];
        if (left < 0) break;
        int j = partition_point(b, b+m+1, [&](ll x) {
            return x <= left;
        }) - b - 1;
        ans = max(ans, i + j);
    }
    cout << ans << '\n';
    return 0;
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int E, Y;
  cin >> E >> Y;
  if (E == 0) {
    if (Y <= 1911) cout << "M" << Y - 1868 + 1 << endl;
    else if (Y <= 1925) cout << "T" << Y - 1912 + 1 << endl;
    else if (Y <= 1988) cout << "S" << Y - 1926 + 1 << endl;
    else cout << "H" << Y - 1989 + 1 << endl;
  } else {
    vector<int> a = {1868, 1912, 1926, 1989};
    cout << Y - 1 + a[E - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			char ch; cin>>ch;
			cnt+=(ch=='#'?1:0);
		}
	cout<<((cnt+1==n+m)?"Possible\n":"Impossible\n");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                int n, i, p, x;
                cin>>n;
                vector<int> spf(N*10), g(N*10, 0), a(n);
                for(i=0; i<sz(spf); i++) spf[i] = i;
                for(i=2; i<=sqrt(1e6); i++){
                        if(spf[i] == i){
                                for(p = i*i; p<sz(spf); p=p+i){
                                        if(spf[p]==p) spf[p]=i;
                                }
                        }
                }
                for(i=0; i<n; i++){
                        cin>>a[i];
                        x = a[i]; 
                        set<ll> fact;
                        while(x>1){
                                if(fact.find(spf[x])==fact.end()){
                                        g[spf[x]]++; fact.ins(spf[x]);
                                }
                                x = x/spf[x];
                        }
                }
                bool ok = true;
                for(i=2; i<sz(g); i++){
                        if(g[i]>1) ok = false;
                }
                if(ok) cout<<"pairwise coprime";
                else{
                        int g = a[0];
                        for(i=1; i<n; i++) g = __gcd(g, a[i]);
                        if(g==1) cout<<"setwise coprime";
                        else cout<<"not coprime";
                }
        }
        return 0;
}

Measured memory_bytes: 15044
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Split(bufio.ScanLines)
	s := read()

	arr := strings.Split(s, "/")
	y, _ := strconv.Atoi(arr[0])
	m, _ := strconv.Atoi(arr[1])
	d, _ := strconv.Atoi(arr[2])
	t := time.Date(2019, 4, 30, 0, 0, 0, 0, time.Local)
	t1 := time.Date(y, time.Month(m), d, 0, 0, 0, 0, time.Local)
	b := t1.Sub(t)
	if b <= 0 {
		fmt.Println("Heisei")
		return
	}
	fmt.Println("TBD")
}

//便利関数群
var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, _ := strconv.Atoi(read())
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x, y int) int {
	if x-y > 0 {
		return x - y
	}
	return -(x - y)
}

type XY struct {
	x, y int
}

type Points []XY

func (p Points) Len() int {
	return len(p)
}
func (p Points) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}
func (p Points) Less(i, j int) bool {
	return p[i].x < p[j].x
}
func (p Points) remove(i int) Points {
	if i >= len(p) {
		return p
	}
	return append(p[:i], p[i+1:]...)
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {

    char x, y;
    cin >> x >> y;
    if(x > y){
        cout << '>' << endl;
    }else if(x < y){
        cout << '<' << endl;
    }else{
        cout << '=' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s="a";

void dfs(char a){
	char c;
	
    if(s.size()==n){
		cout<<s<<endl;
		return;
	}
	
    for(c='a';c<=char(a+1);c++){
        s+=c;
        dfs(max(c,a));
        s.erase(s.end()-1);
    }
}

int main(){
    cin>>n;
    dfs('a');
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define For(i, l, r) for(int i = (l); i <= (int)(r); ++i)
#define Fordown(i, r, l) for(int i = (r); i >= (int)(l); --i)
using namespace std;

inline int read(){
    int x = 0, fh = 1; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for(; isdigit(ch); ch = getchar()) x = (x<<1) + (x<<3) + (ch^'0');
    return x * fh;
}

const int N = 1000000, M = 2000000 << 1;
const long long inf = 1ll * 0x3f3f3f3f * 0x7f7f7f7f;
int n, m;

struct graph {
    int to[M], Head[N], Next[M], val[M], e;
    void init() {
        e = 0;
        Set(Head, 0);
    }
    void add_edge (int u, int v, int w) {
        to[++e] = v;
        val[e] = w;
        Next[e] = Head[u];
        Head[u] = e;
    }
};
graph G;
#define Travel(i, u, G) for(int i = G.Head[u]; i; i = G.Next[i])

bool inq[N];
int S, T;
void spfa(long long dis[]) {
    queue<int> Q;
	For (i, 1, n) dis[i] = inf;
    Q.push(S); dis[S] = 0;
    while (!Q.empty() ) {
        int now = Q.front(); Q.pop();
        inq[now] = false;
        Travel(i, now, G) {
            int v = G.to[i];
            if (dis[v] > dis[now] + G.val[i]) {
                dis[v] = dis[now] + G.val[i];
                if (!inq[v]) { inq[v] = true; Q.push(v); }
            } 
        }
    }
}

typedef long long ll;
ll dis1[N], dis2[N];

const int Mod = 1e9 + 7;
ll dp1[N], dp2[N], dp[N], dis[N];

ll Dp(int u) {
	if (dp[u]) return dp[u];
    Travel(i, u, G) {
        int v = G.to[i];
        if (dis[u] - G.val[i] == dis[v]) 
            dp[u] = (dp[u] + Dp(v) ) % Mod;
    }
    return dp[u];
}

int main (){
#ifdef zjp_shadow
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
    G.init();
    n = read(), m = read();
	S = read(), T = read();
    while (m--) {
        int u = read(), v = read(), w = read();
        G.add_edge(u, v, w);
        G.add_edge(v, u, w);
    }
    spfa(dis1); Cpy(dis, dis1); dp[S] = 1; Dp(T); Cpy(dp1, dp);

	Set(dp, 0); dp[T] = 1;

	swap(S, T);
	spfa(dis2); Cpy(dis, dis2); Dp(T); Cpy(dp2, dp);
	swap(S, T);

	long long max_dis = dis1[T];
	long long ans = (ll)dp1[T] * dp1[T] % Mod;

	For (i, 1, n) if (dis1[i] == dis2[i]) 
		(ans += Mod - dp1[i] * dp1[i] % Mod * dp2[i] % Mod * dp2[i] % Mod) %= Mod;
	
	For (i, 1, n)
		for (int j = G.Head[i]; j; j = G.Next[j]) {
			int u = i, v = G.to[j], w = G.val[j];
			if (dis1[u] + dis2[v] + w == max_dis && abs(dis1[u] - dis2[v]) < w)
				(ans += Mod - dp1[u] * dp1[u] % Mod * dp2[v] % Mod * dp2[v] % Mod) %= Mod;
		}
	cout << ans << endl;
}


Measured memory_bytes: 56308
def main():
    n = int(input())
    a = [None]*n
    for i in range(n):
        x, y = map(int, input().split())
        a[i] = [x, y]
    a.sort(key=lambda x: (x[0]+x[1]), reverse=True)
    score = 0
    for i in range(n):
        if i % 2 == 0:
            score += a[i][0]
        else:
            score -= a[i][1]
    print(score)

if __name__ == "__main__":
    main()

Measured memory_bytes: 24416
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        reader.useDelimiter("");
        int res = 0;
        for (int i = 0; i < 4; ++i) {
            switch (reader.next()) {
                case "+": {
                    res++;
                    break;
                }
                case "-": {
                    res--;
                    break;
                }
            }
        }
        System.out.println(res);
        reader.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int i,j=0,k=1,n,W[100],f=0,b=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>W[i];
	}
	for(i=0;i<n;i++)
	{
		if(f>b)
		{
			b+=W[n-k];
			k++;
		}
		else
		{
			f+=W[j];
			j++;
		}
	}
	if(f>b)
		cout<<f-b;
	else
		cout<<b-f;
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
c = [0,0]
for i in range(n):
    if (s[i]=="E"):
        c[0] += 1
    else:
        c[1] += 1
b = [0,0]
ans = c[0]
for i in range(n):
    if (s[i]=="E"):
        c[0] -= 1
        b[0] += 1
    else:
        c[1] -= 1
        b[1] += 1
    ans = min(ans,c[0]+b[1])
print(ans)

Measured memory_bytes: 9704
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define MOD 1000000007
using namespace std;
int main()
{
	vector<ll> dp;
	ll k=-130;
	while(k<130)
	{
	dp.pb(k*k*k*k*k);
	k++;
	}
	fast;
	ll t;
	cin>>t;
	bool flag=false;
	ll ans1=0;
	ll ans2=0;
	for (int i = 0; i <=dp.size(); ++i)
	{
		for(int l=0;l<=dp.size();l++)
		{
			//cout<<dp[i]<<"  "<<dp[l]<<endl;
			ll diff=dp[i]-dp[l];
			if(diff==t)
			{
				ans1=i-130;
				ans2=l-130;
				flag=true;
				break;
			}
		}	
			if(flag)
				break;		
	}
	// if(abs(ans1)<abs(ans2))
	// {
	// ans1=ans1*-1,ans2=ans2*-1;
	// swap(ans1,ans2);
	// }
	cout<<ans1<<" "<<ans2<<endl;
	
}



Measured memory_bytes: 3660
N, K = map(int, input().split())
a = list(map(int, input().split()))
chk = [0] * N
start = -1
ido = [0]
chk[0] = 1
index = 0
cnt = 0
while True:
    index = a[index] - 1
    if chk[index] == 0:
        chk[index] += 1
        cnt += 1
        ido.append(index)
    else:
        start = index
        break

if cnt >= K:
    print(ido[K] + 1)
    exit()
tmp = ido.index(start)
ido = ido[tmp:]
K -= tmp
print(ido[K % len(ido)] + 1)

Measured memory_bytes: 32380
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);

  map<char, int> mp;
  for (auto e : s) mp[e]++;

  puts(sz(mp) == 2 && mp[s[0]] == 2 ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n,x;
  int num=0;

  while(cin>>n>>x,(n||x)){
  int num=0;
    for(int i=1; i<(n-1); i++){
      for(int j=i+1; j<n; j++){
	for(int k=j+1; k<(n+1); k++){
	  if((i+j+k)==x){
	    num+=1;
	  }
	}
      }
    }
    cout <<num<<endl;

  }

  return 0;
}



Measured memory_bytes: 3092
#include <iostream>

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a-1); i >= (b); i--)

using namespace std;

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

    u int N;

    cin >> N;

    u int M[N] = { 0 };

    REP(i, 1, N)
    {
        u int x;
        cin >> x;

        if (x > 0)
            M[x - 1]++;
    }

    REP(i, 0, N)
        cout << M[i] << "\n";
}

Measured memory_bytes: 4428
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        v: [chars; h]
    }
    let v: Vec<Vec<char>> = v.iter().cloned().filter(|s| s.iter().any(|&x| x == '#')).collect();
    let mut ans = vec![vec![]; v.len()];
    for j in 0..w {
        let mut f = false;
        for i in 0..v.len() {
            if v[i][j] == '#' {
                f = true;
                break;
            }
        }
        if !f {
            continue;
        }
        for i in 0..v.len() {
            ans[i].push(v[i][j]);
        }
    }
    for s in &ans {
        println!("{}", s.iter().cloned().collect::<String>());
    }
}


Measured memory_bytes: 4352