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 K = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int ans = 0;
        if(K>=N){
            ans=N*X;
        }else{
            ans=K*X+(N-K)*Y;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 9680
#include <iostream>
#include <vector>

using namespace std;

int main() {

	unsigned int h, w;
	char tmp[101];
	bool flag = true;

	cin >> h >> w;

	char s[50][50];

	for (int i = 0; i < h; i++) {
		cin >> tmp;
		for (int j = 0; j < w; j++) {
			s[i][j] = tmp[j];
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			if (s[i][j] == '#') {
				if (s[i - 1][j] == '#') {}
				else if (s[i + 1][j] == '#') {}
				else if (s[i][j - 1] == '#') {}
				else if (s[i][j + 1] == '#') {}
				else
					flag = false;

			}

			if (flag == false) break;
		}
		if (flag == false) break;
	}
	if (flag == true)
		cout << "Yes" << endl;
	else if (flag == false)
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define P pair<int,int>
#define ll long long
#define f first
#define s second
using namespace std;
int n,nn,nx,mx=-INF,mn=INF;
P a[200005];
ll ans=1e18;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i].f=read(),a[i].s=read();
		if(a[i].f>a[i].s) swap(a[i].f,a[i].s);
		mx=max(mx,a[i].s),mn=min(mn,a[i].s);
	}
	sort(a+1,a+n+1);
	ans=1ll*(mx-mn)*(a[n].f-a[1].f),nn=nx=a[1].s;
	for(int i=2;i<=n;++i){
		ans=min(ans,1ll*(mx-a[1].f)*(max(nx,a[n].f)-min(nn,a[i].f)));
		nn=min(nn,a[i].s),nx=max(nx,a[i].s);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1792
from collections import deque

H, W = map(int, input().split())
s = [input() for _ in range(H)]

stack = deque([(0, 0)])
d = [[-1]*W for _ in range(H)]
d[0][0] = 0

while stack:
  nowx, nowy = stack.popleft()
  if nowx >= 1:
    if s[nowy][nowx-1]=='.' and d[nowy][nowx-1]==-1:
      d[nowy][nowx-1] = d[nowy][nowx] + 1
      stack.append((nowx-1, nowy))
  if nowx <= W-2:
    if s[nowy][nowx+1]=='.' and d[nowy][nowx+1]==-1:
      d[nowy][nowx+1] = d[nowy][nowx] + 1
      stack.append((nowx+1, nowy))
  if nowy >= 1:
    if s[nowy-1][nowx]=='.' and d[nowy-1][nowx]==-1:
      d[nowy-1][nowx] = d[nowy][nowx] + 1
      stack.append((nowx, nowy-1))
  if nowy <= H-2:
    if s[nowy+1][nowx]=='.' and d[nowy+1][nowx]==-1:
      d[nowy+1][nowx] = d[nowy][nowx] + 1
      stack.append((nowx, nowy+1))

if d[H-1][W-1] == -1:
  print(-1)
  exit()
  
white = 0
for si in s:
  for sii in si:
    if sii == '.':
      white += 1
print(white-d[H-1][W-1]-1)

    


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#define MOD 1000000007

typedef long long ll;
using namespace std;

int main(void) {
    int a,b;
    cin >> a >> b;
    int c=0;
    if(a<=b){
        c=1;
    }else{
        c=0;
    }
    cout << a + c - 1 << endl;
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;   
    scc_graph graph(N);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph.add_edge(a, b);
        graph.add_edge(b,a);
    }
    cout << graph.scc().size() - 1 << endl;
}

Measured memory_bytes: 10920
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Console.WriteLine(SumAll(input,0));
        }

        static string[] SplitByIndex(string str,int i){
            string[] res = new string[2];
            res[0] = str.Substring(0,i);
            res[1] = str.Substring(i,str.Length-i);

            return res;
        }

        static long SumAll(string str, long begin){
            long res=0;
            
            if(str.Length==1){
                return begin+long.Parse(str);
            }else{
                res += begin+long.Parse(str);

                for(int i=1;i<str.Length;i++){
                    string[] parts = SplitByIndex(str,i);
                    
                    int a = int.Parse(parts[0]);
                    res += SumAll(parts[1], a+begin);
                }

                return res;
            }


        }
    }

}


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

int main(void){
    char a[3][3];
    scanf("%s\n%s\n%s",a[0],a[1],a[2]);

    printf("%c%c%c\n",a[0][0],a[1][1],a[2][2]);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
ll reflect(ll A, ll B)
{
    if (A > B) swap(A, B);

    ll ref = B / A;
    if (B % A == 0)
    {
        return A * (ref * 2 - 1);
    }
    else
    {
        return A * ref * 2 + reflect(B % A, A);
    }
}

void _main()
{
    ll N, X;
    cin >> N >> X;
    cout << N + reflect(X, N - X) << endl;
}


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

int main(){
    int x;
    cin >> x;
    cout << x*x*x << endl;
    return 0;
}


Measured memory_bytes: 3020
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,v,p = LI()
    a = LI()
    a.sort()
    l = -1
    r = n-1
    while l+1 < r:
        i = (l+r) >> 1
        A = a[i]+m
        ri = bisect.bisect_right(a,A)
        j = n-ri
        if j >= p:
            l = i
            continue
        li = bisect.bisect_right(a,a[i])
        res = v-j-li
        if res <= 0:
            r = i
            continue
        res -= (p-j-1)
        s = 0
        for j in range(li,ri-(p-j-1)):
            s += A-a[j]
        if s >= res*m:
            r = i
        else:
            l = i
    print(n-r)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 58736
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int main(){
fastio();

          int n,x;
          cin>>x>>n;
          int arr[n];
          unordered_map<int,int>mp;
          int mini=INT_MAX,maxi=-1;
          for(int i=0;i<n;i++)
             cin>>arr[i],mp[arr[i]]++,mini=min(mini,arr[i]),maxi=max(maxi,arr[i]);

          int mn=INT_MAX;
          int ans=x;

          for(int i=-1000;i<=1000;i++)
          {
              int dif=abs(i-x);
              if(dif<mn && mp[i]==0)
              {
                  mn=dif;
                  ans=i;
              }
          }

        cout<<ans<<endl;






return 0;
}



Measured memory_bytes: 3700
n, y = gets.split.map(&:to_i)
ans = false
(n+1).times do |a|
  (n+1).times do |b|
    c = n - (a + b)
    break if c < 0
    if 10000*a + 5000*b + 1000*c == y
      ans = "#{a} #{b} #{c}"
      break
    end
    break if ans
  end
  break if ans
end
puts ans ? ans : "-1 -1 -1"


Measured memory_bytes: 1788
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "nomura2020_b.cpp"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string t;
  cin >> t;
  int len = t.length();
  REP(i, len) {
    if (t[i] == '?')
      t[i] = 'D';
  }
  cout << t << endl;
}


Measured memory_bytes: 3740
#include<stdio.h>

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if(a == b) {
    if (a != c) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }
  else {
    if(a == c) {
      printf("Yes\n");
    }
    else {
      if(b == c) {
        printf("Yes\n");
      }
      else {
        printf("No\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
n = int(input())
before = ''
said = set([])
f = True
for i in range(n):
    if i==0:
        before = input()
        said.add(before)
        continue
    s = input()
    if before[-1] != s[0] or s in said:
        f = False
    before = s
    said.add(s)
print('Yes' if f else 'No')



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

using namespace std;

int main(int argc, char const *argv[]) {
	int a,b,c,x;
	std::cin >> a >> b >> c >> x;
	int count = 0;

	int five;
	five = 0;
	five = min(a, x / 500);

	for (size_t i = 0; i <= five; i++) {
		for (size_t j = 0; j <= b; j++) {
			for (size_t k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					count++;
				}
			}
		}
	}

	std::cout << count << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int R = 0, B = 0;
  for (int i = 0; i < S.size(); i++){
    if (S[i] == '0'){
      R++;
    } else {
      B++;
    }
  }
  cout << min(R, B) * 2;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String str = sc.next();
		String[] strArray = str.split("");
		
		int count = 0;
		for(int i = 0;i < strArray.length;i++){
			if(strArray[i].equals("+")){
				count++;
			}else if(strArray[i].equals("-")){
				count--;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

const int N = 1e5 + 27;

int main()
{
	int n, a[N], ans = 0;

	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];
                           
	for (int i = 1; i < n; i++)
	{
		if (a[i] == i)
		{
			swap(a[i], a[i + 1]);
			ans++;
		}
	}

	if (a[n] == n)
		ans++;

	cout << ans;
		
	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, T, A[MAX];

int main(){
    cin >> N >> T;
    rep(i, N) cin >> A[i];

    int minA[MAX];
    int now = INF;
    rep(i, N - 1) {
        minA[i] = now = min(now, A[i]);
    }
    minA[N - 1] = INF;

    int maxA[MAX];
    now = 0;
    for (int i = N - 1; i >= 1; --i) {
        maxA[i] = now = max(now, A[i]);
    }
    maxA[0] = 0;

    int maxR = 0;
    rep(i, N - 1) {
        maxR = max(maxR, maxA[i + 1] - minA[i]);
    }

    map<P, int> m;
    int ans = 0;
    rep(i, N - 1) {
        if (maxA[i + 1] - minA[i] == maxR) {
            if (m[P(maxA[i + 1], minA[i])] == 0) {
                ans++;
                m[P(maxA[i + 1], minA[i])]++;
            }
        }
    }

    cout << ans << endl;
}

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

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    int p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    int n,a[200000],i,x=0,y=0;
    memset(a,0,sizeof(a));

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> a[i];
        if(x < a[i])
        {
            x = a[i];
        }else if(y <= a[i])
        {
            y = a[i];
        }
    }
    for(i=0; i<n; i++)
    {
        if(a[i] == x)
        {
            cout << y << endl;
        }else
        {
            cout << x << endl;
        }
    }
}

Measured memory_bytes: 2432
n,m,q = gets.to_s.split.map{|t|t.to_i}

abcd = []
$<.read.split.map(&:to_i).each_slice(4) do |a, b, c, d|
    abcd.push [a-1, b-1, c, d]
end

ans = 0
(1..m).to_a.repeated_combination(n) do |cmb|
  
  cnt = 0
  abcd.each do |a,b,c,d|
    
    if cmb[b] - cmb[a] == c
      cnt += d
    end
  end
  
  ans = cnt if ans < cnt
end

puts ans

Measured memory_bytes: 14652
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (n, z, w): (usize, isize, isize);
    input!(n, z, w);
    let a = input_vector::<isize>();

    if n == 1 {
        println!("{}", (w - a[0]).abs());
        return;
    }
    println!(
        "{}",
        std::cmp::max((w - a[n - 1]).abs(), (a[n - 1] - a[n - 2]).abs())
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

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

  priority_queue<ll, vector<ll>, greater<ll>> plus;
  priority_queue<ll> minus;

  vector<ll> L(N);
  ll L_sum = 0;
  rep(i, N) {
    cin >> L[i];
    L_sum += L[i];
    plus.push(L[i]);
  }

  vector<ll> C(N);
  rep(i, N) cin >> C[i];

  vector<ll> R(N);
  ll R_sum = 0;
  rep(i, N) {
    cin >> R[i];
    R_sum += R[i];
    minus.push(R[i]);
  }

  vector<ll> plus_sum(N + 1);
  plus_sum[0] = L_sum;
  repp(k,0, N-1) {
    plus.push(C[k]);
    L_sum += C[k];
    L_sum -= plus.top();
    plus.pop();
    plus_sum[k + 1] = L_sum;
  }

  vector<ll> minus_sum(N + 1);
  minus_sum[N] = R_sum;
  repr(k, N - 1, 0) {
    minus.push(C[k]);
    R_sum += C[k];
    R_sum -= minus.top();
    minus.pop();
    minus_sum[k] = R_sum;
  }

  ll ans = -LINF;
  rep(i, N + 1) {
    chmax(ans, plus_sum[i] - minus_sum[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 5876
# coding:utf-8

N = int(input())

d = list(map( lambda x:int(x), input().split(" ") ))

sum_d = 0

for i in range(len(d)-1):
    for j in range(i+1, len(d)):
        sum_d += d[i] * d[j]
        
print(sum_d)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,c[10][10]; cin>>h>>w;
    rep(i,10)rep(j,10)cin>>c[i][j];
    rep(k,10)rep(i,10)rep(j,10)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
    int ans=0;
    rep(i,h*w){
        int a; cin>>a;
        if(a==-1)continue;
        ans+=c[a][1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
S = input()
ans = 0
streak = 0
for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T":
        streak += 1
    else:
        if ans < streak:
            ans = streak
        streak = 0
if ans < streak:
    ans = streak
print(ans)

Measured memory_bytes: 3060
import collections

n = int(input())
List = list(map(int, input().split()))
Col = collections.Counter(List)
Col2 = sorted(Col.items())
CountList = [0]*n
for i in Col2:
    CountList[i[0]-1] = i[1]
#CountList = list(Col2.values()) 
#for i in range(n-len(CountList)):
#    CountList.append(0)

for i in CountList:
    print(i)



Measured memory_bytes: 122148
import java.util.Scanner;
public class Main {
	public static void main(String []args) {
		double m=Math.PI;
		double angle,pi_angle;
		Scanner sc=new Scanner(System.in);
		int length,high;
		double c;
		while(sc.hasNextInt()) {
		length=sc.nextInt();
		high=sc.nextInt();
		c=sc.nextInt();
		if(c<=length*length*high/2) {
		double h=c/length/high*2;
		pi_angle=Math.atan(h/high);
		angle=90-(pi_angle*180/m);
		System.out.println(String.format("%.10f", angle));
	}
		if(c>length*length*high/2) {
			double h=(length*high-c/length)*2/length;
			pi_angle=Math.atan(h/length);
			angle=pi_angle*180/m;
			System.out.println(String.format("%.10f", angle));
		}
		}
	}
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int sum = 0;
		for (int i = 0; i < x; i++) {
			if (isPrime(scanner.nextInt())) {
				sum++;
			}
		}
		System.out.println(sum);
	}

	public static boolean isPrime(int i) {
		if (i == 2)
			return true;
		if (i % 2 == 0)
			return false;
		if (i < 8)
			return true;
		if (i % 3 == 0)
			return false;
		int k = 5;
		while (k * k <= i) {
			if (i % k == 0)
				return false;
			if (i % (k + 2) == 0)
				return false;
			k += 6;
		}
		return true;
	}
}

Measured memory_bytes: 31064
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
const ll mod=1000000007;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  vector<string> s(3);
  rep(i,3) cin>>s[i];
  vector<int> id(3,0);
  int now=0;
  while(1){
    if(s[now].size()==id[now]){
      rep(i,3){
        if(now==i){
          char c=now+'A';
          cout<<c<<endl;
        }
      }
      return 0;
    }else{
      id[now]++;
      now=s[now][id[now]-1]-'a';
    }
  }

  return 0;
}


Measured memory_bytes: 256
n, Y = map(int, input().split())
frag = 0
tmp = 0
a = 0
b = 0
c = 0
for x in range(n + 1):
    for y in range(n - x + 1):
        tmp = x * 10000 + y * 5000 + (n - x - y) * 1000
        if tmp == Y:
            frag = 1
            a = x
            b = y
            c = n - x - y
            break
if frag == 0:
    print("-1 -1 -1")
else:
    print(f"{a} {b} {c}")


Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

long long predp[9];
int main() {
    

    for (int i=0;i<9;i++){
        predp[i] = 0;
    }
    predp[0] = 1;
    predp[1] = 2;
    for (int i=2;i<9;i++){
        predp[i] = 0;
        for (int j=i-2;j>=0;j--){
            predp[i] += predp[j];
        }
        predp[i] += 2;
    }


    int h,w,k;
    cin >> h >> w >> k;
    static const int H = h;
    static const int W = w;

    long long dp[H][W];
    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){
            dp[i][j] = 0;
        }
    }
    if(w-2 >= 0) {
        dp[0][0] = predp[w - 2];
    }else{
        dp[0][0] = 1;
    }
    if(w-3 >= 0 and w > 1){
        dp[0][1] = predp[w-3];
    }else if(w > 1) {
        dp[0][1] = 1;
    }

    for (int i=0;i<h-1;i++){
        for (int x=0;x<w;x++){
            if(x-1 >= 0 and w-x-2 >= 0){
                dp[i+1][x] += dp[i][x] * predp[x-1] * predp[w-x-2];
            }else if(x-1 >= 0){
                dp[i+1][x] += dp[i][x] * predp[x-1];
            }else if (w-x-2 >= 0){
                dp[i+1][x] += dp[i][x] * predp[w-x-2];
            }else {
                dp[i+1][x] += dp[i][x];
            }
            if(x-1 >= 0) {
                if (x - 2 >= 0 and w - x - 2 >= 0) {
                    dp[i + 1][x] += dp[i][x - 1] * predp[x - 2] * predp[w - x - 2];
                } else if (x - 2 >= 0) {
                    dp[i + 1][x] += dp[i][x - 1] * predp[x - 2];
                } else if (w - x - 2 >= 0) {
                    dp[i + 1][x] += dp[i][x - 1] * predp[w - x - 2];
                } else {
                    dp[i + 1][x] += dp[i][x - 1];
                }
            }
            if(x+1 < w){
                if (x - 1 >= 0 and w - x - 3 >= 0) {
                    dp[i + 1][x] += dp[i][x+1] * predp[x-1] * predp[w-x-3];
                } else if (x - 1 >= 0) {
                    dp[i + 1][x] += dp[i][x+1] * predp[x-1];
                } else if (w - x - 3 >= 0) {
                    dp[i + 1][x] += dp[i][x+1] * predp[w-x-3];
                } else {
                    dp[i + 1][x] += dp[i][x+1];
                }
            }
            dp[i+1][x] %= 1000000007;

        }
    }
    cout << dp[h-1][k-1] << endl;



}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int a[] = new int[n];
        int mn[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
            if(i>0){
                mn[i] = Math.min(mn[i-1],a[i]);
            }else mn[i]=a[i];
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]==mn[i]) cnt++;
        }
        out.println(cnt);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 46188
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
    int h, w;

    while (true)
    {

        cin >> h >> w;
        if (h == 0 && w == 0)
            break;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (i == 0 || i == h-1 || j == 0 || j == w-1) {
                    printf("#");
                } else {
                   printf("."); 
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define all(c) (c).begin(),(c).end()

using namespace std;
int in(){int x;cin>>x;return x;}

#define int long long
main(){
    while(1){
        int m=in(),n=in(),t=in(),p=in();
        if(n==0 and m==0 and t==0 and p==0) break;
        vector<vector<int> > v(n,vector<int>(m,1));
        int a = 0,b = 0;
        rep(_,t){
            int d=in(),c=in();
            if(d==2){
                vector<vector<int> > w(n,vector<int>(m));
                rep(i,c){
                    rep(j,m)w[c-1-i][j]+=v[i][j];
                }
                rep2(i,c,n-1)rep(j,m)w[i-c][j]+=v[i][j];
                v=w;
            }
            else{
                vector<vector<int> > w(n,vector<int>(m));
                rep(i,n)rep(j,c)w[i][c-1-j]+=v[i][j];
                rep(i,n)rep2(j,c,m-1)w[i][j-c]+=v[i][j];
                v = w;
            }
        }
        int ans = 0;
        rep(i,p){
            int x=in(),y=in();
            cout << v[y][x] << endl;
        }
                
    }
}


Measured memory_bytes: 3120
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 100001;

int main() {
	int N;
	bool p[MAX] = { false };
	int t[MAX] = { 0 };

	p[0] = true;
	p[1] = true;
	for (int i = 2; i < MAX; i++) {
		if (p[i])continue;
		for (int j = i + i; j < MAX; j += i)p[j] = true;
	}
	int cnt = 0;
	for (int i = 0; i < MAX; i++) {
		if (p[i] == false && p[(i + 1) / 2] == false)cnt++;
		t[i] = cnt;
	}

	cin >> N;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;

		cout << t[r] - t[l - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
s = input()

def getindexlist(s):
  l = []
  for i in range(0,len(s)-1):
    if s[i:i+2] == 'RL':
      l.append(i)
  return l

l = getindexlist(s)
ans = [0]*len(s)
searching = 0
for i in l:
  while True:
    if searching >= len(s):
      break
    if searching > i and s[searching] == 'R':
      break
    else:
      if abs(searching-i)%2 == 0:
        ans[i] += 1
      else:
        ans[i+1] += 1
      searching += 1
print(' '.join(map(str,ans)))

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

#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(){
    int N;
    cin >> N;

    vector<int> l(2*N);
    rep(i,2*N){
        cin >> l[i];
    }

    sort(l.begin(),l.end());
    int ans = 0;
    rep(i,N){
        //cout << min(l[2*i], l[2*i+1]) <<endl;
        ans += min(l[2*i], l[2*i+1]);
    }

    cout << ans << endl;



    return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

   int n, a, cnt = 0;
   cin >> n;
   set<int> x;

   rep(i, 0, n)
   {
      cin >> a;
      x.insert(a);
   }

   rep(i, 0, x.size())
   {
      ++cnt;
   }

   cout << cnt << '\n';
   return 0;
}

Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as IntSet
import Control.Monad.ST

main = do
  n <- readLn
  points <- U.replicateM n $ do
    [x,y] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (x,y)
  let b = 1 + (U.maximum $ U.map fst points)
  let m0 :: IntMap.IntMap IntSet.IntSet
      m0 = U.foldr' (\(x,y) -> IntMap.insertWith IntSet.union x (IntSet.singleton y)) IntMap.empty points
      m1 :: IntMap.IntMap IntSet.IntSet
      m1 = U.foldr' (\(x,y) -> IntMap.insertWith IntSet.union y (IntSet.singleton x)) IntMap.empty points
      resultR :: U.Vector Int
      resultS :: V.Vector IntSet.IntSet
      resultN :: U.Vector Int
      (resultR, resultS, resultN) = runST $ do
        root <- U.thaw $ U.enumFromN 0 b
        ss <- VM.replicate b IntSet.empty
        forM_ (IntMap.assocs m0) $ \(k,v) -> VM.write ss k v
        numberOfElements <- UM.replicate b 1
        let getRoot !i = do
              !j <- UM.read root i
              if i == j
                then return i
                else do k <- getRoot j
                        UM.write root i k
                        return k
            unify !i !j = do
              !i' <- getRoot i -- []
              !j' <- getRoot j -- []
              if i' == j'
                then return ()
                else do
                let !k = min i' j'
                UM.write root i' k
                UM.write root j' k
                s1 <- VM.read ss i'
                s2 <- VM.read ss j'
                VM.write ss k $! IntSet.union s1 s2
                n1 <- UM.read numberOfElements i'
                n2 <- UM.read numberOfElements j'
                UM.write numberOfElements k (n1 + n2)
        forM_ (IntMap.elems m1) $ \t -> do
          let t0:ts = IntSet.toList t
          forM_ ts $ \j ->
            unify t0 j
        liftM3 (,,) (U.freeze root) (V.freeze ss) (U.freeze numberOfElements)
  let l = sum [IntSet.size (resultS V.! i) * resultN U.! i | i <- [0..b-1], resultR U.! i == i]
  print $ l - n


Measured memory_bytes: 41340
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int A;
	int B;
	int C;
	int D;
	int E;
	cin >> A >> B >> C >> D >> E;
	cout <<15-A-B-C-D-E << endl;
}

	

Measured memory_bytes: 3148
N, M = map(int, raw_input().split())
#print N, M

state = [-1 for i in range(N)]
pena = [0 for i in range(N)]
WA = [0 for i in range(N)]

for i in range(M):
    s = raw_input().split()
    p = int(s[0])
    sc = s[1]
    #print p, sc
    p -= 1
    if (state[p] == 0):
        continue
    if sc == 'WA':
        pena[p] += 1
    else:
        state[p] = 0

ok = 0
pn = 0
for i in range(N):
    if state[i] == 0:
        ok += 1
        pn += pena[i]

print ok, pn


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define ll	        long long
#define all(v)      (v).begin() , (v).end()
#define vi          vector <ll>
#define vii         vector <pair<ll,ll>>
#define ii          pair<int,int>
#define lp(i,a,b)	for(int i=a;i<b;i++)
#define pb          push_back
#define F           first
#define S           second
const ll MOD=1e9+7,MAX=5e5+5;

int n,k;

int add(int x, int y)
{
    x += y;
    while(x >= MOD)
        x -= MOD;
    while(x < 0)
        x += MOD;
    return x;
}

int mult(int x, int y)
{
    return (1LL * x * y) % MOD;
}

int power(int base, int exp)
{
    int ret = 1;
    for (; exp; exp >>= 1, base = mult(base, base))
        if (exp&1)
            ret = mult(ret, base);

    return ret;
}

void fast();
int main()
{
    fast();
    cin>>n>>k;
    ll ans[k+1]={},res=0;

    for(ll i=k;i>=1;i--){

        ll x=power(k/i,n);
        ans[i]=add(ans[i],x);
        x=ans[i];
        for(ll j=2;j*j<=i;j++){
            if(i%j==0){
                ans[j]=add(ans[j],-x);
                if(i/j!=j)
                    ans[i/j]=add(ans[i/j],-x);
            }
        }
        if(i!=1)
            ans[1]=add(ans[1],-x);
        res=add(res,mult(ans[i],i));
    }
    cout<<res;
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*
1399 178 54 25 7 7 1 1 1 1 1 1
*/


Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define prvsort(v) sort(v.begin(), v.end(), greater<pair<ll, ll>>())
#define ll long long
#define ld long double
#define fixset(val) fixed << setprecision(10) << val 
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll N, a = 1, ans = 0; cin >> N;
  vector<vector<ll>> mtrx(10, vector<ll>(10, 0));
  rep(k, 1, N + 1) {
    if (k / a == 10) a *= 10;
  	mtrx[k / a][k % 10]++;
  }
  rep(i, 0, 10) {
  	rep(j, 0, 10) {
      	ans += mtrx[i][j] * mtrx[j][i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> H;
    H.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    
    int cnt = 0;
    int ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (H[i - 1] >= H[i])
        {
            cnt++;
        }else
        {
            if (ans < cnt)
            {
                ans = cnt;
            }
            cnt = 0;
            
        }
        
    }
    if (ans < cnt)
    {
        ans = cnt;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
// problem: "https://atcoder.jp/contests/abc157/tasks/abc157_b"

#include<bits/stdc++.h>

using namespace std;

void isIn(int x,vector<vector<int>>&V)
{
    int i,j;
    for(i=0;i!=3;i++)
        for(j=0;j!=3;j++)
            if(V[i][j] == x)
                V[i][j] = 0;
}

bool Diag(vector<vector<int>>&V)
{
    if(V[0][0] == 0 && V[1][1] == 0 && V[2][2] == 0)
        return true;

    return V[2][0] == 0 && V[1][1] == 0 && V[0][2] == 0;
}

bool Row(vector<vector<int>>&V)
{
    int i;
    for(i=0;i!=3;i++)
        if(V[i][0] == 0 && V[i][1] == 0 && V[i][2] == 0)
            return true;

    return false;
}

bool Col(vector<vector<int>>&V)
{
    int i;
    for(i=0;i!=3;i++)
    if(V[0][i] == 0 && V[1][i] == 0 && V[2][i] == 0)
        return true;

    return false;
}

bool checkZero(vector<vector<int>>&V)
{
    return Diag(V) || Row(V) || Col(V);     // define
}

int main()
{
    vector<vector<int>>V(3,vector<int>(3,0));
    int i,j;
    for(i=0;i!=3;i++)
        for(j=0;j!=3;j++)
            cin>>V[i][j];

    int n,x;
    cin>>n;
    while(n--)
    {
        cin>>x;
        isIn(x,V);      // define
    }

    if(checkZero(V))        // define
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,M;
  cin>>N>>M;
  priq Q;
  rep(i,0,N){
    int X; cin>>X;
    Q.push(X);
    }
  rep(i,0,M){
    int K=Q.top();
    Q.pop();
    Q.push(K/2);
    }
  int ans=0;
  rep(i,0,N){
    ans+=Q.top();
    Q.pop();
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  int N,s[100];
  cin>>N;
  for (int i(0);i<N;i++)cin>>s[i]; 
  sort(s,s+N);
  int sum=accumulate(s,s+N,0);
  if (sum%10!=0){
    cout << sum << endl;
  }else{
    for (int i(0);i<N;i++){
      if (s[i]%10!=0){
        sum-=s[i];
        cout << sum << endl; 
        return 0;
      }
    }
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

uplist = inputs[1]
lolist = inputs[2]

# body
if $debugFlag
  p uplist
  p lolist
end

uplist_sum = []
uplist.length.times do |i|
  if i == 0
    uplist_sum[i] = uplist[i]
  else
    uplist_sum[i] = uplist[i] + uplist_sum[i-1]
  end
end

lolist_sum = []
lolist.length.times do |i|
  if i == 0
    lolist_sum[i] = lolist[i] + uplist_sum[i]
  else
    lolist_sum[i] = lolist[i] + [uplist_sum[i], lolist_sum[i-1]].max
  end
end

puts lolist_sum[-1]


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

f80 dp[301][301][301];

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  vi32 cnt(3);
  rep(i, n) {
    cnt[a[i] - 1]++;
  }
  function<f80(int i, int j, int k)> rec = [&](int i, int j, int k) {
    if (i == 0 && j == 0 && k == 0) return (f80) 0;
    if (dp[i][j][k]) return dp[i][j][k];
    f80 ret = 0;
    if (i > 0) ret += rec(i - 1, j, k) * i;
    if (j > 0) ret += rec(i + 1, j - 1, k) * j;
    if (k > 0) ret += rec(i, j + 1, k - 1) * k;
    ret = (ret + n) / (i + j + k);
    return dp[i][j][k] = ret;
  };
  cout << rec(cnt[0], cnt[1], cnt[2]) << endl;
}


Measured memory_bytes: 282496
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin >> n;
	
	FOR(i, 1, 10) {
		if (n % i == 0) {
			if (n / i < 10) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;

ll n, w;
vector<ll> vvv, www;

void solve() {
  ll maxv = 100*1000;
  vector<ll> dp(maxv+1, INF);
  dp[0] = 0;
  for (ll i=0; i<n; ++i) {
    for (ll j=maxv; j>=vvv[i]; --j) {
      dp[j] = min(dp[j], dp[j-vvv[i]] + www[i]);
    }
  }
  ll res = 0;
  for (ll i=maxv; ~i; --i) {
    if (dp[i] <= w) {
      cout << i;
      break;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> w;
  vvv = vector<ll>(n);
  www = vector<ll>(n);
  for (ll i=0; i<n; ++i) {
    cin >> www[i] >> vvv[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, m;
  cin >> n >> m;
  int c = 0;
  c += min(n, m / 2);
  m -= c * 2;
  c += m / 4;
  cout << c << endl;
}


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


int main(){
                                                                     

    string s;

    int i, w;


    cin >> s >> w;


    for( i = 0 ; i < s.size() ; i = i + w ){

         cout << s.at(i);

         }


    cout << endl;
    

    return 0;

    }

Measured memory_bytes: 256