akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

int main() {
    int K;
    long long sum = 0;
    cin >> K;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    char a;
    string s;
    cin>>s;
    map<string,int>p;
    a=s[s.size()-1];
    p[s]++;
    for(int i=0;i<n-1;i++){
        cin>>s;
        if(a==s[0] && p[s]==0){
            a=s[s.size()-1];
            p[s]++;
        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

int main()
{
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    
    vector<int> L(Q), R(Q);
    for(int i = 0; i < Q; i++) {
        cin >> L[i] >> R[i];
    }
    
    vector<int> sum(N + 1, 0);
    for (int i = 1; i < N; i++) {
        if (S[i - 1] == 'A' && S[i] == 'C') {
            sum[i + 1] = sum[i] + 1;
        }else{
            sum[i + 1] = sum[i];
        }
    }
    for (int i = 0; i < Q; i++) {
        int ans = sum[R[i]] - sum[L[i]];
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 2304
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import heapq
    n = int(readline())
    dist = [[INF] * n for _ in range(n)]
    hq = []
    table = [[0] * n for _ in range(n)]

    for i in range(n):
        a = list(map(int, readline().split()))
        for j in range(i + 1, n):
            hq.append((a[j], i, j))
            table[i][j] = a[j]
            dist[i][j] = a[j]
            dist[j][i] = a[j]

    for i in range(n):
        dist[i][i] = 0

    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
                    dist[j][i] = dist[i][j]

    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] != table[i][j]:
                print(-1)
                sys.exit()

    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(n):
                if k != i and k!= j:
                    if dist[i][j] == dist[i][k] + dist[k][j]:
                        break
            else:
                ans += dist[i][j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 82120
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N];
bitset<N> sum;
int n,k;
bool judge(int mid)
{
	if(a[mid]>=k) return  1;
	sum.reset();sum[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(i!=mid)
			sum|=(sum<<a[i]);//求a[i]的前缀和sum1，即把sum的前sum1位均赋值1
	}
	for(int i=k-a[mid];i<=k-1;i++)
	{
		 if(sum[i]) return 1;
	}
	return 0;
	
}
int main()
{
	
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int l=1,r=n+1;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(judge(mid))
			r=mid;
		else
			l=mid+1;
	}
	cout<<l-1<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] abc = new int[3];
    for (int i = 0; i < 3; i++) {
      abc[i] = sc.nextInt();
    }
    int k = sc.nextInt();
    Arrays.sort(abc);
    for (int i = 0; i < k; i++) {
      abc[2] *= 2;
    }
    System.out.println(abc[0] + abc[1] + abc[2]);
  }

}


Measured memory_bytes: 21844
//#include<bits/stdc++.h>
//using namespace std;
//int dis[100005];
//int n;
//vector<int>vec[100005];
//void dfs(int i)
//{
//	dis[i]=1;
//	for(int j=0;j<vec[i].size();j++)
//		if(dis[vec[i][j]]==0)
//		{
//			dfs(vec[i][j]);
//			dis[i]+=dis[vec[i][j]];
//		}
//}
//vector<int>ans;
//bool vis[100005],ok;
//void dfs2(int x)
//{
//	vis[x]=1;
//	if(!ok)ans.push_back(x);
//	if(x==n)
//	{
//		ok=1;
//		return;
//	}
//	for(int i=0;i<vec[x].size();i++)
//		if(!vis[vec[x][i]])
//			dfs2(vec[x][i]);
//	if(!ok)ans.pop_back();
//}
//int main()
//{
//	cin>>n;
//	for(int i=0;i<n-1;i++)
//	{
//		int x,y;
//		cin>>x>>y;
//		vec[x].push_back(y);
//		vec[y].push_back(x);
//	}
//	dfs(1);
////	for(int i=1;i<=n;i++)
////		cout<<dis[i]<<' ';
////	cout<<endl;
//	dfs2(1);
//	int x=ans[(ans.size()+1)/2];
////	for(int i=0;i<ans.size();i++)
////		cout<<ans[i]<<' ';
////	cout<<endl;
//	x=dis[x];
//	if(x>=n-x)cout<<"Snuke";
//	else cout<<"Fennec";
//	return 0;
//}

#include<bits/stdc++.h>
using namespace std;
int n,p[100005],sz[100005],cnt1,col[100005];
vector<int>vec[100005];
void dfs(int x)
{
	sz[x]=1;
	for(int i=0;i<vec[x].size();i++)
	{
		if(vec[x][i]!=p[x])
		{
			p[vec[x][i]]=x;
			dfs(vec[x][i]);
			sz[x]+=sz[vec[x][i]];
		}
	}
}
void dfs2(int x)
{
	cnt1++;
	for(int i=0;i<vec[x].size();i++)
		if(vec[x][i]!=p[x]&&col[vec[x][i]]==0)
			dfs2(vec[x][i]);
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	dfs(1);
	vector<int>path;
	int c=n;
	while(c>0)
	{
		path.push_back(c);
		c=p[c];
	}
	reverse(path.begin(),path.end());
//	int l=0,r=0;
//	int i=0,j=path.size()-1;
//	while(i<=j)
//	{
//		l+=path[i++];
//		if(i<=j)r+=path[j--];
//	}
//	if(l>r)cout<<"Fennec";
//	else cout<<"Snuke";
	for(int i=(path.size()+1)/2;i<path.size();i++)
		col[path[i]]=1;
//	for(int i=0;i<path.size();i++)
//		cout<<path[i]<<' ';
//	cout<<endl;
//	for(int i=1;i<=n;i++)
//		cout<<col[i]<<' ';
//	cout<<endl;
	dfs2(1);
	int cnt2=n-cnt1;
//	cout<<cnt1<<' '<<cnt2<<endl;
	if(cnt1>cnt2)cout<<"Fennec";
	else cout<<"Snuke";
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

template<typename T>
struct edge {
    int src, to;
    T cost;

    // to, costで初期化
    edge (int to, T cost) : src(-1), to(to), cost(cost) {}

    // src, to, costで初期化
    edge (int src, int to, T cost) : src(src), to(to), cost(cost) {}

    // toにxを代入？
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    // edge()でtoを返す？
    operator int() const {return to;}
};

template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<Edges<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

struct BipartiteMatching {
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;

  BipartiteMatching(int n) : graph(n), alive(n, 1), used(n, 0), match(n, -1), timestamp(0) {}

  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int idx) {
    used[idx] = timestamp;
    for(auto &to : graph[idx]) {
      int to_match = match[to];
      if(alive[to] == 0) continue;
      if(to_match == -1 || (used[to_match] != timestamp && dfs(to_match))) {
        match[idx] = to;
        match[to] = idx;
        return true;
      }
    }
    return false;
  }

  int bipartite_matching() {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return ret;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      if(i < match[i]) {
        cout << i << "-" << match[i] << endl;
      }
    }
  }
};


int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vector<P> a(n), b(n);
  REP(i, n) {
    cin >> a[i].fi >> a[i].se;
  }
  REP(i, n) {
    cin >> b[i].fi >> b[i].se;
  }

  BipartiteMatching bm(2*n);
  REP(i, n) {
    REP(j, n) {
      if(a[i].fi < b[j].fi && a[i].se < b[j].se) {
        bm.add_edge(i, n + j);
      }
    }
  }
  
  cout << bm.bipartite_matching() << endl;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];
    int m=1e8;
   int a=k-1;
   if((n-1)%a==0)cout<<(n-1)/a<<endl;
   else cout<<((n-1)/a)+1<<endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  ull a; double b;
  cin >> a >> b;
  ull bb = b * 100 + 0.5;
  ull ans = a*bb;
  ans /= 100;
  cout << ans << endl;
  return 0;
}


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

int main() {
    int A[3][3];

    cin >> A[0][0] >> A[0][1] >> A[0][2];
    cin >> A[1][0] >> A[1][1] >> A[2][2];
    cin >> A[2][0] >> A[2][1] >> A[2][2];

    int N;

    cin >> N;

    int b[N];

    for(int i = 0; i < N; i++) {
        cin >> b[i];
    }


    int r[3][3] = {{0,0,0},{0,0,0},{0,0,0}};

    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < N; k++) {
                if(A[i][j] == b[k]) {
                    r[i][j] = 1;
                }
            }
        }
    }

           if(r[0][0] && r[0][1] && r[0][2]) {
        cout << "Yes" << endl;
    } else if(r[1][0] && r[1][1] && r[2][2]) {
        cout << "Yes" << endl;
    } else if(r[2][0] && r[2][1] && r[2][2]) {
        cout << "Yes" << endl;
    } else if(r[0][0] && r[1][0] && r[2][0]) {
        cout << "Yes" << endl;
    } else if(r[0][1] && r[1][1] && r[0][2]) {
        cout << "Yes" << endl;
    } else if(r[0][2] && r[2][2] && r[2][2]) {
        cout << "Yes" << endl;
    } else if(r[0][0] && r[1][1] && r[2][2]) {
        cout << "Yes" << endl;
    } else if(r[0][2] && r[1][1] && r[2][0]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
class BIT:
    def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

    def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & (-i)
        return s


def main():
    from string import ascii_lowercase
    import sys
    input = sys.stdin.readline

    N = int(input())
    s = input().rstrip()
    Q = int(input())

    conv = {c: i for i, c in enumerate(ascii_lowercase)}
    s = [conv[c] for c in s]

    bs = [BIT(N) for _ in range(26)]
    for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

    ans = []
    for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 146464
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void init(){
	for(int i=0;i<MAX_V;i++)G[i].clear();
	for(int i=0;i<MAX_V;i++)rG[i].clear();
	for(int i=0;i<MAX_V;i++){
		cmp[i]=0;
		used[i]=0;
	}
}

void add_edge(int from,int to){
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v){
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
		if(!used[G[v][i]])dfs(G[v][i]);
	vs.push_back(v);
}

void rdfs(int v,int k){
	used[v]=true;
	cmp[v]=k;
	for(int i=0;i<rG[v].size();i++)
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
	memset(used,0,sizeof(used));
	vs.clear();
	for(int v=0;v<V;v++)
		if(!used[v])dfs(v);

	memset(used,0,sizeof(used));
	int k=0;
	for(int i=vs.size()-1;i>=0;i--)
		if(!used[vs[i]])rdfs(vs[i],k++);

	return k;
}

int main(){
	while(cin>>V,V){
		init();
		double p[101];
		for(int i=0;i<V;i++){
			int a;
			cin>>p[i]>>a;
			for(int j=0;j<a;j++){
				int k;
				cin>>k;
				k--;
				add_edge(i,k);
			}
		}
		int use[101]={};
		int k=scc();
		//cout<<k<<endl;
		vector<int> P[101];
	
		for(int i=0;i<V;i++){
			//cout<<cmp[i]<<endl;
			P[cmp[i]].push_back(i);
			for(int j=0;j<G[i].size();j++){
				if(cmp[G[i][j]]!=cmp[i])use[cmp[G[i][j]]]=1;
			}
		}
	
		vector<double> ans;
		for(int i=0;i<k;i++){
			if(use[i])continue;
			double tt;
			for(int j=0;j<P[i].size();j++){
				if(j==0)tt=p[P[i][j]];
				else{
					tt*=p[P[i][j]];
				}
			}
			ans.push_back(1-tt);
		}
	
		double sum;
		for(int i=0;i<ans.size();i++){
			if(i==0)sum=ans[i];
			else{
				sum*=ans[i];
			}
		}
		printf("%lf\n",sum);
	}
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	ll c;
	cin >> n >> c;
	ll x[n], v[n];
	for(int i=0; i<n; i++) cin >> x[i] >> v[i];

	ll l[n], r[n], s=0, ans=0;
	for(int i=0; i<n; i++){
		s+=v[i];
		l[i]=s-x[i];
		ans=max(ans, l[i]);
	}
	for(int i=0; i<n; i++){
		r[i]=s+v[i]-c-l[i];
		ans=max(ans, r[i]);
	}

	ll ml[n], mr[n];
	ml[1]=l[0];
	mr[n-2]=r[n-1];
	for(int i=2; i<=n-1; i++) ml[i]=max(ml[i-1], l[i-1]);
	for(int i=n-3; i>=0; i--) mr[i]=max(mr[i+1], r[i+1]);
	for(int i=0; i<=n-2; i++){
		ans=max(ans, l[i]-x[i]+mr[i]);
	}
	for(int i=1; i<=n-1; i++){
		ans=max(ans, r[i]-(c-x[i])+ml[i]);
	}

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

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

#define int long long
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; }

signed main(){
	int s, w;
	cin >> s >> w;
	if(s <= w){
		cout << "unsafe" << endl;
	}else{
		cout << "safe" << endl;
	}

	return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	vector<int> inp(3);
	rep(i, 3) cin >> inp[i];
		
	cout << sum(inp) - max(inp) << endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}

int sum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int min(vector<int> v) {
	int min = INT32_MAX;
	for(auto it = v.begin();it != v.end();it++) 
		min = std::min(min,*it);
	return min;
}
int max(vector<int> v) {
	int max = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (auto&& e : s) {
    cin >> e;
  }
  int res = 1e9;
  for (int bt = 0; bt < 1 << (h - 1); ++bt) {
    vector<int> p{0};
    for (int i = 1; i < h; ++i) {
      if (bt >> (i - 1) & 1) {
        p.push_back(i);
      }
    }
    p.push_back(h);
    int n = p.size() - 1;
    int cur = n - 1;
    int l = 0, r = 0;
    while (l < w) {
      vector<int> c(n);
      while (r < w) {
        for (int t = 0; t < n; ++t) {
          for (int i = p[t]; i < p[t + 1]; ++i) {
            c[t] += s[i][r] == '1';
          }
        }
        if (*max_element(begin(c), end(c)) > k) {
          break;
        }

        ++r;


      }
if (l == r) {
        cur = 1e9;
        break;
      }
      l = r;
      cur += l < w;
    }
    res = min(res, cur);
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;

struct UnionFind {
    vi dt; // 根なら要素数*(-1), 子なら親の番号が入る
    UnionFind(int n) : dt(n, -1) {}

    // 根の頂点番号を返す
    int root(int v){
        if (dt[v] < 0) return v;
        return dt[v] = root(dt[v]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x,y);
        dt[x] += dt[y]; // 要素数を増やす (ただし負で計算)
        dt[y] = x; // 小さい方のグループ y の親を大きい方のグループ x に
        return true;
    }

    int size(int v) {return -dt[root(v)];}

    bool isConnect(int x, int y) {return root(x) == root(y);}
};

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


  int N,M,K; cin>>N>>M>>K;

  UnionFind uf(N);
  vi frd(N, 0);
  REP(i,M) {
    int A,B; cin>>A>>B;
    A--;B--;
    uf.unite(A,B);
    frd[A]++;
    frd[B]++;
  }

  vi ene(N, 0);
  REP(i,K) {
    int C,D; cin>>C>>D;
    C--;D--;
    if (uf.isConnect(C,D)){
      ene[C]++;
      ene[D]++;
    }
  }

  REP(i,N) {
    int cand = uf.size(i) - 1 - frd[i] - ene[i];
    printf("%d%c", cand, i==N-1 ? '\n' : ' ');
  }


  return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#include <string.h>

int main(void)
{
    char len1[5], len2[5];
    char tmp1, tmp2;
    int hit, blow, i, j;

    scanf("%s %s",len1, len2);

    while (strcmp(len1, "0")) {
        hit = 0;
        blow = 0;
        for (i = 0; i < 4; i++) {
            if (len1[i] == len2[i]) {
                hit++;
            }
        }
        for (i = 0; i < 4; i++) {
            for (j = 0; j < 4; j++) {
                if (len1[i] == len2[j]) {
                    blow++;
                }
            }
        }
        printf("%d %d\n",hit, blow-hit);
        scanf("%s %s",len1, len2);
    }
    return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <cstdlib>
#include<string>
#include<stdlib.h>
using namespace std;

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


int main()
{
    string a,b;
    
    cin>>a>>b;
    if((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0]))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
        
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>
using namespace std;

int main(void){
    // Your code here!
    int n, m;
    int count[50] = {};
    
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        count[a-1]++;
        count[b-1]++;
    }
    
    for(int i = 0; i < n; i++)
        cout << count[i] << endl;
        
    return 0;
        
}

Measured memory_bytes: 256
s = input()
t = input()

sc = {}
tc = {}

for i in range(len(s)):
    if s[i] in sc:
        sc[s[i]].append(i)
    else:
        sc[s[i]] = [i]

    if t[i] in tc:
        tc[t[i]].append(i)
    else:
        tc[t[i]] = [i]

sc = list(sc.values())
tc = list(tc.values())

print("Yes" if sc == tc else "No")

Measured memory_bytes: 19944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int[] dp = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1] - h[0]);
		for(int i = 2; i < n; i++) {
			dp[i] = Math.min(dp[i - 2] + Math.abs(h[i] - h[i - 2]), dp[i - 1] + Math.abs(h[i] - h[i - 1]));	
		}
		System.out.println(dp[n - 1]);
	}

}


Measured memory_bytes: 50868
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>S;
    int ls = S.size();
    ll ans = 0;
    int nbc = 0;
    bool fc = false;
    for(int i = ls-1; i >= 0; --i){
        char s = S.at(i);
        if(s == 'A'){
            if(!fc){
                ans += nbc;
            }else{
                nbc = 0; 
            }
            //cout<<ans<<i+1<<endl;
            fc = false;
        }
        if(s == 'B'){
            if(fc) {
                ++nbc;
            }else{
                nbc = 0;
            }
            fc = false;
        }
        if(s == 'C'){
            if(fc) nbc = 0;
            fc = true;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

int l;
char z[220000];
void work () {
	int i , t , ans;
	scanf ( "%s" , z + 1 );
	l = strlen ( z + 1 );
	t = ans = 0;
	for ( i = 1 ; i <= l ; i++ ) {
		if ( z[i] == 'S' ) t++;
		else {
			if ( t > 0 ) t--, ans++;
		}
	}
	printf ( "%d\n" , l - ans * 2 );
}
int main () {
	work ();
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int a; string s;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>s;
    if(a>=3200) cout<<s<<'\n';
    else cout<<"red"<<'\n';
    return 0;
}


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

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

#define SCAN_INT(n) scanf("%i",&n)
#define SCAN_P_INT(n,m) scanf("%i %i",&n,&m)
#define PRINT_P_INT(n,m) printf("%i %i\n",n,m);
#define PRINT_INT(n) printf("%i\n",n)


#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 1000000007


#define MAXSIZE 

int c[11][11];
int h,w;
int wynik = 0;

int main(){
	SCAN_P_INT(h,w);
	REP(i,10)
		REP(j,10)
			SCAN_INT(c[i][j]);
		
	
	FOR(k,0,9){
		FOR(i,0,9){
			FOR(j,0,9){
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
			}
		}
	}
	
	REP(i,h){
		REP(j,w){
			int temp;
			SCAN_INT(temp);
			if(temp!=-1){
				wynik+=c[temp][1];
			}
		}
	}
	PRINT_INT(wynik);
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin, a, b, c;
    ll sum = c - a - b;
    if (sum < 0) {
        cout << "No" << endl;
        return 0;
    } else {
        if (4 * a * b < sum * sum) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
	char s[4];
  	scanf(" %s", s);
  	int ans = 0;
  	for (int i = 0; i < 3; i++) {
      	if (s[i] == '1') {
         	ans += 1; 
        }
    }
  
  	printf("%d\n", ans);
}

Measured memory_bytes: 128
/*
Aldew
PROB: Fencing
CLASSIFICATION:
DIFFICULTY:
*/

#include <bits/stdc++.h>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;

using namespace std;

//void io()
//{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
//}

vector <int> factors(int x) {
    vector <int> result;
    int i = 1;
    while(i*i <= x) {
        if(x % i == 0) {
            result.push_back(i);
            if(x/i != i) {
                result.push_back(x/i);
            }
        }
        i++;
    }
    return result;


}
unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


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

    int a = 0;
    while (a < n){
        a += 1000;
    }
    cout << a - n << endl;



    return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

main() {
  char a;
  int top, n, e, w, s, sum, x;
  int i, time;
  while(scanf("%d", &time) != EOF) {
    if(time == 0) break;

    n=5;
    e=3;
    w=4;
    s=2;
    top = sum = 1;
    for(i=0 ; i<time ; i++) {
      while(1) {
	scanf("%c", &a);
	if(a == 'N' || a == 'E' || a == 'W' || 
	   a == 'S' || a == 'R' || a == 'L') break;
      }
      
      if(a == 'N') {
	x=top;
	top=7-n;
	n=x;
	s=7-n;
	sum+=top;
      }
      else if(a == 'E') {
	x=top;
	top=7-e;
	e=x;
	w=7-e;
	sum+=top;
      }
      else if(a == 'W') {
	x=top;
	top=7-w;
	w=x;
	e=7-w;
	sum+=top;
      }
      else if(a == 'S') {
	x=top;
	top=7-s;
	s=x;
	n=7-s;
	sum+=top;
      }
      else if(a == 'R') {
	x=n;
	n=w;
	w=s;
	s=e;
	e=x;
	sum+=top;
      }
      else if(a == 'L') {
	x=n;
	n=e;
	e=s;
	s=w;
	w=x;
	sum+=top;
      }

    }
    while(a != '\n') {
	scanf("%c", &a);
	}
    printf("%d\n", sum); 
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer,Integer> map = new TreeMap<>();
		for(int i = 0;i < N;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(map.containsKey(b)) {
				map.put(b, map.get(b)+a);
			}else {
				map.put(b, a);
			}
		}
		sc.close();
		int sum = 0;
		String ans = "Yes";
		for(Map.Entry<Integer, Integer> entry : map.entrySet()) {
			sum += entry.getValue();
			if(sum > entry.getKey()) {
				ans = "No";
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 120260
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int tmp;
    if(N>=K)
      tmp = N - K;
    else {
        tmp = 0;
        K = N;
    }
    P(K*X+tmp*Y);
    return 0;
}



Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

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

    int h,w;
    cin>>h>>w;

    int dp[1005][1005]={};
    char mas[1005][1005];
    reps(i,h){
	reps(j,w){
	    cin>>mas[i][j];
	}
    }

    dp[1][1]++;
    reps(i,h){
	reps(j,w){

	    if(mas[i][j]!='#'){
		dp[i][j]+=dp[i-1][j]+dp[i][j-1];
		dp[i][j]%=1000000007;
	    }
	
	}
    }

    cout<<dp[h][w]<<'\n';
    return 0;
}


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

int h, w, l;
const int INF = 1e18 + 1;

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

string s = "NESW";

bool contain(int y, int x){
	return (0 <= y && y < h && 0 <= x && x < w);
}

struct State{
	int y, x, dr;
};

signed main(){
	while(1){
		cin >> h >> w >> l;
		if(h + w + l == 0) break;
		int sy, sx;
		char c[110][110], cc;
		rep(i, 0, h){
			rep(j, 0, w){
				cin >> c[i][j];
				if(c[i][j] != '.' && c[i][j] != '#'){
					sy = i; sx = j; cc = c[i][j];
				}
			}
		}
		int dir = s.find(cc);
		/*State next[110][110][4];
		rep(i, 0, h){
			rep(j, 0, w){
				rep(k, 0, 4){
					int ny = i + dy[k];
					int nx = j + dx[k];
					if(!co
				}
			}
		}*/
		int d[110][110][4];
		rep(i, 0, h) rep(j, 0, w) rep(k, 0, 4) d[i][j][k] = INF;
		d[sy][sx][dir] = 0;
		int y = sy, x = sx;
		int roop = -1;
		int roop_st = -1;
		int cnt = 0;
		while(1){
			int ny, nx, ndir;
			rep(i, 0, 4){
				ny = y + dy[(dir + i) % 4];
				nx = x + dx[(dir + i) % 4];
				ndir = (dir + i) % 4;
				if(!contain(ny, nx) || c[ny][nx] == '#') continue;
				break;
			}
			if(d[ny][nx][ndir] != INF){
				roop_st = d[ny][nx][ndir];
				roop = d[y][x][dir] + 1 - d[ny][nx][ndir]; break;
			}
			//cout << ny << " " << nx << " " << s[ndir] << " " << endl;
			d[ny][nx][ndir] = d[y][x][dir] + 1;
			cnt = d[ny][nx][ndir];
			y = ny; x = nx; dir = ndir;
		}
		if(cnt < l){
			l = roop_st + (l - roop_st) % roop;
		}
		rep(i, 0, h) rep(j, 0, w) rep(k, 0, 4) if(d[i][j][k] == l){
			cout << i + 1 << " " << j + 1 << " " << s[k] << endl; j = w; i = h; break;
		}
		//cout << "======" << endl;
	}
}

Measured memory_bytes: 3556
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, k, h, ans = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &h);
    if (h >= k)
      ans++;
  }
  printf("%d\n", ans);
}

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

int main() {
  int N;
  cin >> N;
  map<pair<int,int>,int> mp;
  vector<pair<int,int>> pe(N);
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    pe[i]=make_pair(x,y);
  }
  sort(pe.begin(),pe.end());
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      pair<int,int> p=make_pair(pe[i].first-pe[j].first,pe[i].second-pe[j].second);
      mp[p]++;
    }
  }
  int mc=0;
  for(auto p:mp){
    if(p.second>mc)mc=p.second;
  }
  cout << N-mc;
}






Measured memory_bytes: 384
A,B, K = map(int, input().split())
def divisor(n):
    div_list = []
    for i in range(1, int(1+ n**0.5)):
        if n%i == 0 and i**2 == n:
            div_list.append(i)
        elif n%i == 0:
            div_list.append(i)
            div_list.append(int(n/i))
    return div_list
lnA = divisor(A)
lnB = divisor(B)
ln = []
for i in lnA:
    if i in lnB:
        ln.append(i)
line = sorted(ln, reverse = True)
print(line[K - 1])

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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int a,b,c;cin >>a>>b>>c;
  if(a+b+c>21)cout << "bust" << endl;
  else cout << "win" << endl;

}


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

int main()
{
    long long n;
cin>>n;
    string str;
    long long a=0,b=0,c=0,d=0;
for(int i=0; i<n; i++)
{
    cin>>str;
    transform(str.begin(), str.end(),str.begin(), ::toupper);

    if(str=="AC")
        a++;
    else if(str=="WA")
        b++;
    else if(str=="TLE")
    c++;
    else if(str=="RE")
        d++;
        else
            continue;
}
cout<<"AC x"<<" "<<a<<endl;
cout<<"WA x"<<" "<<b<<endl;
cout<<"TLE x"<<" "<<c<<endl;
cout<<"RE x"<<" "<<d<<endl;

}

Measured memory_bytes: 3608
n = int(input())
s1 = list(str(input()))

s2 = list(reversed(s1))

s1s = [0]*(n+1)
s2s = [0]*(n+1)

for i in range(n):
  if s1[i] == 'W':
    s1s[i+1] = s1s[i]+1
  else:
    s1s[i+1] = s1s[i]
  
  if s2[i] == 'E':
    s2s[i+1] = s2s[i]+1
  else:
    s2s[i+1] = s2s[i]

min_s = 3*10**5+1
for j in range(n):
  min_s = min(min_s, s1s[j]+s2s[n-1-j])
print(min_s)

Measured memory_bytes: 65904
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  int n;
  cin>>n;
  int a[n];
  bool flag=true;
  map<int,int> mp;
  REP(i,n){
    cin>>a[i];
    mp[a[i]]++;
    if(a[i]>0){
      flag = false;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(n%3 != 0){
    cout<<"No"<<endl;
    return 0;
  }
  
  int cnt=0;
  vector<int> temp;
  for(auto p:mp){
    if(p.second>0){
      cnt++;
      temp.push_back(p.first);
      if(cnt>3){
        break;
      }
    }
  }
  
  int x=0;
  flag = false;
  if(cnt>3 || cnt==1){
    cout<<"No"<<endl;
  }else if(cnt==2){
    if(mp[0]>0){
      REP(i,(int)temp.size()){
        if(temp[i] !=0){
          if(mp[temp[i]]==2*mp[0]){
            flag = true;
          }
        }
      }
      if(flag){
        cout<<"Yes"<<endl;
      }else{
        cout<<"No"<<endl;
      }
    }else{
      cout<<"No"<<endl;
    }
  }else{
    REP(i,(int)temp.size()){
      x ^= temp[i];
    }
    if(x==0 && mp[temp[0]]==mp[temp[1]] && mp[temp[1]]==mp[temp[2]]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 4224
N,M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

cnt = 0
sum = A.inject(:+)

A.each do |a|
    cnt += 1 if a >= sum * (1 / (4.to_f * M))
end

if cnt >= M
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	vector<int> dp(n,inf);
	dp[0] = 0;
	rep(i, n - 1)
	{
		for (int j = k - 1; j >= 0;j--){
			if (i - j >= 0)
				dp[i + 1] = min(dp[i + 1], dp[i - j] + abs(h[i + 1] - h[i - j]));
		}
	}
	cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=200000+5;
const ll oo=1e18+5;
const ll mod=998244353;

vector<pair<int,int>> v[55];
ll dp[55][2505];

struct node{
	ll val;
	int id,sum;
	node(ll val,int id,int sum): val(val),id(id),sum(sum) {}
};

void min_self(int& a,int b){
	if(a>b) a=b;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	const int maxx=2500;
	int n,m,s;
	cin>>n>>m>>s;
	vector<int> a(105),b(105),c(55),d(55);
	for(int i=0;i<m;++i){
		int x,y;
		cin>>x>>y>>a[i]>>b[i];
		--x;
		--y;
		v[x].push_back({y,i});
		v[y].push_back({x,i});
	}
	for(int i=0;i<n;++i) cin>>c[i]>>d[i];
	min_self(s,maxx);
	for(int i=0;i<n;++i){
		for(int j=0;j<=maxx;++j) dp[i][j]=oo;
	}
	queue<node> Q;
	dp[0][s]=0;
	Q.push({0,0,s});
	while(!Q.empty()){
		node ele=Q.front();
		Q.pop();
		int idx=ele.id;
		int coin=ele.sum;
		if(ele.val>dp[idx][coin]) continue;
		int n_coin=min(maxx,coin+c[idx]);
		if(dp[idx][n_coin]>dp[idx][coin]+d[idx]){
			dp[idx][n_coin]=dp[idx][coin]+d[idx];
			Q.push({dp[idx][n_coin],idx,n_coin});
		}
		for(pair<int,int> x:v[idx]){
			int xx=x.first;
			int idd=x.second;
			if(coin<a[idd]) continue;
			if(dp[xx][coin-a[idd]]>dp[idx][coin]+b[idd]){
				dp[xx][coin-a[idd]]=dp[idx][coin]+b[idd];
				Q.push({dp[xx][coin-a[idd]],xx,coin-a[idd]});
			}
		}
	}
	for(int i=1;i<n;++i){
		ll ans=oo;
		for(int coin=0;coin<=maxx;++coin){
			ans=min(ans,dp[i][coin]);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 5360
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int a[4];
int final;
int main()
{
	int i;
	for(i=1;i<=3;i++)
	  scanf("%d",&a[i]);
	sort(a+1,a+4);
	for(i=2;i<=3;i++)
	  final+=abs(a[i]-a[i-1]);
	printf("%d",final);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long 
#define MOD 1000000007
 
using namespace std;
 
signed main(){
 
    int N;
    string s;

    cin >>N;
    cin >>s;

    int r=0;
    int b=0;

    for(auto c:s){
        if(c=='R'){
            r++;
        }
        else{
            b++;
        }
    }

    if(r>b){
        cout <<"Yes"<<endl;
    }

    else{
        cout <<"No"<<endl;
    }

 	return 0;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#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 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
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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;

struct Edge{
    // 始点, 終点, 重み, 最大量
    long long src, dst, weight, capacity;
    Edge(): src(0), dst(0), weight(0), capacity(0) {}
    Edge(long long s, long long d, long long w): src(s), dst(d), weight(w) {}
    Edge(long long s, long long d, long long w, long long c): src(s), dst(d), weight(w), capacity(c) {}
};

class Graph{
public:
    long long size;
    vector<vector<Edge>> node;
    Graph(long long n): size(n), node(n) {}
    // 無向辺の追加
    void addEdge(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
        node[d].emplace_back(d, s, w);
    }
    // 有向辺の追加
    void addArc(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
    }
    // ノードの追加
    void addNode(){
        size++;
        node.emplace_back();
    }
};

// TopologicalSort; トポロジカルソート
// ：有向非巡回グラフ（DAG）の全ての辺が右向きになるように整列する。[O(E+V)]
vector<long long> TopologicalSort(const Graph &g){
    vector<long long> indegree(g.size), sorted;
    for(long long v=0; v<g.size; v++) for(auto &edge: g.node[v]) indegree[edge.dst]++;
    queue<long long> que;
    for(long long i=0; i<g.size; i++) if(indegree[i] == 0) que.push(i);
    while(!que.empty()){
        long long v = que.front();
        que.pop();
        sorted.emplace_back(v);
        for(auto &edge: g.node[v]) if (--indegree[edge.dst] == 0) que.push(edge.dst);
    }
    return *max_element(indegree.begin(), indegree.end()) == 0LL ? sorted : vector<long long>();
}

// DAGMaxDistance; DAGにおける最大距離の計算
// ：TopologicalSortによる整列順に巡回し、最大距離を計算する。
long long maxDistance(const Graph &g, const vector<long long> &sorted){
    vector<long long> dp(g.size, 0);
    long long maxDist = 0;
    for(auto &v: sorted){
        for(auto &edge: g.node[v]){
            chmax(dp[edge.dst], dp[v]+1);
            chmax(maxDist, dp[edge.dst]);
        }
    }
    return maxDist;
}

int main(){
    Init();
    ll n, m; cin >> n >> m;
    Graph g(n);
    rep(i, m){
        ll x, y; cin >> x >> y; x--; y--;
        g.addArc(x, y, 1);
    }
    auto sorted = TopologicalSort(g);
    cout << maxDistance(g, sorted) << endl;
}

Measured memory_bytes: 9720