akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
int n, k;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    int ans=1;
    set<int> se;
    for(int i=0;i<k;i++){
        se.insert(a[i]);
    }
    for(int i=k;i<n;i++){
        auto be=se.begin();
        int temp=*be;
        int ai=a[i-k];
        se.erase(ai);
        se.insert(a[i]);
        auto en=se.end();
        en--;
        int temp1=*en;
        /*
        cout<<temp<<" "<<temp1<<"\n";
        cout<<a[i-k]<<" "<<a[i]<<"\n";
        cout << ans << "\n";
        */
        if(temp==a[i-k]&&temp1==a[i])continue;
        ans++;
    }
    int count=0;
    int sum=0;
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1]){
            count++;
        }
        else{
            if(count>=k){
                sum++;
                count--;
            }
            count=1;
        }
    }
    if(count>=k){
                sum++;
                count--;
    }
    ans-=max(sum-1,0);
    cout << ans << "\n";
}



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


int main()
{
    int n;cin>>n;
    long long sum = 0;
    for(int i=1; i<=n; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            int m = __gcd(i,j);
            sum = sum + m*6;
            for(int k=j+1; k<=n; k++)
            {
                sum = sum + __gcd(m,k)*6;
            }
        } 
    }

    sum = sum + (n*(n+1))/2;
    cout<<sum;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll mw;
	cin >>n >>mw;
	VL w(n), v(n);
	rep(i, n) cin >>w[i] >>v[i];
	ll khw = w[0], ans = 0;
	vector<VL> dp(n+2, VL(3*n+5));
	
	rep(i, n){
		repr(j, n, 0) repr(k, 3*n+1, 0) if(k==0 || dp[j][k]>0){
			if(khw*j + k + w[i] <= mw){
				dp[j+1][k+w[i]-khw] = max(dp[j+1][k+w[i]-khw] , dp[j][k] + v[i]);
				ans = max(ans, dp[j+1][k+w[i]-khw]);
			}
		}
	}
	cout << ans <<"\n";
	return 0;
}


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

using namespace std;

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

    int n;
    cin>>n;
    int m[3][n+1];
    memset(m,0,sizeof m);

    for(int i=1;i<=2;i++) {
        for(int j=1;j<=n;j++){
            cin>>m[i][j];
            m[i][j]+=max(m[i-1][j],m[i][j-1]);
        }
    }
    cout<<m[2][n]<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [0]*13
for i in map(int, input().split()):
    a[i] += 1

ans = 0
if any(i>2 for i in a) or a[0] or a[12]>1:
    pass
else:
    s = [[0]]
    for i in range(1, 13):
        nxt = []
        if a[i] == 0:
            nxt = s
        elif a[i] == 1:
            for si in s:
                nxt.append(si+[i])
                nxt.append(si+[24-i])
        else:
            for si in s:
                nxt.append(si+[i, 24-i])
        s = nxt
    for si in s:
        si.sort()
        tmp = float("Inf")
        for i in range(len(si)):
            k = abs(si[i]-si[i-1])
            k = min(k, 24-k)
            tmp = min(tmp, k)
        ans = max(ans, tmp)
print(ans)

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

using namespace std;
int main() {
    //freopen("input.txt", "r", stdin);
    int n; cin>>n;
    string s; cin>>s;
    int ans = 0;
    
    for(int i =0; i<=n-3; i++){
        if(s[i] =='A' && s[i+1]=='B' && s[i+2] =='C'){
            ans++;
        }
    }
    cout<<ans;

    return 0;
}

//ABCCABCBABCCABACBCBBABCBCBCBCABCB

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int h, w;
string s[2020];
int hori[2020][2020];
int vert[2020][2020];


void init() {

}

void input() {
  cin >> h >> w;
  REP(i, h) cin >> s[i];
}

void solve() {
  REP(i, 2020) REP(j, 2020) {
    hori[i][j] = 0;
    vert[i][j] = 0;
  }
  REP(i, h) {
    int start = -1;
    REP(j, w+1) {
      if (j == w || s[i][j] == '#') {
        if (start != -1) {
          FOR(k, start, j) hori[i][k] = j-start;
          start = -1;
        }
      } else {
        if (start == -1) start = j;
      }
    }
  }
  REP(i, w) {
    int start = -1;
    REP(j, h+1) {
      if (j == h || s[j][i] == '#') {
        if (start != -1) {
          FOR(k, start, j) vert[k][i] = j-start;
          start = -1;
        }
      } else {
        if (start == -1) start = j;
      }
    }
  }

  int res = 0;
  REP(i, h) REP(j, w) chmax(res, hori[i][j] + vert[i][j] - 1);
  cout << res << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    int follow[100005];
    vector<int> block[100005];

    UnionFind tree(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        //友達インクリメント
        follow[a]++;
        follow[b]++;
        //結合
        tree.unite(a,b);      
    }

    rep(i,k){
        int a, b;
        cin >> a >> b;
        --a; --b;
        block[a].emplace_back(b);
        block[b].emplace_back(a);
    }

    rep(i,n){
        //友達のグループから　自分と既に友達の数を引く
        int ans = tree.size(i) - 1 - follow[i];
        //ブロックされているペアも引く(同じグループに限る)
        for(int b : block[i]){
            if(tree.same(i,b)) --ans;
        }
        printf("%d ",ans);
    }
    cout << endl;
} 

Measured memory_bytes: 6784
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int tail = s.size() - 1;
    int ans = 0;
    for(int i = 0;i < s.size() / 2;i++){
        if(s[i] != s[tail - i]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{

    int n;
    cin>>n;

    string s;
    cin>>s;

    int cnt=1;
    for(int i=0;i<n-1;i++){
        if(s.at(i+1)!=s.at(i))
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}  


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  int ans=0;
  sort(l.begin(),l.end());
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      int t=distance(l.begin(),lower_bound(l.begin(),l.end(),l[i]+l[j]));
      ans+=t-j-1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,x;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>x;
        deq.emplace_back(x);
    }
    int min=1000000;
    for (int p=0;p<100;p++) {
        int sum=0;
        for (int j=0;j<deq.size();j++) {
            sum+=(deq[j]-p)*(deq[j]-p);
        }
        if (min>sum) {
            min=sum;
        }
    }
    cout<<min<<endl;
}

Measured memory_bytes: 256
def gcd (a, b):
    if a < b:
        a, b = b, a
    
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm (a, b):
    return a * b // gcd(a, b)

n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

b = 1
for i in range(n):
    b = lcm(b, t[i])

print(b)

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

int main() {
    int n, m, l;
    int a[100][100], b[100][100];
    long long int c[100][100];

    for (int i = 0; i < 100; i++) {
        for (int h = 0; h < 100; h++) {
            a[i][h] = 0;
            b[i][h] = 0;
            c[i][h] = 0;
        }
    }

    cin >> n >> m >> l;

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


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

    for (int i = 0; i < n; i++) {
        for (int h = 0; h < l; h++) {
            for (int s = 0; s < m; s++) {
                c[i][h] += a[i][s] * b[s][h];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int h = 0; h < l; h++) {
            cout << c[i][h];
            if (h != (l - 1)) {
                cout << " ";
            } else {
                cout << endl;
            }
        }
    }
}

Measured memory_bytes: 3200
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;



int main(){
  long long h = 0;
  long long ans = 1;
  int count = 0;
  cin >> h;

  while(h > 1){
    h /= 2;
    count += 1;
  }
  count += 1;
  while(count >0){
    ans *= 2;
    count --;
  }
  ans = ans -1;
  cout << ans;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int n = sc.nextInt();
        int[] p = new int[n];
        boolean[] searched = new boolean[n];

        int ans = 0;

        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (searched[i]) {
                continue;
            }
            if (p[i] == i + 1) {
                ans++;
                if (i != n - 1 && p[i + 1] == i + 2) {
                    searched[i + 1] = true;
                }
            }
        }
        System.out.println(ans);
    }
}

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

//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: usize;
    input!(n);
    let mut a = input_vector::<usize>();
    a.sort();

    for i in 1..n {
        if a[i] == a[i - 1] {
            println!("NO");
            return;
        }
    }
    println!("YES");
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;

const int N=4e5+5;
const int mod=1e9+7;
int n,k,igt[N],gt[N];

int Power(int x,int n)
{
    if(n==0) return 1;
    if(n==1) return x;
    if(n%2) return Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return tmp*tmp%mod;
}

int C(int k,int n)
{
    if(k<0||k>n) return 0;
    if(k==0) return 1;
    return gt[n]*igt[n-k]%mod*igt[k]%mod;
}

void init()
{
    gt[0]=1;
    for(int i=1;i<=N-5;i++) gt[i]=gt[i-1]*i%mod;
    igt[N-5]=Power(gt[N-5],mod-2);
    for(int i=N-5-1;i>=0;i--) igt[i]=igt[i+1]*(i+1)%mod;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    cin>>n>>k;
    int res=0;
    for(int i=0;i<=min(n,k);i++)
    {
        res=(res+C(i,n)*C(i,i+n-i-1))%mod;
    }
    cout<<res;
}


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

int main(){
    int N;
    cin >> N;
    vector<long long> A(N+1,0);
    vector<long long> B(N, 0);

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

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

    long long count = 0;
    for(int i=0; i<N; i++){
        long long r = B[i] - A[i];
        if(r <= 0){
            count += B[i];
        }else{
            count += A[i];
            long long r2 = A[i+1] - r;
            if(r2 <= 0){
                count += A[i+1];
                A[i+1] = 0;
            }else{
                count += r;
                A[i+1] = r2;
            }
        }
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/

int main()
{
  int N,M;cin>>N>>M;
  ll a[N];
  ll sum=0;
  for(ll i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  ll sum2=0;
  for(ll i=0;i<N;i++){
    if(a[i]>=1.*sum/(4*M))sum2++;
  }
  string ans= sum2>=M ? "Yes":"No";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = (1e5)+1;

int n, l[MAX], r[MAX], sz[MAX];
ll dl, dr, c;
priority_queue<ll> pql;
priority_queue<ll, vector<ll>, greater<ll>> pqr;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) cin >> l[i] >> r[i], sz[i] = r[i] - l[i];
	pql.push(l[0]);
	pqr.push(l[0]);
	for(int i = 1; i < n; i++) {
		dl -= sz[i], dr += sz[i-1];
		if(pql.top() + dl < l[i] && pqr.top() + dr > l[i]) {
			pql.push(l[i] - dl);
			pqr.push(l[i] - dr);
		} else if(l[i] >= pqr.top() + dr) {
			c += l[i] - (pqr.top() + dr);
			pqr.push(l[i] - dr);
			pqr.push(l[i] - dr);
			pql.push(pqr.top() + dr - dl);
			pqr.pop();
		} else {
			c += pql.top() + dl - l[i];
			pql.push(l[i] - dl);
			pql.push(l[i] - dl);
			pqr.push(pql.top() + dl - dr);
			pql.pop();
		}
	}
	cout << c;
}


Measured memory_bytes: 3308
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int N = 0;
    int K = 0;
    char S[50] = {0};

    scanf("%d",&N);
    scanf("%d",&K);
    scanf("%s",S);
    
    for (int i = 0; i < K; i++) {
        if (i+1 == K) {
            if (S[i] == 'A') {
                S[i] = 'a';
            }else if(S[i] == 'B'){
                S[i] = 'b';
            }else{
                S[i] = 'c';
            }
        }
    }
    
    printf("%s",S);
}


Measured memory_bytes: 128
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
//#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	int n; cin>>n;
	ll a[n];
	f(i,n) cin>>a[i];
	ll ans = 0;
	for(int i=1;i<n;i++) if(a[i] < a[i-1]){
		ans += (a[i-1] - a[i]);
		a[i] = a[i-1];
	}
	cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 5156
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int N=1e6+5;
typedef long long ll;
struct node{
    int u,v,nxt;
}edge[N*2];
int head[N],mcnt;
int du[N];
int a[N];
int n;
void add_edge(int u,int v){
    mcnt++;
    du[u]++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
}
void nosol(){
    puts("NO");
    exit(0);
}
void dfs(int u,int fa){
    if(du[u]==1)
        return ;
    int sum=0,mx=0;
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
        if(v==fa)
            continue;
        dfs(v,u);
        sum+=a[v];
        mx=max(mx,a[v]);
    }
    if(sum<a[u]||sum>2*a[u])
        nosol();
    if(mx>a[u])
        nosol();
    a[u]=2*a[u]-sum;
}
int main()
{
    //freopen("tree.in","r",stdin);
    //freopen("tree.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n==2){
        if(a[1]==a[2])
            puts("YES");
        else
            puts("NO");
        return 0;
    }
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
        add_edge(v,u);
    }
    int root=1;
    while(du[root]==1)
        root++;
    dfs(root,0);
    if(a[root])
        nosol();
    puts("YES");
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
      cin >> v[i];
  int ans = 2e7;
  int auxSum;
  for(int i = -100; i <= 100; i++)
  {
    auxSum = 0;
    for (int j = 0; j < n; j++)
    {
      auxSum += abs(v[j] - i) * abs(v[j] - i);
    }
    ans = min(ans, auxSum);
  }
  cout << ans;
  return 0;
}


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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int n, k;
    cin >> n >> k;

    veci v(n);
    for (int i=0; i<n; ++i) {
        cin >> v[i];
    }

    int ans = 0;
    int p = 0;
    while (p<n-1) {
        ans += 1;
        p += k-1;
    }
    cout << ans << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    int num[3];
    cin >> num[0] >> num[1] >> num[2];
    int count = 0;
    for(int i=0;i<3;i++){
        if(num[i]==5){count++;}
    }
    if(count==2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;
const int INF = 100000;

char buf[25][25];
int g[25*25][25*25];

int main(void) {
  int nRow, nCol;
  scanf("%d%d", &nRow, &nCol);
  REP(i, nRow) {
    scanf("%s", buf[i]);
  }
  int n = nRow*nCol;
  REP(i, n) REP(j, n) {
    g[i][j] = i == j ? 0 : INF;
  }
  
  REP(i, nRow) REP(j, nCol) {
    if(i+1 < nRow) {
      if(buf[i][j] == '.' && buf[i+1][j] == '.') {
        g[i*nCol+j][(i+1)*nCol+j] = 1;
        g[(i+1)*nCol+j][i*nCol+j] = 1;
      }
    }
    if(j+1 < nCol) {
      if(buf[i][j] == '.' && buf[i][j+1] == '.') {
        g[i*nCol+j][i*nCol+j+1] = 1;
        g[i*nCol+j+1][i*nCol+j] = 1;
      }
    }
  }

  REP(k, n) REP(i, n) REP(j, n) {
    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  }
  int maxi = 0;
  REP(i, n) REP(j, n) {
    if(g[i][j] < INF) {
      maxi = max(maxi, g[i][j]);
    }
  }
  cout << maxi << endl;
  return 0;
}


Measured memory_bytes: 1280
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    ll N;
    cin >> N;
    ll i;
    
    vector<ll> A (N+1, 0);
    vector<ll> B (N+1, 0);
    vector<ll> C (N+1, 0);
    vector<ll> D (N+1, 0);

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

    ll D_sum = 0;
    for(i=1;i<=N;i++){
        ll count_1;
        ll count_0;
        count_1 = B[i] - 1;
        count_0 = B[i];
        C[i] = count_1 * (count_1-1) / 2;
        D[i] = count_0 * (count_0-1) / 2;
        D_sum += D[i];
    }


    for(i=1;i<=N;i++){
        cout << D_sum - D[A[i]] + C[A[i]] << endl;    
    }

    return 0;
}


Measured memory_bytes: 9192
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Long> c = new ArrayList<Long>();
		long mini = 1000000000;
		
		long a = sc.nextInt();
		int b = sc.nextInt();
		for(int i = 0; i < a; i++){
			long d = sc.nextInt();
			c.add(d);
		}
		Collections.sort(c);
		for(int i = 0; i < a; i++){
			if(i > a-b){
				break;
			}
			long f = c.get(i+b-1)-c.get(i);
			if(mini>f){
				mini = f;
			}
		}
		System.out.println(mini);
	}
}

Measured memory_bytes: 60616
#include <iostream>

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	
	int answer = 0;
	if (B >= A * C)
	{
		answer = C;
	}
	else if (B >= A) {
		answer = B / A;
	}
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  var inputs = input.split("\n");
  var k = parseInt(inputs[0].split(" ")[1], 10);
  var l = inputs[1].split(" ").map(e => parseInt(e, 10)).sort((a, b) => b - a);
  var sum = 0;
  for (var i = 0; i < k; i++) sum += l[i];
  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
typedef long long ll;

#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(a) (a).begin(), (a).end()

int main()
{
    int w, a, b;
    cin >> w >> a >> b;

    cout << (abs(a - b) <= w ? 0 : abs(a - b) - w) << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main(){
	int x[100],y[100],n,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<n;i++)cin>>y[i];
	for(int i=0;i<n;i++){
		if(x[i]>y[i])cnt+=(x[i]-y[i]);
	}
	cout<<cnt;
	
	return 0;
} 

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

int main() {
  int N;
  cin >> N;
  
  while (true) {
    int a = N / 100;
    int b = (N/10) % 10;
    int c = N % 10;
    
    if (a == b && b == c) {
      cout << 100 * a + 10 * b + c << endl;
      return 0;
    }
    N++;
  }
  
  
  
  
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> c(n-1), s(n-1), f(n-1);
    rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
    rep(i,n-1){
        int ans=s[i]+c[i];
        for(int j=i; j<n-2; ++j){
            if(ans<=s[j+1]){
                ans=s[j+1]+c[j+1];
            }else{
                int kari=(ans-s[j+1]+f[j+1]-1)/f[j+1];
                ans=s[j+1]+kari*f[j+1]+c[j+1];
            }
        }
        cout<<ans<<endl;
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 3632
N, T = gets.chomp.split(" ").map(&:to_i)
inputs = gets.chomp.split(" ").map(&:to_i)
ans = 0
time_lag = []
(N-1).times do |i|
    time_lag << inputs[i+1] - inputs[i]
end

time_lag.each do |i|
    ans += T > i ? i : T
end

puts ans+T

Measured memory_bytes: 19588
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int[] intArray = cin.ReadIntArray(n);

            int max = intArray[0];
            int min = intArray[0];

            for (int i = 0; i < intArray.Length; i++)
            {
                if (max < intArray[i]) max = intArray[i];
                if (min > intArray[i]) min = intArray[i];
            }

            WriteLine(Abs(max - min));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11348
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int m, n; scanf("%d%d",&m,&n);
    int M=-1;
    for (int i=0; i<m; i++) {
        int sum=0;
        for (int j=0; j<n; j++) {
            int s; scanf("%d",&s);
            sum+=s;
        }
        M=max(M,sum);
    }
    printf("%d\n",M);
}

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

int partition(vector<int>& A,vector<char>& C,int p,int r) {
  int x = A[r];
  int i = p - 1;
  for(int j=p;j<r;j++) {
    if(A[j] <= x) {
      i++;
      swap(A[i],A[j]);
      swap(C[i],C[j]);
    }
  }
  swap(A[i+1],A[r]);
  swap(C[i+1],C[r]);
  return i+1;
}
void quick_sort(vector<int>& A,vector<char>& C,int p,int r) {
  if(p < r) {
    int q = partition(A,C,p,r);
    quick_sort(A,C,p,q-1);
    quick_sort(A,C,q+1,r);
  }
}

// ????????¨
void merge(vector<int>& A,vector<char>& C,int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> L(n1+1);
  vector<char> LC(n1+1);
  vector<int> R(n2+1);
  vector<char> RC(n2+1);
  for(int i=0;i<n1;i++) {
    L[i] = A[left+i];
    LC[i] = C[left+i];
  }
  for(int i=0;i<n2;i++) {
    R[i] = A[mid+i];
    RC[i] = C[mid+i];
  }
  L[n1] = 0x7FFFFFFF;
  R[n2] = 0x7FFFFFFF;
  int i = 0; int j = 0;
  for(int k=left;k<right;k++) {
    if(L[i] <= R[j]) {
      A[k] = L[i];
      C[k] = LC[i];
      i++;
    }
    else {
      A[k] = R[j];
      C[k] = RC[j];
      j++;
    }
  }
}
void merge_sort(vector<int>& A,vector<char>& C,int left, int right) {
  if(right - left > 1) {
    int mid = (left + right) / 2;
    merge_sort(A,C,left, mid);
    merge_sort(A,C,mid, right);
    merge(A,C,left, mid, right);
  }
}

bool is_equal(vector<int>& A1,vector<char>& C1,vector<int>& A2,vector<char>& C2,int n) {
  for(int i=0;i<n;i++) {
    if(C1[i] != C2[i]) return false;
    if(A1[i] != A2[i]) return false;
  }
  return true;
}


int main() {
  int n;
  cin >> n;
  vector<int> A(n); vector<char> AC(n);
  vector<int> B(n); vector<char> BC(n);
  for(int i=0;i<n;i++) {
    char c; int num;
    cin >> c >> num;
    A[i] = num; AC[i] = c;
    B[i] = num; BC[i] = c;
  }

  quick_sort(A,AC,0,n-1);
  merge_sort(B,BC,0,n);

  if(is_equal(A,AC,B,BC,n)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  for(int i=0;i<n;i++) {
    cout << AC[i] << " " << A[i] << endl;
  }
}

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

using namespace std;

int main() {

    int a[] = {1,3,5,7,8,10,12};
    int b[] = {4,6,9,11};
    int c = 2;

    int x,y;

    cin >> x >> y;

    char cx,cy;

    for(int i = 0;i < 7;i++){
        if(x == a[i]) cx = 'a';
        if(y == a[i]) cy = 'a';
    }
    for(int i = 0;i < 4;i++){
        if(x == b[i]) cx = 'b';
        if(y == b[i]) cy = 'b';
    }
    if(x == 2) cx = 'c';
    if(y == 2) cy = 'c';

    if(cx == cy) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 256
Q = int(input())
N = 10**5 + 1000

def getPrimes():
    isPrime = [True] * N
    isPrime[1] = False
    for i in range(2, N):
        if not isPrime[i]:
            continue
        for p in range(i + i, N, i):
            isPrime[p] = False
    return isPrime

isPrime = getPrimes()

A = [0] * (N)
for i in range(2, N):
    if i % 2 == 1 and isPrime[i] and isPrime[(i + 1) // 2]:
        A[i] = 1
accA = [0] * (N + 1)
for i, a in enumerate(A, start=0):
    accA[i] += accA[i - 1] + a

for _ in range(Q):
    l, r = map(int, input().split())
    print(accA[r] - accA[l - 1])



Measured memory_bytes: 7924
import java.util.*;

public class Main{

     public static void main(String []args){

         int[] k = new int[101];
        for(int i = 1; i < 101; i++){
            k[i] = 0;
        }
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int cnt = 0;
        int b;
        for(int i = 0; i<a; i++){
            b = sc.nextInt();
            k[b]++;
        }
        
        for(int j = 1; j< 101; j++){
            if(k[j] != 0)
            cnt++;
        }
        System.out.println(cnt);
     }
}

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

using namespace std;

#define max 150

struct rect{
	int w;
	int h;
	int l;	//対角線の長さの2乗

	//sortを用いるために演算子 < をオーバーロードする
	bool operator<( const rect& right ) const {
        return l == right.l ? h < right.h : l < right.l;
    }
};

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	//長方形テーブル作成
	vector<rect> v;

	for(int i = 1; i <= max; i++) {
		for(int j = i + 1; j <= max; j++) {
			rect r;
			r.h = i;
			r.w = j;
			r.l = i * i + j * j;
			v.push_back( r );
		}
	}

	//長方形をソート
	sort( v.begin(), v.end() );


	while(1) {
		int w, h;
		cin >> h >> w;
		if( h == 0 && w == 0 ) break;


		int ans = -1;
		for(int i = 0; i < v.size(); i++) {
			if( h == v.at(i).h && w == v.at(i).w ) {
				ans = i + 1;
				break;
			}
		}
		cout << v.at( ans ).h << " " << v.at( ans ).w << endl;

	}

	//while(1){}

	return 0;
}

Measured memory_bytes: 1348
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))

index = 0
ans = 10**10
cnt = 0
for i in range(n):
    temp = t-h[i]*0.006
    if ans > abs(a-temp):
        ans = abs(a-temp)
        cnt = i+1
print(cnt)

Measured memory_bytes: 9188
#include<stdio.h>
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
	int a,b,c,d,e,f;
	while(1){
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
		if(a<0||b<0||c<0||d<0||e<0||f<0)break;
		a--;
		d--;
		int one=a*365+a/4-a/100+a/400;
		int two=d*365+d/4-d/100+d/400;
		a++;
		d++;
		for(int i=0;i<b-1;i++)one+=m[i];
		for(int i=0;i<e-1;i++)two+=m[i];
		one+=c;
		two+=f;
		if(b>2&&(a%4==0&&((a%100==0&&a%400==0)||a%100)))one++;
		if(e>2&&(d%4==0&&((d%100==0&&d%400==0)||d%100)))two++;
		printf("%d\n",two-one);
	}
}

Measured memory_bytes: 0
n, k = map(int, input().split())
d = list(map(int, input().split()))
t = input()
ans = 0
lis = [-1] * n
for i in range(n):
    if t[i] == 'r':
        ans += d[2]
        val = 2
    if t[i] == 's':
        ans += d[0]
        val = 0
    if t[i] == 'p':
        ans += d[1]
        val = 1
    lis[i] = val
    if i >= k:
        if lis[i-k] == val:
            ans -= d[val]
            lis[i] = -1
print(ans)


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N,A,B;
    cin>>N>>A>>B;
    vector<ll> x(N);
    rep(i,0,N)
        cin>>x[i];
    ll ans = 0;
    rep(i,1,N) {
        ans += min((x[i] - x[i-1])*A,B);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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 modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll A, B;
  cin >> A >> B;

  ll gcdAB = gcd(A, B);
  set<ll> st;

  ll tmp = gcdAB;



  for(ll i = 2; i*i < gcdAB; i++){
    while(tmp%i == 0){
      tmp = tmp / i;
      st.insert(i);
    }
    if(tmp == 1){
      break;
    }
  }
  if(tmp > 1){
    st.insert(gcdAB);
  }

  cout << (st.size()+1) << endl;

  // for(auto itr = st.begin(); itr != st.end(); itr++){
  //   cout << *itr << endl;
  // }

  // for(auto itr = sB.begin(); itr != sB.end(); itr++){
  //   cout << *itr << endl;
  // }
  


  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>
 
using namespace std;
 
typedef long long ll;
 
typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;
 
int occs[(int)1e6 + 5], tree[1000005], n, ans[500005];
 
void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}
 
int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}
 
int main()
{

 
    int q, s, e;
    vector<node> v;
    scanf("%d", &n);
    scanf("%d", &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
    
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
 
    sort(v.begin(), v.end());
 
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
 
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
 
    return 0;
}

Measured memory_bytes: 25384
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s=input()
print(s.count("1"))

Measured memory_bytes: 38428
import java.util.Scanner;

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

		// 入力値の取得
		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		// 結果の出力
		System.out.println(sc.next().equals(S)? A-1 + " " + B : A + " " + (B-1));
		
		sc.close();
	}
}


Measured memory_bytes: 27084
import sys
import itertools

input = sys.stdin.readline

consume_times = [int(input()) for _ in range(5)]

combi_list = list(itertools.permutations(consume_times))

ans = 650
for comb in combi_list:
    time = 0
    res = 0
    for x in comb:
        time += x
        if time % 10 != 0:
            res = (10 - x%10)
            time += res
    time -= res
    if time < ans:
        ans = time

print(ans)

Measured memory_bytes: 38384
/*
3 3
1 1 4
2 3 1
連続したものの和と同じものがあるとうれしい

*/

#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int h[1600], w[1600];
int hdata[1500*1000 + 100];
int wdata[1500*1000 + 100];

int main(void)
{
	int n, m;
	while (cin >> n >> m, n && m){
		fill(hdata, hdata + 1500*1000+100, 0);
		fill(wdata, wdata + 1500*1000+100, 0);
		
		for (int i = 0; i < n; i++){
			cin >> h[i];
		}
		for (int i = 0; i < m; i++){
			cin >> w[i];
		}

		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += h[i];
			int tmp = sum;
			for (int j = 0; j <= i; j++){
				hdata[tmp]++;
				tmp -= h[j];
			}
		}
		sum = 0;
		for (int i = 0; i < m; i++){
			sum += w[i];
			int tmp = sum;
			for (int j = 0; j <= i; j++){
				wdata[tmp]++;
				tmp -= w[j];
			}
		}

		int ret = 0;
		for (int i = 0; i <= 1500*1000; i++){
			ret += wdata[i] * hdata[i];
		}

		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 12892
#include <stdio.h>          // printf(), scanf()

long
power(long x, long n, long M)
{
	if (n == 0)
		return 1;

	long res = power((x * x) % M, n / 2, M);
	if (n & 1)
		res = (res * x) % M;

	return res;
}

int
main(int argc, char** argv)
{
	int n, m;

	scanf("%d %d", &n, &m);
	printf("%ld\n", power(n, m, 1000000007));
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    int max=0;
    int min=1000;
    for(size_t i = 0; i < n; i++)
    {
        cin >> v[i];
        if(v[i]>max) max=v[i];
        if(v[i]<min) min=v[i];
    }
    cout << max-min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<string, string> pss;

int N;
string S;

int main(){
	cin >> N >> S;
	map<pss, ll> mpa, mpb;
	for(int i = 0; i < (1 << N); i++){
		string a1, b2;
		for(int j = 0; j < N; j++){
			if(i & (1 << j)){
				a1 += S[j];
			}else{
				b2 += S[j];
			}
		}
		reverse(b2.begin(), b2.end());
		mpa[pss(a1, b2)]++;
	}
	for(int i = 0; i < (1 << N); i++){
		string a2, b1;
		for(int j = 0; j < N; j++){
			if(i & (1 << j)){
				a2 += S[2 * N - j - 1];
			}else{
				b1 += S[2 * N - j - 1];
			}
		}
		reverse(b1.begin(), b1.end());
		mpb[pss(a2, b1)]++;
	}
	ll res = 0LL;
	for(auto e : mpa){
		res += e.second * mpb[e.first];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 103424
#include <iostream>
#include <string.h>

#define MAX_LINE 8
#define MAXA_DATA 50

using namespace std;

// プロトタイプ宣言
void searchString(string box);

int main() {
    int i, count = 0;
    int max = MAX_LINE * MAXA_DATA;
    char str[8];
    string box;
    for (i=0; i<max; i++) {
        cin >> str;
        box.append(str);
        //cout << str << endl;
        count++;
        if(count%8 == 0){
            //cout << box << endl << endl;
            // 文字列チェック
            searchString(box);
            box = "";
        }
        /*if((string)str == "finish"){
            break;
        }*/
    }
}

void searchString(string box){
    string A("1100000011");
    string B("1000000010000000100000001");
    string C("1111");
    string D("1000000110000001");
    string E("11000000011");
    string F("100000001100000001");
    string G("110000011");
    if (box.find(A) != std::string::npos) {
        cout << "A" << endl;
    }
    else if(box.find(B) != std::string::npos) {
        cout << "B" << endl;
    }
    else if(box.find(C) != std::string::npos) {
        cout << "C" << endl;
    }
    else if(box.find(D) != std::string::npos) {
        cout << "D" << endl;
    }
    else if(box.find(E) != std::string::npos) {
        cout << "E" << endl;
    }
    else if(box.find(F) != std::string::npos) {
        cout << "F" << endl;
    }
    else if(box.find(G) != std::string::npos) {
        cout << "G" << endl;
    }
}


Measured memory_bytes: 3028
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define pb push_back
#define INF 1e9
#define PI 3.1415926535
#define FOR(a,b) for(int a=0;a<b;a++)
#define FORN(a,m,n,p) for(int a=m;a<n;a+=p)
#define REP(a,m,n) for(int a=m;a<n;a++)
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define sz(a) a.size()
typedef long long ll;
using namespace std;

map<int,int> mp;
int a[200001];
int up(int n){
	ll x;
	for(int i=1;;i++){
		x=pow(2,i);
		if(x>n)return x;
	}
}
int main(){
	int n;
	int cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[i]=x;
		mp[x]++;
	}
	sort(a,a+n);
	for(int i=n-1;i>=0;i--){
		if(mp[a[i]]<=0)continue;
		int x=a[i];
		int y=up(x)-x;
		//cout<<x<<" "<<y<<endl;
		if(mp[y]){
			mp[x]--;
			mp[y]--;
			if(mp[y]>=0)
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

int main() {
    int N;  cin >> N;
    vector<char> S(N);  rep(i, N) cin >> S[i];

    bool flag = false;
    rep(i, N) {
        if (S[i] == 'Y') {
            flag = true;
            break;
        }
    }

    if (flag) cout << "Four" << endl;
    else cout << "Three" << endl;
}




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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i < (n)i++)
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define int long long
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   int a, b;
   cin >> a >> b;
   string s[100010];

   rep(i, a) cin >> s[i];

   sort(s, s + a);
   rep(i, a) cout << s[i];
}

Measured memory_bytes: 1024
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

a,b,c,d=map(int, input().split())

if (a+b > c+d):
    print("Left")
elif (a+b < c+d):
    print("Right")
else:
    print("Balanced")





Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;


int main() {
    string n;
    cin>>n;
    string t=n;
    reverse(n.begin(),n.end());
    if(n==t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

Measured memory_bytes: 256