akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    static int N;
    static long K;
    static Long[] A;
    static Long[] F;
    public static boolean isOK(long index) {
        long sum = K;
        int flag = 0;
        for (int i=0;i<N;i++) {
            if (index<F[i]*A[i]) {
                // sum -= Math.ceil((double)(F[i]*A[i]-index)/F[i]);
                sum -= (F[i]*A[i]-index)/F[i];
                if ((F[i]*A[i]-index)%F[i]!=0) {
                    sum--;
                }
            }
            if (sum<0) {
                flag = 1;
                break;
            }
        }
        if (flag==0) return true;
        // if (a[index] >= key) return true;
        else return false;
    }

    public static long binary_search() {
        long left = -1L;
        long right = 9223372036854775807L-1000000000L;

        while (right - left > 1) {
            long mid = left + (right - left) / 2;

            if (isOK(mid)) right = mid;
            else left = mid;
        }
        return right;
    }
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Comparator<Long> comparator = new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                return Long.compare(o2, o1);
            }
        };

        N = in.nextInt();
        K = in.nextLong();
        A = new Long[N];
        F = new Long[N];
        for (int i=0;i<N;i++) {
            A[i] = in.nextLong();
        }
        for (int i=0;i<N;i++) {
            F[i] = in.nextLong();
        }
        Arrays.sort(A, comparator);
        Arrays.sort(F);

        out.println(binary_search());

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}


Measured memory_bytes: 65492
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	s := 0
	a := make([]int, n)
	nc := make([]int, 100001)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		s += a[i]
		nc[a[i]]++
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		b := nextInt()
		c := nextInt()

		s += nc[b] * (c - b)
		nc[c] += nc[b]
		nc[b] = 0
		fmt.Println(s)
	}

}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 6216
#include <iostream>
#include <vector>
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int times(lli a) {
	int count = 0;
	while (a % 2 == 0) {
		count++;
		a /= 2;
	}
	return count;
}

int main(void)
{
	int N; cin >> N;
	vector<lli> a;
	rep(i, 0, N) {
		lli tmp; cin >> tmp;
		if (tmp % 2 == 0)a.push_back(tmp);
	}

	int ans = 0;
	rep(i, 0, a.size())ans += times(a[i]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
X, N = map(int, input().split(' '))
if N > 0:
    P = set(map(int, input().split(' ')))
else:
    P = set()

for n in range(102):
    if X - n not in P:
        print(X - n)
        break
    elif X + n not in P:
        print(X + n)
        break


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
int main()
{
ll n;
cin >> n ;
vector<vector<ll>> g(n);
//多重辺がないならsetでもよい（辺を消去したいときなど）この場合はinsert
//set<ll> g[n];
rep(i, n-1)
{
  ll a, b;
  cin >> a >> b;
  g[a - 1].push_back(b - 1);
  g[b - 1].push_back(a - 1); //無向辺
}
vector<ll> v(n+1);
v[0]=1;
rep(i,n){
  v[i+1]=mod(v[i]*2);
}

vector<vector<ll>> child(n);
vector<vector<ll>> num(n);
vector<ll> par(n);
vector<ll> sum(n);
queue<ll> q;
queue<ll> qq;
ll root=0;
q.push(root);
par[root]=-1;
//親の定義と葉を見つける
while(!q.empty()){
  ll p=q.front();
  q.pop();
  if(g[p].size()==1 && p!=root){qq.push(p);}
  for(auto r:g[p]){
    if(r==par[p])continue;
    par[r]=p;
    q.push(r);
  }
}
while(!qq.empty()){
  ll p=qq.front();
  qq.pop();
  child[par[p]].push_back(p);//親に値を追加する
  num[par[p]].push_back(sum[p]+1);
  sum[par[p]]+=sum[p]+1;
  //根の時は例外処理
  if(child[par[p]].size()==g[par[p]].size()){
    //child[par[p]]に子の値が入ってる
  }
  //全ての葉が親に追加し終わった
  if(child[par[p]].size()==g[par[p]].size()-1 && par[p]!=root){
    //child[par[p]]に子の値が入ってる
    qq.push(par[p]);
  }
}
rep(i,n){
  ll t=0;
  for(auto r:num[i]){
    t=mod(t+v[r]-1);
  }
  t=mod(t+v[n-sum[i]-1]);
  ans=mod(ans+v[n-1]-t);
}
cout << mod(ans*mypow(v[n],mo-2)) << endl;
return 0;
}

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

using namespace std;

int main()
{
    long long k, a[100001];
    cin >> k;
    for (int i = 1; i <= k; ++i)
        cin >> a[i];

    if (a[k] != 2) {
        cout << "-1";
        return 0;
    }
    long long inf = 2, sup = 3;
    for (int i = k - 1; i >= 1; --i) {
        if (inf % a[i] != 0)
            inf = (inf / a[i] + 1) * a[i];
        sup = (sup / a[i]) * a[i];
        if (inf > sup) {
            cout << "-1";
            return 0;
        }
        sup += a[i] - 1;
    }
    cout << inf << " " << sup;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
main(){
	string s;
	cin>>s;
	int cnt=0;
	string a="AIDUNYAN";
	sort(ALL(a));
	if(s.size()<8){
		cout<<s<<endl;
		return 0;
	}
	rep(i,s.size()-7){
		string t=s.substr(i,8);
		sort(ALL(t));
		if(t==a){
			s=s.substr(0,i)+"AIZUNYAN"+s.substr(i+8);
			i+=7;
		}
	}
	cout<<s<<endl;
}

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

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  if (A1+A2+A3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
program and_grid
  implicit none
  integer :: h, w, i, j, k
  integer :: r(500,500), b(500,500)
  character(500) :: s
  r = 0
  b = 0
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      if (s(j:j).eq."#") then
        r(i,j) = 1
        b(i,j) = 1
      end if
    end do
  end do
  r(1:h,1) = 1
  b(1:h,w) = 1
  do i = 1, h
    if (mod(i,2).eq.1) then
      r(i,2:w-1) = 1
    else
      b(i,2:w-1) = 1
    end if
  end do
  call output(r(1:h,1:w))
  write(*,*)
  call output(b(1:h,1:w))
  stop
contains
  subroutine output(a)
    implicit none
    integer, intent(in) :: a(:,:)
    integer :: h, w, i
    character(500) :: s
    h = size(a(:,1))
    w = size(a(1,:))
    do i = 1, h
      s = ""
      do j = 1, w
        s(j:j) = "."
        if (a(i,j).gt.0) s(j:j) = "#"
      end do
      write(*,'(a)') trim(adjustl(s))
    end do
    return
  end subroutine output
end program and_grid

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

int main(){ 
  int a,b;
  cin >> a >> b;
  if(a==1) a= 14;
  if(b==1) b= 14;

  if(a>b)      cout << "Alice"<< endl;
  else if(a<b) cout << "Bob"  << endl;
  else         cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    string s;
    cin >> s;
    
    if (s == "ABC") cout << "ARC" << '\n';
    else cout << "ABC" << '\n';
    
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;


public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String line1 = scanner.nextLine();
		scanner.close();
		String[] linestr =line1.split(" ",0);
		long cards = Long.parseLong(linestr[3]);
		long ans = 0;
		long[] cardsArr = new long[3];
		long[] ansArr = new long[3];
		
		for (int i = 0; i < 3; i++) {
			cardsArr[i] += Long.parseLong(linestr[i]);
		}

		for (int i = 0; i < 3; i++) {
			if (cards - cardsArr[i] >= 0) {
				cards = cards - cardsArr[i];
				ansArr[i] = cardsArr[i];
			} else {
				ansArr[i] = cards;
				break;
			}
		}
		ans = ansArr[0] * 1 + ansArr[1] * 0 + ansArr[2] * -1;
		System.out.println(ans);

	}
}


Measured memory_bytes: 35792
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String ans = "No";
    for(int i=1; i<10; ++i){
      for(int j=1; j<10; ++j){
        if(i*j == n) {
          ans = "Yes";
          i=10; j=10;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22100
N, M = gets.split.map(&:to_i)
C = Array.new(N + 2, 0)
M.times do 
  l,r = gets.split.map(&:to_i)
  C[l] += 1
  C[r + 1] -= 1
end
(1 .. N).each{|i| C[i] += C[i - 1]}
puts (1 .. N).count{|i| C[i] == M }


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

using namespace std;

int main(void){
  int N;
  cin >> N;
  int X;
  for(X = 0; X <= 50000; X++){
    if(108 * X / 100 == N) break;
  }
  if(X > 50000) cout << ":(" << endl;
  else cout << X << endl;
  return 0;
}


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

int main(){
	const int MAX_N = 1000;
	int N;
	string str;
	int dp[MAX_N][8];
	int pin[MAX_N], res;
	
	for(int i = 0; i < MAX_N; i++){
		for(int j = 0; j < 8; j++){
			dp[i][j] = 0;
		}
	}
	
	cin >> N;
	cin >> str;
	
	for(int i = 0; i < str.size(); i++){
		if(str[i] == 'J') pin[i] = 0;
		else if(str[i] == 'O') pin[i] = 1;
		else if(str[i] == 'I') pin[i] = 2;
	}
	
	for(int i = 0; i < 8; i++){
		if(i >> 0 & 1 && i >> pin[0] & 1) dp[0][i] = 1;
		else dp[0][i] = 0;
	}
	for(int i = 1; i < N; i++){
		for(int j = 0; j < 8; j++){
			for(int k = 0; k < 8; k++){
				if((j & k) && (j >> pin[i] & 1)){
					dp[i][j] += dp[i - 1][k];
				}
			}
			dp[i][j] %= 10007;
		}
	}
	
	res = 0;
	for(int i = 0; i < 8; i++) res += dp[N - 1][i];
	
	cout << res % 10007 << endl;
	
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n;
	cin >> n;
	double ans=0;
	double a;
	for(int i=0;i!=n;i++){
		cin >> a;
		ans+=1/a;
	}
	cout << setprecision(12) << 1/ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;

ll n,a,b,c,d;
string s;
string ans="Yes";
signed main() {
    cin>>n>>a>>b>>c>>d;
    cin>>s;
    if(d<c){
        ans="No";
        FOR(i,b,d+1)if(s[i]!='#'&&s[i-1]!='#'&&s[i-2]!='#')ans="Yes";
    }
    FOR(i,min(a,b),max(c,d)+1)if(s[i]=='#'&&s[i-1]=='#')ans="No";
    cout<<ans<<endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> m1(m);
    rep(i, m)
    {
        cin >> m1.at(i);
    }
    long long sum = 0;
    rep(i, m)
    {
        sum += m1.at(i);
    }
    if (sum > n)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n - sum << endl;
    }
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int a,b;
  cin >> a >> b;
  cout << "100 100" << endl;
  a--,b--;
  for(int i=0;i<50;i++){
    if(i%2){
      for(int j=0;j<50;j++){
        cout << ".";
        if(b>0) cout << "#",b--;
        else cout << ".";
      }
    }else{
      for(int j=0;j<50;j++){
        cout << "..";
      }
    }
    cout << endl;
  }
  for(int i=0;i<50;i++){
    if(i%2){
      for(int j=0;j<50;j++){
        cout << "#";
        if(a>0) cout << ".",a--;
        else cout << "#";
      }
    }else{
      for(int j=0;j<50;j++){
        cout << "##";
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);
using namespace std;
int main(){
	fast;
	string s;
	cin>>s;
	int sum=0,maxv=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C')sum++;
		else sum=0;
		maxv=max(sum,maxv);
	}
	cout<<maxv;
}

Measured memory_bytes: 256
import Text.Printf

solve4 as = printf "%d %d %d\n" mimm maxx summ
  where
    mimm = foldl1 min as
    maxx = foldl1 max as
    summ = foldl1 (+) as

main = do
  _ <- getLine
  as' <- getLine
  let as = map read. words $ as' :: [Int]
  solve4 as



Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;



int N, K;
vector<int> G[100000];
int ans;
int dfs(int cur_v, int p) {
    int res = 0;
    
    for(int nv : G[cur_v])
      res = max(res, dfs(nv, cur_v) + 1);
    
    if(res == K - 1 && p != 0) {
        ++ans;
        res = -1;
    }
    return res;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    ans = 0;
    rep(i, N) {
        int p;
        cin >> p;
        --p;
        if(i == 0) {
            if(p != 0) ++ans;
            continue;
        }
        G[p].emplace_back(i);
    }
    dfs(0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
N=int(input())
a={i+1:int(input()) for i in range(N)}

cnt=1
flag=0
b=a[1]

for i in range(N):
    if b==2:
        flag=1
        break
    else:
        b=a[b]
        cnt+=1
    

print(cnt if flag else -1)

Measured memory_bytes: 17892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int ans = 0;
        for (int i = 0; i < S.length(); i++) {
            ans += S.charAt(i) == '+' ? 1 : -1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
 
using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;
 
#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
 
 
 
 
int main()
{
	int hh, ww;
	int H, W;
	cin >> H >> W;
	REP(i, H) {
		REP(j, W) {
			string s;
			cin >> s;
			if (s == "snuke") {
				hh = i;
				ww = j;
			}
		}
	}
	cout << (char)(ww + 'A') << hh+1 << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

int a[3];

int main() {
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a+3);

    int res = 0;

    if (a[0] != a[1]) {
        while (a[0] < a[1]) {
            a[0] += 2;
            ++res;
        }
    }

    if (a[0] != a[1]) {
        ++a[1], ++a[2];
        ++res;
    }

    if (a[1] < a[2]) {
        while (a[1] < a[2]) {
            ++a[0], ++a[1];
            ++res;
        }
    }

    if (a[2] < a[1]) {
        while (a[2] < a[1]) {
            a[2] += 2;
            ++res;
        }
        if (a[1] < a[2]) {
            ++a[0], ++a[1];
            ++res;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
/*
    A - Children and Candies (ABC Edit)
    https://atcoder.jp/contests/abc043/tasks/abc043_a
*/

#include <iostream>

using namespace std;

#define ll long long
#define forn(i, s, n) for (int i = s; i < n; i++)
#define whilen(val, n) while(n-- && cin >> val)
#define r_1(v) cin >> v
#define r_2(v1, v2) cin >> v1 >> v2

int main() {
    int n;
    r_1(n);
    cout << (n * (n + 1)) / 2;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    long long int w, h, x, y;
    cin >> w >> h >> x >> y;

    bool half_x = w % 2 == 0 && w / 2 == x;
    bool half_y = h % 2 == 0 && h / 2 == y;

    bool mul = half_x && half_y;
    printf("%6f %d\n", (double)(w * h) / 2, mul);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

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

int main(){
    string s;
    cin >> s;
    rep(i,s.length()){
        cout << 'x';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
fun main (arg: Array<String>){
	var N = readLine()!!.toInt()
	var list = readLine()!!.split(" ").map(String::toInt)
	var linear:Double = 0.0
	for(l in list){
		linear = linear + (2 * l)
	}
	var position = Math.round(linear / (2*N))
	
	var result = 0
	for(i in list){
		result  = result + ((i - position)*(i - position)).toInt()
	}
	println(result)
}

Measured memory_bytes: 37676
n = int(input())
A = list(map(int, input().split()))
count = [0 for _ in range(9)]
for i in range(n):
    if A[i] // 400 >= 8:
        count[8] += 1
    elif count[A[i] // 400] == 0:
        count[A[i] // 400] += 1

if count[8] == sum(count):
    print(1, sum(count))
else:
    print(sum(count)-count[8], sum(count))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (int i = (a); i >= (b); --i)
#define edge(i, u) for (int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define N 200005
#define ls(u) t[u].s[0]
#define rs(u) t[u].s[1]
#define lowbit(x) x & -x
#define ll long long
ll n, m, now, ans;
char s[N];
int main ()
{
    scanf("%s", s + 1);
    n = strlen(s + 1);
    fd (i, n, 1)
        if (s[i] == 'W')
        {
            ++now;
        }
        else
        {
            ans += now;
        }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);

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

  ll nmax=0;
  ll sum=0;

  for(ll i=0;i<N;i++){
      if(A[i]>=nmax){
         nmax=A[i]; 
      }
      else{
          sum+=nmax-A[i];
      }
  }
cout<<sum<<endl;



}











Measured memory_bytes: 4772
import java.util.HashMap;
import java.util.Scanner;

class Problem {
    private int N;
    private int[] C;
    private final int MOD = (int) 1e9 + 7;

    Problem() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        C = new int[N];
        for (int i = 0; i < N; i++) {
            C[i] = sc.nextInt();
        }
    }

    int solve() {
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] dp = new int[N];

        dp[N - 1] = 1;
        map.put(C[N-1], N-1);

        for (int i = N - 2; i >= 0; i--) {
            int n = map.getOrDefault(C[i], -1);
            if (n > i + 1) {
                dp[i] = (dp[i+1] + dp[n]) % MOD;
            } else {
                dp[i] = dp[i+1];
            }
            map.put(C[i], i);
        }
        return dp[0];
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Problem().solve());
    }
}


Measured memory_bytes: 95496
#include <bits/stdc++.h>
int main(void)
{
  int n, k, tmp, a[200000] = {};
  long long ans = 0;
  std::cin >> n >> k;
  for(int i = 0; i != n; i++){
    std::cin >> tmp;
    a[tmp - 1]++;
  }
  std::sort(a, a + n, std::greater<int>());
  for(int i = k; i != n; i++) ans += a[i];
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    readLine()
    val list = readLine()!!.split(" ").map { it.toInt() }
    val ans = Array (list.size) {0}
    list.forEachIndexed { i, v ->
        ans[v - 1] = i + 1
    }
    ans.forEach {
        print(it)
        print(" ")
    }
}


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


void trace(int A[],int N){
    for(int i=0;i<N;i++) {
        if(i>0) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}


void insertionSort(int A[],int N){
    for(int i=1;i<N;i++){
        int temp = A[i];
        int j = i-1;
        while(j>=0&&A[j]>temp){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = temp;
        trace(A,N);
    }
}

int main(){
    int N;
    int A[100];
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    trace(A,N);
    insertionSort(A,N);
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
    cin>>n;
        
        string s;
        cin>>s;
        string ans;
    
    for(int i=0;i<s.length();i++){
      int a=s[i]-'A';
        
         a=(a+n)%26;
       // cout<<a; 
        a=a+'A';
        // cout<<(char)(a); 
        ans+=(char)(a);
    } 
  cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e - a > k){
    cout << ":(";
  } else {
    cout << "Yay!";
  }
}

Measured memory_bytes: 256
n,c,*stc = map(int,open(0).read().split())
stc = list(zip(stc[::3],stc[1::3],stc[2::3]))

stc.sort()

record = []

for s,t,c in stc:
    
    for i,(rt,rc) in enumerate(record):
        if s-0.5 >= rt:
            record[i] = (t,c)
            break
        elif c == rc and  s>= rt:
            record[i] = (t,c)
            break
    else:
        record.append((t,c))
    
    record.sort(reverse=True)

print(len(record))
        

Measured memory_bytes: 30536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s;
    cin >> s;
    if(s == "SUN") cout<<7<<endl;
    if(s == "MON") cout<<6<<endl;
    if(s == "TUE") cout<<5<<endl;
    if(s == "WED") cout<<4<<endl;
    if(s == "THU") cout<<3<<endl;
    if(s == "FRI") cout<<2<<endl;
    if(s == "SAT") cout<<1<<endl;
    
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll n;
string s[101];
ll p[101],ind[101];

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i] >> p[i];
        ind[i] = i;
    }

    ll ans[101];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[ind[i]] > s[ind[j]]){
                ll tmp = ind[i];
                ind[i] = ind[j];
                ind[j] = tmp;
            }
            else if(s[ind[i]] == s[ind[j]]){
                if(p[ind[i]] < p[ind[j]] ){
                    ll tmp = ind[i];
                    ind[i] = ind[j];
                    ind[j] = tmp;
                }
            }
        }
    }

    for(int i = 0; i < n; i++){
        cout << ind[i]+1 << endl;
    }
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int n;
	cin >> n;

	int x = 0;
	vector <int> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		x ^= arr[i];
	}
	for (int i = 0; i < n; i++) {
		cout << (x ^ arr[i]) << " ";
	}
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	solve();

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n, m;
	cin >> n >> m;

	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	priority_queue<ll> pq;
	for (int i = 0; i < n; i++) {
		pq.push(a[i]);
	}

	for (int tCnt = 0; tCnt < m; tCnt++) {
		ll x = pq.top(); pq.pop();
		ll buyCost = x / 2LL;
		pq.push(buyCost);
	}

	ll ans = 0;
	while (!pq.empty()) {
		ans += pq.top(); pq.pop();
	}

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


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
  
    rep(i,N) cin >> A[i];
  
    sort(A.begin(), A.end());
    int flag = 0;
    for(int i = 0; i < N -1 ; i++){
        if(A[i] == A[i+1]) flag = 1;
    }
    if(flag == 1) cout << "NO" << endl;
    else cout << "YES" << endl;
  
    return 0;
}


Measured memory_bytes: 1024
def lower_bound(ary, n)
    return ary.size if ary[-1]<n
    u = ary.size-1
    l = 0
    while u>l
      s = (u+l)/2
      ary[s] < n ? l = s+1 : u = s
    end
    l
end

def upper_bound(ary, n)
    return ary.size if ary[-1]<=n
    u = ary.size-1
    l = 0
    while u>l
      s = (u+l)/2
      ary[s] <= n ? l = s+1 : u = s
    end
    l
end

n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

a.sort!
c.sort!

sum = 0
b.each do |bi|
    sml = lower_bound(a, bi)
    big = upper_bound(c, bi)
    sum += sml * (n-big)
end

p sum


Measured memory_bytes: 23156
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ct = 0;
		int hp = sc.nextInt();
		int at = sc.nextInt();
		while(hp > 0){
			hp -= at;
			ct ++;
		}
		System.out.println(ct);
	}

}

Measured memory_bytes: 35392
n=int(input())
dp=[0]*n
l69=sorted([1]+[6**i for i in range(1,7)]+[9**i for i in range(1,6)])
g=0
for i in range(n):
    for j in range(len(l69)):
        if i+1-l69[j]>=0:
            g=j
    dp[i]=min(dp[i-p]+1 for p in l69[:g+1])

print(dp[n-1])

Measured memory_bytes: 43612
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
constexpr int kMax = 2e5;
typedef long long LL;

int main() {
  int N, P; cin >> N >> P;
  string S; cin >> S;

  LL count = 0;
  if (P == 2 || P == 5) {
    for (int i = 0; i < N; ++i) {
      int d = S[i] - '0';
      if (d % P == 0) count += (LL)(i + 1);
    }
  } else {
    LL u = 0;
    LL x = 1;
    map<int, LL> m;
    m[0] = 1;
    for (int i = N-1; i >= 0; --i) {
      LL d = S[i] - '0';
      u = (d * x + u) % P;
      x = x*10%P;

      count += m[u];
      ++m[u];
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 1028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		Set<Integer> set = new HashSet<Integer>();
		for (int i=0;i<3;i++) {
			set.add(sc.nextInt());
		}
		System.out.println(set.size());


	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

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

Measured memory_bytes: 22996
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

ll dp[3010][3010][4];

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll r, c, k; cin >> r >> c >> k;
    vector<vector<ll>> vec(r, vector<ll>(c));
    rep(i, k){
        ll x, y, z; cin >> x >> y >> z;
        x--; y--;
        vec[x][y] = z;
    }

    /*
    rep(i, r){
        rep(j, c){
            cout << vec[i][j] << " ";
        }br;
    }
    */

    rep(i, r){
        rep(j, c){
            rep(k, 4){
                //拾う場合
                if(k != 3){
                    dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + vec[i][j]); //横
                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k] + vec[i][j]); //縦
                }
                //拾わない場合
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]); //横
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]); //縦
            }
        }
    }

    /*
    rep(i, r+1){
        rep(j, c+1){
            cout << dp[i][j][0] << " ";
        }br;
    }
    br;br;
    rep(i, r+1){
        rep(j, c+1){
            cout << dp[i][j][1] << " ";
        }br;
    }
    br;br;
    rep(i, r+1){
        rep(j, c+1){
            cout << dp[i][j][2] << " ";
        }br;
    }
    br;br;
    rep(i, r+1){
        rep(j, c+1){
            cout << dp[i][j][3] << " ";
        }br;
    }
    br;br;
    */

    ll ans = 0;
    rep(i, 4){
        ans = max(ans, dp[r-1][c][0]);
    }
    rep(i, 4){
        ans = max(ans, dp[r][c-1][0]);
    }
    cout << ans << endl;
    /*
    cout << dp[r][c][0] << endl;
    cout << dp[r][c][1] << endl;
    cout << dp[r][c][2] << endl;
    cout << dp[r][c][3] << endl;
    */

}

Measured memory_bytes: 355900
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();

        int kingaku = inpt[0];

        char[] ngList = Reader.ReadLine().Split(' ').Select(a=>a[0]).ToArray();

        for (int i = kingaku; i < 100000; i++)
        {
            string num = i.ToString();
            bool isValid = true;

            ngList.ToList().ForEach(a =>
            {
                if (num.IndexOf(a) >= 0)
                {
                    isValid = false;
                }
            });
            if (isValid)
            {
                Console.WriteLine(i);
                break;
            }
        }


    }

    List<String> src = new List<string>();



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


9999 1
0

";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 7000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		char c[] = s.toCharArray();
		int happy = 0;
		for (int i = 0; i < c.length - 1; i++) {
			if (c[i] == c[i + 1]) {
				happy++;
			}
		}
System.out.println(Math.min(happy+(k*2),n-1));

		//int x[] = new int[happy];
		//Renzoku(c, x);
	}

	static void show(int x[]) {
		for (int i = 0; i < x.length; i++) {
			System.out.print(x[i] + " ");
		}
		System.out.println();
	}

	public static int Renzoku(char c[], int x[]) {

		int mode = 0;
		int val = 0;

		for (int i = 0; i <= c.length - 2; i++) {
			if ((c[i] == c[i + 1]) && i != c.length - 2) {
				val++;
			} else {
				if ((c[i] == c[i + 1]) && i == c.length - 2) {
					val++;
				}
				val++;
				x[mode] = val;
				mode++;

				if ((c[i] != c[i + 1]) && i == c.length - 2) {
					x[mode] = 1;
					mode++;
				}

				val = 0;
			}

		}
		return mode;

	}

}

Measured memory_bytes: 28336
import sys

input = sys.stdin.readline


def main():
    N = int(input())

    # Initialize
    l, r = 0, N - 1
    print(l, flush=True)
    sl = input().rstrip()
    print(r, flush=True)
    sr = input().rstrip()
    if sl == "Vacant" or sr == "Vacant":
        exit()

    for _ in range(18):
        mid = (l + r) // 2
        print(mid, flush=True)
        s = input().rstrip()
        if s == "Vacant":
            exit()
        if (mid - l) % 2 == 0:
            if sl == s:
                l = mid
                sl = s
            else:
                r = mid
                sr = s
        else:
            if sl == s:
                r = mid
                sr = s
            else:
                l = mid
                sl = s


if __name__ == "__main__":
    main()


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

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


Measured memory_bytes: 3068
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto N = IN();
	print(N/3);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<ll> > data(N + 1, vector<ll>(N + 1, 0));
  vector<vector<ll> > sum(N + 1, vector<ll>(N + 1, 0));
  rep(i, M) {
    int l, r;
    cin >> l >> r;
    data[l][r]++;
  }
  REP(i, 0, N) {
    REP(j, 0, N) {
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + data[i + 1][j + 1];
    }
  }
  rep(i, Q) {
    int p, q;
    cin >> p >> q;
    cout << sum[q][q] - sum[p - 1][q] - sum[q][p - 1] + sum[p - 1][p - 1]
         << endl;
  }
  return 0;
}


Measured memory_bytes: 4864
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
count = 0
for i in range(N):
    x -= a[i]
    if 0 == x:
        count += 1
        break
    elif (0 < x) and (i+1 != len(a)):
        count += 1
    else:
        break
print(count)

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

int main(){
  int n;
  cin >> n;
  int x[n],y[n],h[n];
  for(int i=0;i<n;i++) cin >> x[i] >> y[i] >> h[i];
  int a=-1,b=-1,c=-1,d=-1;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      for(int k=0;k<n;k++){
        if(h[k]>0){
          d=h[k]+abs(x[k]-i)+abs(y[k]-j);
        }
      }
      bool check=true;
      for(int k=0;k<n;k++){
        if(h[k]!=max(d-abs(x[k]-i)-abs(y[k]-j),0)){
          check=false;
        }
      }
      if(check){
        a=i,b=j,c=d;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

void add(vector<ll>& vs, ll a){
  for(ll v : vs){
    minch(a,(a^v));
  }
  if(a!=0){
    vs.push_back(a);
    sort(all(vs)); reverse(all(vs));
  }
}

bool is_contain(const vector<ll>& vs, ll a){
  for(ll v : vs){
    minch(a,(a^v));
  }
  return (a==0);
}

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

  int T;
  cin>>T;
  while(T--){
    int N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    string S;
    cin>>S;

    vector<ll> dp;
    dp.push_back(0);

    bool ok=true;
    for(ll i=N-1;i>=0;i--){
      if(S[i]=='0'){
        add(dp,A[i]);
      }else{
        if(!is_contain(dp,A[i]))ok=false;
      }
    }
    if(ok)cout<<"0\n";
    else cout<<"1\n";
  }

  return 0;
}


Measured memory_bytes: 3492
s = str(raw_input())
count0 = 0
for i in range(int(len(s)/2)):
	if s[2*i] == '0':
		count0 += 1
	if s[2*i+1] == '1':
		count0 += 1
if len(s) % 2 == 1:
	if s[-1] == '0':
		count0 += 1
print min(count0, len(s)-count0)

Measured memory_bytes: 4228
S = gets.chomp
T = gets.chomp
(T.size).times do |i|
  tmp = ""
  idx = i
  (T.size).times do
    tmp += T[idx]
    idx += 1
    if idx > (T.size - 1) then
      idx = 0
    end
  end

  if S==tmp then
    puts "Yes"
    exit
  end
end
puts "No"

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B; cin >> A >> B;
  if(abs(A-B) >= 2){
    cout << max(A, B)*2 -1 << endl;
  }else{
    cout << A + B << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	while(true) {
        		int m = sc.nextInt();
        		int n = sc.nextInt();
        		if(m==0 && n==0) break;
        		int w [] = new int[n];
        		int sum = 0;
        		int max = 0;
        		for(int i=0;i<n;i++) {
        			w[i] = sc.nextInt();
        			sum += w[i];
        			max = Math.max(w[i], max);
        		}
        		max = Math.max(max, sum/m);
        		
        		for(int i=max;;i++) {
        			sum = 0;
        			int count = 0;
        			for(int j=0;j<n;j++) {
        				sum += w[j];
        				if(sum>i) {
        					j--;
        					count++;
        					sum = 0;
        				}
        				if(count==m) break;
        			}
        			if(count<m) {
        			System.out.println(i);
        			break;
        			}
        		}
        	}	
        }
    }
}



Measured memory_bytes: 29736
#include <stdio.h>

#define WHITE 0
#define GRAY 1
#define BLACK 2

int time = 0;
int d[100] = {};
int f[100] = {};
int color[100] = {};
int array[100][100] = {};
int n;

void dfs(int,int *);
void visit(int,int *);

int main() {
  int i,j;
  int u;
  int k;
  int v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d %d",&u,&k);
    array[u-1][0] = u;
    array[u-1][1] = k;
    for(j=0;j<k;j++) {
      scanf(" %d",&v);
      array[u-1][j+2] = v;
    }
  }
  for(u=0;u<n;u++) {
    color[u] = WHITE;
  }
  for(i=0;i<n;i++) {
    if(color[i] == WHITE)
      dfs(i,array[i]);
  }
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",array[i][0],d[i],f[i]);
  }
}

void dfs(int t,int *V) {
  int u;
  int minus = 101;
  /*
  for(u=0;u<n;u++) {
    color[u] = WHITE;
  }
  time=0;
  */
  //printf("%d\n",t);
  //for(u=0;u<n;u++) {
    if(color[t] == WHITE) {
      visit(t,V);
    }
    //}
  

}

void visit(int u,int *V) {
  int v;
  color[u] = GRAY;
  d[u] = ++time;

  //printf("%d:%d\n",V[0],V[1]);
  for(v=1;v<=V[1];v++) {
    //if(V[0] == 3) printf("%d\n",V[0]);
    if(color[V[v+1]-1] == WHITE) {
      visit(V[v+1]-1,array[V[v+1]-1]);
    }
  }
  
  color[u] = BLACK;
  
  f[u] = ++time;
} 



Measured memory_bytes: 2088