akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
#define MOD               998244353

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// メイン
void Solve()
{
	string S;
	cin >> S;
	VL word(26, 0);
	REP(i, S.size()) word[S[i] - 'a']++;
	sort(ALL(word), greater<ll>());

	string ans = "YES";
	if (S.size() == 1) {
		cout << ans << endl;
		return;
	}
	if (S.size() == 2) {
		if (word[0] == 2) ans = "NO";
		cout << ans << endl;
		return;
	}

	ll diffCnt = accumulate(word.begin() + 2, word.end(), (ll)0);
	if (diffCnt + 1 < word[0]) {
		ans = "NO";
	}
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int x,a,b,H;
   cin>>x;
   a=(x-x%500)/500;
   b=((x-a*500)-((x-a*500)%5))/5;
   H=a*1000+b*5;
   cout<<H;
   return 0;
   
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    int tmp = N;
    int mod = 0;
    while(tmp!=0){
        mod += tmp % 10;
        tmp /= 10;
    }

    if(N%mod==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import math

N,M=map(int,input().split())
ans=0
for i in range(1,100000):
    ans+=i*(1900*M+(N-M)*100) * (0.5)**M * (1-(0.5)**M)**(i-1)

a=math.floor(ans)
b=math.ceil(ans)

if abs(a-ans)>abs(b-ans):
    print(b)
else:
    print(a)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
void printReverseArray(int*,int);
int main(void)
{
  int i,n;
  int *arr;
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  printReverseArray(arr,n);
  return 0;
}
void printReverseArray(int *arr,int n)
{
  int i;
  for(i=n-1;i>=0;i--)
    {
      if(i<n-1) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}


Measured memory_bytes: 2044
# 自分の回答
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n - i + 1):
            if(10000 * i + 5000 * j + 1000 * (n - i - j) == y):
                print(i, j, n - i - j)
                exit()
print("-1 -1 -1")


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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> house(N);
  for (int i = 0; i < N; i++) {
    cin >> house.at(i);
  }
  int dist = K + house.at(0) - house.at(N-1);
  for (int i = 0; i < N - 1; i++) {
    if (dist < house.at(i+1) - house.at(i)) {
      dist = house.at(i+1) - house.at(i);
    }
  }
  cout << K - dist << endl;
}

Measured memory_bytes: 1024
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n,k;
  cin>>n>>k;
  
  vector<int> X(n);
  rep(i,n) cin>>X[i];
  
  int mi=1e9;  
  for(int i=0;i+k-1<n;i++){
    if(X[i]>=0) mi=min(mi,X[i+k-1]);
    else if(X[i+k-1]<=0) mi=min(mi,-X[i]);
    else{
      if(X[i+k-1]>=-X[i]) mi=min(mi,-2*X[i]+X[i+k-1]);
      else mi=min(mi,2*X[i+k-1]-X[i]);
    }
  }
  cout<<mi<<endl;

  return 0;
}

Measured memory_bytes: 3720
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		double max = 0;
		double min = 0;
		double num = 0;
		ArrayList<Double> height = new ArrayList<Double>();
		while(sc.hasNext()){
			height.add(sc.nextDouble());
		}
		min = height.get(0);
		for(int i = 0; i < height.size();i++){
			num = height.get(i);
			if(max<num){
				max = num;
			}
			if(min>num){
				min = num;
			}
		}
		num = max - min;
		System.out.println(num);
	}
}

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

int main(void){
	long long n,m;
	cin>>n>>m;
	long long c = 0;

	if (2*n > m) { // 余らない
		c = -1;
		c = m/2;
	} else { // 余る
		c = min(n,m*2);
		n -= c;
		m -= (c*2);
//		cout<<c<<" "<<m<<endl;

		c += (m/4);
	}
	cout<<c<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int a;
string s;
int main() {
    DAU
    cin >> a >> s;
    if (a < 3200)
        s = "red";
    cout << s;
    PLEC
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll x,y;
void Main(){
  cin>>x>>y;
  if(x%y==0) cout<<-1<<endl;
  else cout<<x<<endl;   
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 998244353;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        String s = in.next();

        if (n % 2 == 1) {
            out.println("No");
            return;
        }

        if (s.substring(0, n / 2).equals(s.substring(n / 2))) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 24404
import math
A,B = list(map(int,input().split()))
s =""
if B == 0:
    print(0)
else:
    for i in range(int(math.log2(B))+1):
        if i == 0:
            a =0
            for j in range(A,4*(divmod(A,4)[0]+1)):
                #print(divmod(j,2)[1])
                a += divmod(j,2)[1]
            for j in range(4*(divmod(B,4)[0]),B+1):
                #print(divmod(j,2)[1])
                a += divmod(j,2)[1]
            s = str(divmod(a,2)[1])
        else:
            # int(divmod(16/16 ,2)[1])
            s = str(divmod((2**i-divmod(A,2**i)[1]) * int(divmod(A/2**i ,2)[1])+(divmod(B,2**i)[1]+1) * int(divmod(B/2**i ,2)[1]),2)[1]) + s
    print(int(s,2))


Measured memory_bytes: 3316
def resolve():
    n = int(input())
    s_list = list(input())
    mod = 10 ** 9 + 7

    if s_list[0] == "W" or s_list[-1] == "W":
        print(0)
        return

    from math import factorial

    l_counter = 0
    res = 1

    for i in range(2 * n):
        s = s_list[i]
        if i % 2 == 0:
            s = "W" if s == "B" else "B"

        if s == "W":
            l_counter += 1
        else:
            res = res * l_counter % mod
            l_counter -= 1
            if l_counter < 0:
                print(0)
                return

    if l_counter != 0:
        print(0)
    else:
        print(res * factorial(n) % mod)
        
resolve()

Measured memory_bytes: 61552
/*
 ***
 Question Name: FlipAndRectangles
 ***
 Question Link: http://arc081.contest.atcoder.jp/tasks/arc081_d
 
 ***
 Idea:
 */

#include <memory.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

class FlipAndRectangles{
    int di[4] = {0, 0, 1, 1};
    int dj[4] = {0, 1, 0, 1};
    int maxRecInLine(vi H){
        // Compute the max_rectangle in one dimension.
        if(H.empty()) return 0;
        H.insert(H.begin(), -2);
        H.push_back(-1);
        int n = (int)H.size(), ans = 0;
        stack<int> stk;
        stk.push(0);
        for(int i=1;i<n;++i){
            while(H[stk.top()] >= H[i]){
                int pivat = stk.top();
                stk.pop();
                ans = max(ans, (i - stk.top()) * (H[pivat]+1));
            }
            stk.push(i);
        }
        return ans;
    }
public:
    int solution(vector<string> M){
        assert(!M.empty() && !M[0].empty());
        int n = (int)M.size(), m = (int)M[0].size();
        assert(n >= 2 && m >=2);
        int ans = max(n, m);
        // From left to right
        vi good(n-1,0);
        for(int j=0;j<m-1;++j){
            for(int i=0;i<n-1;++i){
                int cnt = 0;
                for(int k=0;k<4;++k) cnt += (M[i+di[k]][j+dj[k]]=='#');
                if(cnt%2) good[i] = 0;
                else ++good[i];
            }
            ans = max(ans, maxRecInLine(good));
        }
          
        return ans;
    }
};




int main(){
    int H,W;
    cin>>H>>W;
    vector<string> M(H);
    for(int i=0;i<H;++i) cin>>M[i];
    cout<<FlipAndRectangles().solution(M)<<endl;
    return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>

int cnt=1;
int oya[500010];
int ko[2][500010];
int val[500010];

int f(int v,int mode){
    if(mode==0)printf(" %d",val[v]);
    if(ko[0][v])f(ko[0][v],mode);
    if(mode==1)printf(" %d",val[v]);
    if(ko[1][v])f(ko[1][v],mode);
    if(mode==2)printf(" %d",val[v]);
}
void push(int v,int va){
	//初回
	if(cnt==1){
		val[cnt]=va;
		cnt++;
		return;
	}
	if(ko[val[v]<va][v])push(ko[val[v]<va][v],va);
	else{
		ko[val[v]<va][v]=cnt;
		oya[cnt]=v;
		val[cnt]=va;
		cnt++;
	}
}

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		char s[10];
		scanf("%s",s);
		if(s[0]=='p'){
			f(1,1);
			puts("");
			f(1,0);
			puts("");
		}else{
			int t;
			scanf("%d",&t);
			push(1,t);
		}
	}
}


Measured memory_bytes: 9516
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m,L;
vector<int>g[305];
int dist[305][305],d2[305][305];
signed main(){
	cin>>n>>m>>L;
	memset(dist,0x3f3f3f3f3f3f3f3f,sizeof dist);
	for(int i=1;i<=m;i++){
		int a,b,c;cin>>a>>b>>c;
		dist[a][b]=min(dist[a][b],c);
		dist[b][a]=dist[a][b];
	}
	for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	memset(d2,0x3f3f3f3f3f3f3f3f,sizeof d2);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i!=j&&dist[i][j]<=L){
				d2[i][j]=1;
				d2[j][i]=1;
			}
		}
		d2[i][i]=0;
	}
	for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
	int q;cin>>q;
	while(q--){
		int s,t;cin>>s>>t;
		if(d2[s][t]<=1000){
			cout<<d2[s][t]-1<<endl;
		}else{
			cout<<-1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;


//zaki_UnionFind
class UnionFind
{
    std::vector<int> data;

  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

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

    ll n, m;
    cin >> n >> m;
    ll x, y, z;
    UnionFind uf(n);
    REP(i, m){
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }
    ll res = 0;
    vll used(n);
    REP(i, n){
        if(!used[uf.root(i)]) res++;
        used[uf.root(i)] = 1;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;





int main()
{
    ll ans=0;
    int n;
    cin>>n;
    int arr[1000];
    for(int i=0;i<2*n;i++)
        cin>>arr[i];
    sort(arr,arr+2*n);
    for(int i=0;i<2*n-1;i+=2)
        ans+=arr[i];
    cout<<ans;

}


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

//#define FILE
#define int long long
//#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fst first
#define scd second
#define inv(x) ksm((x),mod - 2)
#define lowbit(x) ((x) & (-(x)))

const int MAXN = 1;
const int INF = 2e9;
const double PI = acos(-1);
const double eps = 1e-6;
//const int mod = 1e9 + 7;
//const int mod = 998244353;
//const int G = 3;

int a,b,c,d;
int ans;

template<typename T> inline void read(T &a) {
	a = 0; char c = getchar(); int f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
	a *= f;
}

signed main () {
#ifdef FILE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	read(a); read(b); read(c); read(d);
	ans = max(max(a * c,b * d),max(a * d,b * c));
	if(a <= 0 && 0 <= b) ans = max(ans,0ll);
	if(c <= 0 && 0 <= d) ans = max(ans,0ll);
	printf("%lld\n",ans);
	return 0;
}



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

int main(){
    int a,b;
    cin >> a >> b;
    if(a%2 == 0 || b%2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

string line;

int main()
{
	while (cin >> line)
	{
		while (line.length() != 1)
		{
			for (int i=0; i<line.length()-1; i++)
			{
				line[i] = ((line[i]-'0') + (line[i+1]-'0')) % 10 + '0';
			}
			line = line.substr(0, line.length()-1);
		}
		cout << line << endl;
	}

	return 0;
}

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

int main(){
	double a=0,b=0,rad=0;
	int c=0;

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

	rad=c*(M_PI/180);
	printf("%.8lf\n",(a*b*sin(rad))/2);
	printf("%.8lf\n",a+b+sqrt(a*a+b*b-2*a*b*cos(rad)));
	printf("%.8lf\n",b*sin(rad));
	return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

	char c; cin >> c;
	cout << ('A' <= c && c <= 'Z' ? 'A' : 'a');
}

Measured memory_bytes: 3652
from itertools import accumulate
from collections import defaultdict

def main():
    N, P = map(int, input().split())
    S = list(map(int, list(input())))
    ans = 0
    if P == 2:
        for i in range(N-1,-1,-1):
            if S[i] % 2 == 0:
                ans += i + 1
        print(ans)
        exit()
    if P == 5:
        for i in range(N-1,-1,-1):
            if S[i] % 5 == 0:
                ans += i + 1
        print(ans)
        exit()
    
    ten = 1
    d = defaultdict(int)
    C = [0] * (N + 1)
    for i in range(N-1,-1,-1):
        tmp = (S[i] * ten) % P
        idx = N - 1 - i
        C[idx + 1] = (C[idx] + tmp) % P
        ten *= 10
        ten %= P

    for c in C:
        d[c] += 1

    for i, j in d.items():
        ans += j * (j - 1) // 2

    print(ans)    


if __name__ == "__main__":
    main()

Measured memory_bytes: 61680
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
    string C_1;
    string C_2;

    cin >> C_1;
    cin >> C_2;

    reverse(C_2.begin(), C_2.end());
    if(C_1 == C_2){
      cout << "YES";
    }else{
      cout << "NO";
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main()
{
    Hello
    ll start = 100, x, cntr = 1;
    cin >> x;
    while(true){
        start += ((start * 1)/(100));
        if(start >= x)
            return cout << cntr, 0;
        cntr++;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
   int n;
   cin >> n;
   vl d(n);
   rep(i, n) cin >> d[i];
   ll ans = 0LL;
   ll sum = d[0];
   REP(i, 1, n) {
       ans += sum * d[i];
       sum  += d[i];
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

pair<char, int> c[4004];
int pb[2004], pw[2004];
int b[4004][2004], w[4004][2004];
int dp[2004][2004];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= 2 * n; i++) {
		cin >> c[i].first >> c[i].second;
		(c[i].first == 'B' ? pb : pw)[c[i].second] = i;
	}

	for (int i = 2 * n; i >= 1; i--) {
		for (int j = 1; j <= n + 1; j++) {
			b[i][j] = b[i + 1][j] + (c[i].first == 'B' && c[i].second < j);
			w[i][j] = w[i + 1][j] + (c[i].first == 'W' && c[i].second < j);
		}
	}

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i > 0 && j > 0) dp[i][j] = min(dp[i - 1][j] + b[pb[i]][i] + w[pb[i]][j + 1], dp[i][j - 1] + b[pw[j]][i + 1] + w[pw[j]][j]);
			else if (i > 0) dp[i][j] = dp[i - 1][j] + b[pb[i]][i] + w[pb[i]][j + 1];
			else if (j > 0) dp[i][j] = dp[i][j - 1] + b[pw[j]][i + 1] + w[pw[j]][j];
		}
	}

	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

class Vec2{
public:
    int x;int y;
    Vec2(int x=0, int y=0) : x(x), y(y){};
    Vec2 operator+(Vec2 v){
        return Vec2(x+v.x, y+v.y);
    }
    Vec2 operator-(Vec2 v){
        return Vec2(x-v.x, y-v.y);
    }
};

int main(void)
{
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> cost(h, vector<int>(w, 0));
    queue<Vec2> q;
    REP(i, h){
        cin >> s[i];
        REP(j, w){
            if(s[i][j]=='#') q.push(Vec2(i,j));
        }
    }

    Vec2 diff[4] = {Vec2(-1,0),Vec2(1,0),Vec2(0,-1),Vec2(0,1)};
    int ans = 0;
    while(q.size()){
        Vec2 f = q.front();q.pop();
        REP(i, 4){
            Vec2 a = f + diff[i];
            if(0 <= a.x && a.x < h && 0 <= a.y && a.y < w){
                if(s[a.x][a.y]=='.'){
                    q.push(a);
                    s[a.x][a.y]='#';
                    cost[a.x][a.y] = cost[f.x][f.y]+1;
                    ans = max(ans, cost[a.x][a.y]);
                }
            }
        }
    }

    pr(ans);
}

Measured memory_bytes: 13456
import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long temp = a*a+b*b+c*c-2*(a*b+a*c+b*c);
        if(c>a+b) {
            System.out.println(0 < temp ? "Yes" : "No");
        }else{
            System.out.println("No");
        }


    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main(){__
	string s;
	cin >> s;
	int n = s.size();
	reverse(all(s));
	vector<int> sum(n);
	int tot =0;
	int pot = 1;
	map<int,int> m;
	lli ans = 0ll;
	m[0] = 1;
	for(int i=0; i <n; i++){
		int x = (s[i]-'0');
		tot = (tot + (pot * x)) % 2019;
		sum[i] = tot;
		int cont = m[tot];
		ans+=cont;
		m[tot]++;
		pot = (pot * 10) % 2019;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4428
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1010;
const string ans3[3] = {"..a",
						"..a",
						"bb.",};
const string ans5[5] = {"aabbc",
						"bbd.c",
						"ccdaa",
						"..abc",
						"..abc"};
const string ans6[6] = {"aaba..",
						"..babb",
						"bacc..",
						"ba..aa",
						"..aabc",
						"aa..bc",};
const string ans7[7] = {"..a..ab",
						"..a..ab",
						"aa.aa.c",
						"..a..ac",
						"..a..ab",
						"aa.aa.b",
						"bbccbb."};
const string ans8[8] = {"aa..bc..",
						"..aabc..",
						"..bcaa..",
						"..bc..aa",
						"aa....bc",
						"..aa..bc",
						"bc..aa..",
						"bc....aa"};
char ans[N][N];
inline void solve(int x1,int y1,int n){
	if (n==5){
		FOR(i,0,n) FOR(j,0,n) ans[x1+i][y1+j]=ans5[i][j];
		return;
	}
	if (n==6){
		FOR(i,0,n) FOR(j,0,n) ans[x1+i][y1+j]=ans6[i][j];
		return;
	}
	if (n==7){
		FOR(i,0,n) FOR(j,0,n) ans[x1+i][y1+j]=ans7[i][j];
		return;
	}
	if (n==8){
		FOR(i,0,n) FOR(j,0,n) ans[x1+i][y1+j]=ans8[i][j];
		return;
	}
	if (n==9){
		FOR(i,0,n) FOR(j,0,n) ans[x1+i][y1+j]=ans3[i%3][j%3];
		return;
	}
	int m=n>>1;
	solve(x1,y1,m),solve(x1+m,y1+m,n-m);
}

int main(){
	int n=read();
	if (n==2) return puts("-1"),0;
	if (n==3){
		puts("aa.");
		puts("..a");
		puts("..a");
		return 0;
	}
	if (n==4){
		puts("aacd");
		puts("bbcd");
		puts("dcaa");
		puts("dcbb");
		return 0;	
	}
	For(i,1,n) For(j,1,n) ans[i][j]='.';
	solve(1,1,n);
	FOR(i,1,n+1){
		FOR(j,1,n+1) printf("%c",ans[i][j]);
		puts("");
	}
}

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

int main()
{
    string s;
    long sum = 0;
    cin>>s;
    int i,x=s.size();
    for (i=0; i<x;i++) sum += s[i] - '0';

    if((sum % 9) == 0) cout <<"Yes"<< endl;
    else cout<<"No"<< endl;

    return 0;
}



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

int main() {
  string S, T;
  cin >> S >> T;

  bool flag = false;

  rep(i, 0, S.size()) {
    if (S == T) {
      flag = true;
      break;
    }
    S = S.back() + S.substr(0, S.size()-1);
  }

  cout << ( flag ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

res = 0
tmp = 0

for i in range(N):
    n = L[i] + tmp
    if i%2 == 0:
        if n >= 0:
            res += n + 1
            tmp = -1
        else:
            tmp = n
    else:
        if n <= 0:
            res += abs(n) + 1
            tmp = 1
        else:
            tmp = n
            
res1 = res

res = 0
tmp = 0
for i in range(N):
    n = L[i] + tmp
    if i%2 == 1:
        if n >= 0:
            res += n + 1
            tmp = -1
        else:
            tmp = n
    else:
        if n <= 0:
            res += abs(n) + 1
            tmp = 1
        else:
            tmp = n
print(min(res1, res))

Measured memory_bytes: 14468
#include<bits/stdc++.h>
using namespace std;
int n,a[10002],i,ans=0;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(i=1;i<=2*n;i++)
	cin>>a[i];
	sort(a+1,a+2*n+1);
	for(i=2*n-1;i>=n%2;i-=2)
		ans=ans+a[i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
/*
bool sw[1000001];
int i;
 
void sws(int k){
        if(k==1){
                sw[i]=true;
                return;
        }
        if(k%2==0) sws(k/2);
        else if(k%3==0) sws(k/3);
        else if(k%5==0) sws(k/5);
        return;
}
*/
// korenisuru
int dp[1000001];
int f(int n){
        if(~dp[n]) return dp[n];
        int ans = 0;
        if(n%2==0) ans |= f(n/2);
        if(n%3==0) ans |= f(n/3);
        if(n%5==0) ans |= f(n/5);
        return dp[n] = ans;
}
 
int main() {
        int m,n;
        for(int i = 0 ; i <= 1000000 ; i++) dp[i] = -1;
        dp[1] = 1;
        for(int i = 1 ; i <= 1000000 ; i++) f(i);
        while(cin >> m && m){
                cin >> n;
                int ans = 0;
                for(int i = m ; i <= n ; i++) ans += dp[i];
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a[MAXN];
void del(int x)
{
    for(int i=x+1;i<=n;i++) a[i-1]=a[i];
}
vector<int> ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        int id=-1;
        for(int j=n-i+1;j>=1;j--)
        {
            if(a[j]==j)
            {
                id=j;
                break;
            }
        }
        if(id==-1) 
        {
            puts("-1");
            return 0;
        }
        ans.push_back(a[id]);
        del(id);
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans) printf("%d\n",x);
    return 0;
}



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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))

map<string,int>mpp;
int main()
{
    int tst;
//
//    cin >> tst;
//
//    while(tst--)
//    {
//
//    }

int a,b,i,j,k,l,m,n;
//ll a,b,i,j,k,l,m,n;

cin >> n;
string s;
for(i=0;i<n;i++)
{
    cin >> s;
    mpp[s]++;
}

cout << "AC x "<<mpp["AC"]<<endl;
cout<<"WA x "<<mpp["WA"]<<endl;
cout<<"TLE x "<<mpp["TLE"]<<endl;
cout<<"RE x "<<mpp["RE"]<<endl;

//cout << m << endl;
}


Measured memory_bytes: 3628
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x:x[1])

temp_total = 0
for a,b in AB:
  temp_total += a
  if temp_total<=b:
    continue
  else:
    print('No')
    break
else:
  print('Yes')


Measured memory_bytes: 31824
inputNumber = input()
K = int(inputNumber.split(" ")[0])
N = int(inputNumber.split(" ")[1])

inputNumber = input()
A=inputNumber.split(" ")

A_Length=len(A)

for i in range(A_Length):
    A[i] = int(A[i])

result=0

for i in range(A_Length):
    if i == A_Length - 1:
        if result < (K - A[i]) + A[0]:
            result = (K - A[i]) + A[0]
    else:
        if result < A[i+1] - A[i]:
            result = A[i+1] - A[i]

#if result < (K - A[i]) + A[0]:
#    result = (K - A[i]) + A[0]


result = K - result
print(result)





Measured memory_bytes: 18636
import java.util.*;

class Stack{
    Object[] stack;
    int sp;
 
    Stack(int n){
	stack = new Object[n];
	sp = 0;
    }
    public void push(Object x){
	stack[sp++] = x;
    }
    public Object pop(){
	return stack[--sp];
    }
    public boolean isEmpty(){
	return sp==0;
    }
    public void clear(){
	sp = 0;
    }
}

public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    int m = kbd.nextInt();
	    if(n!=0 && m!=0){
		solve(n, m);
	    }
	}
    }

    static void solve(int n, int m){
	int i;
	int r = kbd.nextInt();
	int[][] time = new int[1000][m+1];
	Stack[] in = new Stack[m+1];
	for(i=0; i<in.length; i++){
	    in[i] = new Stack(r);
	}

	while(r>0){
	    put(time, in);
	    r--;
	}

	int q = kbd.nextInt();
	while(q>0){
	    answer(time);
	    q--;
	}
	for(i=0; i<in.length; i++){
	    in[i].clear();
	}
    }

    static void answer(int[][] time){
	int ts = kbd.nextInt();
	int te = kbd.nextInt();
	int m = kbd.nextInt();
	int i=0;
	int usetime = 0;

	while(time[i][m]!=0 && ts!=te){
	    if(ts < time[i][m]){
		if(te > time[i][m]){
		    if(te <= time[i+1][m]){
			usetime += te-time[i][m];
			ts = te;
		    }
		    else if(te > time[i+1][m]){
			usetime += time[i+1][m]-time[i][m];
			ts = time[i+1][m];
		    }
		}
	    }
	    else if(ts >= time[i][m]){
		if(ts < time[i+1][m]){
		    if(te <= time[i+1][m]){
			usetime += te-ts;
			ts = te;
		    }
		    else if(te > time[i+1][m]){
			usetime += time[i+1][m]-ts;
			ts = time[i+1][m];
		    }
		}
	    }
	    i+=2;
	}
	System.out.println(usetime);
    }

    static void put(int[][]time, Stack[] in){
	int t = kbd.nextInt();
	int n = kbd.nextInt();
	int m = kbd.nextInt();
	int s = kbd.nextInt();

	if(s==1){
	    in[m].push(t);
	}
	else if(s==0){
	    int e = (Integer)in[m].pop();
	    if(in[m].isEmpty()){
		int i=0;
		while(time[i][m]!=0) i++;
		time[i][m] = e;
		time[i+1][m] = t;
	    }
	}
    }
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n,m,q; cin>>n>>m>>q;
  vector<vector<ll>> a(n+2, vector<ll>(n+2));

  rep(i, m) {
    ll l,r; cin>>l>>r;
    a[l][r]++;
  }
  rep(i, n) rep(j, n) {
    a[i+1][j+1] += a[i][j+1] + a[i+1][j] - a[i][j];
  }

  vector<ll> ans;
  while (q--) {
    ll x, y; cin>>x>>y; x--;
    ans.push_back(a[y][y]-a[y][x]-a[x][y]+a[x][x]);
  }

  for (auto v:ans) cout << v << endl;

  return 0;
}


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

same = []
ok = 0
max_ok = 0
for i in range(N):
    x, y = input().split()
    if x == y:
        ok+=1
    else:
        max_ok = max(max_ok, ok)
        ok = 0
max_ok = max(max_ok, ok)

if max_ok >= 3:
    print('Yes')
else:
    print('No')


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


int main() {
  int n,k;
  cin>>n>>k;
  vector <long long> val(n,0);
  vector <long long> wght(n,0);
  int sum=0;
  for(int i=0;i<n;i++){
      cin>>wght[i]>>val[i];
      sum+=val[i];
  }
  vector <long long> dp(sum+1,INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;i++){
      for(int j=sum;j>=0;j--){
          if(j>=val[i])dp[j]=min(dp[j],dp[j-val[i]]+wght[i]);
          
      }
      // cout<<i<<endl;
      // for(int j=0;j<=sum;j++){
      //     cout<<ndp[j]<<" ";
      // }
      //cout<<endl;
  }
    int ans=0;
    //cout<<sum<<endl;
    for(int i=sum;i>=0;i--)if(dp[i]<=k){ans=i;break;}
    cout<<ans<<endl;
}

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

vector<int> g[100010];
bool used[100010];
vector<int> result;
int mark[100010];

void dfs(int v)
{
  used[v] = true;
  for (auto to : g[v])
  {
    if (!used[to]) dfs(to);
  }
  result.push_back(v);
}

void solve()
{
  int n, m; cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++)
  {
    if(!used[i]) dfs(i);
  }
  
  reverse(result.begin(), result.end());
  
  int mx = 0;
  
  for (int i = 0; i < result.size(); i++)
  {
    for (auto to : g[result[i]])
    {
      mark[to] = max(mark[to], mark[result[i]] + 1);
      mx = max(mx, mark[to]);
    }
  }
  
  cout << mx << endl;
}

int main()
{
  solve();
  return 0;
}

Measured memory_bytes: 8824
import java.util.*;
public class Main{
    final static Scanner sc=new Scanner(System.in);
    public static int isValid(long a, 
                                long b, long c) 
    {  
        if (a + b <= c || a + c <= b || b + c <= a) 
            return 0; 
        else
            return 1; 
    } 
    public static void main(String args[]){
        int s=sc.nextInt();
        long arr[]=new long[s];
        for(int i=0;i<s;i++){
            arr[i]=sc.nextLong();
        }
        int ans=0;
        for(int i=0;i<s;i++){
            for(int j=i+1;j<s;j++){
                for(int k=j+1;k<s;k++){
                    if(arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k] && isValid(arr[i],arr[j],arr[k])==1L ){
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 36920
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int W;
int weights[10] ={1,2,4,8,16,32,64,128,256,512};
int main()
{
  while(cin>>W){
    if(cin.eof())
      break;
    int type[10]={0};
    int first = 100;
    for(int j = 9;j >=0;j--){
      if(W-weights[j] >=0){
	W -=weights[j];
	type[j] = 1;
	if(first ==100)
	  first =j;
      }
    }
      for(int i = 0;i <=first;i++){
	if(type[i] ==1){
	  cout <<weights[i];
	  if(i !=first){
	  cout <<" ";
	  }
	}
	if(i ==first)
	  cout <<endl;
      }
  }
  return 0;
}

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

int main(void){
  int X;
  int i, j, k;
  int max = -1;
  int buf;
  scanf("%d", &X);
  for(i = 1; i <= ((int) sqrt((double) X)); i++){
    for(j = 2; j <= 10; j++){
      buf = (int) pow((double) i, (double) j);
      if(buf > max && buf <= X){
        max = buf;
      }
    }
  }
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 384
K=int(input())

def gcd(a,b):
    if b!=0:
        return (gcd(b,a%b))
    else:
        return (a)

s=0
for i in range(1,K+1):
    for j in range(i,K+1):
        m=gcd(i,j)
        for k in range(j,K+1):
            if i==j and j==k:
                s=s+gcd(m,k)
            elif i==j and j!=k:
                s=s+gcd(m,k)*3
            elif i!=j and j==k:
                s=s+gcd(m,k)*3
            else:
                s=s+gcd(m,k)*6
print (s)

Measured memory_bytes: 9204
#include<iostream>
#include<vector>
#define int long long
using namespace std;
const int N=2e5+2;
const int inf=1e18+2;
int it[4*N],dp[N],lazy[4*N];
vector<pair<int,int> > que[N];
void upd(int idx,int l,int r,int lef,int rig,int val){
	if(lef>r||rig<l){
		return;
	}
	if(l>=lef&&r<=rig){
		it[idx]+=val;
		lazy[idx]+=val;
		return;
	}
	if(lazy[idx]){
		it[2*idx]+=lazy[idx];
		it[2*idx+1]+=lazy[idx];
		lazy[2*idx]+=lazy[idx];
		lazy[2*idx+1]+=lazy[idx];
		lazy[idx]=0;
	}
	upd(2*idx,l,(l+r)/2,lef,rig,val);
	upd(2*idx+1,(l+r)/2+1,r,lef,rig,val);
	it[idx]=max(it[2*idx],it[2*idx+1]);
}
int getmax(int idx,int l,int r,int lef,int rig){
	if(l>rig||r<lef){
		return -inf;
	}
	if(l>=lef&&r<=rig){
		return it[idx];
	}
	if(lazy[idx]){
		it[2*idx]+=lazy[idx];
		it[2*idx+1]+=lazy[idx];
		lazy[2*idx]+=lazy[idx];
		lazy[2*idx+1]+=lazy[idx];
		lazy[idx]=0;
	}
	return max(getmax(2*idx,l,(l+r)/2,lef,rig),getmax(2*idx+1,(l+r)/2+1,r,lef,rig));
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,i,j,k,l,ans=0;
	cin>>n>>m;
	for(i=1;i<=m;i++){
		cin>>j>>k>>l;
		que[j+1].push_back({j+1,l});
		que[k+2].push_back({j+1,l});
	}
	for(i=2;i<=n+1;i++){
		for(j=0;j<que[i].size();j++){
			if(que[i][j].first==i){
				upd(1,1,n+1,1,que[i][j].first-1,que[i][j].second);
			}
			else{
				upd(1,1,n+1,1,que[i][j].first-1,-que[i][j].second);
			}
		}
		dp[i]=getmax(1,1,n+1,1,i-1);
		upd(1,1,n+1,i,i,dp[i]);
		ans=max(ans,dp[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 29184
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int digitSum(int n,int digit=8) {
	// digit > 2
	int x = 1;
	FOR(i,0,digit){
		x *= 10;
	}
	int sum = 0;
	FOR(i, 0, digit) {
		sum += n / x;
		n %= x;
		x /= 10;
	}
	sum += n;
	return sum;
}


int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	FOR(i, 0, s.length()) {
		if (s[i] == s[i + 1]) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
int main()
{
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
    string a,b;
    cin>>n;
    k=n/2;
    if(n%2==1)
    {
        k++;
    }
    cout<<fixed<<setprecision(10)<<(DL)k/(DL)n<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
const int M=2e2+20;
ll v[N];
ll C[M][M]; 
void init()
{
	memset(C,0,sizeof(C));
	C[0][0]=1;
	for(int i=1;i<=50;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int main()
{
	int n,A,B;
	init();
	while(cin>>n>>A>>B)
	{
		double ave=0;
		for(int i=0;i<n;i++)
			cin>>v[i];
		sort(v,v+n);
		reverse(v,v+n);//大->小
		for(int i=0;i<A;i++) 
			ave+=v[i];
		ave/=A;
		int num=0,k=0;
		for(int i=0;i<n;i++)
		{
			if(v[i]==v[A-1])
			{
				num++;
				if(i<A)
					k++;
			}
		}	
		ll ans=0; 
		if(k==A)//前A个相同,可以增加个数 
		{
			for(int i=A;i<=B;i++)
				ans+=C[num][i];
		}
		else
			ans+=C[num][k];

 		cout.precision(20);
 		printf("%.15f\n",ave);
 		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
n = int(input())
x = list(map(int, input().split()))

S_min = float("inf")

for i in range(1, 101):
    S = 0
    for j in range(n):
        S += (x[j] - i) ** 2
    if S < S_min:
        S_min = S

print(S_min)

Measured memory_bytes: 3064
-- | Main entry point to the application.
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe

-- | The main entry point.
main :: IO ()
main = do
    [a] <- concatMap (fmap (read :: String -> Int) . words) . lines <$> getContents
    putStrLn $ show $ a * a * a

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
#define rep(i, n) for (int i = 0; i < n; ++i)
llong as[200000], oddas[200000], psum[200000];
int main()
{
    llong n, m, v, p, ans = 0;
    scanf("%lld%lld%lld%lld", &n, &m, &v, &p);
    rep(i, n)
        scanf("%lld", &as[i]),
        oddas[i] = as[i];
    sort(oddas, oddas + n, greater<llong>());
    psum[0] = 0;
    for (int i = 1; i <= n; ++i)
        psum[i] = oddas[i - 1] + psum[i - 1];
    for (llong i = 0; i < n;)
    {
        llong ni = upper_bound(oddas + i, oddas + n, oddas[i], greater<llong>()) - oddas;
        llong snm = ni - i;
        if (i < p)
            ans += snm;
        else
        {
            llong dis = i - p + 1;
            llong sumdis = psum[i] - psum[p - 1];
            llong rvnm = max(v - n + dis, 0LL) * m;
            llong avg = (sumdis + rvnm) / dis;
            if ((sumdis + rvnm) % dis) avg++;
            avg = max(avg, oddas[p - 1]);
            if (avg <= oddas[i] + m)
                ans += snm;
        }
        i = ni;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 3584