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

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

		int n = sc.nextInt();
		int y = sc.nextInt();
	    int a = -1;
	    int b = -1;
	    int c = -1;
		
		for(int i=0;i<=n;i++) {
			for(int j=0;j<=n-i;j++) {
				if( 10000*i + 5000*j + 1000*(n-i-j) == y ) {
					a = i;
					b = j;
					c = n-i-j;
				}
			}
		}
		System.out.println(a + " " + b + " " + c);
	}
}


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

using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
const int N=1e5+5;///1e18+5

void solve()
{
    int a,b,c;
    int x;
    cin>>a>>b>>c>>x;
    for(int i=0; i<x; i++)
    {
        if(c<=b || c<=a)
        {
            c=c*2;
            continue;
        }
        if(b<=a && b<c)b=b*2;
    }
    //cout<<a<<' '<<b<<' '<<c<<endl;
    if(c>b && b>a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main()
{
   // freopen("input.txt","r",stdin);
    IO;

    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}


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

void solve(int A, int B){
    int ans = -1;
    for(int x = 1; x <= 10000; x++){
        if(floor((double)x*0.08) == A && floor((double)x*0.10) == B){
            ans = x;
            break;
        }
    }
    cout << ans << endl;
    return;
}

int main(){
    int A;
    scanf("%id",&A);
    int B;
    scanf("%id",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3680
N, K, Q = map(int, input().split())
scores = [0] * N
i = 0
while i < Q:
    ans = int(input()) - 1
    scores[ans] += 1
    i += 1
for x in scores:
    if (K - (Q - x)) > 0:
        print("Yes")
    else:
        print("No")


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

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

    string s;
    cin >> s;

    int cnt[n + 1] = {};

    for (int i = 1; i < s.length(); i++) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            cnt[i] = cnt[i - 1] + 1;
        } else {
            cnt[i] = cnt[i - 1];
        }
    }

    int l[q], r[q];
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < q; i++) {
        cout << cnt[r[i] - 1] - cnt[l[i] - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, X;
    cin >> N >> X;
    ll A = X, B = N - X;
    if(A < B) swap(A, B);
    ll ret = 0;
    while(A > 0 && B > 0){
        ll num = A / B;
        ret += num * 3 * B;
        ll tA = B;
        ll tB = A % B;
        A = tA, B = tB;
    }
    
    output(ret, 0);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//万能头文件
using namespace std;
string a;
int main()
{
    cin>>a;//输入字符串
    bool flag=false;//定义标记变量
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C')
            flag=true;//如果碰到‘C’，就标记一下
        if(a[i]=='F')
            if(flag)//碰到‘F’，判断‘C’有没有出现过
            {
                cout<<"Yes"<<endl;//如果出现，就输出
                exit(0);//终止程序
            }
            else
                continue;//如果没有出现过，继续寻找
    }
    cout<<"No"<<endl;//输出“No”
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,j,i,k;
  cin>>n;
  vector<int>a(n);
  for(i=0;i<n;i++)
    cin>>a[i];

  for(int i=0;i<n;i++)
    {
    int x=a[i];
    int j=i-1;
    while(j>=0&&a[j]>x)
    {
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=x;
    for(k=0;k<n-1;k++)
    cout<<a[k]<<" ";
    cout << a[n-1]<<endl;
  }
 
}




Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int abs(int a)
{
    if(a>=0) return a;
    else return -a;
}

int main()
{
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++) cin >> h[i];
    int dp[n];
    for(int i=0;i<n;i++) dp[i]=0;
    dp[n-2]=abs(h[n-1]-h[n-2]);
    for(int i=n-3;i>=0;i--) dp[i]=min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]));
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
  long long n;
  cin >> n;
  long long sum = n * (n + 1) / 2;
  sum -= n / 3 * (n / 3 + 1) / 2 * 3;
  sum -= n / 5 * (n / 5 + 1) / 2 * 5;
  sum += n / 15 * (n / 15 + 1) / 2 * 15;
  cout<<sum<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
int main() {
	int h, w;
	std::cin >> h>> w;
	std::vector<std::vector<char>>v(h, std::vector<char>(w));
	for (int i = 0; i < h; ++i)for (int j = 0; j < w; ++j)std::cin >> v[i][j];
	for (int i = 0; i < w + 2; ++i)std::cout << "#";
	std::cout << "\n";
	for (int i = 0; i < h; ++i) { for (int j = 0; j < w + 2; ++j) { (j == 0 || j == w + 1) ? std::cout << "#" : std::cout << v[i][j-1]; }std::cout << "\n"; }
	for (int i = 0; i < w + 2; ++i)std::cout << "#";
	std::cout << "\n";
	return 0;
}

Measured memory_bytes: 256
//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define DP_maxn 16
#define maxn 1000000+10
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

int n,a[30];
int ans = 1;

int main(){
	cin>>n;
	for(int i = 1;i<=n;i++) cin>>a[i];
	for(int i = 2;i<=n;i++){
		for(int j = 1;j<=i;j++){
			if(j == i){
				ans++;
			}
			if(a[i] >= a[j]) continue;
			else break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[105], p = 1;
int main(){
	scanf("%i", &n);
	for(int i=0;i<n;i++){
		scanf("%i", &a[i]);
		if(a[i] % 2 == 1) p *= 1;
		else p *= 2;
	}
	long long ans = (pow(3, n) - p);
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
a, b = [int(x) for x in input().split()]

if a > 0:
    print("Positive")
elif a * b <= 0:
    print("Zero")
elif (b - a + 1) % 2 == 0:
    print("Positive")
else:
    print("Negative")

# print(*data, sep='\n')


Measured memory_bytes: 38256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b >= c) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n,i,j,k,s=0,c=1,x=1,t;
    cin>>n;
    for(i=0;i<=n;i++)
    {
              if(i%3==0 || i%5==0)
                   continue;
                   else s+=i;
    }
    cout<<s;
}


Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()
ans = 0
val = 0
for ch in s:
  if ch == "I":
    val += 1
    ans = max(ans, val)
  elif ch == "D":
    val -= 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

void printvec(vi& x, int size = 0) {
    if (x.size() == 0) {
        cout << endl;
        return;
    }
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    int q;
    cin >> q;
    while (q--) {
        int b, m, e;
        cin >> b >> m >> e;
        rotate(as.begin() + b, as.begin() + m, as.begin() + e);
    }

    printvec(as);
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
        using namespace std;
        #define ll long long int
        int main()
        {
              std::ios_base::sync_with_stdio(false);
    		cin.tie(0); cout.tie(0);
         	int n,k;
          	cin>>n>>k;
          	ll arr[n],dp[n+2];
          	for(int i=0;i<n;i++)
            cin>>arr[i];
          	dp[0]=0;
          	dp[1]=abs(arr[0]-arr[1]);
          	for(int i=2;i<n;i++)
            {
              	int min = INT_MAX;int ans=INT_MAX;
         		for(int j=1;j<=k;j++)
                {
                  if(i-j>=0)
                  ans = dp[i-j]+abs(arr[i]-arr[i-j]);
                  if(ans<min)
                  min=ans;
         		}
              dp[i]=min;
            }
                    cout<<dp[n-1];
        	return 0;
        }

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main() {
    char s[11];
    scanf("%s",s);
    int len = strlen(s);
    int num,dif,min = 999;
    for(int count = 0;count < len - 2;count++) {
        num = (s[count] - '0') * 100 + (s[count+1] - '0') * 10 + (s[count+2] - '0');
        if(num < 753) dif = 753 - num;
        else dif = num - 753;
        if(dif < min) min = dif;
    }
    printf("%d\n",min);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAX_N=20000;
int par[MAX_N];
int height[MAX_N];

void init(int n)
{
	for(int i=0;i<n;i++)
	{
		par[i]=i;
		height[i]=0;
	}
}

int root(int x)
{
	if(par[x]==x)return x;
	else return par[x]=root(par[x]);
}

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

void unite(int x,int y)
{
	x=root(x);
	y=root(y);
	if(x==y)return;
	if(height[x]<height[y])par[x]=y;
	else
	{
		par[y]=x;
		if(height[x]==height[y])height[x]++;
	}
}

int main()
{	
	int n,q,a,b,c;
	cin>>n>>q;
	init(n);
	for(int i=0;i<q;i++)
	{
		cin>>a>>b>>c;
		if(a==0)unite(b,c);
		else
		{
			if(same(b,c))cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	return 0;	
}


Measured memory_bytes: 3188
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline ll read() {
    ll res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n, m, solved, penalty;
bool vis[N];
int cnt[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int p;
        char s[5];
        scanf("%d %s", &p, s);
        if (s[0] == 'W') {
            if (!vis[p]) cnt[p]++;
        } else {
            if (!vis[p]) {
                vis[p] = true;
                solved++;
                penalty += cnt[p];
            }
        }
    }
    printf("%d %d\n", solved, penalty);
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
    #define ll long long 
    using namespace std;
     
    int n;
    bool b=true;
    int main(){
    	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++){
        	cin>>arr[i];
    	}
    	sort(arr,arr+n);
    	for(int i=0;i<n-1;i++){
    		if(arr[i]==arr[i+1]){
    			cout<<"NO"<<endl;
    			b=false;
    			break;
    		}
    	}
    	if(b)
        cout<<"YES"<<endl;
        
        
        
    	return 0;
    }

Measured memory_bytes: 1024
// C - Attention
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; string S; cin>>N>>S;
	int w = 0;
	int count = 0;
	rp(i, 0, N){
		if(S[i]=='W') w++;
		else if(w>0){
			w--;
			count++;
		}
	}
	cout<< count <<endl;
}

Measured memory_bytes: 900
(let ((n (read))
      (m (read))
      (q (read))
      (a (make-array '(600 600) :element-type 'integer
                                :initial-element 0
                                :adjustable t))
      l r)
  (loop repeat m do
        (setf l (read))
        (setf r (read))
        (incf (aref a r l)))
  (loop for i from 1 upto n do
        (loop for j from 1 upto n do
              (incf (aref a i (1+ j)) (aref a i j))
              (incf (aref a i j) (aref a (1- i) j))))
  (loop repeat q do
        (setf l (read))
        (setf r (read))
        (format t "~A~%" (- (+ (aref a (1- l) (1- l)) (aref a r r)) (+ (aref a r (1- l)) (aref a (1- l) r))))))


Measured memory_bytes: 62496
s=input()
n=int(input())
cnt=0
left=[]
right=[]
for _ in range(n):
    tmp=input()
    if tmp[0]=="1":
        cnt+=1
    else:
        num,side,st=tmp.split()
        if side=="1":
            if cnt%2==0:
                left.append(st)
            else:
                right.append(st)
        else:
            if cnt%2==0:
                right.append(st)
            else:
                left.append(st)
left="".join(left)
left=left[::-1]
right="".join(right)
s=left+s+right
if cnt%2==1:
    s=s[::-1]
print(s)

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

struct LowLink {
    struct Edge {
        int to;
        Edge(int to) : to(to) { }
    };
    vector<vector<Edge>> graph;
    int v;
    vector<int> used, order, low_link, articulation_points;
    vector<pair<int, int>> bridges;
    LowLink(int v) : v(v), graph(v),  used(v, 0), order(v, 0), low_link(v, 0) {}
    void add_edge(int start, int to) {
        graph[start].emplace_back(to);
        graph[to].emplace_back(start);
    }
    void build() {
        int current_order = 0;
        for (int i = 0; i < v; ++i) {
            if (!used[i]) current_order = dfs(i, current_order, -1);
        }
    }
    int dfs(int id, int current_order, int parent) {
        used[id] = true;
        order[id] = current_order++;
        low_link[id] = order[id];
        bool is_articulation_points = false;
        int child_count = 0;
        for (Edge& e : graph[id]) {
            if (!used[e.to]) {
                ++child_count;
                current_order = dfs(e.to, current_order, id);
                low_link[id] = min(low_link[id], low_link[e.to]);
                if (parent != -1 && order[id] <= low_link[e.to]) is_articulation_points = true;
                if (order[id] < low_link[e.to]) bridges.emplace_back(id, e.to);
            } else {
                if (e.to != parent) {
                    low_link[id] = min(low_link[id], order[e.to]);
                }
            }
        }
        if (parent == -1 && child_count >= 2) is_articulation_points = true;
        if (is_articulation_points) articulation_points.push_back(id);
        return current_order;
    }
};

/*
    verified http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
    verified http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A&lang=jp
*/
int main() {
    int V, E; cin >> V >> E;
    LowLink low_link(V);
    for (int i = 0; i < E; ++i) {
        int s, t; cin >> s >> t;
        low_link.add_edge(s, t);
    }
    low_link.build();

    // birdges
    // for (auto& bridge : low_link.bridges) if (bridge.first > bridge.second) swap(bridge.first, bridge.second);
    // std::sort(low_link.bridges.begin(), low_link.bridges.end());
    // for (auto bridge : low_link.bridges) {
    //     cout << bridge.first << " " << bridge.second << endl;
    // }

    // articulation_points
    std::sort(low_link.articulation_points.begin(), low_link.articulation_points.end());
    for (auto articulation_point : low_link.articulation_points) {
        cout << articulation_point << endl;
    }
}



Measured memory_bytes: 4432
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        final var scanner = new Scanner(System.in);
        final var n = scanner.nextLine();
        final var A = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        final var A_set = new HashSet(A);

        final var counter = new HashMap<Integer, Integer>();
        for (var a : A) {
            counter.merge(a, 1, Integer::sum);
        }

        var count = 0;
        for (var a : A) {
            if (counter.get(a) > 1) {
                count += 1;
                continue;
            }

            var i = 1;
            while (i * i <= a) {
                if (a % i == 0) {
                    if (A_set.contains(i) && i != a) {
                        count += 1;
                        break;
                    }
                    if (i != (a / i)) {
                        if (A_set.contains(a / i) && (a / i) != a) {
                            count += 1;
                            break;
                        }
                    }
                }
                i += 1;
            }
        }
        System.out.println(A.size() - count);
    }
}


Measured memory_bytes: 92540
/*
Code By: Sai Harsha K
 */

#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main() {
#ifndef ONLINE_JUDGE
  // these lines to be executed in local machine not online judge
  // get input
  freopen("input.txt", "r", stdin);
  // put output
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false); cin.tie(NULL);

  // solution
  int t = 1;
  while(t--) {
    int n, W;
    cin>>n>>W;
    int w[n], v[n];
    for(int i = 0; i < n; i++) {
      cin>>w[i]>>v[i];
    }
    // we always check i-1 for when calculating i, no need to use dp[n][W] actually.
    vector<lli> dp(W+1, 0);
    // populate dp
    for(int i = 0; i < n; i++) {
      // consider some x weight is already present in knapsack
      for(int weight_already = W-w[i]; weight_already >= 0; weight_already--) { // we can take item only once so this is correct
      // for(int weight_already = 0; weight_already <= W - w[i]; weight_already++) { // this is useful when we can take items multiple times
        dp[weight_already + w[i]] = max(dp[weight_already + w[i]], dp[weight_already] + v[i]);
      }
    }
    cout<<dp[W];
  }

  return 0;
}


Measured memory_bytes: 3968
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
	    long[] x = new long[n];
	    for(int i=0; i<n; i++) {
	        x[i] = Long.parseLong(sc.next());
            
	    }
	    long l, r;
	    long min = (long)Math.pow(10, 9)+7;
	    long count = 0;
	    for(int i=0; i<n-k+1; i++) {
	        l = x[i];
	        r = x[i+k-1];

            count = Math.min(Math.abs(l)+Math.abs(r-l), Math.abs(r)+Math.abs(r-l));

	        min = Math.min(min, count);
	    }
	    
	    if(min == (long)Math.pow(10, 9)+7) min = 0;
	    System.out.println(min);
    }
    
}

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

using namespace std;

int main()
{
    int no_of_stones, no_of_steps;
    cin >> no_of_stones >> no_of_steps;

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
        cin >> height[i];

    const int oo = 1e9;
    vector <int> minimum_cost(no_of_stones + 1, oo);
    minimum_cost[1] = 0;

    for(int i = 2; i <= no_of_stones; i++)
    {
        for(int j = i - 1; j >= max(1, i - no_of_steps); j--)
        {
            minimum_cost[i] = min(minimum_cost[i], minimum_cost[j] + abs(height[i] - height[j]));
        }
    }

    cout << minimum_cost[no_of_stones];
    return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String[] s = str.split("");
        int countR = 0;
        int countB = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i].equals("0"))
                countR++;
            else
                countB++;
        }
        System.out.println(Math.min(countR, countB) * 2);
    }
}


Measured memory_bytes: 33156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    n -= 400;
    n /= 200;
    cout << 8 -n << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
const long long INF = 1LL << 60;
using namespace std;

int main(int argc, char const *argv[])
{
    ll n, c;
    cin >> n >> c;
    ll last = n - 1;
    ll x[n], v[n];
    rep(i, n) cin >> x[i] >> v[i];
    ll sushir[n], sushil[n];
    sushir[0] = v[0];
    rep(i, 1, n) sushir[i] = sushir[i - 1] + v[i];

    sushil[last] = v[last];
    rep(i, 1, n) sushil[last - i] = sushil[last - i + 1] + v[last - i];

    ll sumr[n], suml[n];
    rep(i, n) sumr[i] = sushir[i] - x[i];
    rep(i, n) suml[last - i] = sushil[last - i] - (c - x[last - i]);

    ll posr[n], posl[n];
    ll bestr[n], bestl[n];
    bestr[0] = max(0ll, sumr[0]);
    posr[0] = x[0];

    rep(i, 1, n) if (bestr[i - 1] < sumr[i])
    {
        bestr[i] = sumr[i];
        posr[i] = x[i];
    }
    else
    {
        bestr[i] = bestr[i - 1];
        posr[i] = posr[i - 1];
    }

    bestl[n - 1] = max(0ll, suml[n - 1]);
    posl[last] = c - x[last];
    rep(i, 1, n) if (bestl[last - i + 1] < suml[last - i])
    {
        bestl[last - i] = suml[last - i];
        posl[last - i] = c - x[last - i];
    }
    else
    {
        bestl[last - i] = bestl[last - i + 1];
        posl[last - i] = posl[last - i + 1];
    };
    rep(i, n) cerr << "sushiR" << i << ":" << sushir[i] << endl;
    rep(i, n) cerr << "sushiL" << i << ":" << sushil[i] << endl;
    rep(i, n) cerr << "sumR" << i << ":" << sumr[i] << endl;
    rep(i, n) cerr << "sumL" << i << ":" << suml[i] << endl;
    rep(i, n) cerr << "bestR" << i << ":" << bestr[i] << endl;
    rep(i, n) cerr << "bestL" << i << ":" << bestl[i] << endl;
    rep(i, n) cerr << "posR" << i << ":" << posr[i] << endl;
    rep(i, n) cerr << "posL" << i << ":" << posl[i] << endl;

    ll ans = 0;
    rep(i, n - 1)
    {
        cerr << bestr[i] << " " << bestl[i + 1] << endl;
        ans = max(ans, bestr[i] + bestl[i + 1] - min(posr[i], posl[i + 1]));
    }
    rep(i, n)
    {
        ans = max(ans, bestr[i]);
        ans = max(ans, bestl[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10112
S=[i for i in range(1,14)]
H=[i for i in range(1,14)]
C=[i for i in range(1,14)]
D=[i for i in range(1,14)]

c=int(input())
for i in range(0,c):
    m,r=input().split()
    r=int(r)
    if m=="S":
        S.remove(r)
    elif m=="H":
        H.remove(r)
    elif m=="C":
        C.remove(r)
    elif m=="D":
        D.remove(r)

for i in S:
    print("S",i)
for i in H:
    print("H",i)
for i in C:
    print("C",i)
for i in D:
    print("D",i)
    


Measured memory_bytes: 5608
int main()
{
  int n, x;
  int i, j, k, count;

  while(1){
    scanf("%d %d", &n, &x);
    
    if(n == 0 && x == 0)
      break;

    count = 0;

    for(i = 1; i < n-1; i++){
      for(j = i+1; j < n; j++){
        for(k = j+1; k < n+1; k++){
          if(i+j+k == x)
            count++;
        }
      }
    }

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

  }

  return 0;
}

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

using namespace std;
using ll = long long;
const int MOD = 1e9+7;


int main(){
    string s;
    while(getline(cin, s)){
        if(s == "."){
            return 0;
        }
        stack<char> sta;
        bool f = true;
        for(char c : s){
            if(c == '('){
                sta.push(c);
            }
            if(c == ')'){
                if(sta.empty()){
                    f = false;
                    break;
                }
                if(sta.top() == '('){
                    sta.pop();
                }else{
                    f = false;
                    break;
                }
            }
            if(c == '['){
                sta.push(c);
            }
            if(c == ']'){
                if(sta.empty()){
                    f = false;
                    break;
                }
                if(sta.top() == '['){
                    sta.pop();
                }else{
                    f = false;
                    break;
                }
            }
        }
        if(!sta.empty())f = false;
        if(f){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
        s.clear();
    }
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll power(ll x, int p){
  ll res = 1;
  while(p--) res = res*x%mod;
  return res;
}
int main(){
  int n;
  cin >> n;
  ll ans = power(10, n)-power(9, n)-power(9, n)+power(8, n);
  ans %= mod;
  ans = (ans+mod)%mod;
  cout << ans << endl;
}

Measured memory_bytes: 3620
#![allow(unused)]

use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};
use std::{cmp, collections, fmt, io, iter, ops, str};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($fmt: expr) => { eprintln!($fmt) };
    ($fmt: expr, $($args: tt)*) => { eprintln!($fmt, $($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($fmt:expr) => {};
    ($fmt:expr, $($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let (a, b, c, d) = {
        let v = parse_vec::<i32>();
        (v[0], v[1], v[2], v[3])
    };

    let is_near = |x: i32, y: i32| -> bool { (x - y).abs() <= d };

    if is_near(a, c) || (is_near(a, b) && is_near(b, c)) {
        println!("Yes");
    } else {
        println!("No");
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn next_prime(x: i32) -> i32 {
    for i in (x + 1).. {
        if is_prime(i) {
            return i;
        }
    }

    panic!("attempt to add with overflow");
}

fn is_prime(x: i32) -> bool {
    let ceil = (x as f64).sqrt().ceil() as i32;
    x == 2 || (2..(ceil + 1)).all(|i| x % i != 0)
}


Measured memory_bytes: 4352
a = []
N = int(input())
min_v = 10**15 + 1
for i in range(5):
    v = int(input())
    min_v = min(min_v, v)

if N  % min_v == 0:
    print(N // min_v + 4)
else:
    print(N//min_v + 5)

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

int main(){
    int h,w;
    cin >> h >> w;
    
    vector<vector<char>> a(h,vector<char>(w));
    vector<vector<char>> b(h+2,vector<char>(w+2,'#'));
    
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    
    for(int i = 1; i < h + 1; i++){
        for(int j  = 1; j < w + 1; j++){
            b[i][j] = a[i-1][j-1];
        }
    }
    
    rep(i,h+2){
        rep(j,w+2){
            cout << b[i][j];
            if(j==w+1) cout << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 105;
const int maxm = 2005;
const int inf = 0x3f3f3f3f;
struct node{
	int to,w,Next;
}E[maxm];
int head[maxn],cnt;
void add(int x,int y,int w)
{
    E[cnt].to = y;
	E[cnt].w = w;
	E[cnt].Next = head[x];
	head[x] = cnt++;	
}
struct Node{
	int x,y,w;
	bool operator < (const Node nd) const 
	{
		return w > nd.w;
	}
};
int dis[maxn][maxm];
int vis[maxn][maxm];
void Dijstrea(int n,int m)
{
	memset(dis,inf,sizeof(dis));
	memset(vis,0,sizeof(vis));
	priority_queue <Node> pq;
	Node tmp;
	for(int i = 0; i <= m; i++)
	{
		tmp.x = 1;
		tmp.y = i;
		tmp.w = 0;
		pq.push(tmp);
		dis[1][i] = 0;
	}
	while(pq.size())
	{
		tmp = pq.top();
		pq.pop();
		if(vis[tmp.x][tmp.y]) continue;
		vis[tmp.x][tmp.y] = 1;
		for(int i = head[tmp.x]; i!=-1; i=E[i].Next)
		{
			int lv = tmp.y;
			int y = E[i].to;
			int w = E[i].w;
			if(dis[y][lv] > dis[tmp.x][lv]+w){
				dis[y][lv] = dis[tmp.x][lv]+w;
				Node nd;
				nd.x = y;
				nd.y = lv;
				nd.w = dis[y][lv];
				pq.push(nd);
			}
			if(lv < m)
			{
				if(dis[y][lv+1] > dis[tmp.x][lv])
				{
					dis[y][lv+1] = dis[tmp.x][lv];
					Node nd;
					nd.x = y;
					nd.y = lv+1;
					nd.w = dis[y][lv+1];
					pq.push(nd);
				}
			}
		} 
	}
}
int main()
{
    int n,m,c;
    while(scanf("%d%d%d",&n,&m,&c)&&m+n+c)
    {
         memset(head,-1,sizeof(head));
		 cnt = 0;
		 for(int i = 1; i <= m; i++)
		 {
		 	int x,y,w;
		 	scanf("%d%d%d",&x,&y,&w);
		 	add(x,y,w);
		 }     
		 Dijstrea(n,m);
		 for(int i = 0; i <= m; i++)
		 {
		 	if(dis[n][i] <= c){
		 		printf("%d\n",i);
		 		break;
		 	}
		 }   
    }
	return 0;
}


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

int w, h, cnt;
char cmp;
char field[50][50];
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };

int main(){
    while( cin >> w >> h && w ){
        for( int i = 0; i < h; i++ ){
            for( int j = 0; j < w; j++ ){
                cin >> field[i][j];
            }
        }
        int cnt_b = 0, cnt_w = 0;
        queue< pair<int, int> > Q;
        for( int i = 0; i < h; i++ ){
            for( int j = 0; j < w; j++ ){
                if( field[i][j] == '.' ){
                    field[i][j] = '#';
                    Q.push( pair<int,int>(j, i) );
                    cnt = 0;
                    cmp = '.';
                    bool ans = true;
                    while( !Q.empty() ){
                        cnt++;
                        for( int k = 0; k < 4; k++ ){
                            int x = Q.front().first + dx[k];
                            int y = Q.front().second + dy[k];
                            if( 0 <= x && x < w && 0 <= y && y < h && field[y][x] != '#' ){
                                if( field[y][x] == 'B' || field[y][x] == 'W' ){
                                    if( cmp == '.' ) cmp = field[y][x];
                                    else if( cmp != field[y][x] ) ans =  false;
                                }else if( field[y][x] == '.' ){
                                    field[y][x] = '#';
                                    Q.push( pair<int,int>(x, y) );
                                }
                            }
                        }
                        Q.pop();
                    }
                    if( ans ){
                        if( cmp == 'B' ){
                            cnt_b += cnt;
                        }
                        else if( cmp == 'W' ){
                            cnt_w += cnt;
                        }
                    }
                }
            }
        }
        cout << cnt_b << ' ' << cnt_w << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int n;
  long ans = 1;
  cin >> n;

  for(int i = 2; i <= n; i++) {
    ans *= i;
    ans %= (1000000000+7);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	ll X, Y;
	cin >> X >> Y;

	int ans = 0;
	while (X <= Y){
		ans++;
		Y /= 2;
	}

	cout << ans << endl;

	return 0;
}

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

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

int main() {
    int n, r;
    while (cin >> n >> r) {
        if (n == 0 && r == 0) break;
        vector<int> pile(n);
        repeat(i, n) {
            pile[i] = n-i;
        }
        repeat(i, r) {
            int p, c; cin >> p >> c;
            vector<int> after(n);
            repeat(j, p-1) {
                after[j+c] = pile[j];
            }
            for (int j = p-1; j < p+c-1; j++) {
                after[j-p+1] = pile[j];
            }
            for (int j = p+c-1; j < n; j++) {
                after[j] = pile[j];
            }
            pile = after;
        }
//        repeat(i, n) cout << pile[i] << ' ';
//        cout << endl;
        cout << pile[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s; 
  int num[26] = {0};
  
  for(int i = 0; i < s.length(); i++){
    num[s[i] - 'a']++;
  }
  
  for(int i = 0; i < 26; i++){
    if(num[i] > 0){
      //処理なし
    } else {
      cout << (char)(i + 'a') << endl;
      break;
    }
    if(i == 25){
      cout << "None" << endl;
      break;
    }
  }
}

Measured memory_bytes: 512
fun main(args:Array<String>) {
  val (n,a,b) = readLine()!!.split(" ").map { it.toLong() }
  (1..n).map { each ->
    val sum = each.toString().map { char ->
      char.toString().toLong()
    }.sum()
    when { 
      a <= sum && sum <= b -> each
      else -> 0
    }
  }.sum().let {
    println(it)
  }
}

Measured memory_bytes: 41724
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

int main() {
    FIO
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0; i<n; i++)
        cin>>arr[i];
    if(n == 1)
    {
        cout<<arr[0];
    }
    else if(n&1)
    {
        for(int i=n-1; i>=0; i-=2)
            cout<<arr[i]<<" ";
        for(int i=1; i<n; i+=2)
            cout<<arr[i]<<" ";
    }
    else
    {
        for(int i=n-1; i>=0; i-=2)
            cout<<arr[i]<<" ";
        for(int i=0; i<n; i+=2)
            cout<<arr[i]<<" ";
    }
    cout<<endl;
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll m,i,j,k,result=0;
  int n;
  int a[LIMIT2]={0},b[LIMIT1]={0};
  int c[LIMIT1]={0};
  map<int,int> dp1,dp2;
  string s;
  
  cin >> n;
  m=1;
  bool ng=false;
  rep(i,n){
    cin >> a[i];
    
    dp1[a[i]]++;
    c[a[i]]++;//個数
  }
  rep(i,n){
    cin >> b[i];
    
    dp2[b[i]]++;
    c[b[i]]++;//個数
    
    if(c[b[i]]>=n+1) ng=true;
  }
  if(ng){
    cout << "No" << endl;
    return 0;
  }
  result=1;
  j=0;
  
  auto itr = dp2.begin();
  rep(i,n){
    while(itr!=dp2.end() && a[i]==itr->first) itr++;
    if(itr==dp2.end()){
      itr = dp2.begin();
      while(itr!=dp2.end() && a[i]==itr->first) itr++;
      if(itr==dp2.end()){
        itr = dp2.begin();
        b[i] = itr->first;
        while(a[i]==b[j]) j++;
        std::swap(b[i],b[j]);
        j++;
        continue;
      }
    }
    //cout << itr->first << " " << itr->second << endl;
    b[i] = itr->first;
    dp2[b[i]] -= 1;
    if(dp2[b[i]]<=0){
      itr++;
      dp2.erase(dp2.find(b[i]));
      if(itr==dp2.end()) itr=dp2.begin();
    }
  }
  
  cout << (result==1 ? "Yes" : "No") << endl;
  if(result == 1){
    rep(i,n){
      cout << b[i] << (i==n-1 ? '\n' : ' ');
    }
  }
  return 0;
}


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

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int a,b,c;
  cin>>a>>b>>c;

  if((a+b==c) || (a+c==b) || (b+c==a))
  	cout<<"Yes";
  else
  	cout<<"No";


  return 0;
}

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

const int MAX = 1000000;
bool IsPrime[MAX];
vector<int> Eratosthenes(int n = MAX) {
    vector<int> res;    // prime numbers
    IsPrime[0] = false; IsPrime[1] = false;
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) if (IsPrime[i]) {
        res.push_back(i);
        for (int j = i * 2; j < n; j += i) IsPrime[j] = false;
    }
    return res;
}

int main() {
    vector<int> prime = Eratosthenes();
    vector<int> acc(prime.size() + 1, 0);
    for (int i = 0; i < prime.size(); i++) {
        acc[i + 1] = acc[i] + prime[i];
    }
    int n;
    while (cin >> n, n) {
        cout << acc[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 4312
solve :: Int -> Int -> [Int] -> Int
solve _ count [] = count
solve 0 count (x:xs) = solve x count xs
solve status count (x:xs)
  | status == x = solve status count xs
  | status /= x = solve 0 (count+1) xs

check :: [Int] -> [Int]
check [x] = []
check (x:y:xs)
  | y-x > 0 = 1 : check	(y:xs)
  | y-x < 0 = -1 : check (y:xs)
  | otherwise = check (y:xs)

main = do
  n <- getContents
  print $ solve 0 1 $ check $ map read $ tail $ words n

Measured memory_bytes: 2428
import sys
input = sys.stdin.readline

N,K = map(int,input().split())
H = [0]+list(map(int,input().split()))+[0]

DP=[[1<<60]*(K+1) for i in range(N+2)]

for k in range(K+1):
    DP[0][k]=0

for i in range(1,N+2):
    
    for k in range(K+1):
        for j in range(k+1):
            DP[i][k]=min(DP[i][k],DP[i-j-1][k-j]+max(0,H[i]-H[i-j-1]))
        
print(min(DP[-1]))


Measured memory_bytes: 44908
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);
void solve()
{
    cio;
    int n,m;
    cin >> n >> m;
    if(n%2==1){
        for(int i = 1; i <= n&&m; i++,m--){
            cout << i << " " << n-i << endl;
        }
        return;
    }
    int l = (n+1)/2;
    for(int i = 1; i <= l/2&&m; i++,m--){
        cout << i << " " << l-i+1 << endl;
    }
    for(int i = 1; m; i++,m--){
        cout << i+l << " " << n-i << endl;
    }
}
int main()
{
    solve();
    return 0;
}





Measured memory_bytes: 3656
#include<stdio.h>

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

        int tx=0, ty=0, a=1, b=1, ans=0;
        while(1){
                if(tx==x && ty==y) break;

                b += a;
                tx += b-1;
                ans++;
                if(tx-a<x && x<=tx && ty<=y && y<ty+a) break;

                a += b;
                ty += a-1;
                ans++;
                if(tx-b<x && x<=tx && ty-b<y && y<=ty) break;

                b += a;
                tx -= b-1;
                ans++;
                if(tx<=x && x<tx+a && ty-a<y && y<=ty) break;

                a += b;
                ty -= a-1;
                ans++;
                if(tx<=x && x<tx+b && ty<=y && y<ty+b) break;
        }

        printf("%d\n", ans%3+1);
        return 0;
}


Measured memory_bytes: 2148
#include "bits/stdc++.h"

#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define inp(x) (cin>>x,x)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

//#define lint long long
typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx9[9] ={ 0,1,1,1,0,0,-1,-1,-1 },
dy9[9] ={ 1,1,0,-1,0,-1,-1,0,1 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };

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

int main(){
	setc;
	
	lint x,a,b;cin>>x>>a>>b;
	x-=a;
	x=x-x/b*b;co(x);
	gc();
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> a( N );
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
		a[i]--;
	}

	int ans = 0;
	for( int i = 0; i < N; i++ ) {
		if( a[i] >= 0 ) {
			int j = a[i];
			if( a[j] >= 0 && a[j] == i ) {
				a[i] = -1;
				a[j] = -1;
				ans++;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    ax, ay, bx, by, cx, cy, dx, dy = (float(s) for s in line.split())

    tx, ty = (ax - bx, ay - by)
    sx, sy = (cx - dx, cy - dy)

    if round(tx * sy - ty * sx, 5) == 0.0:
        print('NO')
    elif round(tx * sx + ty * sy, 5) == 0.0:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 4296
#include <cstdio>
#include <cstring>
#include <cstdlib>

char s[200010];
int szS;

int main()
{
	scanf("%s", s);
	szS = strlen(s);
	int numOfBlack = 0;
	
	long long total = 0;
	
	for (int i = 0 ; i < szS ; i++)
	{
		if (s[i] == 'W')
			total = total + numOfBlack;
		else	//'B'
			numOfBlack++;
	}
	
	printf("%lld\n", total);
	return 0;
}

Measured memory_bytes: 384