akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		isRange(a,b,c);
	}

	static public void isRange(int a,int b,int c){
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26044
#include<stdio.h>
#include<string.h>
int main(void)
{
    char s[200001];
    char t[200001];
    int i,cnt,len1,len2;
    cnt = 0;
	if(scanf("%s %s", s, t) < 2) {
      return 0;
    }
 	len1 = strlen(s);
 	len2 = strlen(t);
    if(len1 != len2){
        return 0;
    }
    for(i=0; i < len1; i++){
		if(!(s[i]>= 'a') && (s[i]<='z')){
          return 0;
        }
		if(!(t[i]>= 'a') && (t[i]<='z')){
          return 0;
        }
        if(s[i] != t[i]){
            cnt = cnt+1;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define NN 110
#define KK 100100
#define QQ 1000000007
ll n,k,a[NN],dp[NN][KK],sum[NN][KK];
ll i,j;
int main()
{
	scanf("%lld %lld",&n,&k);
	for(i=1;i<=n;++i)
	  scanf("%lld",&a[i]);
	for(i=1;i<=n;++i)
	    dp[i][0]=1;
	for(i=0;i<=k;++i)
	    sum[0][i]=1; 
		sum[1][0]=1;	 
	for(i=1;i<=n;++i)
	{
	  for(j=1;j<=k;++j)
	    {
	    	dp[i][j]=sum[0][j]%QQ;
	    	if(j>a[i]) dp[i][j]=(dp[i][j]-sum[0][j-a[i]-1]+QQ)%QQ;
	    	sum[1][j]=(sum[1][j-1]+dp[i][j])%QQ;
		}
	  for(j=0;j<=k;++j)
	    sum[0][j]=sum[1][j];	
	} printf("%lld\n",dp[n][k]);
	return 0;
}

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

int main() {
  int n, l; cin >> n >> l;
  string s[n];
  for (int i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  for (int i = 0; i < n; ++i) cout << s[i];
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A, B = [], []
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
l = []
for i in range(N):
  l.append(A[i]+B[i])
l.sort(reverse=True)

ans = 0
for i in range(N//2):
  ans += l[2*i]
if N % 2 == 1:
  ans += l[-1]
ans -= sum(B)
print(ans)

Measured memory_bytes: 21308
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		String[] s = new String[n];
		for (i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		sc.close();
		HashMap<String, Integer> map = new HashMap<>();
		for (i = 0; i < n; i++) {
			if(map.get(s[i])==null) {
				map.put(s[i], 1);
			} else {
				map.put(s[i], map.get(s[i])+1);
			}
		}
		ArrayList<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(map.entrySet());
		list.sort((e1,e2)->e1.getValue()==e2.getValue()?e1.getKey().compareTo(e2.getKey()):e2.getValue()-e1.getValue());
		int mx = list.get(0).getValue();
		for (Entry<String, Integer> entry : list) {
			if(entry.getValue() != mx) break;
			out.println(entry.getKey());
		}
	}
}


Measured memory_bytes: 91172
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 2e4+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int c[N],a[400][N],n,ans,t,day[N];
signed main()
{
	Very_fast;
	cin>>n;
	for(int i=0;i<26;i++)cin>>c[i];
	rep(i,n)
	rep(j,26)cin>>a[i][j];
	rep(i,n)
	{
		int mx=-1,num;
		rep(j,26)if((i-day[j]+1)*c[j]>mx)mx=(i-day[j]+1)*c[j],num=j+1;
		cout<<num<<"\n";
	}
	return 0;
}

Measured memory_bytes: 5148
#include<stdio.h>

int main(void){
	int a,b,c,k,ans;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	if(k<=a){
		ans=k;
	}else if(a+b>=k){
		ans=a;
	}else{
		ans=a-(k-a-b);
	}
	printf("%d\n",ans);
	return 0;
}
	


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <math.h>
#include <string>
typedef long long int ll;
#define pb(b) push_back(b)
#define mp(a,b) make_pair(a,b)
#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d",n)
#define pfs(s) printf("%s",s)
 
int main()
{
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ll n,q,l,r,t,sum = 0,k,last = 0;
    std::vector<ll> a,b,d;
    string s;
	int degree[26] = {0};
 
   cin>>s;
  if(s[1] == 'R')
    cout<<"ABC\n";
  else
    cout<<"ARC\n";
    return 0;
}


Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????


		Scanner scan = new Scanner(System.in);
		ArrayList<Integer[]> list = new ArrayList<Integer[]>();

		Integer[] ary;

		while(scan.hasNext()){

			ary = new Integer[2];
			//???H
			ary[0] = scan.nextInt();
			//?¨?W
			ary[1] = scan.nextInt();

			if(ary[0] != 0 && ary[1] != 0){

				list.add(ary);
			}else{
				scan.close();
				break;
			}

		}

		for(int i = 0; i < list.size(); i++){

			ary = list.get(i);
			//???
			for(int j = 0; j < ary[0]; j++){

				if(j == 0 || j == ary[0] - 1){

					//?¨????????????¨???????????°?????????
					for(int k = 0; k < ary[1]; k++){
						System.out.print("#");
					}
					System.out.println("");
				}else{

					System.out.print("#");
					for(int l = 0; l < ary[1] - 2; l++){
						System.out.print(".");

					}
					System.out.print("#");
					System.out.println("");
				}

			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 25720
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
int main(){
    int n;
    cin >> n;
    vector<int> a(n,0);
    rep(i,n){
        std::cin >> a[i];
        a[i]--;
    }
 
    int ans = 0;
    for(int i=0; i<n; i++){
        if(i==a[a[i]]) ans++;
    }
    cout << ans/2 << "\n";
    return 0;
}


Measured memory_bytes: 3780
#include<stdio.h>

int main() 
{
	long long x, y;
	int kotae;
	kotae = 0;
	bool flag=true;
	scanf("%lld%lld", &x, &y);
	while (flag) {
		kotae++;
		x = x*2;
		flag = (x <= y);
	}
	printf("%d", kotae);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const long long mod=1000000007;

long long pw[1000];
long long sum[300];
long long fact[300];

void init(){
	pw[0]=1;
	for(int i=1;i<1000;i++) pw[i]=(pw[i-1]*10)%mod;
	fact[0]=1;
	for(int i=1;i<300;i++) fact[i]=(fact[i-1]*i)%mod;
	for(int i=0;i<300;i++){
		if(i==0){
			sum[i]=1;
			continue;
		}
		long long tmp=1;
		sum[i]=1;
		for(int j=i;j>=0;j--){
			tmp=(tmp*j)%mod;
			sum[i]=(sum[i]+tmp)%mod;
		}
	}
}

int getDig(int n){
	if(n==0) return 1;
	int c=0;
	while(n>0){
		n/=10;
		c++;
	}
	return c;
}

vector<int> digs;
long long dp[2][201][801];

long long dp2[5][201][801];
bool checked[5];

long long solve(vector<int> vec){
	long long res=0;
	for(int i=0;i<5;i++) checked[i]=false;
	int N=vec.size();
	for(int i=0;i<N;i++){
		int k=getDig(vec[i]);
		int t=0;
		if(checked[k]) goto end_dp;
		checked[k]=true;
		digs.clear();
		for(int j=0;j<N;j++){
			if(i==j) continue;
			digs.push_back(getDig(vec[j]));
		}
		for(int a=0;a<=200;a++) for(int b=0;b<=800;b++) dp[0][a][b]=0;
		dp[0][0][0]=1;
		t=0;
		for(int j=0;j<N-1;j++){
			for(int a=0;a<=200;a++) for(int b=0;b<=800;b++) dp[1-t][a][b]=0;
			for(int a=0;a<=200;a++) for(int b=0;b<=800;b++){
				dp[1-t][a][b]+=dp[t][a][b];
				if(a+1<=200&&b+digs[j]<=800){
					dp[1-t][a+1][b+digs[j]]+=dp[t][a][b];
				}
			}
			for(int a=0;a<=200;a++) for(int b=0;b<=800;b++){
				dp[1-t][a][b]%=mod;
			}
			t=1-t;
		}
		for(int a=0;a<=200;a++) for(int b=0;b<=800;b++) dp2[k][a][b]=dp[t][a][b];
		end_dp:;
		for(int a=0;a<=200;a++) for(int b=0;b<=800;b++){
			int c=N-1-a;
			long long coe1=sum[c];
			long long coe2=pw[b];
			//long long coe3=dp[t][a][b];
			long long coe3=dp2[k][a][b];
			long long tmp=(coe1*coe2)%mod;
			tmp*=coe3;
			tmp%=mod;
			tmp*=fact[a];
			tmp%=mod;
			tmp*=vec[i];
			tmp%=mod;
			res=(res+tmp)%mod;
		}
	}
	return res;
}

int a[200];

int main(){
	init();
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d",a+i);
	if(N==1){
		printf("%d\n",a[0]);
		return 0;
	}
	long long ans=0;
	vector<int> tmp1,tmp2;
	for(int i=0;i<N;i++){
		tmp1.push_back(a[i]);
		if(a[i]!=0) tmp2.push_back(a[i]);
	}
	ans=solve(tmp1);
	if(tmp1.size()!=tmp2.size()) ans-=solve(tmp2);
	ans%=mod;
	ans+=mod;
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8628
n = gets.chomp.to_i
line = gets.chomp.split.map(&:to_i)
ary = Array.new(n,0)

n.times do |i|
	tmp = line[i]
	cnt = 0
	while tmp % 2 == 0
		cnt += 1
		tmp /= 2
	end
	ary[i] = cnt
end

p ary.inject(:+)

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

int main(){
	int H, W; cin >> H >> W;
	string S[H];
	for(int i=0; i<H; i++) cin >> S[i];
	int inf[H][W][4];
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(i == 0){
				if(S[i][j] == '#') inf[i][j][0] = 0;
				else inf[i][j][0] = 1;
			}else{
				if(S[i][j] == '#') inf[i][j][0] = 0;
				else inf[i][j][0] = 1 + inf[i-1][j][0];
			}
		}
	}
 
	for(int i=0; i<W; i++){
		for(int j=0; j<H; j++){
			if(i == 0){
				if(S[j][i] == '#') inf[j][i][2] = 0;
				else inf[j][i][2] = 1;
			}else{
				if(S[j][i] == '#') inf[j][i][2] = 0;
				else inf[j][i][2] = 1 + inf[j][i-1][2];
			}
		}
	}
	for(int i=H-1; i>=0; i--){
		for(int j=0; j<W; j++){
			if(i == H-1){
				if(S[i][j] == '#') inf[i][j][1] = 0;
				else inf[i][j][1] = 1;
			}else{
				if(S[i][j] == '#') inf[i][j][1] = 0;
				else inf[i][j][1] = 1 + inf[i+1][j][1];
			}
		}
	}
	for(int i=W-1; i>=0; i--){
		for(int j=0; j<H; j++){
			if(i == W-1){
				if(S[j][i] == '#') inf[j][i][3] = 0;
				else inf[j][i][3] = 1;
			}else{
				if(S[j][i] == '#') inf[j][i][3] = 0;
				else inf[j][i][3] = 1 + inf[j][i+1][3];
			}
		}
	}
	int ans = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == '.'){
				if(ans < inf[i][j][0] + inf[i][j][1] + inf[i][j][2] + inf[i][j][3] - 3){
					ans = inf[i][j][0] + inf[i][j][1] + inf[i][j][2] + inf[i][j][3] - 3;
				}
			}
		}
	}
  cout << ans << endl;
	return 0;
}


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



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


    int n;
    cin>>n;
    int a[n];
    int m = 1e9;
    int M = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        m = min(m,a[i]);
        M = max(M,a[i]);
    }
    int c[n] = {};
    if(M-m>1){
        cout<<"No"<<endl;
        return 0;
    }
    if(m==M){
        if(a[0] == n-1){
            cout<<"Yes"<<endl;
            return 0;
        }
        else{
            n/=2;
            if(n >= a[0]){
                cout<<"Yes"<<endl;
                return 0;
            }
            cout<<"No"<<endl;
            return 0;
        }
    }
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(a[i] == m ) cnt++;
    }

    n -= cnt;
    if(n==1 || M<=cnt || cnt+n/2 < M){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;

    
    




    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll mod =1e9+7;
 
int main(){
    string s;cin>>s;
    if(s.at(s.length()-1)=='s'){
        cout <<s+"es";
    }
    else cout <<s+"s";
}

Measured memory_bytes: 3624
def main():
    while True:
        N, T, L, B = map(int, input().split())
        if N == T == L == B == 0:
            break
        Lose = []
        for i in range(L):
            Lose.append(int(input()))
        isLose = {i:False for i in range(N)}
        for i in Lose:
            isLose[i] = True
        Back = []
        for i in range(B):
            Back.append(int(input()))
        #print(N, T, L, B, end=':\t')

        Board = [0.0 for x in range(N+1)]
        Board[0] = 1.0

        Lose_Board = [0.0 for x in range(N+1)]
        for turn_i in range(T):
            new_Board = [0.0 for x in range(N+1)]
            for board_i in range(N):
                if isLose[board_i]:
                    Board[board_i], Lose_Board[board_i] = Lose_Board[board_i], Board[board_i]
                if Board[board_i] == 0.0:
                    continue
                for i in range(1, 7):
                    new_board_i = board_i + i
                    if new_board_i > N:
                        new_board_i = N - abs(new_board_i - N)
                    new_Board[new_board_i] += Board[board_i] * (1/6)
            for i in Back:
                new_Board[0] += new_Board[i]
                new_Board[i] = 0.0
            new_Board[-1] += Board[-1]
            Board = new_Board
        print(f'{Board[N]:.6f}')


main()


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

using namespace std;

int main()
{
    int n, a, v;
    
    cin >> n;
    
    vector<int> c(n, 0);
    
    for(int i = 0; i < n; i++)
    {
        cin >> a >> v;
        
        c[a - 1] += v;
    }
    
    int ptr = -1, cnt = -1;
    
    for(int i = 0; i < n; i++)
    {
        if(cnt < c[i])
        {
            ptr = i;
            cnt = c[i];
        }
    }
    
    cout << ptr + 1 << ' ' << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>

using namespace std;

int main(){
  string S;

  cin >> S;

  int len = S.length();


  int ct = len/2;
  int sp = 0;
  int ep = len-1;

  int i =0;
  while(ct > 0 ){
    if( S[sp] != S[ep] ){
      S[sp] = S[ep];
      i++;
    }
    sp++;
    ep--;
    ct--;
  }

  cout << i << endl;
}


Measured memory_bytes: 256
a,b,m = [int(x) for x in input().split()]
lia = [int(x) for x in input().split()]
lib = [int(x) for x in input().split()]
wari = list()
for _ in range(m):
    wari.append([int(x) for x in input().split()])
ans = 10**20
for i in wari:
    s = lia[i[0]-1]+lib[i[1]-1]-i[2]
    ans = min(ans,s)
x = min(lia)+min(lib)
ans = min(ans,x)
print(ans)

Measured memory_bytes: 32496
#include<stdio.h>
int main()
{
    long long int a,b,c,d,p,q,l,m,t,gcd,lcm;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    l=c;
    m=d;
   while(m!=0)
   {
       t=m;
       m=l%m;
       l=t;
   }
   gcd=l;
   lcm=(c*d)/gcd;
   p=(b/c)+(b/d)-(b/lcm)-((a-1)/c)-((a-1)/d)+((a-1)/lcm);
   q=b-a+1-p;
   printf("%lld",q);
    return 0;
}


Measured memory_bytes: 128
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

MOD = 1000000007

N,K = [int(s) for s in input().split(' ') if s]

for i in range(K):
    red_in_blue = cmb(N-K+1,i+1) % MOD
    blue_pattern = cmb(K-1, i) % MOD
    ret = (red_in_blue*blue_pattern) % MOD
    print(ret)

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define INF (ll) 1e18
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


int main(){
    IOS;
    make2(ll,n,k);
    makevec(ll,vec,n);
    vector <ll> dp(n,INF);
    dp[0]=0;
    for(ll i=1;i<n;i++){
        for(ll j=i-1;j>=max((ll)0,i-k);j--){
            dp[i]=min(dp[i],dp[j]+abs(vec[i]-vec[j]));
        }
    }
    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define N 100
#define white 0
#define gray 1
#define black 2
int n, qpt1 = 0, qpt2 = 0;
int A[N][N], color[N], d[N], Q[N];

void enq(int u) {
  Q[++qpt1] = u;
}

int deq(void) {
  int u = Q[++qpt2];
  return u;
}

void bfs(void) {
  int s = 0;
  int u;
  for ( int i = 0; i < n; ++i ) {
    color[i] = white;
    d[i] = -1;
  }
  color[s] = gray;
  d[s] = 0;
  enq(s);

  while ( qpt1 != qpt2 ) {
    u = deq();
    for ( int v = 0; v < n; ++v) {
      if ( A[u][v] && color[v] == white) {
        color[v] = gray;
        d[v] = d[u] + 1;
        enq(v);
      }
    }
    color[u] = black;
  }
}

void print(void) {
  for ( int i = 0; i < n; ++i ) {
    printf("%d %d", i + 1, d[i]);
    putchar('\n');
  }
}

int main(void) {
  int u, k, v;
  scanf("%d", &n);
  for ( int i = 0; i < n; ++i ) {
    scanf("%d%d", &u, &k);
    u--; //0-origin
    for ( int j = 0; j < k; ++j ) {
      scanf("%d", &v);
      v--; //0-origin
      A[u][v] = 1;
    }
  }
  bfs();
  print();
}



Measured memory_bytes: 1988
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int bob = 0,alice = 0;
    int sum = 0;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    
    sort(a,a+n,greater<int>());
    for(int i = 0; i < n; i++) {
        if(i % 2 == 0) alice += a[i]; 
    }
    bob = sum - alice;

    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int):
    if len(A) > len(B):
        ret = 'GREATER'
    elif len(A) < len(B):
        ret = 'LESS'
    else:
        ret = 'EQUAL'
        for i in range(len(A)):
            if A[i] > B[i]:
                ret = 'GREATER'
                break
            elif A[i] < B[i]:
                ret = 'LESS'
                break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = str(next(tokens))  # type: int
    B = str(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define in long long
signed main(){
  int n,k,ans=0;
  int p[10000];
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p,p+n);  
  for(int i=0;i<k;i++){
    ans+=p[i];
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 3608
fun main(args: Array<String>) {
    abc055c()
}

fun abc055c() {
    val (n, m) = readLine()!!.split(" ").map { it.toLong() }

    val scc = Math.min(n, m / 2)
    val cccc = (m - scc * 2) / 4

    val answer = scc + cccc

    println(answer)
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; string s; cin >> n >> s;
	int x = 0,m=0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')x++;
		else x--;
		m = max(m, x);
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<climits>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}
inline ll qpow(ll a,ll b)
{
	ll r=1,t=a; 
	while(b)
	{
		if(b&1)
			r=(r*t)%mod;
		b>>=1;
		t=(t*t)%mod;
	}
	return r;
}
inline ll inv1(ll b)
{
	return qpow(b,mod-2);
}
inline ll exgcd(ll a,ll b,ll &x,ll &y)
{
	if(!b)
	{
		x=1;
		y=0;
		return a;
	}
	ll r=exgcd(b,a%b,y,x);
	y-=(a/b)*x;
	return r;
}
inline ll read()
{
	ll x=0,f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())
	if(c=='-')
		f=-1;
	for(;isdigit(c);c=getchar())
		x=x*10+c-'0';
	return x*f;
}
 
long long n, x,ans;
ll gcdgcd(ll x,ll n)
{
    if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+gcdgcd(n%x, x);
    return ans;
}
 
int main()
{
    cin>>n>>x;
    cout<<gcdgcd(x, n-x)+n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <vector>
using namespace std;

vector<int>& operator-=(vector<int>& l, const vector<int>& r) {
	for(int i = l.size() - 1; i >= 0; --i) {
		l[i] -= r[i];
		if(l[i] < 0) {
			l[i - 1] -= 1;
			l[i] += 10;
		}
	}

	return l;
}

int eval(const vector<int>& v) {
	int res = 0;
	for(int i = 0; i < (int)v.size(); ++i)
		res = res * 10 + v[i];

	return res;
}

int main() {
	for(int a, l; scanf("%d %d", &a, &l), a | l;) {
		vector<int> number(l);
		for(int i = l - 1; i >= 0; --i) {
			number[i] = a % 10;
			a /= 10;
		}

		vector<vector<int> > array;
		array.push_back(number);
		vector<vector<int> >::iterator it;
		for(int i = 1;; ++i) {
			sort(number.begin(), number.end(), greater<int>());
			vector<int> mn(number);
			reverse(mn.begin(), mn.end());
			number -= mn;
			if((it = find(array.begin(), array.end(), number)) != array.end()) {
				const int idx = it - array.begin();
				printf("%d %d %d\n", idx, eval(number), i - idx);
				break;
			}
			array.push_back(number);
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1072
n = int(input())
hs = list(map(int, input().split()))

candidate = []
current = 0
for i in range(n - 1):
    if hs[i] >= hs[i + 1]:
        current += 1
    else:
        candidate.append(current)
        current = 0

candidate.append(current)

print(max(candidate))

Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    ans=K
    for i in range(N-1):
        ans*=K-1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
<?php
fscanf(STDIN, "%d %d %d %d",$n,$a,$b,$c);
//得たい竹リスト
$abc=[$a,$b,$c];

//持っている竹リスト
for ($i=0;$i<$n;$i++){
	fscanf(STDIN, "%d",$L);
	$l[]=$L;
}
//最小コスト初期値
$minCost = INF;
//a、b、c、未使用の4パターンの全探索
for ($i=0;$i<pow(4, $n);$i++){
	$arrayA = array();
	$arrayB = array();
	$arrayC = array();
	$arrayD = array();
	//n個の手持ちの竹を得たいどの竹で使用するか
	for ($j=0;$j<$n;$j++){
		//aの竹
		if ((($i>>($j*2))&3)==3){
			$arrayA[]=$l[$j];
		//bの竹	
		}else if ((($i>>($j*2))&3)==2){
			$arrayB[]=$l[$j];
		//cの竹	
		}else if ((($i>>($j*2))&3)==1){
			$arrayC[]=$l[$j];
		//未使用
		}else {
			//未使用なので何もしない
		}
	}
	//a、b、cの竹を作っているか
	if (count($arrayA)==0 || count($arrayB)==0 || count($arrayC)==0) {
		continue;
	} else {
		//コスト計算
		$cost = abs((array_sum($arrayA)-$a)) + ((count($arrayA)-1)*10) + abs((array_sum($arrayB)-$b)) + ((count($arrayB)-1)*10) + abs((array_sum($arrayC)-$c)) + ((count($arrayC)-1)*10);
		//最小コスト
		if ($cost < $minCost) {
			$minCost = $cost;
		}
	}
}
echo $minCost;

Measured memory_bytes: 3828
#include <stdio.h>

int main(){
  int S;
  scanf("%d" , &S);

  int h =S/3600;

  int m =S/60%60 ;

  int s =S%60 ;
  
  //  printf("%d\n", h:m:s);

  printf("%d:%d:%d\n", h,m,s);
  return 0;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<tuple<int, int, int, int>> abcd(Q);
  for (int i=0; i<Q; i++) cin >> get<0>(abcd[i]) >> get<1>(abcd[i]) >> get<2>(abcd[i]) >> get<3>(abcd[i]);
  vector<int> ans;
  for (int A1=1; A1<=M; A1++) {
    for (int A2=A1; A2<=M; A2++) {
      for (int A3=A2; A3<=M; A3++) {
        for (int A4=A3; A4<=M; A4++) {
          for (int A5=A4; A5<=M; A5++) {
            for (int A6=A5; A6<=M; A6++) {
              for (int A7=A6; A7<=M; A7++) {
                for (int A8=A7; A8<=M; A8++) {
                  for (int A9=A8; A9<=M; A9++) {
                    for (int A10=A9; A10<=M; A10++) {
                      vector<int> A = {A1, A2, A3, A4, A5, A6, A7, A8, A9, A10};
                      int num = 0;
                      for (int i=0; i<Q; i++) {
                        if (A[get<1>(abcd[i])-1]-A[get<0>(abcd[i])-1]==get<2>(abcd[i])) num += get<3>(abcd[i]);
                        ans.push_back(num);
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans[0] << endl;
}

Measured memory_bytes: 36088
#include<cstdio>
#include<cmath>
const int N=1002;
bool f[N];
int i,j,k,n;
double t,x[N],y[N],r[N],d[N],a[N][N];
int main()
{
	scanf("%lf%lf%lf%lf%d",x,y,x+1,y+1,&n);
	for(i=2;i<n+2;++i)scanf("%lf%lf%lf",x+i,y+i,r+i);
	for(i=1;i<n+2;++i)for(j=0;j<i;a[j][i]=a[i][j],++j)
		if((a[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j])<0)a[i][j]=0;
	for(i=0;i<n+2;++i)d[i]=a[0][i];
	for(f[i=0]=1;i<n;++i)
	{
		for(t=2e9,j=1;j<n+2;++j)
			if(!f[j]&&d[j]<t)k=j,t=d[j];
		for(f[k]=j=1;j<n+2;++j)
			if(d[k]+a[k][j]<d[j])d[j]=d[k]+a[k][j];
	}
	printf("%.9f",d[1]);
}

Measured memory_bytes: 8064
from __future__ import division
from collections import defaultdict
from heapq import heappush, heappop
from sys import stdin

class UnionFindSet:
	def __init__(self, nodes):
		self.fa = {}
		for n in nodes:
			self.fa[n] = n

	def find(self, x):
		if self.fa[x] == x:
			return x
		else:
			self.fa[x] = self.find(self.fa[x])
			return self.fa[x]

	def union(self, x, y):
		fx = self.find(x)
		fy = self.find(y)
		if fx == fy:
			return fx
		else:
			self.fa[fx] = fy
			return fy


"""
graph is a hash
graph["nodes"] is a list of all nodes in the graph
graph["edges"] is a list of all edges in the graph in (x, y, w) form
  - x is the first nodes
  - y is the second nodes
  - w is the weight of the edges
graph["relation"] is the graph relation of the graph
"""

def kruscal(graph):
	"kruscal minimum spanning tree algorithm"
	ufset = UnionFindSet(graph["nodes"])

	ret = 0

	for (x, y, w) in sorted(graph["edges"], key = lambda x: x[-1]):
		fx = ufset.find(x)
		fy = ufset.find(y)
		if fx != fy:
			ret += w
			ufset.union(fx, fy)
		else:
			pass
	return ret


def dijkstra(graph, root):
	dis, vis = {}, {}
	for n in graph["nodes"]:
		dis[n] = 10 ** 9
		vis[n] = False

	heap = []
	dis[root] = 0
	heappush(heap, (0, root))

	while heap:
		_, n = heappop(heap)
		vis[n] = True
		for (y, w) in graph["adj"][n]:
			if not vis[y] and dis[n] + w < dis[y]:
				dis[y] = dis[n] + w
				heappush(heap, (dis[y], y))

	return dis

if __name__ == '__main__':
	V, E, root = map(int, stdin.readline().strip().split())
	graph = {}
	graph["nodes"] = [i for i in range(V)]
	graph["edges"] = []
	graph["adj"] = defaultdict(list)
	for _ in range(E):
		x, y, w = map(int, stdin.readline().strip().split())
		graph["edges"].append((x, y, w))
		graph["adj"][x].append((y, w))

	dis = dijkstra(graph, root)

	for n in graph["nodes"]:
		print dis[n] if dis[n] < 10 ** 9 else "INF"

Measured memory_bytes: 173656
# -*- coding: utf-8 -*-
import sys
from itertools import product
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    K=int(input())
    X,Y=map(int,input().split())
    
    def is_on_square(x0,y0,x1,y1):
        return (abs(x1-x0)==K and y0-K<=y1<=y0+K) or (abs(y1-y0)==K and x0-K<=x1<=x0+K)
    
    rX=X-Y
    rY=X+Y
    x,y=0,0
    ans=[]
    while True:
        # 残り一打
        if max(abs(x-rX),abs(y-rY))==K:
            ans.append((rX,rY))
            break
        # 残り二打以内の可能性あり
        elif abs(x-rX)<=K*2 and abs(y-rY)<=K*2:
            for nx,ny in list(product((x+K,x-K),(rY+K,rY-K)))+list(product((rX+K,rX-K),(y+K,y-K))):
                if is_on_square(x,y,nx,ny) and is_on_square(rX,rY,nx,ny) and (nx+ny)%2==0:
                    x,y=nx,ny
                    break
            else:
                # Kが奇数なら一打後残り二打になる
                if K%2:
                    if x<rX:
                        x+=K
                    else:
                        x-=K
                    if y<rY:
                        y+=K
                    else:
                        y-=K
                else:
                    ans=[]
                    break
        
        else:
            # x==rX or y==rYに寄せる
            if abs(x-rX)<abs(y-rY):
                if abs(x-rX)>=K:
                    if x>rX:
                        x-=K
                    else:
                        x+=K
                    if y>rY:
                        y-=K
                    else:
                        y+=K
                else:
                    x=rX
                    if y>rY:
                        y-=K
                    else:
                        y+=K
                    if (x+y)%2:
                        x+=1
            else:
                if abs(y-rY)>=K:
                    if x>rX:
                        x-=K
                    else:
                        x+=K
                    if y>rY:
                        y-=K
                    else:
                        y+=K
                else:
                    y=rY
                    if x>rX:
                        x-=K
                    else:
                        x+=K
                    if (x+y)%2:
                        y+=1
        ans.append((x,y))
    
    if not ans:
        print(-1)
    else:
        print(len(ans))
        for x,y in ans:
            print((y+x)//2,(y-x)//2)
                
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 58828
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,vector<int> >P;
int main(){
  int n,m,ans=0;
  cin>>n>>m;
  int a,b;
  vector<int>mp[n+1],gg;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    mp[a].push_back(b);
    mp[b].push_back(a);
  }
  priority_queue<P,vector<P>,greater<P> >pq;
  gg.push_back(1);
  pq.push(P(1,gg));
  while(!pq.empty()){
    P now=pq.top();
    pq.pop();
    int cos=now.first;
    vector<int>sum=now.second;
    if(sum.size()==n){
      ans++;
    }else{
      for(int i=0;i<mp[cos].size();i++){
	int aaa=0;
	for(int j=0;j<sum.size();j++){
	  if(mp[cos][i]==sum[j]){
	    aaa=1;
	    break;
	  }
	}
	if(aaa==0){
	  vector<int>ex=sum;
	  ex.push_back(mp[cos][i]);
	  pq.push(P(mp[cos][i],ex));
	}
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 384
using System;
using System.Linq;

class AtCoder {
  static void Main() {
    //var inputs = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToList();
    var N = int.Parse(Console.ReadLine().Trim());
    var S = Console.ReadLine().Trim();    
    var answer = 0;
    
    while(true) {
      var i = S.IndexOf("ABC");
      if(i == -1) break;
      S = S.Remove(i, 3);
      answer++;
    }    
    Console.WriteLine(answer);
  }
}

Measured memory_bytes: 13404
#include <iostream>
#include <array>
#include <limits>

using namespace std;

int main() {
    int len;
    cin >> len;
    array<int, 200000> nums;

    for (int i = 0; i < len; i++) cin >> nums[i];
    
    int mi = nums[0];
    int diffMax = numeric_limits<int>::min();
    for (int i = 1; i < len; i++) {
        diffMax = max<int>(diffMax, nums[i] - mi);
        mi = min<int>(mi, nums[i]);        
    }
    
    cout << diffMax << endl;

    return 0;
}

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
int x[510];
int a[510 * 510];
int fl[510 * 510];
int nd[510];
set<pair<int, int>> ss;
multiset<int> sfr;

void ex() {
	cout << "No\n";
	exit(0);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", x + i);
		--x[i];
		fl[x[i]] = 1;
		a[x[i]] = i;
	}
	for (int i = 0; i < n; ++i)
		nd[i] = n - i - 1;
	for (int i = 0; i < n; ++i)
		ss.insert(make_pair(-x[i], i));
	for (int i = n * n - 1; i >= 0; --i) {
		if (fl[i]) {
			int x = a[i];
			if (nd[x])
				ex();
			for (int j = 0; j < x; ++j)
				sfr.insert(x);
		}
		else {
			while (!ss.empty()) {
				int x = ss.begin()->second;
				if (!nd[x]) {
					ss.erase(ss.begin());
					continue;
				}
				else {
					--nd[x];
					a[i] = x;
					break;
				}
			}
			if (ss.empty()) {
				if (sfr.empty())
					ex();
				a[i] = *sfr.begin();
				sfr.erase(sfr.begin());
			}
		}
	}
	printf("Yes\n");
	for (int i = 0; i < n * n; ++i)
		printf("%d ", a[i] + 1);
	printf("\n");
	return 0;
}




Measured memory_bytes: 8448
#include <iostream>
#include <string>


using namespace std;

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

		cin >> a;
	
		for (int i = 0; i < n; i++) {
			
			if (i == k - 1) {
				if (a[k - 1] == 'A') {
					cout << "a";
				}
				else if (a[k - 1] == 'B') {
					cout << "b";
				}
				else  {
					cout << "c";
				}
			}
			else {
				cout << a[i];
			}
		}
	return 0;


}

Measured memory_bytes: 384
MAX_VAL = 99999999999
while 1:
    n,m = list(map(int,input().split()))
    if n == 0:break
    costs = {x:[] for x in range(1,n+1)}
    min_cost = [[MAX_VAL for x in range(2)] for y in range(n+1)]
    for i in range(m):
        a,b,c = list(map(int,input().split()))
        costs[a].append((b,c))
        costs[b].append((a,c))

    spam = [(0,1,2)] #(cost,num,free tickets count)
    while len(spam) > 0:
        mc = min(spam)
        spam.remove(mc)

        tic_i = 0 if mc[2] == 2 else 1

        if mc[2] != 1 and min_cost[mc[1]][tic_i] != MAX_VAL:
            continue

        if mc[2] != 1:
            min_cost[mc[1]][tic_i] = mc[0]

        #移動できる場所の登録
        for cv in costs[mc[1]]:
            #チケット不使用
            if mc[2] != 1:
                spam.append((mc[0] + cv[1],cv[0],mc[2]))
            #チケット使用
            if mc[2] > 0:
                spam.append((mc[0],cv[0],mc[2]-1))

    #print(min_cost[n])
    print(min(min_cost[n]))

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, T;
    cin >> N >> T;
    vector<int>Times(N);
    for (int i=0; i<N; i++){
        cin >> Times[i];
    }
    int ans = T;

    for (int i=1; i<N; i++){
        int dt = Times[i] - Times[i-1];
        if (dt < T)ans += dt;
        else ans += T;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    ll count=0;
    cin>>n;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll p=0;
            while(n%i==0)
            {
                n/=i;
                p++;
            }
            
            for(j=1;j<=1000000;j++)
            {
                if((j*(j+1))/2>p)
                {
                    break;
                }
            }
            count+=j-1;
        }
    }
    if(n!=1)
    {
        count++;
    }
    cout<<count;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3616
import sys
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for n in range(1, N+1):
    m = 2
    while n != 1:
        if n % m == 0:
            d[m] += 1
            n //= m
            m = 2
        else:
            m += 1
ans = 0
# count 3, 5, 15, 25, 75
count = [0, 0, 0, 0, 0]
for v in d.values():
    if v >= 74:
        count[4] += 1
    elif v >= 24:
        count[3] += 1
    elif v >= 14:
        count[2] += 1
    elif v >= 4:
        count[1] += 1
    elif v >= 2:
        count[0] += 1
ans += count[4]
ans += sum(count[3:])*(sum(count)-1)
ans += sum(count[2:])*(sum(count[1:])-1)
ans += sum(count[1:])*(sum(count[1:])-1)//2*(sum(count)-2)
print(ans)


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

int main(){

int huyuyasumi_nissu;
int kokugo_page;
int sansu_page;
int kokugo_a_day;
int sansu_a_day;
int kokugo_kakaru_day;
int sansu_kakaru_day;

cin>> huyuyasumi_nissu>>kokugo_page>> sansu_page>>kokugo_a_day>>sansu_a_day;

if(kokugo_page % kokugo_a_day == 0) {
	kokugo_kakaru_day = kokugo_page / kokugo_a_day;
	}else{
	kokugo_kakaru_day = kokugo_page / kokugo_a_day + 1;
	}

if(sansu_page % sansu_a_day == 0) {
	sansu_kakaru_day = sansu_page / sansu_a_day;
	}else{
	sansu_kakaru_day = sansu_page / sansu_a_day + 1;
	}

if( kokugo_kakaru_day > sansu_kakaru_day ) {
 	cout << huyuyasumi_nissu - kokugo_kakaru_day << endl;
	}else{
	cout << huyuyasumi_nissu -  sansu_kakaru_day << endl;
	}

return 0;
}


Measured memory_bytes: 3068
import re
N = int(input())

S = []
for i in range(N):
  S.append(input())

inner = 0
Bxxx = 0
xxxA = 0
BxxA = 0

pattern = re.compile(r'AB')

for s in S:
  mo = pattern.findall(s)
  inner += len(mo)
  if s[0] == "B" and s[-1] == "A":
    BxxA += 1
  elif s[0] == "B":
    Bxxx += 1
  elif s[-1] == "A":
    xxxA += 1
if BxxA > 0:
  total = inner + BxxA - 1
else:
  total = inner
if xxxA > 0 and BxxA > 0:
  total += 1
  xxxA -= 1
if Bxxx > 0 and BxxA > 0:
  total += 1
  Bxxx -= 1
total += min(xxxA, Bxxx)
print(total)

Measured memory_bytes: 3828
def main():
    H, W = map(int, input().split())
    a = []
    for _ in range(H):
        a.append(input())
    b = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if a[i][j] == '#':
                b[i][j] = 0
                continue
            if i == 0 and j == 0:
                b[i][j] = 1
            elif i == 0:
                b[i][j] = b[i][j-1]
            elif j == 0:
                b[i][j] = b[i-1][j]
            else:
                b[i][j] = b[i-1][j] + b[i][j-1]
    print(b[-1][-1] % (10**9 + 7))

main()





Measured memory_bytes: 157420
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> path(N);
    vector<vector<ll>> num(M, vector<ll>(2));
    rep(i, M)cin >> num[i][0] >> num[i][1];
    rep(i, N)path[i] = i + 1;
    ll cnt = 0;
    do {
        bool ans = true;
        for (int i = 0; i < N - 1; i++) {
            bool yes = false;
            for (int j = 0; j < M; j++) {
                if (path[i] == num[j][0] && path[i + 1] == num[j][1])yes = true;
                if (path[i] == num[j][1] && path[i + 1] == num[j][0])yes = true;
            }
            if (!(yes))ans = false;
        }
        if (ans)cnt++;
    } while (next_permutation(path.begin() + 1, path.end()));
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int[] lst = new int[n];
        long ans = 0;
        for(int i = 0; i < n; i++) {
            lst[i] = scan.nextInt();
        }
        for(int i = 0; i < n - 1; i++) {
            if(lst[i] + lst[i + 1] > x){
                ans += lst[i] + lst[i + 1] - x;
                lst[i + 1] = Math.max(0, x - lst[i]);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50484
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

ll gcd(ll a, ll b) {
	ll temp;
	while (a % b != 0)
	{
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

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

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

	string s;
	cin >> s;
	sort(all(s));

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>ahzong(n);
  for(int i = 0; i<n;i++){
    cin >> ahzong[i];
  }
sort(ahzong.begin(),ahzong.end());
bool ok = 1;
for(int i = 0;i+1<n;i++){
if(ahzong[i]==ahzong[i+1]){
  ok = 0;
  break;
}
}
if(ok == 0){
  cout << "NO";
}
else {cout <<"YES";}
return 0;
}

Measured memory_bytes: 1024
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

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

    vector<pii> v,w;

    int a,b,x,y;
    for(int i=0;i<n;++i)
    {
        cin>>a>>b;
        x=a-b;
        y=a+b;

        v.pb({y,x});
        w.pb({x,y});
    }

    sort(all(v));
    sort(all(w));

    map<pii,int> mp;
    for(int i=0;i<n;++i)
        mp[w[i]]=i;

    vector<int> pre(n,1),suf(n,1);
    vector<int> mx(n);

    int pos;
    mx[0]=pre[0];
    for(int i=1;i<n;++i)
    {
        pos=upper_bound(all(v),make_pair(v[i].S,inf))-v.begin();

        if(pos-1>=0)
            pre[i]=mx[pos-1]+1;

        mx[i]=max(mx[i-1],pre[i]);
    }

    mx[n-1]=suf[n-1];
    for(int i=n-2;i>=0;--i)
    {
        pos=lower_bound(all(w),make_pair(w[i].S,-inf))-w.begin();

        if(pos<n)
            suf[i]=mx[pos]+1;

        mx[i]=max(mx[i+1],suf[i]);
    }

    int ans=0;
    for(int i=0;i<n;++i)
    {
        ans=max(ans,pre[i]+suf[mp[{v[i].S,v[i].F}]]-1ll);
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 12004