akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll p, q, r;
    cin >> p >> q >> r;
    cout << min(p+q, min(q+r, r+p)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define M 2000000


int H,A[M+1];

void maxheapify(int i){
  int l,r,largest,cng;

  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r] > A[largest])largest=r;

  if(largest != i){
    cng=A[largest];
    A[largest]=A[i];
    A[i]=cng;
    maxheapify(largest);
  }
}

int main(){
  int i;

  scanf("%d",&H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=H/2;i>=1;i--){
    maxheapify(i);
  }

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
 printf("\n");
  return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x;
    scanf("%d",&x);
    vector<int> vec = {3,5,7};
    string ans = "NO";
    for(int i=0;i<3;i++){
        if (x == vec.at(i)) ans = "YES";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
--prewritten code: https://github.com/antma/algo
{-# LANGUAGE BangPatterns #-}
{-# Options_GHC -O2 #-}
import Data.ByteString.Builder
import Data.Monoid
import System.IO
import qualified Data.ByteString.Char8 as C
import Data.Char

ru, ri :: C.ByteString -> Int

ru = C.foldl' (\a c -> a * 10 - 48 + ord c) 0
ri s
  | C.head s == '-' = negate $ ru $ C.tail s
  | otherwise = ru s

solve :: [Int] -> Int
solve (n:a) = sum $ filter ( > 0) $ zipWith (-) v c
  where
    (v, t) = splitAt n a
    c = take n t
    
main :: IO ()
main = print . solve . map ri . C.words =<< C.getContents


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

void solve(long long X) {
    if (400 <= X && X <= 599) {
        cout << "8" << endl;
    } else if (600 <= X && X <= 799) {
        cout << "7" << endl;
    } else if (800 <= X && X <= 999) {
        cout << "6" << endl;
    } else if (1000 <= X && X <= 1199) {
        cout << "5" << endl;
    } else if (1200 <= X && X <= 1399) {
        cout << "4" << endl;
    } else if (1400 <= X && X <= 1599) {
        cout << "3" << endl;
    } else if (1600 <= X && X <= 1799) {
        cout << "2" << endl;
    } else if (1800 <= X && X <= 1999) {
        cout << "1" << endl;
    }
}

int main() {
    long long X;
    scanf("%lld", &X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3712
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
lli po[10] = {2, 3, 5, 7, 11, 13, 17, 19 , 23, 29};


void solve(long long N, string S) {
  set<lli> o, ni, san;
  rrep(i,N){
    lli fu  = S[i] - '0';;
    for(auto j:ni){
      san.insert(po[fu]* po[fu] * po[fu] * po[fu]  * j);
    }
    for(auto s:o){
      ni.insert( po[fu] * po[fu]* s );
    }
    o.insert(po[fu]);
  }
  cout << san.size() << endl;
}

int main() {
  int a;
  long long N;
  scanf("%lld", &N);
  string S;
  cin >> S;
  solve(N, S);
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int K, S;
  cin>>K>>S;
  int ans = 0;
  for(int X=0;X<=K;++X) {
    for(int Y=0;Y<=K;++Y) {
      if(0<=S-X-Y && S-X-Y<=K) ans++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    ll s = 0;
    rep(i,n) s += a[i];
    
    vector<ll> x(n);
    ll temp = 0;
    for(int i=1; i<=n-2; i+=2){
        temp += a[i];
    }
    x[0] = s-2*temp;
    for(int i=1; i<n; i++){
        x[i] = 2*a[i-1] - x[i-1];
    }
    rep(i,n){
        cout << x[i] << endl;
        
    }


}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  string s;
  
  cin >> s;
  
  if(s=="Rainy")
  {
    cout << "Sunny" << endl;
  }
  else if(s=="Sunny")
  {
    cout << "Cloudy" << endl;
  }
  else if(s=="Cloudy")
  {
    cout << "Rainy" << endl;
  }
  
  return 0;
}

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

#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

int main() {
    vector<int> a(4, 0);
    rep(i, 6) {
        int x;
        cin >> x;
        x--;
        a[x]++;
    }
    bool valid = (*max_element(a.begin(), a.end()) <= 2);
    cout << (valid ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double INF=1e77;

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
};

double abs(const point &a){ return sqrt(a.x*a.x+a.y*a.y); }

struct segment{
	point a,b;
	segment(){}
	segment(const point &a,const point &b):a(a),b(b){}
};

int n;
segment S[14];

double d[14][2][14][2];

double dp[14][2][1<<14];
double dfs(int i,int j,int S){
	if(S==(1<<n)-1) return 0;

	if(dp[i][j][S]!=-1) return dp[i][j][S];

	double res=INF;
	rep(k,n) if((S>>k&1)==0) rep(l,2) {
		res=min(res,dfs(k,l,S|1<<k)+d[i][1-j][k][l]);
	}
	return dp[i][j][S]=res;
}

int main(){
	for(int cas=1;scanf("%d",&n),n;cas++){
		rep(i,n) scanf("%lf%lf%lf%lf",&S[i].a.x,&S[i].a.y,&S[i].b.x,&S[i].b.y);

		rep(i,n) rep(j,n) {
			d[i][0][j][0]=abs(S[i].a-S[j].a);
			d[i][0][j][1]=abs(S[i].a-S[j].b);
			d[i][1][j][0]=abs(S[i].b-S[j].a);
			d[i][1][j][1]=abs(S[i].b-S[j].b);
		}

		double ans=INF;
		rep(i,n) rep(j,2) rep(S,1<<n) dp[i][j][S]=-1;
		rep(i,n) rep(j,2) ans=min(ans,dfs(i,j,0));
		rep(i,n) ans+=d[i][0][i][1];
		printf("Case %d: %.9f\n",cas,ans);
	}

	return 0;
}

Measured memory_bytes: 4684
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)



itn main() {
	std::ios::sync_with_stdio(false);

	int n;

	cin >> n;

	int a;

	REP(i, n) {
		cin >> a;
		if (!(a % 2)) {
			if ((a % 3) && (a % 5)) {
				cout << "DENIED";
				return 0;
			}
		}
	}

	cout << "APPROVED";

	return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
// O(N^3)くらいまでなら許す
const int MAX_N = 3e2 + 1;

int N;
string S[MAX_N];

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

  cin >> N;
  REP(i, N) {
    cin >> S[i];
  }
    
  ll ans = 0ll;
  
  REP(i, N) {
    vector< string > tmp(N);
    REP(j, N) {
      tmp[j] = S[j].substr(i + 1) + S[j].substr(0, i + 1);
    }

    bool ok = true;
    REP(hi, N) {
      REP(wi, N) {
	if (tmp[hi][wi] != tmp[wi][hi]) {
	  ok = false;
	}
      }
    }
    if (ok) ans += N;
    // debug(ans);
  }

  cout << ans << endl;

  return 0;
}



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

int main() {

	ll a, b; cin >> a >> b;
	ll tmp = a + b;
	if (tmp % 2 == 1) cout << "IMPOSSIBLE" << endl;
	else cout << tmp / 2 << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int h,r,a;
	scanf("%d",&h);
	scanf("%d",&r);
	if(h+r==0){
		a=0;
	}
	if(h+r>0){
		a=1;
	}
	if(h+r<0){
		a=-1;
	}
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 2108
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {
    val in = StdIn.readLine().split(" ").map(s => s.toInt)
    println("%d %d %.8f".format(in(0) / in(1),in(0) % in(1),in(0).toDouble / in(1).toDouble))
  }
}

Measured memory_bytes: 43876
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

int F[N + 1];

void add(int x) {
    for (; x <= N; x = (x | (x + 1))) {
        F[x]++;
    }
}

int get(int x) {
    int res = 0;
    for (; x >= 0; x = (x & (x + 1)) - 1) {
        res += F[x];
    }
    return res;
}

vector<int> segm[N + 1];
vector<pair<int, int> > Q[N + 1];
int ans[N + 1];

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m;
    cin >> n >> m;
    rep(i, 0, n) {
        int l, r;
        cin >> l >> r;
        segm[l].push_back(r);
    }
    fill(ans + 1, ans + m + 1, n);
    for (int x = 1; x <= m; x++) {
        for (int y = 0; y < m; y += x) {
            Q[y + 1].push_back(mp(min(m, y + x - 1), x));
        }
    }
    repb(i, m, 0) {
        for (int x : segm[i]) {
            add(x);
        }
        for (auto it : Q[i]) {
            ans[it.se] -= get(it.fi);
        }
    }
    rep(i, 1, m + 1) {
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 23284
import java.io.*;
import java.util.*;
 
public class Main {
	static final Reader in = new Reader();
	
	public static void main(String[] args) {
		int n=in.nextInt();
		Pair[] p = new Pair[2*n];
		long[] a = new long[2];
		for(int i=0; i<2*n; ++i) {
			p[i] = new Pair(in.nextInt(), i);
			a[i&1]+=p[i].a;
		}
		a[0]=Math.min(a[1], a[0]);
		a[1]=0;
		Arrays.sort(p, new Comparator<Pair>() {
			public int compare(Pair a, Pair b) {
				return a.a==b.a?a.b-b.b:a.a-b.a;
			}
		});
		int[] q = new int[2*n];
		for(int i=0; i<n; ++i)
			a[1]+=p[i].a;
		for(int i=0; i<2*n; ++i)
			q[p[i].b]=i;
		for(int i=0; i<n; ++i) {
			long c=a[1];
			int j=n;
			while(j-(q[2*i]<j?1:0)-(q[2*i+1]<j?1:0)<n)
				c+=p[j++].a;
			for(int k=2*i; k<2*i+2; ++k)
				if(q[k]<j)
					c-=p[q[k]].a;
			a[0]=Math.min(c, a[0]);
		}
		System.out.println(a[0]);
	}
	
	static class Pair {
		int a, b;
		Pair(int a, int b) {
			this.a=a;
			this.b=b;
		}
	}
	
	static class Reader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 51168
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b, x;
	cin >> x >> a >> b;
	string s;
	if (b <= a) s = "delicious";
	else if (b <= x + a)s = "safe";
	else s = "dangerous";
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
 
#define ulli unsigned long long int
 
#define Pi 3.14159265358979323846264338327950288419716939937510
 
int main(){
 
	ios :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	
	string s;
	
	cin>>s;
	
	if(s == "SUN"){
		
		cout<<"7";
	}
	
	else if(s == "MON"){
		
		cout<<"6";
	}
	
	else if(s == "TUE"){
		
		cout<<"5";
	}
	
	else if(s == "WED"){
		
		cout<<"4";
	}
	
	else if(s == "THU"){
		
		cout<<"3";
	}
	
	else if(s == "FRI"){
		
		cout<<"2";
	}
	
	else if(s == "SAT"){
		
		cout<<"1";
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<ctype.h>
#include<math.h>
#include<map>
#include<time.h>
#include<algorithm>
using namespace std;
const int N=100+1;
map<int,int> a;
typedef pair<int,int> PAIR;
bool cmp(const PAIR& left,const PAIR& right)
{
	return left.second==right.second?left.first<right.first:left.second>right.second;
}
int main()
{
	int n;
	while(~scanf("%d",&n))
		a[n]++;
	vector<PAIR> v(a.begin(),a.end());
	sort(v.begin(),v.end(),cmp);
	int max=v[0].second;
	for(int i=0;i!=v.size();i++)
		if(v[i].second==max)
			printf("%d\n",v[i].first);
		else break;
	return 0;
}


Measured memory_bytes: 3196
import java.util.*;

public class Main{
		
	public static void main(String[] args){
		Map<Integer, Team> num_team_map = new HashMap<Integer, Team>();
		List<Integer> ac_set = new ArrayList<Integer>();

		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String str = sc.nextLine();
			Team t = new Team(str);
			if(t.number == 0 && t.accepted == 0) break;
			else{
				num_team_map.put(t.number, t);
				if(!ac_set.contains(t.accepted)) ac_set.add(t.accepted);
			}
		}
		
		//sort
		Collections.sort(ac_set, new Comparator<Integer>() {
			public int compare(Integer o1, Integer o2){
				if(o1 > o2) return -1; else if(o1 == o2) return 0; else return 1;
			}});
		
		//output
		while(sc.hasNextLine()) {
			int query = Integer.parseInt(sc.nextLine());
			System.out.println(rankOf(ac_set, num_team_map.get(query).accepted));
		}
		sc.close();
	}
	
	static int rankOf(List<Integer> aclist, int ac) {
		for(int i = 0; i < aclist.size(); i++) if(aclist.get(i) == ac) return i+1;
		return 0;
	}
}

class Team{
	int number;
	int accepted;

	Team(String str){
		Scanner sc = new Scanner(str);
		sc.useDelimiter(",");
		this.number = sc.nextInt();
		this.accepted = sc.nextInt();
		sc.close();
	}
}

Measured memory_bytes: 29748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
ll fc[maxn],f[maxn];

ll qpow(ll a,ll b){
	ll s = 1;
	a %= mod;
	while(b){
		if(b & 1) s = (s % mod) * (a % mod) % mod;
        b >>= 1;
        a = (a % mod) * (a % mod) % mod;
	}
	s %= mod;
	return s;
}

ll c(ll x,ll y){
	return fc[x]*qpow(fc[y]*fc[x-y]%mod,mod-2)%mod;
}
int main(){
	fc[0] = 1;
	for(int i = 1;i < maxn;i++)
		fc[i] = (fc[i-1]*i % mod);
	ll n,k;
	cin >> n >> k;
	f[1] = 1;
	for(int i = 2;i < maxn;i++)
		f[i] = (f[i-1]*i%mod);
	ll sum = 0;
	for(ll i = 0;i <= min(n,k);i++){
		sum += (c(n,i)*c(n-1,n-i-1)) % mod;
		sum %= mod;
	}
	cout << (sum + mod) % mod;
	return 0;
}

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

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

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

    int N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    std::vector<int> leftCumE(N, ((S[0] == 'E') ? 1 : 0));
    for (int i = 1; i < N; ++i) {
        leftCumE[i] = leftCumE[i - 1] + ((S[i] == 'E') ? 1 : 0);
    }

    int ans = N-1;
    // first
    chmin(ans, leftCumE[N-1] - leftCumE[0]);

    // middle
    for (int i = 1; i < N-1; ++i) {
        const int nbL = i + 1 - leftCumE[i];
        const int nbR = leftCumE[N-1] - leftCumE[i+1];
        chmin(ans, nbL + nbR);
    }
    // last
    chmin(ans, N - 1 - leftCumE[N-2]);

    std::cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1812
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,b,c,d[256];
main()
{
	cin>>n>>a>>b>>c;
	int I=0;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		for(int j=0;j<=I;j++)d[j+I+1]=d[j]+x;
		I+=I+1;
	}
	int ans=d[0]=5e8;
	for(int i=0;i<=I;i++)for(int j=0;j<=I;j++)
	{
		ans=min(ans,abs(d[i&j]-a)+abs(d[i&~j]-b)+abs(d[j&~i]-c)+__builtin_popcount(i|j)*10);
	}
	cout<<ans-30<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int total = sc.nextInt();
		List<Integer> spade = new ArrayList<Integer>();
		List<Integer> heart = new ArrayList<Integer>();
		List<Integer> club = new ArrayList<Integer>();
		List<Integer> diamond = new ArrayList<Integer>();

		for(int i=0;i<total;i++) {
			char symbol = sc.next().charAt(0);
			int number = sc.nextInt();

			if(symbol=='S') {
				spade.add(number);
			}else if(symbol=='H') {
				heart.add(number);
			}else if(symbol=='C') {
				club.add(number);
			}else if(symbol=='D') {
				diamond.add(number);
			}
		}

		for(int i=1;i<=13;i++) {
			if(!(spade.contains(i))) {
				System.out.println("S "+i);
			}
		}
		for(int i=1;i<=13;i++) {
			if(!(heart.contains(i))) {
				System.out.println("H "+i);
			}
		}
		for(int i=1;i<=13;i++) {
			if(!(club.contains(i))) {
				System.out.println("C "+i);
			}
		}
		for(int i=1;i<=13;i++) {
			if(!(diamond.contains(i))) {
				System.out.println("D "+i);
			}
		}
	}
}



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

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

    int N;
    cin >> N;
    int64_t p1, p2;
    if(N == 0){
        cout << 2 << endl;
        return 0;
    }else if(N == 1){
        cout << 1 << endl;
        return 0;
    }
    p1 = 2;
    p2 = 1;
    int64_t tmp;
    for(int i = 2; i < N; i++){
        tmp = p1;
        p1 = p2;
        p2 = tmp + p2;
    }
    cout << p1 + p2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long



#if 0
const int MOD = ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}
#endif

#if 0
int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}
#endif

using namespace std;



int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int n, m;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string s, t;
    cin >> n >> m;
    cin >> s >> t;
    ll l = 1LL * n * m / __gcd(n, m);
    map <ll, char> mp;
    int sz = 0;
    for(ll i = 0; i < l; i += l / n) {
        mp[i] = s[sz++];
    }
    sz = 0;
    for(ll i = 0; i < l; i += l / m) {
        if(mp[i] != 0 && mp[i] != t[sz]) {
            cout << -1;
            return 0;
        }
        mp[i] = t[sz++];
    }

    cout << l;

    return 0;
}


Measured memory_bytes: 10880
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<vector<bool> >in(n,vector<bool>(30));
    vector<string>in1(n);
    rep(i,n){
      int d;
      cin>>in1[i]>>d;
      rep(j,d){
	int a;
	cin>>a;
	in[i][a]=true;
      }
    }
    vector<int>score(n);
    rep(i,30){
      int co=0;
      rep(j,n)if(in[j][i])co++;
      if(!co)continue;
      else rep(j,n)if(in[j][i])score[j]+=n-co+1;
    }
    int mini=1e9;
    rep(i,n)mini=min(mini,score[i]);
    vector<string>out;
    rep(i,n)if(mini==score[i])out.pb(in1[i]);
    sort(all(out));
    //rep(i,n)cout<<score[i]<<" "<<in1[i]<<endl;
    cout<<mini<<" "<<out[0]<<endl;
  }
}

Measured memory_bytes: 1224
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class modMCalc
    {
        private const int M = 1000000007;       // 素数(int範囲)

        // 乗算結果 % Mを求める
        static public int Mul(int a, int b)
        {
            return (int)(Math.BigMul(a, b) % M);
        }

        // 冪乗(mod M)
        static public int Pow(int a, int m)
        {
            if (0 == m)
            {
                return 1;
            }
            if (1 == m)
            {
                return a;
            }

            int result = 1;
            int param = a;
            for (; m > 0; m >>= 1)
            {
                if ((m & 0x01) == 1)
                {
                    result = Mul(result, param);
                }

                param = Mul(param, param);
            }

            return result;
        }

        // 除算(mod M)
        static public int Div(int a, int b)
        {
            return Mul(a, Pow(b, M - 2));
        }
    }

    class CombinationPermutation
    {
        private readonly int[] fac;

        // コンストラクタ
        // (mod Mの)階乗テーブル作成する
        public CombinationPermutation(int n)
        {
            fac = new int[n + 1];
            fac[0] = 1;
            for (int i = 1; i <= n; ++i)
            {
                fac[i] = modMCalc.Mul(fac[i - 1], i);
            }
        }

        // 階乗求める
        public int Factorial(int n)
        {
            return fac[n];
        }

        public int nCr(int n, int r)
        {
            if (n < r) { return 0; }
            if (n == r) { return 1; }
            int res = Factorial(n);
            res = modMCalc.Div(res, Factorial(r));
            res = modMCalc.Div(res, Factorial(n - r));
            return res;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int K = int.Parse(s[1]);

            Console.WriteLine(N - K + 1);

            int R = N - K;
            int B = K;

            CombinationPermutation c = new CombinationPermutation(N);

            for (int i = 1; i < K; i++)
            {
                int ans = c.nCr(B - 1, i);      // 青ボールから間を選択する通り
                int b = c.nCr(R + 1, i + 1);
                ans = modMCalc.Mul(ans, b);

                Console.WriteLine(ans);
            }

        }
    }
}


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

using namespace std;

int main(){
    long long n;
    cin>>n;
    long long s=0;
    long long c=0;
    while(s<=n){
        ++c;
        s+=c;
    }
    s-=c;
    --c;
    long long res=n-s;
    if(res==0){
        string a(c,')'),b(c,'(');
        cout<<a+b<<endl;
        return 0;
    }
    --res;
    string ans=")(",as(c,')'),t(c,'(');
    ans+=as+t;
    if(res>0)swap(ans[1],ans[1+res]);
    for (auto i:ans) {
        cout<<i;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3320
#include <iostream>
using namespace std;
int main(){

int H,W;
cin>>H>>W;

while(H!=0&&W!=0){
for(int a=0;a<H;a++){
	if(a%2==0){
		for(int b=0;b<W;b++){
			if(b%2==0){
				cout<<"#";
			}
			else if(b%2==1){
				cout<<".";
			}
		}
	}
	else if(a%2==1){
		for(int b=0;b<W;b++){
			if(b%2==0){
				cout<<".";
			}
			else if(b%2==1){
				cout<<"#";
			}
		}
	}
cout<<endl;
}
cout<<endl;	
cin>>H>>W;
}
	

return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, a, b, d[10010], res[10010], c[10010];
vector<int> e[10010], dd[10010];

void rec(int v, int p) {
    dd[d[v]].push_back(v);
    each(i,e[v]) if (i!=p) d[i] = d[v]+1, rec(i,v);
}

signed main() {
    cin >> n;
    rep(i,n-1) {
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b), e[b].push_back(a);
    }
    rep(i,n) cin >> c[i];
    sort(c,c+n), reverse(c,c+n);
    rec(0,-1);
    int id = 0;
    rep(i,10010) each(j,dd[i]) res[j] = c[id++];
    cout << accumulate(c+1,c+n,0ll) << endl;
    rep(i,n) cout << res[i] << bln(i,n);
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static class Triple implements Comparable<Triple> {
	// 	public int A, B, C;
	// 	Triple(int A, int B, int C) {
	// 		this.A = A;
	// 		this.B = B;
	// 		this.C = C;
	// 	}

	// 	@Override
	// 	public String toString() {
	// 		return String.format("(%d, %d, %d)", A, B, C);
	// 	}

	// 	@Override
	// 	public int compareTo(Triple o) {
	// 		int a = this.A - o.A;
	// 		if (a != 0) return a;
	// 		int b = this.B - o.B;
	// 		if (b != 0) return b;
	// 		return this.C - o.C;
	// 	}
	// }

	final static long MOD = 2019;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();
		long L2 = L % MOD;
		long len = Math.min(R - L, MOD);
		long R2 = L2 + len;
		// System.out.format("%d %d %n", L2, R2);

		long min = MOD - 1;
		for (long i = L2; i <= R2; i++) {
			for (long j = i + 1; j <= R2; j++) {
				min = Math.min(min, i * j % MOD);
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n;
  cin >> n;
  vector<int> p(n), a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) p[i] = i + 1;

  int k = 0, A, B;
  do {
    if (a == p) A = k;
    if (b == p) B = k;
    ++k;
  } while (next_permutation(p.begin(), p.end()));
  cout << abs(A - B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> inv(max(n + 1, 4));
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= max(n, 3); i++) {
    inv[i] = mod - (ll) mod / i * inv[mod % i] % mod;
  }
  int ans = 0, coef = inv[n];
  for (int i = 0; i < n; i++) {
    coef = (ll) coef * inv[3] % mod;
    ans = (ans + (ll) coef * inv[n - i]) % mod;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4096
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

typedef long long ll;
// #define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k){
    cout << "Yay!" << endl;
  } else cout << ":(" << endl;
  
  return 0;
}

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

int main()
{
    int a, b;
    double c;
    double rad, pi = acos(-1);
    double S, L, h;

    cin >> a >> b >> rad;

    if( rad < 90 )
    {
        if( a == b )
            c = a;
        else if( a > b )
            c = sqrt( pow( a*sin(rad*pi/180), 2 ) + pow( b-a*cos(rad*pi/180), 2 ) );
        else
            c = sqrt( pow( b*sin(rad*pi/180), 2 ) + pow( a-b*cos(rad*pi/180), 2 ) );
        S = a * sin(rad*pi/180) * b / 2;
        L = a + b + c;
        h = b * sin(rad*pi/180);
    }
    else if( rad > 90 )
    {
        if ( a > b )
        {
            c = sqrt( pow(a*sin((180-rad)*pi/180),2) + pow( b+a*cos((180-rad)*pi/180),2 ) );
            S = b*a*sin((180-rad)*pi/180)/2;
            h = b*sin((180-rad)*pi/180);
        }
        else
        {
            c = sqrt( pow(b*sin((180-rad)*pi/180),2) + pow( a+b*cos((180-rad)*pi/180),2 ) );
            S = a*b*sin((180-rad)*pi/180)/2;
            h = a*sin((180-rad)*pi/180);
        }
        L = a + b + c;
    }
    else
    {
        if( a > b )
            h = b;
        else
            h = a;
        c = sqrt(a*a+b*b);
        S = a * b / 2;
        L = a + b + c;
    }

    cout << fixed;
    cout << setprecision(11) << S << endl;
    cout << L << endl;
    cout << h << endl;

    return 0;
}


Measured memory_bytes: 3484
def print_rectangle(h, w):
    """
    h: int
    w: int
    outputs rectangle using '#'

    >>> print_rectangle(3, 4)
    ####
    ####
    ####
    >>> print_rectangle(5, 6)
    ######
    ######
    ######
    ######
    ######
    >>> print_rectangle(2, 2)
    ##
    ##
    """
    for i in range(h):
        print('#' * w)


if __name__ == '__main__':
    #import doctest
    #doctest.testmod()

    while True:
        (h, w) = [int(i) for i in input().split(' ')]
        if h == 0 and w == 0:
            break
        print_rectangle(h, w)
        print()

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

int main(){
	int n;
	cin >> n;
    vector<string> s(n);
    vector<bool> flg(n, 0);
    for(int i=0; i<n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());

    long long ans=0, tmp=1;
    string l=s[0];
    for(int i=1; i<n; i++){
        if(s[i]==l) tmp++;
        else{
            ans += tmp*(tmp-1)/2;
            tmp=1;
            l=s[i];
        }
    }
    ans += tmp*(tmp-1)/2;
    
	cout << ans << endl;
}

Measured memory_bytes: 7296
#include<stdio.h>

#define N 15

int main(){

  int n;
  //char str[N][N]=;
    char str[N];
  int a[5]={0};
  
  scanf("%d",&n);
  
  //while( n ){}

  for(int i=0; i<n; i++){
  scanf("%s",str);
  if( !strcmp("AC",str ) ) a[0]++;
  else if( !strcmp("WA",str) ) a[1]++; 
  else if( !strcmp("TLE",str ) )a[2]++;
  else if( !strcmp("RE",str ) )a[3]++;
  }
  
printf("AC x %d\n",a[0]);
printf("WA x %d\n",a[1]);
printf("TLE x %d\n",a[2]);
printf("RE x %d\n",a[3]);
  
  
return 0;
}


/*
AC x 10
WA x 0
TLE x 0
RE x 0
*/

/*
6
AC
TLE
AC
AC
WA

array index order 
AC x 3
WA x 1
TLE x 2
RE x 0

*/

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

N = int(input().strip())
d_list = list(map(int, input().rstrip().split()))
#-----

sum=0
for i in range(N-1):
    for j in range(i+1,N):
        calc = d_list[i] * d_list[j]
        sum += calc

print(sum)


Measured memory_bytes: 2940
#include <iostream>
 
using namespace std;
 
int main(){
  int A,B,C,X;
  int count = 0;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; ++i) {
    if (500*i > X) {
      break;
    }
    for (int j=0; j <= B; ++j) {
      if (500*i + 100*j > X) {
        break;
      }
      for (int k=0; k <= C; ++k) {
        if (500*i + 100*j + 50*k == X) {
          ++count;
          break;
        }
      }
    }
  }
END:
	cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	private static Set<Integer> heihosu;

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

			int[][] x = new int[n][d];
			for (int i = 0; i < n; i++) {
				for(int j = 0; j < d; j++) {
					x[i][j] = sc.nextInt();
				}
			}

			setHeihosu();

			int result = 0;
			for (int i = 0; i < n - 1; i++) {
				for (int j = i + 1; j < n; j++) {
					if (calc(x[i], x[j])) {
						result++;
					}
				}
			}
			System.out.println(result);
		}
	}

	private static boolean calc(int[] a, int[] b) {
		int tmp = 0;
		for (int i = 0; i < a.length; i++) {
			tmp += (a[i] - b[i]) * (a[i] - b[i]);
		}

		return heihosu.contains(tmp);
	}

	private static void setHeihosu() {
		heihosu = new HashSet<Integer>();
		for (int i = 0; i < 1000; i++) {
			heihosu.add(i * i);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    string s;cin>>s;
    bool can = true;
    if(s[0] != 'A') can = false;
    else {
        int i;
        for(i = 1; i < (int)s.size(); i++){
            if(s[i] == 'C') break;
        }
        if(i >= (int)s.size() - 1 || i == 1) can = false;
        else{
            for(int j = 1; j < (int)s.size(); j++){
                if(j == i) continue;
                if(s[j] < 'a') can = false;
            }
        
        }
    }    
    cout << (can ? "AC" : "WA") << endl;
    return 0;
    
}

Measured memory_bytes: 256
// Hack it and have it ;) //
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows!* * * * * * */
#include      <bits/stdc++.h>
using namespace std;
#define IOS       ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC      cout.precision (10); cout << fixed
#ifdef CONVICTION
#include "/home/convict/Dropbox/myfiles/sport_coding/cplib/snippets/debug.h"
#else
#define debug(x...)
#endif
//Don’t practice until you get it right. Practice until you can’t get it wrong

void preproc() {
}

void solve() {
   char ch;
   cin >> ch;
   if (ch - 'A' >= 0 and ch - 'A' <= 25) {
      cout << "A\n";
   }
   else {
      cout << "a\n";
   }
}

signed main() {
  IOS; PREC;
  preproc();

  int tc = 1;
  // cin >> tc;
  for (int Tt = 1; Tt <= tc; ++Tt) {
    // cout << "Case #" << Tt << ": ";
    solve();
  }
  return EXIT_SUCCESS;
}


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

int main() { // a * b / gcd(a,b) = lcd(a,b)
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int a, b, c; cin >> a >> b >> c;
	int t = c / a;
	cout << b * t << '\n';





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ld long double

using namespace std;

const int mod = (int)1e9 + 7;
const int maxn = (int)2e6;
int fac[maxn];


int binpow(int a, int p){
    if(p == 0)return 1;
    if(p % 2 == 0){
        int k = binpow(a, p / 2);
        return (k * k) % mod;
    } else {
        return (a * binpow(a, p - 1)) % mod;
    }
}

void prepare(){
    fac[0] = 1;
    for(int i = 1; i < maxn; ++i){
        fac[i] = (fac[i - 1] * i) % mod;
    }
}

inline int rev(int a){
    return binpow(a, mod - 2);
}


int c(int n, int k){
    //cerr << n << " " << k << "\n";
    assert(n >= 0 && k >= 0 && n - k >= 0);
    return ((fac[n] * rev(fac[n - k])) % mod * rev(fac[k]) % mod);
}





void solve(){
    prepare();
    int n;
    cin >> n;
    if(n == 2){
        cout << 1 << "\n";
        return;
    }
    int ans = 0;
    int prv = 0;
    int num = 0;
    vector < int > a(n);
    for(int i = (n + 1) / 2; i <= n - 1; ++i){
        a[i] = (c(i - 1, n - i - 1) * ((fac[i] * fac[n - i - 1]) % mod)) % mod;
    }
    for(int i = (n + 1) / 2; i <= n - 1; ++i){
        ans = ((ans + ((a[i] - a[i - 1] + mod) % mod) * i) % mod) % mod;
    }
    cout << ans << "\n";
}




signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        cin >> t;
    #endif
    for(int i = 0; i < t; ++i){
        solve();
    }
}


Measured memory_bytes: 23680
def search(b, s, e, t):
    if e - s == 1:
        return s

    mid = (e + s) // 2

    if b[mid] <= t:
        return search(b, mid, e, t)
    else:
        return search(b, s, mid, t)

INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

ans = 0
j = M
for i, va in enumerate(a):
    if va > K:
        break
    index = search(b, 0, len(b), K-va)
    ans = max(i+index, ans)
print(ans)






Measured memory_bytes: 47660
a,b,c,d=map(int,input().split())
x=c-a;y=d-b
l=['R','L','U','D']
t=''
for j in range(2):
  for i in range(x):
    t+=l[j]
  for i in range(y):
    t+=l[j+2]
for j in range(2):
  t+=l[3-j]
  for i in range(x+1):
    t+=l[j]
  for i in range(y+1):
    t+=l[j+2]
  t+=l[1-j]
print(t)

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

string s;

int main(void)
{
	cin >> s;
	
	bool used[3];
	while(1){
		bool flag = false;
		string t;
		for(int i = 0; i < 3; i++) used[i] = false;
		for(int i = 0; i < s.size(); i++){
			if(i+2 < s.size() && s.substr(i, 3) == "ABC"){
				t += "x";
				i += 2;
				flag = true;
				continue;
			}
			t += s[i];
			used[s[i]-'A'] = true;
		}
		if(t == "x"){
			cout << "Yes" << endl;
			return 0;
		}
		if(!flag){
			cout << "No" << endl;
			return 0;
		}
		
		llint x = 3, cnt = 0;
		for(int i = 0; i < 3; i++){
			if(used[i]) cnt++, x -= i;
		}
		if(cnt != 2){
			cout << "No" << endl;
			return 0;
		}
		for(int i = 0; i < t.size(); i++){
			if(t[i] == 'x') t[i] = (char)(x+'A');
		}
		s = t;
	}
	
	return 0;
}


Measured memory_bytes: 3228
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let k: usize = s.trim().parse().unwrap();
    let (t, v) = make_table(k);
    let ans = get_ans(k, &t, &v);
    println!("{}", ans);
}

fn get_ans(n: usize, t: &Vec<Vec<usize>>, v: &Vec<usize>) -> usize {
    let mut ans = 0;
    for i in 1..(n+1) {
        for j in 1..(n+1) {
            ans += v[i] * t[i][j];
        }
    }
    ans
}

fn make_table(n: usize) -> (Vec<Vec<usize>>, Vec<usize>) {
    let mut t = vec![vec![0; n+1]; n+1];
    let mut v = vec![0; n+1];
    let mut c;
    for i in 1..(n+1) {
        for j in 1..(n+1) {
            c = calc_table(i, j, &t);
            t[i][j] = c;
            v[c] += 1;
        }
    }
    (t, v)
}

fn calc_table(i: usize, j: usize, t: &Vec<Vec<usize>>) -> usize {
    if t[i][j] > 0 {
        return t[i][j];
    } else if i % j == 0 {
        return j;
    } else {
        return calc_table(j, i%j, &t);
    }
}


Measured memory_bytes: 2460
#include<bits/stdc++.h>
using namespace std;
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> data(h,vector<char>(w) );
  for ( int i = 0 ; i < h ; i++ ) {
    for ( int j = 0 ; j < w ; j++ ) {
      cin >> data.at(i).at(j);
    }
  }
  
  vector<int> a(0),b(0);
  
  
  for ( int i = 0 ; i < h ; i++ ) {
    for ( char j : data.at(i)  ){
      if (j=='#'){
        a.push_back(i);
        break;
      }
    }
  }
  
  for ( int j = 0 ; j < w ; j++ ) {
    for ( int i = 0 ; i < h ; i++   ){
      if (data.at(i).at(j)=='#'){
        b.push_back(j);
        break;
      }
    }
  }
  
  for ( int i = 0 ; i < a.size() ; i++ ) {
    for ( int j = 0 ; j < b.size() ; j++ ) {
      cout << data.at(a.at(i)).at(b.at(j));
    }
    cout << endl;
  }
}

Measured memory_bytes: 256