akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
const int N = 301;
double dp[N][N][N];
 
int main(){
	int n;	
	cin >> n;
 
	int cnt[4] = {0};
 
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		cnt[x]++;
	}
 
	dp[0][0][0] = 0;
 
	for(int three = 0 ; three <= n ; three++){
		for(int two = 0 ; two <= n ; two++){
			for(int one = 0 ; one <= n ; one++){
				int zero = n - three - two - one;
				if (zero == n){
					continue;
				}
				if (one + two + three > n){
					continue;
				}
				double val = 1;
				if(three > 0)val += (1.0 * three/n) * dp[three-1][two+1][one];
				if(two > 0)val += (1.0 * two/n) * dp[three][two-1][one+1];
				if(one > 0)val += (1.0 * one/n) * dp[three][two][one-1];
 
				dp[three][two][one] = val / (1 - 1.0 * zero/n);
			}
		}
	}
 
	cout << setprecision(9) << fixed;
	cout << dp[cnt[3]][cnt[2]][cnt[1]];
 
	return 0;
}

Measured memory_bytes: 111128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
	
	string str;
	
	cin >> str;
	
	bool C = false;
	bool F = false;
	
	for(int i = 0; i < str.size(); i++){
		if(!C){
			if(str[i] == 'C'){
				C = true;
			}
		}else if(!F){
			if(str[i] == 'F'){
				F = true;
			}
		}
	}
	
	if(F){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    F = input().split()

    A  = int(F[0])
    OP = F[1]
    B  = int(F[2])

    if OP == "+":
        ans = A + B
    elif OP == "-":
        ans = A - B
    else:
        assert False

    print(ans)

if __name__ == "__main__": main()


Measured memory_bytes: 3060
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			u = scanner.nextInt();
			if ((n | u) == 0)
				break;
			need = new int[n];
			int all = 0;
			unit = new int[n];
			for (int i = 0; i < n; i++) {
				unit[i] = scanner.nextInt();
				all += unit[i];
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					int x = scanner.nextInt();
					need[i] |= (1 << x);
				}
			}
			if (all == u) {
				System.out.println(n);
				continue;
			}
			v = new boolean[1 << n];
			PriorityQueue<Point> deque = new PriorityQueue<Point>();
			deque.offer(new Point(0, 0, 0));

			while (!deque.isEmpty()) {
				Point p = deque.poll();
				if (p.have >= u) {
					System.out.println(p.one);
					break;
				}
				for (int i = 0; i < n; i++) {
					int a = p.bit | (1 << i);
					if (v[a] || (a | need[i]) != a)
						continue;
					v[a] = true;
					deque.offer(new Point(a, p.one + 1, p.have + unit[i]));
				}
			}
		}
	}

	class Point implements Comparable<Point> {
		int bit, one, have;

		public Point(int bit, int one, int have) {
			super();
			this.bit = bit;
			this.one = one;
			this.have = have;
		}

		@Override
		public String toString() {
			return "Point [bit=" + bit + ", one=" + one + ", have=" + have
					+ "]";
		}

		@Override
		public int compareTo(Point o) {
			if (one == o.one)
				return o.have - have;
			return one - o.one;
		}

	}

	int n, u;
	int[] need, unit;
	int ans;
	boolean[] v;
}

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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

#define DIV 2019 

vector<vector<int>> mul10_mod(DIV, vector<int>(9, -1));

int get_mul10_mod(int x, int y){
  if (mul10_mod[x][y-1] == -1) {
    mul10_mod[x][y-1] = (x * 10 + y) % DIV;
  }

  return mul10_mod[x][y-1];
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  READ(S);

  // main procedure
  size_t len_S = S.size();
  
  vector<int> digits_vec(len_S);
  for (size_t i = 0; i < len_S; ++i) {
    digits_vec[i] = S[i] - '0';
  }

  ll ans = 0;

  vector<ll> mod_count_map(DIV, 0);
  for (size_t i = 0; i < len_S; ++i) {
    vector<ll> tmp_map = mod_count_map;
    mod_count_map = vector<ll>(DIV, 0);

    for (size_t j = 0; j < DIV; ++j) {
      mod_count_map[get_mul10_mod(j, digits_vec[i])] += tmp_map[j];
    }
    mod_count_map[digits_vec[i]]++;

    ans += mod_count_map[0];
  }
  
  // output
  WRITE_N(ans);

  return 0;
}


Measured memory_bytes: 4496
#include <iostream>
#include<string>
using namespace std;
string s;
int ans[1000000];
int main(){
    cin >> s;
    int l = s.size();
    int left = 0;
    int a = 0;
    int b = 0;
    int right = 0;
    bool on_R = true;
    for(int i=0;i<l;i++){
        ans[i] = 0;
    }
    for(int i=0;i<l;i++){
        if(on_R){
            if(s[i+1] == 'L'){
                a = i;
                b = i+1;
                on_R = false;
            }
        }
        else{
            if(i == (l-1)||s[i+1] == 'R'){
                ans[a] = (i-b+1)/2 + (a-left+2)/2;
                ans[b] = (i-b+2)/2+(a-left+1)/2;
                left = i+1;
                on_R = true;
            }
        }
    }

    for(int i=0;i<(l-1);i++){
        cout << ans[i] << " ";
    }
    cout << ans[l-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    abc092a()
}

fun abc092a() {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val d = readLine()!!.toInt()

    println(Math.min(a, b) + Math.min(c, d))
}


Measured memory_bytes: 32036
a = int(input())
b = int(input())
c = int(input())
x = int(input())

A = 500
B = 100
C = 50
count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            amount = i*A + j*B + k*C
            if amount == x:
                count += 1


print(count)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<assert.h>

typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll n;
	scanf("%lld", &n);
	if (n%2)
	{
		printf("0");
		return 0;
	}
	ll sum=0;
	for (ll i = 10; i <= n; i*=5)
	{
		sum += n / i;
	}
	printf("%lld",sum);
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,x;
    cin>>n>>m>>x;
    int f[101]={0};
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        f[a]=1;
    }
    int c1=0,c2=0;
    for(int i=x;i<n;i++){
        if(f[i])c1++;
    }
    for(int i=x;i>=0;i--){
        if(f[i])c2++;
    }
    int ans=min(c1,c2);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin>>n;
    for(int s=2;s<n.size();s++)
    {
        if(n[s]==n[s-1]&&n[s]==n[s-2])
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

ll mod_pow(ll x, ll n, ll M){
    ll res = 1;
    while(n > 0){
        if (n & 1) (res *= x) %= M;
        (x *= x) %= M;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    vector<int> a;
    cin >> n;
    REP(i,0,n){
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());

    vector<int> b;
    for (int i = n - 1; i > 0; i -= 2){
        b.push_back(i);
        b.push_back(i);
    }
    if (n % 2) b.push_back(0);
    sort(b.begin(), b.end());

    ll ans = 0;
    if (a == b) ans = mod_pow(2, n / 2, MOD);

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

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a[5];
  int k;
  for(int i=0;i<5;i++){
    cin>>a[i];
  }
  cin>>k;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
      if(a[j]-a[i]>k){
        cout<<":("<<endl;
        return 0;
      }
    }
  }cout<<"Yay!"<<endl;
  return 0;
}

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

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

    int x;
    for (int i = 1; i <= n; i++)
    {
        x=i;
        if(x%3 == 0) cout << " " << i;
        else while (x)
        {
            if(x%10 == 3){
                 cout << " " << i;
                 break;
            }
            else x /= 10;
        }
        
    }
    cout << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>

using namespace std;

int p[100001];
int main(){
    int n;
    cin>>n;
    long long r = 0;
    for(int i = 0;i<n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        p[i] = -(a+b);
        r -=b;
    }
    sort(p,p+n);
    for(int j = 0;j<n;j+=2)
        r-=p[j];
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[LS() for _ in range(n)]
  x=S()

  ans=0
  f=False
  for a,b in l:
    if f:
      ans+=int(b)
    if a==x:
      f=True

  return ans

# main()
print(main())


Measured memory_bytes: 8260
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    double a,b,c,d,e,f,x,y;
    while(cin >> a >> b >> c >> d >> e >> f){
	x = (c*e - b*f)/(a*e - b*d);
	y = (a*f - c*d)/(a*e - b*d);
	if(x == 0) x = 0.000;
	if(y == 0) y = 0.000;
	printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
long long psum[200005];
long long mod = 1000000007;
int main(){
	long long n,k;
	cin>>n>>k;
	for(int i=1; i<=n; i++) psum[i] = i;
	for(int i=1; i<=n; i++) psum[i]+=psum[i-1];
	long long ret = 0;
	for(int i=k; i<=n+1; i++){
		long long minsum = psum[i-1];
		long long maxsum = psum[n];
		if(i<n+1) maxsum-=psum[n-i];
		ret+=(maxsum-minsum+1);
		ret%=mod;
	}
	cout<<ret;
}

Measured memory_bytes: 5076
#include <stdio.h>

int main(void)
{
	int n;
	char s[101], t[101];
	int i;

	scanf("%d", &n);

	scanf("%s %s", s, t);

	for (i = 0; i < n; i++)
	{
		printf("%c%c", s[i], t[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int A, B, C, K; cin >> A >> B >> C >> K;
  int cnt = 0;
  while(A>=B) {
    B*=2; cnt++;
  }
  while(B>=C){
    C*=2; cnt++;
  }
  if(cnt<=K) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3640
use proconio::{fastout, input};
use std::cmp;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut k: u64,
        r#as: [u64; n],
        bs: [u64; m],
    }

    let mut i = 0;
    let mut j = 0;

    while i < n && r#as[i] <= k {
        k -= r#as[i];
        i += 1;
    }
    while j < m && bs[j] <= k {
        k -= bs[j];
        j += 1;
    }

    let mut max = i + j;

    while i > 0 {
        k += r#as[i - 1];
        i -= 1;
        while j < m && bs[j] <= k {
            k -= bs[j];
            j += 1;
        }
        max = cmp::max(max, i + j);
    }

    println!("{}", max);
}


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

int main()
{
    int n, l, ans = 0,tmp=500,minv=500;
    cin >> n >> l;

    for (int i = 0; i < n; i++)
    {
        if(tmp > abs(i+l))
        {
            tmp = abs(i+l);
            minv = (i+l);
        }
        ans+=(i+l);
    }
    // cout<<tmp<<endl;
    // cout<<minv<<endl;
    cout<<ans-minv<<endl;
}

Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
if n%3==0:
    n=int(n/3)
    if A[0]==A[n-1] and A[n]==A[2*n-1] and A[2*n]==A[3*n-1] and A[0]^A[n]^A[2*n]==0:
        ans=1
    else:
        ans=0
else:
    if(A[n-1]==0):
        ans=1
    else:
        ans=0
print("Yes" if ans==1 else "No")


Measured memory_bytes: 14116
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define ii pair<ll,ll>
#define sc second
#define mp make_pair
#define All(v) v.begin(),v.end()
using namespace std;
/// Segment Tree
const int max_node = 10000000;
ll tree[max_node];
ll A[max_node];
ll n,k;
void update(int node , int start , int _end , int idx , int val)
{
    if(start == _end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start+_end)/2;
        if(start <= idx && idx <= mid)
        {
            update(node*2,start,mid,idx,val);
        }
        else
        {
            update(node*2+1,mid+1,_end,idx,val);
        }
        tree[node] = tree[2*node]+tree[2*node+1];
    }
 }

ll query(int node , int start , int _end, int l , int r)
{
    if(r < start || l > _end)
    {
        return 0;
    }
    if(l <= start && _end<= r)
    {
        return tree[node];
    }
    int mid = (start+_end)/2;
    int x1 = query(2*node  ,start , mid , l , r);
    int x2 = query(2*node+1,mid+1 ,_end , l , r);
    return (x1+x2);
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&A[i]);
            A[i]-=k;
        }
    ll dp[n+1];
    vector < ll > v;
    map < ll , ll > my;
    map < ll, ll > my2;
    memset(dp,0,sizeof(dp));
    dp[0] = 0;
    v.push_back(0);
    for(int i=1;i<=n;i++)
    {
        dp[i] = dp[i-1]+A[i];
        v.push_back(dp[i]);
    }
    sort(v.begin() , v.end());
    ll last = v[0];
    my[v[0]] = 1;
    my2[1] = v[0];
    int cnt = 2;
    for(int i=1;i<v.size();i++)
    {
        if(v[i]!= last)
        {
            my[v[i]] = cnt;
            my2[cnt] = v[i];
            cnt++;
        }
        last = v[i];
    }
    ll TT = cnt+100;
    dp[0] = my[dp[0]];
    for(int i=1;i<=n;i++)
    {
        dp[i] = my[dp[i]];
        update(1,1,TT,dp[i],1);
    }
    ll sum = 0;
    for(int i=1;i<=n;i++)
    {
        ll target = dp[i-1];
        sum+=query(1,1,TT,target,TT);
        update(1,1,TT,dp[i],-1);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 36080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int query(string x){
    cout << "? " << x << endl;
    int ret; cin >> ret;
    return ret;
}

int main(){
    string s;
    rep(i, 26) s += 'a'+i;
    rep(i, 26) s += 'A'+i;
    rep(i, 10) s += '0'+i;
    int cnt[62], N = 0;
    rep(i, 62){
        string x;
        rep(j, 128) x += s[i];
        N += cnt[i] = 128-query(x);
    }
    string ans;
    rep(i, 62){
        rep(j, cnt[i]){
            int n = sz(ans), l = 0, r = n+1; //[l,r)
            while(r-l > 1){
                int m = (l+r)/2;
                string x;
                rep(k, m) x += ans[k];
                x += s[i];
                rep(k, n-m) if(ans[m+k] == s[i]) x += ans[m+k];
                if(query(x) == N-sz(x)) l = m;
                else r = m;
            }
            string tmp;
            rep(k, l) tmp += ans[k];
            tmp += s[i];
            rep(k, n-l) tmp += ans[l+k];
            swap(ans, tmp);
        }
    }
    cout << "! " << ans << endl;
}

Measured memory_bytes: 3772
#include <iostream>
using namespace std;
int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res=0;
  for (int a=0; a<=A; a++){
    for (int b=0; b<=B; b++){
      for (int c=0; c<=C; c++){
        int total = 500*a + 100*b + 50*c;
        if (total == X) res++;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a[5], k;
    
    rep(i, 5){
        scanf("%d", &a[i]);
    }
    
    scanf("%d", &k);

    rep(i, 5){
        rep(j, 5){
            if (a[i]-a[j]>k) {
                printf(":(");
                return 0;
            }
        }
    }
    
    printf("Yay!");
    
    return 0;
}



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

long long n,a[100005];

int main(){
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{	
		cin>>a[i];
		if(a[i]==0){
			cout<<0<<endl;
			return 0;
		}
	}
	
	long long pro=1;
	for(int i=1;i<=n;i++)
	{
		if(1000000000000000000/pro>=a[i])
			pro*=a[i];
		else{
			cout<<-1<<endl;
			return 0;
		}
	}
	
	cout<<pro<<endl;
	return 0;
}

Measured memory_bytes: 4368
n,m,x,y=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
z=min(b)
for i in range(n):
    if a[i]>=z:
        print("War")
        exit()
if x<z<=y:
    print("No War")
else:
    print("War")

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

int main(){
    int a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=a;i<=b;i++){
        bool pali=0;
        string s;
        s=to_string(i);
        vector<char>g(s.size());
        for(int j=0;j<s.size();j++){
            g[j]=s[s.size()-1-j];
        }
        for(int k=0;k<s.size();k++){
            if(g[k]==s[k])pali=1;
            else {
                pali=0;
                break;
            }
        }
        if(pali)cnt+=1;
        else cnt+=0;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
def divisor(n):
    tank = []
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            tank.append((i, n//i))
    return tank

m,d = map(int,input().split())
cnt = 0
for i in range(1,m+1):
    k = divisor(i)
    for x,y in k:
        a = int(str(x)+str(y))
        if a//10>=2 and a%10>=2 and a<=d:
            cnt += 1
        if x!=y:
            b = int(str(y)+str(x))    
            if b//10>=2 and b%10>=2 and b<=d:
                cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0;
  for (auto c : s)
    if (c == 'R') r++;
    else r--;
  if (r > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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


Measured memory_bytes: 3824
int main(void) {

    int n, a, k, l, card[4][13];
    char mark;
    scanf("%d", &n);
    
    for(k = 0; k < 4; k++)
    {
        for(l = 0; l < 13; l++)
        {
            card[k][l] = 0;
        }
    }
    for(k = 0; k < n; k++)
    {
        scanf(" %c%d", &mark, &a);
        if(mark == 'S') card[0][a-1] = 1;
        else if(mark == 'H') card[1][a-1] = 1;
        else if(mark == 'C') card[2][a-1] = 1;
        else card[3][a-1] = 1;
    }
    for(k = 0; k < 4; k++)
    {
        for(l = 0; l < 13; l++)
        {
            if(k == 0 && card[k][l] == 0)
                printf("S %d\n", l+1);
            else if(k == 1 && card[k][l] == 0)
                printf("H %d\n", l+1);
            else if(k == 2 && card[k][l] == 0)
                printf("C %d\n", l+1);
            else if(k == 3 && card[k][l] == 0)
                printf("D %d\n", l+1);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define pdd pair<double,double>
#define cpdd const pdd
int mod=1e9+7;
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int a[2005];
    LL ans=0;
    for(int i = 0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(a[i]>a[j]){
                if(i<j){
                    ans+=k;
                }
                ans+=(LL)k*(k-1)/2;
                //printf("%d %d %d\n",ans,i,j);
                ans%=mod;
            }
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>

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

using namespace std;

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

	// 現在の場所
	int now_t = 0, now_x = 0, now_y = 0;
	// 次に行く場所
	int t, x, y;

	REP(i, N) {
		scanf("%d %d %d", &t, &x, &y);

		// まず最低限必要な時間
		int rest_t = t - now_t - (abs(x - now_x) + abs(y - now_y));
		if (rest_t < 0 || rest_t % 2 == 1) {
			printf("No\n");
			return 0;
		}

		// 更新
		now_t = t;
		now_x = x;
		now_y = y;
	}

	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
import math
import itertools
import statistics
#import collections

#n =  list(map(int, input().split()))
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

dif = []
for i in range(n):
    dif.append(v[i]-c[i])

total = 0
for i in range(n):
    if dif[i] > 0:
        total += dif[i]

print(total)



Measured memory_bytes: 5148
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N + 1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + ABC[i][j])

ans = 0

for i in range(3):
    ans = max(ans, dp[N][i])

print(ans)


Measured memory_bytes: 74200
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool iszero = (s[0]=='0');
    char bef = s[0];
    vector<int> cc(n);
    int i = 1;
    cc[0] = 0;
    int count = 0;
    for(char c: s){
        if(bef == c){
            count++;
        }else{
            cc[i] = count+cc[i-1];
            count = 1;
            i++;
        }
        bef = c;
    }
    cc[i] = count+cc[i-1];
    for(int j = i; j < n; j++){
        cc[j] = cc[i];
    }
//    for(int j = 0; j <= i; j++){
//        cerr << cc[j] << endl;
//    }

    int m = 0;
    if(iszero){
        m = max(m, cc[k*2]);
        if(1+k*2 > i){
            m = n;
        }
        for(int j = 1; j+k*2+1 <= n; j+=2){
            m = max(m, cc[j+k*2+1] - cc[j]);
//            cerr << m << endl;
        }
    }else {
        if(k * 2+1 > i){
            m = n;
        }
        for(int j = 0; j + k * 2+1 <= n; j+=2) {
            m = max(m, cc[j + k * 2+1] - cc[j]);
//            cerr << m << endl;
        }
    }
    if(m == 0){
        cout << n << endl;
    }else {
        cout << m << endl;
    }
    return 0;
}


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

H,W,N = map(int,input().split())
XY = sorted(tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())

"""
・Tは常に移動
・選択肢はAのみ。Aが詰み地点に誘導するゲーム
・Aが誘導できるy座標集合は、今まで仕留められる場所が存在した場合を除いて区間[1,U]
"""

X_to_Y = [set() for _ in range(H+1)]
for x,y in XY:
    X_to_Y[x].add(y)

U = 0
for x in range(1,H+1):
    if x == H:
        break
    if not (U+1 in X_to_Y[x]):
        U += 1
    # ゴールしていればbreak
    if any(y<=U for y in X_to_Y[x+1]):
        break

print(x)

Measured memory_bytes: 77448
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
x=int(input())
if x>=400 and x<=599:
    print(8)
elif x>=600 and x<=799:
    print(7)
elif x>=800 and x<=999:
    print(6)
elif x>=1000 and x<=1199:
    print(5)
elif x>=1200 and x<=1399:
    print(4)
elif x>=1400 and x<=1599:
    print(3)
elif x>=1600 and x<=1799:
    print(2)
elif x>=1800 and x<=1999:
    print(1)


Measured memory_bytes: 62036
def main():
    number = input()
    temp_list = list(map(int, input().split()))
    count_dict = {"APPROVED":0, "DENIED":0}

    for i in temp_list:
        if i%2 == 0 and (i%3 != 0 and i%5 != 0):
           count_dict["DENIED"] += 1
            
    if count_dict["DENIED"] == 0:
        print("APPROVED")
    else:
        print("DENIED")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<long long,int>>ED(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        ED[i] = make_pair(a, b);
    }
    sort(ED.begin(), ED.end());
    long long ans = 0;
    int count = M;
    for (int i = 0; i < N; i++) {
        ans += ED[i].first*min(ED[i].second, count);
        count -= min(ED[i].second, count);
        if (count == 0)break;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1792
#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>
#include <chrono>
#include <random>

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>;
template<typename T> using VT = vector<T>;
#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;

#define int LL

int nn[5][11];

int f(int n, int i, int j) {
    return 63 * j + 9 * i + 9;
}

void init(int n) {
    REP(i, 5) REP(j, 11) {
        nn[i][j] = f(n, i + 1, j + 1) % 11;
    }
}

signed main(void) {
    int n, k;
    cin >> n >> k;
    int _n = n;
    init(n);
    int ans = 0;
    REP(i, 5) {
        n = _n;
        n -= 2;
        ans += n / 11;
        n %= 11;
        REP(j, n) ans += (k == nn[i][j]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

bool check(string s) {
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    int j = n - 1 - i;
    if (i >= j) break;
    if (s[i] != s[j]) return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (check(s) && check(s.substr(0, (n - 1) / 2)) && check(s.substr((n + 3) / 2 - 1))) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    long c = scanner.nextLong();
    long[] x = new long[n + 1];
    long[] v = new long[n + 1];
    for (int i = 0; i < n; i++) {
      x[i + 1] = scanner.nextLong();
      v[i + 1] = scanner.nextLong();
    }
    System.out.println(solve(n + 1, c, x, v));
  }

  private static long solve(int n, long c, long[] x, long[] v) {
    long res = 0;

    long sum = 0;
    long[] rsum = new long[n];
    for (int i = 1; i < n; i++) {
      rsum[i] = rsum[i - 1];
      sum += v[i];
      if (sum - x[i] * 2 > rsum[i]) {
        rsum[i] = sum - x[i] * 2;
      }
    }
    sum = 0;
    long[] lsum = new long[n];
    for (int i = 1; i < n; i++) {
      lsum[i] = lsum[i - 1];
      sum += v[n - i];
      if (sum - (c - x[n - i]) * 2 > lsum[i]) {
        lsum[i] = sum - (c - x[n - i]) * 2;
      }
    }

    // Start at 0 and exit at right
    sum = 0;
    for (int right = 0; right < n; right++) {
      sum += v[right];
      long r = sum - x[right];
      if (r > res) res = r;
    }
    // Start at 0, go to right and then back to left, then exit there
    sum = 0;
    for (int left = n - 1; left > 0; left--) {
      sum += v[left];
      long r = sum + rsum[left - 1] - (c - x[left]);
      if (r > res) res = r;
    }

    // Start at 0 and exit at left
    sum = 0;
    for (int left = n - 1; left >= 0; left--) {
      sum += v[left];
      long r = sum - (c - x[left]);
      if (r > res) res = r;
    }
    // Start at 0, go to left and then back to right, then exit there
    sum = 0;
    for (int right = 1; right < n; right++) {
      sum += v[right];
      long r = lsum[n - right - 1] + sum - x[right];
      if (r > res) res = r;
    }

    return res;
  }
}


Measured memory_bytes: 92408
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 4e4+5;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll a, b, k;
    cin >> a >> b >> k;
    ll val = min(k, a);
    a -= val, k -= val;
    b = max(0LL, b - k);
    cout << a << ' ' << b;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	void solve(){
		lli N,i,j,p,q;
		p=q=0;
		string s;
		cin>>s;
		N=s.size();
		for(i=0;i<N;i++){
			if(s[i]=='0')p+=1;
			if(s[i]=='1')q+=1;
		}
		cout<<min(p,q)*2;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


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

int main() {
  string S;
  cin >> S;
  
  vector<char> C(S.size());
  for (int i = 0; i < S.size(); i++) {
    C.at(i) = S.at(i);
  }
  
  vector<int> N(S.size());
  for (int i = 0 ; i < S.size(); i++) {
    N.at(i) = C.at(i) - '0';
  }
  
  vector<int> n(S.size() - 2);
  for (int i = 0 ; i < S.size() - 2; i++) {
    n.at(i) = N.at(i)*100 + N.at(i+1)*10 + N.at(i+2);
  }
  
  vector<int> X(S.size() - 2);
  for (int i = 0 ; i < S.size() - 2; i++) {
    if (n.at(i) >= 753){
      X.at(i) = n.at(i) - 753;
    }
    else {
      X.at(i) = 753 - n.at(i);
    }
  }
  
  sort(X.begin(), X.end());
  cout << X.at(0) << endl;
}
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n;
    cin >> n;
    const int MAX = 100000;
    vector<int> as(MAX, 0);
    rep(i, n) {
        int a; cin >> a;
        as[a]++; 
    }
    int ret = 0;
    rep(i, as.size()-2) {
        int cnt = as[i] + as[i+1] + as[i+2];
        ret = max(ret, cnt); 
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int main()
{           
    IOS;
    ll k,a,b;
    cin>>k>>a>>b;
    ll tmp=k+1;
    if(b<=a)
    {
    	cout<<k+1;
    	return 0;
    }
    if(k<a+1)
    {
    	cout<<k+1;
    	return 0;
    }
    ll ans=1;
    k-=(a+1);
    ans=b;
    ans+=(k/2)*(b-a)+(k%2!=0);
    cout<<max(ans,tmp);
    
}   	

Measured memory_bytes: 256
import sys
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
#print(AB)

ABs=sorted(AB,key=lambda x:x[1])
#print(ABs)

t=0
for ab in ABs:
    t+=ab[0]
    if t>ab[1]:
        print('No')
        sys.exit()

print('Yes')


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

#define ll long long
// #define endl '\n'

void max_self(int &a, int b){a = max(a, b);}
// void min_self(int &a, int b){a = min(a, b);}

const int nax = 2e5 + 5;
vector< int > G[nax], vis(nax);
int cnt;

void dfs(int node){
	vis[node] = 1;
	cnt++;
	for(int i : G[node]){
		if(!vis[i]){
			dfs(i);
		}
	}
}

void solve(){
	int n, m; cin>>n>>m;
	for(int i = 0; i<m; i++){
		int a, b; cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for(int i = 1; i<=n; i++){
		if(!vis[i]){
			cnt = 0;
			dfs(i);
			max_self(ans, cnt);
		}
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 21068
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for j in range (n)]
ans = "No"
for k in range (n):
  for l in range(3):
    for m in range(3):
      if a[l][m] == b[k]:
        a[l][m] = 0
for o in range(3):
  if a[o][0] == a[o][1] == a[o][2] or a[0][o] == a[1][o] == a[2][o]:
    ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] or a[2][0] == a[1][1] == a[0][2]:
  ans = "Yes"
print(ans)

Measured memory_bytes: 9192
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <limits>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;
	cin >> h >> w;
	char a[100][ 100];
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][ j];
		}
	}
	bool hs[200];
	bool ws[200];
	rep(i, 200) { hs[i] = ws[i] = false; }
	rep(j, w) {
		bool f = true;
		rep(i, h) {
			if (a[i][ j] != '.') { f = false; break; }
		}
		if (f) { ws[j] = true; }
	}
	rep(i, h) {
		bool f = true;
		rep(j, w) {
			if (a[i][ j] != '.') { f=false; break; }
		}
		if (f) { hs[i] = true; }
	}
	rep(i, h) {
		if (hs[i]) { continue; }
		rep(j, w) {
			if (ws[j]) { continue; }
			cout << a[i][ j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())

P = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    if i+1 == P[i]:
        P[i],P[i+1] = P[i+1],P[i]
        ans += 1

if P[N-1] == N:
    P[N-1],P[N-2] = P[N-2],P[N-1]
    ans += 1
    
print(ans)

Measured memory_bytes: 14008
N=int(input())
Hi=[int(x) for x in input().split()]
Hi.reverse()
ans='No'
for i in range(N-1):
  if Hi[i+1]-Hi[i]>=2:
    break
  elif Hi[i+1]-Hi[i]==1:
    Hi[i+1]-=1
    if Hi[i+1]<=0:
      break
else:
  ans='Yes'
print(ans)

Measured memory_bytes: 14252
using System;
using System.Linq;

class Program {
  static void Main (string[] args) {
    string[] str = Console.ReadLine().Split(' ');
    int n = int.Parse(str[0]);
    int m = int.Parse(str[1]);
    int c = int.Parse(str[2]);
    string[] b_str = Console.ReadLine().Split(' ');
    int[] b = b_str.Select(int.Parse).ToArray();
    int count = 0;
    for (int cnt = 0; cnt < n; cnt++) {
      string[] a_str = Console.ReadLine().Split(' ');
      int[] a = a_str.Select(int.Parse).ToArray();
      int pls = 0;
      for (int ct = 0; ct < m; ct++) {
        pls += b[ct] * a[ct];
      }
      pls += c;
      if (pls > 0) count++;
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	long long N,C;
	cin>>N>>C;
	
	vector<long long> x(N+1,0),v(N+1,0);
	
	for(int i=0;i<N;i++){
		cin>>x[1+i]>>v[1+i];
	}
	
	vector<long long> maxi1(N+1,0);
	long long s = 0;
	for(int i=N;i>=1;i--){
		s += v[i];
		maxi1[N+1-i] = s - (C - x[i]);
	}
	s=0;
	vector<long long> maxi2(N+1,0);
	for(int i=1;i<=N;i++){
		s += v[i];
		maxi2[i] = s-x[i];
	}
	
	for(int i=1;i<=N;i++){
		maxi1[i] = max(maxi1[i],maxi1[i-1]);
		maxi2[i] = max(maxi2[i],maxi2[i-1]);
	}
	
	long long ans = 0;
	s=0;
	
	for(int i=0;i<=N;i++){
		s += v[i];
		ans = max(ans,s - x[i]);
		ans = max(ans,s-2*x[i]+maxi1[N-i]);
	}
	
	s=0;
	for(int i=0;i<=N;i++){
		int a = N-i+1;
		if(i==0)a=0;
		s += v[a];
		ans = max(ans,s-(C-x[a]));
		ans = max(ans,s-2*(C-x[a])+maxi2[N-i]);
	}
	
	cout<<ans<<endl;
		
    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
  int N,p=0;
  scanf("%d", &N);
  int a[N],b[N];
  for(int i=0;i<=N;i++) b[i]=0;
  for(int i=0;i<N;i++){
    scanf("%d", &a[i]);
    if(a[i]>N) p++;
    else b[a[i]]++;
  }
  for(int i=1;i<=N;i++){
    if(b[i]!=i && b[i]!=0){
      if(b[i]<i) p+=b[i];
      if(b[i]>i) p+=b[i]-i;
    }    
  } 
  printf("%d\n", p);
  return 0;
}

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

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

  m=n;

  int sum=0;
  while(n>10){
    int a=0;

    a=n%10;
    sum+=a;
    n/=10;

  }
    sum+=n;
    
  if(m%sum==0){
    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++)
#define ll long long
using namespace std;

int main() {
  int n; cin>>n;
  vector<ll> a(n);
  ll sum=0;
  rep(i, n) {
    cin>>a[i];
    sum+=a[i];
  }
  ll tmp=0;
  rep(i, n) {
    tmp+=a[i];
    if (tmp>=sum/2) {
      ll X = tmp - a[i];
      ll Y = sum - tmp;
      cout<<abs(abs(X-Y)-a[i])<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> group[111111];
int p[111111], parent[111111];

int Find(int x)
{
	if (x == parent[x])
		return x;
	else
		return parent[x] = Find(parent[x]);
}

int main(void)
{
	int n, m, i, j, ans = 0;

	scanf("%d %d" ,&n, &m);
	for (i = 1; i <= n; i++)
	{
		scanf("%d" ,&p[i]);
		parent[i] = i;
	}

	while (m--)
	{
		int x1, x2;

		scanf("%d %d" ,&x1, &x2);

		x1 = Find(x1);
		x2 = Find(x2);

		if (x1 != x2)
			parent[x2] = x1;
	}

	for (i = 1; i <= n; i++)
		group[Find(parent[i])].push_back(i);

	for (i = 1; i <= n; i++)
		for (j = 0; j < group[i].size(); j++)
		{
			int it = lower_bound(group[i].begin(), group[i].end(), p[group[i][j]]) - group[i].begin();

			if (!(it == group[i].size() || group[i][it] != p[group[i][j]]))
				++ans;
		}

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

Measured memory_bytes: 9780
#include <iostream>
#include <vector>
#include <string>
class dice
{
private:
	std::vector<int> faces;
public:
	dice(int *surface){
		for(int i = 0 ; i < 6 ; i ++){
			faces.push_back(surface[i]);
		}
	};
	int getSurface(){
		return faces[0];
	};
	dice roll(char d){
		int *s = new int[6];
		switch(d){
			case 'S':
			s[0] = faces[4]; s[1] = faces[0]; s[2] = faces[2];
			s[3] = faces[3]; s[4] = faces[5]; s[5] = faces[1];
			break;
			case 'N':
			s[0] = faces[1]; s[1] = faces[5]; s[2] = faces[2];
			s[3] = faces[3]; s[4] = faces[0]; s[5] = faces[4];
			break;
			case 'E':
			s[0] = faces[3]; s[1] = faces[1]; s[2] = faces[0];
			s[3] = faces[5]; s[4] = faces[4]; s[5] = faces[2];
 			break;
			case 'W':
			s[0] = faces[2]; s[1] = faces[1]; s[2] = faces[5];
			s[3] = faces[0]; s[4] = faces[4]; s[5] = faces[3];
			break;
		}
		dice newdice(s);
		delete[] s;
		return newdice;
	};
};

int main(int argc, char const *argv[])
{
	int *s = new int[6];
	for(int i = 0 ; i < 6 ; i ++){
		std::cin >> s[i];
	}
	dice d(s);

	std::string ops;
	std::cin >> ops;
	for(char op : ops){
		d = d.roll(op);
	}
	std::cout << d.getSurface() << std::endl;
	delete[] s;
	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main(void)
    {
        int N;
        cin >> N;
        vector<long long> lub;
        long long sum = 0;
      
      
        for(int i=0;i<N;i++){
            long long num;
            cin >>num;
            lub.push_back(num);
          sum+=lub[i];
        }
     
        long long result=0;
        for(int i=0;i<N;i++){
            if(sum<= (long long)2*lub[i]){
              long long a = sum;
              long long b = (long long)2*lub[i]-sum;
                result= min(a,b);
                break;
            }
            else{
                sum -= (long long)2*lub[i];
            }
        }
     
        cout<<result<<endl;
      return 0;
    }

Measured memory_bytes: 2548
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXH = 15;
const int MAXW = 1005;

int a[MAXH][MAXW];
int H,W,K;

void solve(){
    cin>>H>>W>>K;

    FOR(i,0,H-1) FOR(j,0,W-1){
        char c; cin>>c;
        a[i][j] = c-'0';
    }

    int Tmask = (1<<H)-1;
    int ans = H*W;

    FOR(mask,0,Tmask){
        vector<vector<int>> reality;
        vector<int> temp(W);
        fill(all(temp),0);
        FOR(i,0,H-1){
            if(mask&(1<<i)){
                FOR(j,0,W-1) temp[j] += a[i][j];
                reality.push_back(temp);
                fill(all(temp),0);
            }else {
                FOR(j,0,W-1) temp[j] += a[i][j];
            }
        }
        reality.push_back(temp);
        int n = reality.size();
        int m = W;

        int cuts = __builtin_popcount(mask);
        int prev = 0;

        bool flag = true;
        FOR(i,0,n-1) FOR(j,0,m-1) if(reality[i][j] > K) flag = false;
        if(flag == false) continue;

        FOR(i,0,n-1) FOR(j,1,m-1) reality[i][j] += reality[i][j-1];

        FOR(j,0,m-1){
            FOR(i,0,n-1){
                if(reality[i][j] - ((prev>0)?reality[i][prev-1]:0) <= K) {
                    continue;
                }else {
                    prev = j;
                    cuts++;
                    break;
                }
            }
        }

        ans = min(ans,cuts);
    }
    cout<<ans<<endl;
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, m;
    cin >> n >> m;

    cout << (m * 1900 + (n - m) * 100) * (1 << m) << '\n';

}   

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define MAX_CX 100
#define MAX_CY 100

int max(int a,int b){
  if(a>b) return a;
  return b;
}

int main(void){
  int n,i,CY,CX,H,flag=0;
  scanf("%d",&n);
  int x[n],y[n],h[n];
  for(i=0;i<n;i++) scanf("%d %d %d",&x[i],&y[i],&h[i]);
  for(CX=0;CX<=MAX_CX;CX++){
    for(CY=0;CY<=MAX_CY;CY++){
      for(i=0;i<n;i++) if(h[i]) break;
      H = h[i] + abs(x[i]-CX) + abs(y[i]-CY);
      for(i=0;i<n;i++){
        if(h[i]!=max(H-abs(x[i]-CX)-abs(y[i]-CY),0)) break;
      }
      if(i==n) flag=1;
      if(flag) break;
    }
    if(flag) break;
  }
  printf("%d %d %d\n",CX,CY,H);
  return 0;
}

Measured memory_bytes: 128