akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ABC170C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split();
            int x = int.Parse(strs[0]);
            int n = int.Parse(strs[1]);
            string p = Console.ReadLine();
            if(p == "")
            {
                Console.WriteLine(x);
                Console.ReadLine();
                return;
            }
            int[] intP = Array.ConvertAll(p.Split(), int.Parse);
            Array.Sort(intP);
            int index = Array.BinarySearch(intP, x);
            if (index < 0)
            {
                Console.WriteLine(x);
                Console.ReadLine();
                return;
            }
            else
            {
                int i = 1;
                while (true)
                {
                    if (index - i < 0)
                    {
                        Console.WriteLine(x - i);
                        Console.ReadLine();
                        return;
                    }
                    else
                    {
                        if (intP[index-i] != x - i)
                        {
                            Console.WriteLine(x - i);
                            Console.ReadLine();
                            return;
                        }
                    }
                    if (index + i >= n)
                    {
                        Console.WriteLine(x + i);
                        Console.ReadLine();
                        return;
                    }
                    else
                    {
                        if (intP[index+i] != x + i)
                        {
                            Console.WriteLine(x + i);
                            Console.ReadLine();
                            return;
                        }
                    }
                    i++;
                }
            }
        }
    }
}


Measured memory_bytes: 27352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"YES"<<endl
#define cN cout<<"NO"<<endl
#define ll long long

unsigned const int MOD = 1e9+7;



int main(void){
    ll n,k;
    cin >> n >> k;
    n++;
    if((n/k)>=2)cY;
    else cN;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: u32,
        mut a: [i32; n],
    }

    a.sort_unstable_by(|i, j| j.cmp(i));

    println!("{}", a.into_iter().enumerate().fold(0, |acc, (i, j)| if i % 2 == 0 {acc + j} else {acc - j}));
}


Measured memory_bytes: 2156
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define debug(...) (cerr<<"'"<<__FUNCTION__<<"': "),fprintf(stderr,__VA_ARGS__)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n;
ll a[55];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	ll ans=0;
	while(true)
	{
/*		bool ok=0;
		for(int i=1;i<=n;i++)ok&=a[i]>=n;
		if(ok)
		{
			break;
		}*/
		ll mx=a[1],mxid=1;
		for(int i=1;i<=n;i++)if(a[i]>mx)mx=a[i],mxid=i;
		if(mx<n)
		{
			break;
		}
		ll coef=max((mx-(n-1))/n,1ll);
		for(int i=1;i<=n;i++)
		{
			if(i==mxid)a[i]-=n*coef;
			else a[i]+=coef;
		}
		ans+=coef;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		String s = kb.next();
		String t = kb.next();
		boolean j = true;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != t.charAt(i)) {
				j = false;
				break;
			}
		}
		if (j && (s.length() + 1 == t.length())) {
			System.out.println("Yes");
		}

		else {
			System.out.println("No");
		}
		kb.close();
	}

}


Measured memory_bytes: 26928
def collatz(n):
    if n%2==0:
        return int(n/2)
    else:
        return 3*n+1
    
a=int(input())
cnt=1
if a==1 or a==2:
    ans=cnt+3
else:
    while a !=4:
        a=collatz(a)
        cnt+=1
    ans=cnt+3  

print(ans)

Measured memory_bytes: 3060
/*
Hanit Banga
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 5;

int main()
{
	ll n, m;
	cin >> n >> m;

	ll ans = min(n, m/2);
	m = max(0ll, m - 2*n);
	ans += m/4;

	cout << ans;	
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    _N,_M = abs(N), abs(M)
    if _M == _N:
        if N == M:
            print(0)
        else:
            print(1)
    elif N == 0:
        if M >= 0:
            print(M-N)
        else:
            print(-M+1)
    elif M == 0:
        if N > 0:
            print(N+1)
        else:
            print(-N)
    elif N*M > 0:
        if M > N:
            print(M-N)
        else:
            print(2+N-M)
    elif N*M < 0:
        print(1+abs(N+M))
            
if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int n,m,h[110000],good[110000];
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    for(int i=1;i<=n;i++){
        good[i]=1;
    }
    
    int s[110000],t[110000];
    
    for(int i=0;i<=m;i++){
        cin>>s[i]>>t[i];
        
        if(h[s[i]]>h[t[i]]){
            good[t[i]]=0;
        }
        else if(h[s[i]]<h[t[i]]){
            good[s[i]]=0;
        }
        else{
            good[t[i]]=0;
            good[s[i]]=0;
        }
    }
    
    
    int ans=0;
    
    for(int i=1;i<=n;i++){
        if(good[i]==1){
            ans++;
        }
    }
    
    
    cout<<ans;
    
    
    
}


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

int N, Q;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            lazyEvaluate(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[k*2+1] + node[k*2+2];
        }
    }

    ll get(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = get(a, b, 2*k+1, l, (l+r)/2);
        ll vr = get(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    cin >> N >> Q;
    LazySegmentTree seg( vector<int>(N, 0) );
    for(int i=0; i<Q; i++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t; ll x; cin >> s >> t >> x;
            seg.add(s-1, t, x);
        }
        else {
            int x; cin >> x;
            cout << seg.get(x-1, x) << endl;
        }
    }
    return 0;
}

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

int main()
{
    int i,N,count = 0,tmp = 1,ans;
    cin >> N;
    vector<int> a(N);
    for ( i = 0 ; i < N ; i++ )
    {
        cin >> a.at(i);
    }
    while ( count <= N + 1 )
    {
        tmp = a[tmp - 1];
        count++;
        if ( tmp == 2 )
            break;
    }
    if ( count >= N + 1 )
        ans = -1;
    else 
        ans = count;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

	int x;cin>>x;
	int z=x/500;
	x-=z*500;
	int z2=x/5;
	int ans=z*1000+z2*5;
	cout<<ans;


    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int K;
	cin >> K;
	if(K <= 6) {
		cout << K << "\n";
		for(int i = 0; i < K; i++) for(int j = 0; j < K; j++) cout << i+1 << ((j == K-1) ? "\n" : " ");
		return 0;
	}
	int N = (K+3)/4;
	vector<int> v[2] = {vector<int>(2*N), vector<int>(2*N)};
	for(int i = 0; i < 2*N; i++) v[0][i] = i+1, v[1][i] = 2*N+i+1;
	int d = 4*N-K;
	for(int i = 0; i < d; i++) v[1][2*i] = v[0][2*i+1];
	for(int i = 0; i < 2*N; i++) if(v[1][i] > K) {
		int x = v[1][i];
		vector<int> occ(K+1, 0);
		for(int j = 0; j < 2*N; j++) occ[(v[0][j] > K) ? 0 : v[0][j]]++;
		for(int j = 0; j < 2*N; j++) occ[(v[1][j] > K) ? 0 : v[1][j]]++;
		for(int j = 1; j <= K; j++) if(occ[j] == 0) {
			for(int k = 0; k < 2*N; k++) if(v[0][k] == x) v[0][k] = j;
			for(int k = 0; k < 2*N; k++) if(v[1][k] == x) v[1][k] = j;
			break;
		}
	}
	cout << 2*N << "\n";
	for(int i = 0; i < N; i++) for(int j = 0; j < 2; j++)
		for(int k = 0; k < 2*N; k++) cout << v[j][(2*i+k)%(2*N)] << ((k == 2*N-1) ? "\n" : " ");
	return 0;
}

// look at my code
// my code is amazing


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

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i <= 2; i++)
    {
        if (s[i] == t[i]) ans ++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: u64,
    };
    println!(
        "{}",
        (1..)
        .take_while(|x| x * x <= n)
        .filter(|x| n % x == 0)
        .map(|x| (n / x).to_string().len())
        .min()
        .unwrap()
    );
}


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

int main(){
        int a,b,c,d,e,k;
        cin >> a >> b >> c >> d >> e >> k;        
        if(e-a<=k){
                cout<<"Yay!"<<endl;
        }else{
                cout<<":("<<endl;
        }
}


Measured memory_bytes: 256
n=int(input())
s=[]
for i in range(n):
    a,b=map(int,input().split())
    s.append([b,a])
s.sort()
count=0
flag=0
for i in range(n):
    count+=s[i][1]
    if count>s[i][0]:
        flag=1
print("Yes" if flag==0 else "No")

Measured memory_bytes: 35608
from collections import deque
k = int(input())
q = deque([i for i in range(1, 10)])

for i in range(k-1):
  tmp = q.popleft()
  r = tmp % 10
  if r != 0:
    q.append(10*tmp + r -1)
  q.append(10*tmp + r)
  if r != 9:
    q.append(10*tmp + r + 1)
print(q.popleft())
  

Measured memory_bytes: 11972
#include <math.h>
#include <stdio.h>
#include <string.h>
void swap_int(int* x, int* y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void swap_char(char* x, char* y) {
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

void asc_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] > array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

void dec_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] < array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

int max(int x, int y) {
    if (x > y) {
        return x;
    } else {
        return y;
    }
}

int min(int x, int y) {
    if (x > y) {
        return y;
    } else {
        return x;
    }
}
int main() {
    int n, a[200];
    int ans = 0;
    int i, j, k;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);

    for (i = 1; i < n; i++) {
        if (a[i - 1] == a[i]) {
            a[i] = -1;
            ans++;
        }
    }

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

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const LL INF = LL(8e18);

int n, k;
int x[50], y[50], xx[50], yy[50];

LL solve(int xs, int xt, int ys, int yt) {
    int cnt = 0;
    forn(i, n) if (xs <= x[i] && x[i] <= xt) {
        if (ys <= y[i] && y[i] <= yt) {
            ++cnt;
        }
    }
    return cnt >= k ? (LL)(xt - xs) * (yt - ys) : INF;
}

int main() {
    scanf("%d%d", &n, &k);
    forn(i, n) scanf("%d%d", x + i, y + i);
    forn(i, n) xx[i] = x[i], yy[i] = y[i];
    sort(xx, xx + n);
    sort(yy, yy + n);
    LL ans = INF;
    forn(i, n) forn(j, i + 1) {
        forn(ii, n) forn(jj, ii + 1) {
            ans = min(ans, solve(xx[j], xx[i], yy[jj], yy[ii]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		int length = S.length();
		char c =' ';
		char d =' ';
		int cnt = 0;

		for(int i=0;i<length/2;i++) {
			c = S.charAt(i);
			d = S.charAt(length-i-1);
			if(c!=d) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  string S;
  cin >> S;
  bool flg = true;
  if(N%2 != 0){
    cout <<"No";
    return 0;  
  }else{
    REP(i,N/2){
      if(S[i] != S[i+N/2]) flg = false;
    }
  }
  if(flg) cout <<"Yes";
  else cout << "No";

  return 0;
}

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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int ll;
typedef double dd;

void Solve(ll) {
  ll n;
  cin >> n;
  vector<ll> seq(n), pos(n);
  ll idx = 0;
  RARA(s, seq) {
    cin >> s;
    --s;
    pos[s] = idx++;
  }
  vector<ll> dp(n);
  VEVE(i, 0, n) {
    dp[i] = 1;
    if (seq[i] > 0 and pos[seq[i] - 1] < i)
      dp[i] = dp[pos[seq[i] - 1]] + 1;
  }
  cout << n - *max_element(ALL(dp)) << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int res = 0;
    rep(i, 3) if (s[i] == '1') res++;
    cout << res << endl;
    return 0;
}

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

#define int long long
#define vi vector <int>
#define endl "\n"
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int N=1e5+5 , MOD=1e9+7;\

vvi adj(N);
int in_degree[N]={0};
bool visited[N]={0};
int dp[N]={0};

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

void dfs(int v)
{
	visited[v] = 1;
	for(int x:adj[v])
	{
		dp[x] = max(dp[x],1+dp[v]);
		in_degree[x]--;
		if(in_degree[x]==0)
			dfs(x);
	}
}

void solve()
{
    int n,m;
    cin >> n >> m;
    while(m--)
    {
    	int x,y;
    	cin >> x >> y;
    	adj[x].pb(y);
    	in_degree[y]++;
    }

    for(int i=1;i<n+1;i++)
    {
    	if(in_degree[i]==0 && !visited[i])
    		dfs(i);
    }
    int ans=0;
    rep(i,1,n+1)
    {
    	ans = max(ans,dp[i]);
    }
    cout << ans << endl;
}

signed main()
{
    speed;
    
 //    int t; cin >> t;
 //    rep(tt,1,t+1)
 //    {
	// cout <<"Case #"<<tt<<": ";
	solve();
 //    }
    return 0;
}

Measured memory_bytes: 10496
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
	int n,m;
	cin>>n>>m;
	vi c(n+1);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		c[a]++,c[b]++;
	}
	bool f=true;
	REP(i,1,n)f&=c[i]%2==0;
	YES(f);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	char str[8];
	int ret = 0;
	cin >> str;

	if (((str[0] == str[1]) && (str[1] == str[2])) ||
		((str[1] == str[2]) && (str[2] == str[3])))
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s;
  cin>>s;
  
  for(int i = 0; i < s.size(); i += 2)
  {
    cout << s[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 592
N, X, Y = map(int, input().split())
X,Y = X-1, Y-1

ans = [0] * N
 
for i in range(N-1):
  for j in range(i+1, N):
    d = min(j-i, abs(i-X) + abs(j-Y) + 1)
    ans[d] += 1

print(*ans[1:], sep='\n')

Measured memory_bytes: 3444
#include <stdio.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    if(a <= b && b <= c) {
     printf("%d %d %d\n", a, b, c);
    }
    else if(b <= a && a <= c) {
    printf("%d %d %d\n", b, a, c);
    }
    else if(c <= a && a <= b) {
    printf("%d %d %d\n", c, a, b);
    }
    else if(a <= c && c <= b) {
    printf("%d %d %d\n", a, c, b);
    }
    else if(b <= c && c <= a) {
    printf("%d %d %d\n", b, c, a);
    }
    else if(c <= b && b <= a) {
    printf("%d %d %d\n", c, b, a);
    }
    return 0;
}


Measured memory_bytes: 2036
N = int(input())
A = list(map(int, input().split()))
X = [0]*(100001)
S = 0
for a in A:
    X[a] += 1
    S += a

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    nB = X[B]
    X[B] = 0
    X[C] += nB
    S += (C-B)*nB
    print(S)

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;
typedef pair<int, int> P;

int wa(ll n) {
    ll ans = 0;
    while (n > 0) {
        ans += (n % 10);
        n /= 10;
    }
    return ans;
}

int main() {

    ll n;
    cin >> n;

    vector<vector<bool >> calendar(10, vector<bool>(n));// calendar[時間帯][お店]
    rep(i, n) {
        rep(t, 10) {
            int c;
            cin >> c;
            calendar[t][i] = c == 1;
        }
    }
    vector<vector<ll >> profit(11, vector<ll>(n));// calendar[マッチ数][お店]
    rep(i, n) {
        rep(t, 11) {
            ll p;
            cin >> p;
            profit[t][i] = p;
        }
    }

    ll ans = MINF;

    for (int i = 1; i < 1 << 10; i++) {
        ll sum = 0;
        for (ll s = 0; s < n; s++) {
            ll match = 0;
            for (ll t = 0; t < 10; t++) {
                if (((i >> t) & 1) == 1) {
                    if (calendar[t][s]) {
                        match++;
                    }
                }
            }
            ll now = profit[match][s];
            sum += now;
        }
        cmax(ans, sum);

    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1e16; //10^9+7


int main(){
    int n;
    int a[102];
    int b[102];
    cin >> n;
    int suma[102];
    int sumb[102];
    suma[0] = sumb[0] = 0;
    REP(i, n){
        cin >> a[i];
        suma[i + 1] = suma[i] + a[i];
    }
    REP(i, n){
        cin >> b[i];
        sumb[i + 1] = sumb[i] + b[i];
    }
    int ans = 0;
    REP(i, n){
        ans = max(ans, suma[i + 1] + sumb[n] - sumb[i]);
    }
    print(ans);
}

Measured memory_bytes: 256
def main():
  x, n = list(map(int, input().split()))

  if n == 0:
    print(x)
    return
  p = list(map(int, input().split()))

  min_abs = 101
  min_e = 0
  for i in p:
    if abs(x-i) < min_abs:
      min_abs = abs(x-i)
      min_e = i

  if min_abs == 0 and min_e not in p:
      print(min_e)
      return

  for i in range(1, 101):
    if min_e - i not in p:
      print(min_e - i)
      return
    if min_e + i not in p:
      print(min_e + i)
      return
    
main()

Measured memory_bytes: 9208
#define _CRT_SECURE_NO_WARNINGS
#include  <stdio.h>


int main(void)
{
	int a, b, c, d;
	int s1, s2;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	s1 = a*b;
	s2 = c*d;
	if (s1 >= s2) {
		printf("%d", s1);
	}
	else {
		printf("%d", s2);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<string> vec(a);
  bool flag = true;
  vector<int> cnt(a);
  cnt = {0};
  for (int i = 0; i < a; i++) cin >> vec[i];
  for (int i = 0; i < a - 1; i++) {
    char c, d;
    c = vec.at(i)[vec[i].size() - 1];
    d = vec.at(i + 1)[0];
    if (c != d) flag = false;
  }
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < a; j++) {
      if (vec[i] == vec[j]) cnt[i]++;
    }
  }
  for (int i = 0; i < a; i++) {
    if (cnt[i] > 1) flag = false;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
input()
l=[[int(c)] for c in raw_input().split()]
for i,a in enumerate(sorted(l)):
    a[0]=i+1
s=0
r=len(l)+1
b=[0]*r
for n, in reversed(l):
    i=n
    while i>0:
        s+=b[i]
        i&=i-1
    while n<r:
        b[n]+=1
        n+=n&-n
print s

Measured memory_bytes: 42276
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    ss = [int(input()) for _ in range(n)]

    ans = sum(ss)
    if ans % 10 == 0:
        try:
            ans -= min([s for s in ss if s % 10 != 0])
        # if all s are 10 times, arert ValueError
        except ValueError:
            ans = 0

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
def reset(n):
    a = [0 for i in range(n+2)]
    return a
    
n = int(input())
s = list(input())
s.append(s[0])

dt = [[1,1],[-1,1],[1,-1],[-1,-1]] #1→sheep,-1→wlf

ans = False
for i in range(4):
    li = reset(n)
    li[0] = dt[i][0]
    li[1] = dt[i][1]

    for j in range(1,len(s)):
        if s[j] =='o':
            li[j+1] = li[j]*li[j-1]
        elif s[j] =='x':
            li[j+1] = li[j]*li[j-1]*(-1)
    if li[0]==li[n] and li[1]==li[n+1]:
        ans = True
        break

if (ans):
    for i in range(n):
        if li[i] == 1:
            print('S',end="")
        else:
            print('W',end="")
    print('')

else:
    print(-1)



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int a;
  string s;
  cin >> a >> s;
  if( a >= 3200 ) cout << s << endl;
  else cout << "red" << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        string s; cin >> s;
        if(s=="ABC")cout<<"ARC"<<endl;
        else cout<<"ABC"<<endl;

return 0;
}



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

int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin>>n;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++)
		cin>>a[i];
	ll count=0;
	map<int,int> elements;

	for(int i=1;i<=n;i++)
	{
		auto it=elements.find(i-a[i]);
		if(it!=elements.end())
			count+=(*it).second;

		elements[i+a[i]]++;
	}

	cout<<count<<"\n";

	return 0;
}

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

int main() {
  int H,N,A;
  int countD = 0;
  cin >> H >> N;
  for(int i = 0; i < N; i++){
    cin >> A;
    countD += A;
  }
  if(H <= countD){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}   

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

const int MAX = 1000;
int h, w, tt[MAX][MAX];
queue<P> q;

void check(int r, int c){
    auto f = [&](int i, int j){
        if(i < 0 || h <= i) return;
        if(j < 0 || w <= j) return;
        if(tt[i][j] >= 0) return;
        q.push(P(i,j));
        tt[i][j] = tt[r][c] + 1;
        return;
    };
    f(r+1, c); f(r-1, c);
    f(r, c+1); f(r, c-1);
    return;
}

int main(){
    cin >> h >> w;
    rep(i, h) rep(j, w){
        tt[i][j] = -1;
        char ch;
        cin >> ch;
        if(ch == '#'){
            q.push(P(i, j));
            tt[i][j] = 0;
        }
    }
    int ans = 0;
    while(!q.empty()){
        int r = q.front().first;
        int c = q.front().second;
        q.pop();
        ans = tt[r][c];
        check(r, c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12304
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    vector<string> Cvec(N);
    map<string, int> mp;
    for_each(ALL(Cvec), [](auto &e){cin >> e;});
    REP(i, N) {
        string C = Cvec[i];
        mp[C]++;
        if (mp.size() > 1) {
            pair<string, int> maxp = MP("", 0);
            int secnum = 0;
            FORE(el, mp) {
                if (maxp.second < el.second) {
                    secnum = maxp.second;
                    maxp = el;
                }
            }
            int macnt = 0;
            FORE(el, mp) {
                if (el.second == maxp.second) macnt++;
                if (secnum < el.second) {
                    if (el.second != maxp.second) secnum = el.second;
                }
            }
            if (macnt > 1) continue;
            if (maxp.second > secnum + (N - (i + 1)) || maxp.second * 2 > N) {
                cout << maxp.first << " " << i + 1 << endl;
                return;
            }
        } else {
            if ((i + 1) * 2 > N) {
                cout << C << " " << i + 1 << endl;
                return;
            }
        }
    }
    cout << "TIE" << endl;
}

int main(void) {
    int n;
    while (cin >> n) {
        if (n == 0) return 0;
        solve(n);
    }
}

Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
namespace tryy
{
	typedef long long ll;
	const int N=55;
	ll s[N],ans;
	int n,ind;
	void initialize()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%lld",s+i);
		std::sort(s+1,s+n+1);
	}
	ll calc()
	{
//		printf("ind = %d\n",ind);
//		for(int i=1;i<=n;i++)
//			printf("%lld ",s[i]);
//		printf("\n");
		ll v=ind+(n-ind+1);
		ll x=s[ind-1],y=s[n]-n+1,d=y-x;
		if(x>=y)return 0;
//		printf(":%lld\n",(d/v)+(d%v!=0));
		return (d/v)+(d%v!=0)-1;
	}
	bool query()
	{
		int cnt=0;
		for(int i=1;i<=n;i++)
			if(s[i]>s[n]-n)cnt++;
		return cnt>=(n-ind+1);
	}
	void doo()
	{
		int p=0;
		for(int i=1;i<=n;i++)
			if(s[i]>s[p])p=i;
		s[p]-=n;
		for(int i=1;i<=n;i++)
			if(i!=p)s[i]++;
	}
	void run(ll x)
	{
		ll d=x*ind,siz=n-ind+1;
		for(int i=1;i<ind;i++)
			s[i]+=siz*x;
		for(int i=ind;i<=n;i++)
			s[i]-=d;
		ans+=siz*x;
		ind--;

		while(!query())doo(),ans++;

		std::sort(s+ind,s+n+1);
	}
	bool check()
	{
		for(int i=1;i<=n;i++)
			if(s[i]>=n)return 0;
		return 1;
	}
	void frun()
	{
//		for(int i=1;i<=n;i++) printf("%lld ",s[i]);
//		printf("\n");
		if(s[1]>n)
		{
			ll d=s[1]-n;
			ans+=d*n;
			for(int i=1;i<=n;i++)
				s[i]-=d;
		}
		while(!check())doo(),ans++;
	}
	void solve() 
	{
		initialize();
		ans=0;ind=n;
		while(ind>1)run(calc());
		frun();
		printf("%lld\n",ans);
	}
}
int main()
{
//	freopen("in","r",stdin);
//	freopen("out","w",stdout);
	tryy::solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int N, K;
	double p[200005];

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	//(1.0/p[0])*((1+p[0])*p[0]/2)

	double e = 0;
	double maxe = 0;
	for (int i = 0; i < K; i++) {
		e += (1 + p[i]) * p[i] / 2.0 / p[i];
	}
	maxe = e;
	for (int i = 0; i < N - K; i++) {
		double ne = e - ((1 + p[i]) * p[i] / 2.0 / p[i]);
		ne += ((1 + p[K + i]) * p[K + i] / 2.0 / p[K + i]);
		if (ne > maxe) {
			maxe = ne;
		}
		e = ne;
	}

	printf("%.12lf\n", maxe);

	return 0;
}

Measured memory_bytes: 1792
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


n,k = inpl()
res = 0
cnt = [0] * (k+5)
for i in reversed(range(1,k+1)):
    tmp = pow(k//i,n,mod)
    cnt[i] = tmp
    now = i
    while True:
        now += i
        if now > k:
            break
        cnt[i] -= cnt[now]
    res += cnt[i] * i
    res %= mod
print(res)

Measured memory_bytes: 78628
import scala.io.StdIn._

object Main extends App {

  val n = readInt()
  val a = readLine().split(" ").map(_.toInt)

  def solve() = {
    val numAndCntMap = a.groupBy(identity).mapValues(_.length)
    numAndCntMap.foldLeft(0) { case (acc, (num, cnt)) =>
      if(num <= cnt) acc + (cnt - num)
      else acc + cnt
    }
  }

  println(solve())

}



Measured memory_bytes: 83520
#include <stdio.h>

int N, M;
char MinaseInori[64][64];
int cost[64][3];

int memo[64][3];

int search(int pos, int current) {
	int ret, candidate;
	if (pos >= N) return current == 2 ? 0 : 100000000;
	if (memo[pos][current]) return ~memo[pos][current];
	ret = search(pos + 1, current) + cost[pos][current];
	if (current < 2 && pos + 1 < N) {
		candidate = search(pos + 1, current + 1) + cost[pos][current];
		if (candidate < ret) ret = candidate;
	}
	return ~(memo[pos][current] = ~ret);
}

int main(void) {
	int i, j;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%s", MinaseInori[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		cost[i][0] = cost[i][1] = cost[i][2] = M;
		for (j = 0; j < M; j++) {
			if (MinaseInori[i][j] == 'W') cost[i][0]--;
			if (MinaseInori[i][j] == 'B') cost[i][1]--;
			if (MinaseInori[i][j] == 'R') cost[i][2]--;
		}
	}
	printf("%d\n", search(0, 0));
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> v(n);
  int cnt = 0;
  int i;
  for(i=0;i<n;i++) cin >> v[i];
  sort(v.begin(),v.end());
  for(i=0;i<k;i++) cnt += v[i];
  cout << cnt << "\n";
  return 0;
}

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

int main(){
    long long int a,b;
    cin>>a>>b;
    int k= max(a,b)-min(a,b);
    if(k%2!=0)cout<<"IMPOSSIBLE"<<endl;
    else{
        k/=2;
        cout<<max(a,b)-k<<endl;
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in3.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    int T=1;
    // cin >> T;
    FOR1(tt, T)
    {
        //cout << "Case #" << tt << ": ";
        int n; cin >> n;
        string c; cin >> c;
        int w = 0, r = 0;
        FOR(i, n){
            if(c[i] == 'W') w++;
            else r++;
        }
        int ans = min(r, w);

        int sp = 0;
        for(int i = 0; i < r; i++){
            if(c[i] == 'W') sp++;
        }
        ans = min(ans, sp);
        cout << ans;
        cout << '\n';
    }
    return 0;
}

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

int main() {
  map<string, int> d;
  int n;
  cin >> n;
  rep(i,0,n) {
    string s;
    cin >> s;
    d[s] += 1;
  }
  cout << "AC x " << d["AC"] << endl;
  cout << "WA x " << d["WA"] << endl;
  cout << "TLE x " << d["TLE"] << endl;
  cout << "RE x " << d["RE"] << endl;
  return 0;
}

Measured memory_bytes: 3628
//
//  main.cpp
//  roadwork
//
//  Created by Dong Truong on 6/1/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>

using namespace std;
#define maxn 1000001

struct rwork
{
    int s,t,x,id;
};
struct pp
{
    int vl,ans,next_empty;
};

rwork g[maxn];pp person[maxn];int n,q;

void nhap()
{
    cin>>n>>q;
    for (int i=1;i<=n;++i)
    {
        int s,t,x;
        cin>>s>>t>>x;
        g[i].s=s;g[i].t=t;g[i].x=x;g[i].id=i;
    }
    for (int i=1;i<=q;++i)
    {
        int x;cin>>x;
        person[i].vl=x;
        person[i].ans=-1;
        person[i].next_empty=i+1;
    }
}
bool vt(rwork a,rwork b)
{
    return a.x<b.x;
}
int findmin(int vt,int x)
{
    int l=1,r=q;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (x<=vt+person[mid].vl && vt+person[mid-1].vl<x) return mid;
        if (x<=vt+person[mid].vl) r=mid-1;
        else l=mid+1;
    }
    return 0;
}
int findmax(int vt,int x)
{
    int l=1,r=q;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (vt+person[mid].vl<=x && vt+person[mid+1].vl>x) return mid;
        if (vt+person[mid].vl<=x) l=mid+1;
        else r=mid-1;
    }
    return -1;
}
void sol()
{
    sort(g+1,g+n+1,vt);
    for (int i=1;i<=n;++i)
    {
        int low=findmin(g[i].x,g[i].s);
        int hi=findmax(g[i].x,g[i].t-1);
        while (low<=hi)
            if (person[low].ans==-1)
            {
                person[low].ans=g[i].x;
                person[low].next_empty=hi+1;
                ++low;
            }
            else
                while (person[low].ans>=0)
                    low=person[low].next_empty;
    }
}
void xuat()
{
    for (int i=1;i<=q;++i)
        cout<<person[i].ans<<"\n";
}
int main(int argc, const char * argv[]) {
    // insert code here...
    //std::cout << "Hello, World!\n";
    //freopen("a.inp","r",stdin);
    nhap();
    person[0].vl=-1e9-1;
    person[q+1].ans=-1;
    person[q+1].vl=1e9+1;
    sol();
    xuat();
    return 0;
}


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

#define mod 998244353
#define  ll long long
using namespace std;
int main() {
    int n;
    cin>>n;
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                cnt++;
            }
        }
    }
    cout<<cnt;

}

Measured memory_bytes: 256
n,h = map(int,input().split())
a_list = []
b_list = []
use_b_list = []
for i in range(n):
  a,b = map(int,input().split())
  a_list.append(a)
  b_list.append(b)
use_a = max(a_list)
import math
for b in b_list:
  if b > use_a:
    use_b_list.append(b)
use_b_list.sort(reverse = True)    
count = 0
if sum(use_b_list) >= h:
  for i in range(len(use_b_list)):
    h -= use_b_list[i]
    count += 1
    if h <= 0:
      break
  print(count)
else:
  h -= sum(use_b_list)
  print(len(use_b_list) + int(math.ceil(h/max(a_list))))

Measured memory_bytes: 68056
import heapq
def dijkstra(G, s):
    dist = [float("inf")]*len(G)
    ret = [-1]*len(G)
    q = []
    dist[s] = 0
    heapq.heapify(q)
    heapq.heappush(q, [0, s])
    while 0 < len(q):
        pre_cost, p = heapq.heappop(q)
        if dist[p] < pre_cost:
            continue
        for v, d in G[p]:
            if dist[v] > dist[p] + d:
                dist[v] = dist[p] + d
                heapq.heappush(q, [dist[v], v])
                ret[v] = p
    return ret

def main():
    n, m = map(int, input().split())
    G = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        G[a].append([b, 1])
        G[b].append([a, 1])
    ans = dijkstra(G, 1)
    f = True
    for i in range(2, n+1):
        if ans[i] == -1:
            f = False
    if f:
        print("Yes")
        for i in range(2, n+1):
            print(ans[i])
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 71964