akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <iostream>
#define rep(i,n) for (int i = 0; i<(n); ++i)
using ll = long long;
using namespace std;

int main() 
{
	int K;
	string S;
	cin >> K;
	cin >> S;

	string partS = S.substr(0, K);

	if (S.size() > K)
	{
		cout << partS << "...";
	}
	else
	{
		cout << S;
	}
}

Measured memory_bytes: 3632
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}


fn main() {
    let (_n, k) = read!(usize, u64);
    let a = read!([usize]);

    // (街, 転移回数)
    let mut visited = HashMap::<usize, usize>::new();
    let mut order = vec![1];
    visited.insert(1, 0);

    let mut trip_num = 0;
    loop {
        trip_num += 1;
        let dist = a[order[order.len()-1]-1];
        if let Some(loop_start) = visited.insert(dist, trip_num) {
            let loop_end = trip_num;
            if k <= loop_start as u64 {
                println!("{}", order[k as usize]);
                return;
            } else {
                let t = loop_end - loop_start;
                let pos = ((k-loop_start as u64) % t as u64) as usize + loop_start;
                println!("{}", order[pos]);
                return;
            }
        } else {
            order.push(dist);
        }
    }
}


Measured memory_bytes: 12360
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
ll factorial[10000];
void fac()
{
    factorial[0]=1;
    for(ll i=1; i<=2000; i++)
    {
        factorial[i] = (factorial[i-1]*i) % mod;
    }
}
ll pow(ll a, ll b, ll MOD)
{
    ll x=1,y=a;
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y);
            if(x>MOD) x%=MOD;
        }
        y = (y*y);
        if(y>MOD) y%=MOD;
        b /= 2;
    }
    return x;
}
ll Inverse(ll n, ll MOD)
{
    return pow(n,MOD-2,MOD);
}
ll binomial_coefficient(ll n, ll k)
{
    return ( factorial[n] % mod * ( Inverse(factorial[k],mod ) ) % mod * (Inverse(factorial[n-k],mod)) % mod ) % mod;
}

signed main() {
    int n , k;
    cin >> n >> k;
    fac();
    int ans=1;
    for(int i=1;i<=k;i++) {
        ans = 0;
        if(n-k+1 >= i) 
        ans = binomial_coefficient(n-k+1 , i);

        if(k-1 >= i-1) {
            ans = ans * binomial_coefficient(k-1 , i-1);
            ans = ans % mod;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 764
use std::io;
use std::cmp::min;

fn input() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("Failed to read line.");
    String::from(buf.trim())
}

fn main() {
    let n = input().parse::<i32>().unwrap();
    let k = input().parse::<i32>().unwrap();
    let sum: i32 = input().split(" ")
        .map(|x| x.parse::<i32>().unwrap())
        .map(|x| 2 * min(x, k - x))
        .sum();
    
    println!("{}", sum);
}


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

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

using namespace std;

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

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

void solve() {
  int n, m;
  cin >> n >> m;
  vi32 ac(n);
  vi32 wa(n);
  int ans_ac = 0;
  int ans_wa = 0;
  rep(i, m) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (s == "AC") {
      if (ac[p]) continue;
      ans_ac++;
      ac[p] = 1;
    } else {
      if (ac[p]) continue;
      wa[p]++;
    }
  }
  rep(i, n) if (wa[i] && ac[i]) ans_wa += wa[i];
  cout << ans_ac << " " << ans_wa << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10,M=3e4+10;
const ll inf=INT_MAX,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}

ll x,k,d,ans,c;

int main()
{
    iosks;
    cin>>x>>k>>d;
    if(x>0){
        c=x%d-d;
        c=(x-c)/d;
        if(c<=k){
            k-=c;
            if(k&1) ans=x%d;
            else ans=abs(x%d-d);
        }
        else ans=x-k*d;
    }
    else{
        c=x%d+d;
        c=(c-x)/d;
        if(c<=k){
            k-=c;
            if(k&1) ans=abs(x%d);
            else ans=x%d+d;
        }
        else ans=abs(x+k*d);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int N, K, C; cin >> N >> K >> C;
    string S; cin >> S;
    S = '#' + S;
    int n = S.size();
    vector<int> l(K + 1), r(K + 1);
    int i = 1, j = 1;

    while (i < n && j <= K) {
        if (S[i] == 'o') {
            l[j++] = i;
            i += C + 1;
        }
        else
            ++i;
    }

    i = n - 1, j = K;
    while (i > 0 && j >= 1) {
        if (S[i] == 'o') {
            r[j--] = i;
            i -= C + 1;
        }
        else
            --i;
    }

    for (int i = 1; i <= K; ++i) {
        if (l[i] == r[i])
            cout << l[i] << '\n';
    }
}

Measured memory_bytes: 3408
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#define M_PI 3.1415926535897932384626433832795

int main() {
	int n;
	cin >> n;
	int p = n;
	if (n % 2 == 1) {
		n = n / 2 + 1;
	}
	else {
		n /= 2;
	}
	cout << double(n)/double(p);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = list(map(int,input().split()))
arc = []
abc = []
cnt = 0
d.sort()
pivot = n//2
k = d[pivot]
for i in range(n):
    if d[i] >= k:
        arc.append(d[i])
    elif d[i] < k:
        abc.append(d[i])
if len(arc) == len(abc):
    cnt = d[pivot] - d[pivot-1]
print(cnt)

Measured memory_bytes: 53100
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  int n;
  cin >> n;
  cout << (n+2-1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=100005;
int n;
int A[MAX_N];
int rec[MAX_N];
priority_queue <int> q;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>A[i];
		rec[A[i]]++;
	}
	for(int i=1;i<MAX_N;i++)
	{
		if(rec[i])
		{
			q.push(rec[i]);
		}
	}
	while(!q.empty())
	{
		int t=q.top();
		if(t==1)break;
		q.pop();
		while(t>=3)t-=2;
		if(t>=q.top() && t==2)
		{
			t=1;
			int t2=q.top();
			q.pop();
			t2--;
			if(t2)q.push(t2);
		}
		if(t)q.push(t);
	}
	int ans=0;
	while(!q.empty())
	{
		ans+=q.top();
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
	int N, H, W;
	cin >> N >> H >> W;

	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;

		if (a >= H && b >= W) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h1[3], h2[3], h3[3];
	int m1[3], m2[3], m3[3];
	int s1[3], s2[3], s3[3];
	int ans;
	int i;

	for (i = 0; i < 3; i < i++){
		scanf("%d %d %d %d %d %d", &h1[i], &m1[i], &s1[i], &h2[i], &m2[i], &s2[i]);
	}

	for (i = 0; i < 3; i++){
		h1[i] = h1[i] * 3600;
		m1[i] = m1[i] * 60;
		s1[i] = h1[i] + m1[i] + s1[i];

		h2[i] = h2[i] * 3600;
		m2[i] = m2[i] * 60;
		s2[i] = h2[i] + m2[i] + s2[i];

		s3[i] = s2[i] - s1[i];

		h3[i] = s3[i] / 3600;
		s3[i] = s3[i] - h3[i] * 3600;
		m3[i] = s3[i] / 60;
		s3[i] = s3[i] - m3[i] * 60;

		printf("%d %d %d\n", h3[i], m3[i], s3[i]);
	}

	return (0);
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  vector<int> dp(n,INT_MAX);
  rep(i,n) cin >> h[i];
  dp[0] = 0;
  for(int i=0;i<n;i++) {
    for(int j=1;j<=k;j++) {
      if(i+j<n) {
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
      }
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std; 
#define vll vector<long long>
#define mll map<long long,long long>
#define pb push_back
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[500005];
ll vis[500005],color[500005],I[101][101];

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

bool isPrime(int n)
{
    if (n<=1) return false; 
    if (n<=3) return true; 
    if (n%2==0||n%3==0) return false; 
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false; 
    return true; 
}

ll bpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res*=n;
			po--;
		}
		else
		{
			n*=n;
			po/=2;
		}
	}
	return res;
}

ll binpow(ll n, ll po, ll mod)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res=(res*n)%mod;
			po--;
		}
		else
		{
			n=(n*n)%mod;
			po/=2;
		}
	}
	return res;
}

ll swap(ll a, ll b)
{
	a=a+b;
	b=a-b;
	a=a-b;
}

ll fact(ll n) { 
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}

ll C(ll n, ll r) {
    if(r > n - r) r = n - r; 
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
        ans=ans%1000000007;
    }

    return ans;
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}


int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b;
}


Measured memory_bytes: 15328
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

int main(){
	long long k, a, b;
	std::cin>>k>>a>>b;

	if(b-a<= 2 || k<a){
		std::cout<<1+k<<std::endl;
		return 0;
	}
	long long ans=a;
	long long times= k-(a-1);
	long long mod= times%2;
	times= times/2;

	ans+= times*(b-a);

	ans+= mod;

	std::cout<<ans<<std::endl;

	return 0;
	
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
  int N;
  cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int x=v[N-1];
  for(int i=1;i<N-1;i+=2){
    x^=v[i]^v[i+1];
  }
  int prec=x;
  cout<<x<<" ";
  for(int i=1;i<N;i++){
    prec=v[i]^v[i-1]^prec;
    cout<<prec<<" ";
  }
}
signed main(){
		ios_base::sync_with_stdio(0);cin.tie(0);
    int T=1;
    //cin>>T;
    while(T--)solve();
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const int MAX_N=1e5;

int N;
ll A[MAX_N],B[MAX_N];
vector <ll> vec;
int main(){
	cin>>N;
	REP(i,N)cin>>A[i];
	REP(i,N)cin>>B[i];
	bool fn=false;
	ll sma=0,smb=0;
	REP(i,N){
		sma+=A[i];
		smb+=B[i];
	}
	int ans=0;
	if (sma<smb){
		ans=-1;
	}else{
		ll rem=sma-smb;
		REP(i,N){
			if (A[i]-B[i]>=0){
				vec.push_back(A[i]-B[i]);
			}else{
				fn=true;
			}
		}
		sort(vec.begin(),vec.end());
		for(auto i:vec){
			if (rem>=i){
				rem-=i;
				ans++;
			}
		}
		if (ans==vec.size()){
			if (rem!=0 && !fn){
				ans--;
			}
		}
		ans=N-ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int num[] = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = scanner.nextInt();
		}
		for (int c = 1; c <= n; c++) {
			System.out.print(num[n - c]);
			if(n-c!=0) {
				System.out.print(" ");
			}
		}
		System.out.println();
		scanner.close();
	}
}



Measured memory_bytes: 26260
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;


int main() {
	int i, j, k;
	int n, t;

	cin >> n >> t;

	 vector<int>list;

	for (i = 0; i < n; i++) {
		int c, tt;
		cin >> c >> tt;

		if (tt <= t) {
			list.push_back(c);
		}
	}
	
	if (list.size() >= 1) {
		sort(list.begin(), list.end());

		cout << list[0] << endl;
	}
	else {
		cout << "TLE" << endl;
	}

	










	getchar();
	getchar();
	return 0;
}

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

using namespace std;

const int maxi=1e6+6;
#define pb push_back
int t,n;
string s;

int main()
{
    cin>>s;

    string ans="";

    int n=s.size();

    for (int i=0;i<n-8;i++)
        ans+=s[i];

    cout<<ans<<"\n";
    return 0;
}
//uradim prva cetiri i aj za Beograd (veliki prljavi grad)


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

int main(){
  int s,s1,s2,s3;
  cin >> s;
  s1 = s/100;
  s2 = (s-s1*100)/10;
  s3 = s-s1*100-s2*10;
  cout << s1 + s2 + s3 << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import heapq

# input
N, M = map(int, input().split())
A = list(map(int, input().split()))

# solve
ans = [-a for a in A]
heapq.heapify(ans)
for i in range(M):
    tmp = heapq.heappop(ans) * (-1) // 2
    heapq.heappush(ans, tmp * (-1))
ans = [-a for a in ans]

# output
print(sum(ans))


Measured memory_bytes: 15076
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        System.out.println((int)((100 * (n - m) + 1900 * m) * Math.pow(2, m)));
    }
}

Measured memory_bytes: 21716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());

            if (a <= 0 && b >= 0) {
                out.println("Zero");
            } else {
                if (a > 0) {
                    out.println("Positive");
                } else if ((b - a + 1) % 2 == 0) {
                    out.println("Positive");
                } else {
                    out.println("Negative");
                }
            }

        }

    }
}



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

int i, n[4][3][10];

int main()
{
    cin >> i;

    while (i--) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        n[b - 1][f - 1][r - 1] += v;
    }

    for (int b = 0; b < 4; ++b) {
        for (int f = 0; f < 3; ++f) {
            for (int r = 0; r < 10; ++r) {
                cout << " " << n[b][f][r];
            }

            cout << endl;
        }

        if (b < 3) {
            cout << "####################" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1164
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = list(list(map(int,input().split())) for i in range(M))
A.sort()
BC = sorted(BC,key = lambda x:x[1],reverse = True)
X = []

for B,C in BC:
    for i in range(min(B,N-len(X))):
        X.append(C)
ans = [sum(A)]
p = len(X)
for i in range(p):
    ans.append(ans[-1]+X[i]-A[i])
print(max(ans))

Measured memory_bytes: 37440
#include<cstdio>

using namespace std;

int max(int a,int b,int c){
   int x=a;
   if(x<b) x=b;
   if(x<c) x=c;
   return x;
}

int main(){
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   int m=max(a,b,c);
   int x=3*m-a-b-c;
   if(x%2==0) printf("%d\n",x/2);
   else printf("%d\n",x/2+2);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const int INF = 1000000000; //10^9

int main() {
    ll n;
    cin >> n;
    vector<ll>x(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    sort(x.begin(),x.end(), greater<ll>());
    ll ans = x[0];
    for (ll i = 1; i < n - 1; i++)
    {
        ans += x[(i - 1) / 2 + 1];
    }
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 4820
#define _USE_MATH_DEFINES

#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)	((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
  
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
    cout.setf(ios::fixed); cout.precision(9);    
    solve();               	
    return 0;
} 

const int MOD = 998244353, MAXN = 100 + 10, INF = 1e9 + 10;
 
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    vector<int> a(1001);
    for (int i = 1; i <= 1000; ++i) {
        a[i] = a[i - 1] + i;
    }

    vector<double> b(n);
    for (int i = 0; i < n; ++i) {
        b[i] = (double)a[p[i]] / p[i];
    }
    vector<double> ps(n + 1);
    for (int i = 1; i <= n; ++i) {
        ps[i] = ps[i - 1] + b[i - 1];
    }

    double ans = 0;
    for (int i = k; i <= n; ++i) {
        ans = max(ans, ps[i] - ps[i - k]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{
    //...#..###.

    int n;
    scn(n);

    string s;
    cin >> s;

    vi pre_b(n, 0), suf_w(n, 0);

    rep(i, 0, n) {
        pre_b[i] = s[i] == '#';
        suf_w[i] = 1 ^ pre_b[i];
    }

    rep(i, 1, n)
    pre_b[i] += pre_b[i-1];

    for(int i=n-2; i>=0; i--)
        suf_w[i] += suf_w[i+1];

    int cost = suf_w[0]; // all black

    rep(i, 1, n) {
        // white till i-1 and black onwards i
        cost = min(cost, pre_b[i-1]+suf_w[i]);
    }

    cost = min(cost, pre_b[n-1]); // all white

    prin(cost);
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5312
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, A[100000];

int main() {
    scanf("%d", &N);
    for (int j = 0; j < N; ++j) { scanf("%d", A+j); }

    int ans = 1;
    int diff = 0;
    for (int j = 1; j < N; ++j) {
        if (diff * (A[j]-A[j-1]) < 0) {
            ++ans;
            diff = 0;
        } else if (diff == 0) {
            diff = A[j] == A[j-1] ? 0 : A[j] - A[j-1] > 0 ? 1 : -1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i, n) for(int i=0;i<n;i++)
typedef long long ll;
#define intv vector<v>
#define llv vector<long long>
#define intvv vector<vector<int>>
#define llvv vector<vector<long long>>
using namespace std;


int main(){
    int n, m;
    cin >> n >> m;
    int mi = 0, ma = 100000;
    for(int i=0;i<m;i++){
        int l, r;
        cin >> l >> r;
        mi = max(l, mi);
        ma = min(r, ma);
    }
    if (ma >= mi) cout << ma - mi + 1 << endl;
    else cout << 0 << endl;
}


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

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    vector<int> fib(n+1);
    fib[0] = 1; fib[1] = 1;
    repr(i, 2, n+1) {
        fib[i] = fib[i-2] + fib[i-1];
    }
    cout << fib[n] << endl;
    return 0;
}


Measured memory_bytes: 3112
def main():
    M,K=map(int, input().split())
    ans=[-1]
    if M==0:
        if K==0:
            ans=[0,0]
    elif M==1:
        if K==0:
            ans=[0,0,1,1]
    else:
        if K<(1<<M):
            L=[i for i in range(1<<M) if i!=K]
            ans=[K]+L+[K]+L[::-1]
    print(*ans)

if __name__ == "__main__":
    main()

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

int main(){
	string x;
	int pos;
	int n;
	cin >> n;
	cin.ignore();
	while (n--){
			getline(cin, x);
		while ((pos=x.find("Hoshino"))!= string::npos){
			x.replace(pos, 7, "Hoshina");
		}
		cout << x << endl;

	}
		return 0;
}

Measured memory_bytes: 1208
n, k = map(int, input().split())
s = list(input())

if s[k-1] == "A":
    s[k-1] ="a"
if s[k-1] == "B":
    s[k-1] ="b"
if s[k-1] == "C":
    s[k-1] ="c"
print("".join(s))

Measured memory_bytes: 3060
#include <iostream>
#define endl "\n"
using namespace std;

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

    int i, count = 0;
    for(i = 0; i < n - 2; i ++)
    {
    	if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
    		count ++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int a,b;
int main(void){
    cin>>a>>b;
    if(a*b%2==1)cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    string s;cin >> s;
    bool f = false;
    for (int i = 0; i < s.length(); i++) {
        if(s[i] == '7') f = true;
    }
    if(f) puts("Yes");
    else puts("No");
    return 0;
}



Measured memory_bytes: 3612
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 300000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;


int N, M, Q;
int to[400002], ne[400002], he[200001], num[400002];
int dame[200001];
int K[200001];

ll S1[400002];
int S2[400002];

pair<ll, int> dfs(int v, int prev) {
	auto s1 = S1 + K[v - 1];
	auto s2 = S2 + K[v - 1];
	int sm = K[v] - K[v - 1];

	//そもそも頂点に辺が一つもない時
	if (sm == 0) return mp(1, 1);

	//まだその頂点から探索したことが無くてデータが空っぽのとき
	if (!dame[v]) {
		dame[v] = prev;
		ll ret1 = 1;
		int ret2 = 1;
		int k = 0;
		for (int i = he[v]; i; i = ne[i]) {

			if (i != prev) {
				auto tmp = dfs(to[i], i ^ 1);
				ret1 = ret1 * f.ifac[tmp.second] % mod * tmp.first % mod;
				ret2 += tmp.second;

			}
			s1[k] = ret1;
			s2[k++] = ret2;
		}
	}

	//前回この頂点から探索した時も今回と同じ辺から来てたとき
	if (dame[v] == prev) return mp(s1[sm - 1] * f.fac[s2[sm - 1] - 1] % mod, s2[sm - 1]);

	//まだその頂点からのデータが完璧じゃなかったとき
	if (dame[v] != -1) {
		auto tmp = dfs(to[dame[v]], dame[v] ^ 1);
		int k = sm - num[dame[v]];
		ll tmp1 = f.ifac[tmp.second] * tmp.first % mod;
		for (int i = k - 1; i < sm; i++) {
			s1[i] = s1[i] * tmp1 % mod;
			s2[i] += tmp.second;
		}
		dame[v] = -1;
	}

	//例外なく全方向へのデータが欲しい時
	if (prev == -1) {
		return mp(s1[sm - 1] * f.fac[s2[sm - 1] - 1] % mod, s2[sm - 1]);
	}

	//その他の時
	int k = sm - num[prev];
	ll ret1 = s1[sm - 1] * modpow(s1[k - 1], mod - 2) % mod;
	if (k >= 2) ret1 = ret1 * s1[k - 2] % mod;

	int ret2 = s2[sm - 1] - s2[k - 1];
	if (k >= 2) ret2 += s2[k - 2];
	else ret2++;

	return mp(ret1 * f.fac[ret2 - 1] % mod, ret2);
}

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


	int N;
	cin >> N;
	int k = 2;
	rep1(i, N - 1) {
		int a, b;
		cin >> a >> b;

		num[k] = K[a]++;
		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		num[k] = K[b]++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	rep1(i, N) K[i] += K[i - 1];


	rep1(i, N) co(dfs(i, -1).first);

	Would you please return 0;
}

Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void test_case(ll lasun)
{
	ll n;
	cin >> n;
	vector<ll> v(n);
	vector<ll> dp(n);
	for(auto& x : v) cin >> x;
	dp[0] = 0;
	dp[1] = abs(v[1] - v[0]);
	for(int i = 2;i<n;i++)
	{
		dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]) , dp[i-2] + abs(v[i] - v[i-2]));
	}
	cout<<dp[n-1]<<"\n";

}

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif
	ll T=1,i=1;
	// cin>>T;
	while(T--)
		test_case(i++);

}

Measured memory_bytes: 4756
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i=0; i<abs(ty-sy); i++) {
    cout << 'U';
  }
  for(int i=0; i<abs(tx-sx); i++) {
    cout << 'R';
  }
  for(int i=0; i<abs(ty-sy); i++) {
    cout << 'D';
  }
  for(int i=0; i<abs(tx-sx); i++) {
    cout << 'L';
  }
  cout << 'L';
  for(int i=0; i<abs(ty-sy)+1; i++) {
    cout << 'U';
  }
  for(int i=0; i<abs(tx-sx)+1; i++) {
    cout << 'R';
  }
  cout << 'D';
  cout << 'R';
  for(int i=0; i<abs(ty-sy)+1; i++) {
    cout << 'D';
  }
  for(int i=0; i<abs(tx-sx)+1; i++) {
    cout << 'L';
  }
  cout << 'U' << endl;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
s=input()
wordlen=a+b+1
flag=0
for i in range(wordlen):
    if i==a:
        if s[i]!='-':
            flag+=1
    else:
        if s[i]=='-':
            flag+=1
if flag==0:
    print('Yes')
else:
    print('No')
            

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <stack>
using namespace std;

int N;
const int maxn = 105;
const int WHITE = 0;
const int BLACK = 2;
int G[maxn][maxn];
vector<int> color;
vector<int> startTime;
vector<int> endTime;
vector<int> nt;

int getNext(int u){
    int res = -1;
    for(int i = nt[u];i<N;i++){
        if(G[u][i] && color[i]==WHITE){
            res = i;
            nt[u] = i;
            break;
        }
    }
    return res;
}

void DFS(int u,int &time){
    if(color[u]!=WHITE) return;
    stack<int> nodeStack;
    nodeStack.push(u);
    startTime[u] = time++;
    while(!nodeStack.empty()){
        int u = nodeStack.top();
        //if(color[u]!=WHITE) continue;
        color[u] = BLACK;

        int v = getNext(u);
        if(v!=-1){
            startTime[v] = time++;
            nodeStack.push(v);
            continue;
        }
        else{
            endTime[u] = time++;
            nodeStack.pop();
        }
    }
}

int main(){
    //freopen("data.txt","r",stdin);
    memset(G,0,sizeof(G));
    cin >> N;
    color.resize(N,WHITE);
    startTime.resize(N,0);
    endTime.resize(N,0);
    nt.resize(N,0);
    int u,k;
    for(int i = 0;i<N;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(int j = 0;j<k;j++){
            int v;
            scanf("%d",&v);
            v--;
            G[u][v] = 1;
        }
    }
    int time = 1;
    for(int i = 0;i<N;i++) if(color[i]==WHITE) DFS(i,time);
    for(int u = 0;u<N;u++){
        printf("%d %d %d\n",u+1,startTime[u],endTime[u]);
    }
    return 0;
}




Measured memory_bytes: 3236
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll HW[2], ans = MAX_10p18;

int main() {
	cin >> HW[0] >> HW[1];
	repi(hw, 0, 2) {
		ll wh = (hw + 1) % 2;
		repi(i, 1, HW[hw]) {
			ll a = (i*HW[wh]);
			ll b, c, tmax, tmin;
			if (i != HW[hw] - 1) {
				b = HW[wh] * ((HW[hw] - i + 1) / 2);
				c = HW[wh] * ((HW[hw] - i) / 2);
				tmax = max(a, max(b, c));
				tmin = min(a, min(b, c));
				ans = min(ans, tmax - tmin);
			}
			b = (HW[hw] - i) * ((HW[wh] + 1) / 2);
			c = (HW[hw] - i) * (HW[wh] / 2);
			tmax = max(a, max(b, c));
			tmin = min(a, min(b, c));
			ans = min(ans, tmax - tmin);
		}
	}
	wrln(ans);
	return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
if N == 0:
    print(X)
    quit()
p = set(map(int, input().split()))
not_p = sorted(set(range(0, 102)) - p)
ans = 0
minval = 101
for i in not_p:
    if minval > abs(X - i):
        minval = abs(X - i)
        ans = i
print(ans)


Measured memory_bytes: 9136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
 
using namespace std;

string yes = "Yes";
string no = "No";

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

	vector<int> a(N);
	rep(i, N) cin >> a[i];

	if (N == 1) {
		cout << (a[0] % 4 ? no : yes) << endl;
		return 0;
	}

	int four = 0;
	int two = 0;
	int other = 0;

	rep(i, N) {
		if (a[i] % 4 == 0) four++;
		else if (a[i] % 2 == 0) two++;
		else other++;
	}

	vector<int> b(N);

	bool ok = true;
	rep(i, N) {
		if (i % 2 == 0) {
			if (other) {
				other--;
				b[i] = 0;
			} else if (two) {
				two--;
				b[i] = 1;
			} else {
				four--;
				b[i] = 2;
			}
		} else {
			if (b[i - 1] == 0) {
				if (four) {
					four--;
					b[i] = 2;
				} else {
					ok = false;
					break;
				}
			} else if (b[i - 1] == 1) {
				if (two) {
					two--;
					b[i] = 1;
				} else if (four) {
					four--;
					b[i] = 2;
				} else {
					ok = false;
					break;
				}
			} else {
				if (other) {
					other--;
					b[i] = 0;
				} else if (two) {
					two--;
					b[i] = 1;
				} else {
					four--;
					b[i] = 2;
				}
			}
		}
	}

	rep(i, N - 1) {
		if (b[i] != 2 && b[i + 1] != 2 && !(b[i] == 1 && b[i + 1] == 1)) ok = false;
	}

	cout << (ok ? yes : no) << endl;

	return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)

ans = 10 ** 20
s_sum = 0
for i in range(n - 1):
    s_sum += a[i]
    ans = min(ans, abs((sum_a - s_sum) - s_sum))
print(ans)

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

int main(int argc, char *argv[]) {
	std::string input_s;
	std::cin >> input_s;

	std::string::size_type first_pos = input_s.find('A');
	std::string::size_type last_pos = input_s.rfind('Z');

	std::cout << (last_pos - first_pos + 1) << std::endl;

	return 0;
}


Measured memory_bytes: 640
h, w = map(int, input().split())
lis = [] * h
for i in range(h):
    lis.append(tuple(map(int, input().split())))
flg = False
res = []
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if not flg and lis[i][j] % 2 == 1:
                res.append(i+1)
                res.append(j+1)
                flg = not flg
            elif flg and lis[i][j] % 2 == 0:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                res.append(i+1)
                res.append(j+1)
            elif flg and lis[i][j] % 2 == 1:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                flg = not flg
    else:
        for j in range(w -1, -1, -1):
            if not flg and lis[i][j] % 2 == 1:
                res.append(i + 1)
                res.append(j + 1)
                flg = not flg
            elif flg and lis[i][j] % 2 == 0:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                res.append(i + 1)
                res.append(j + 1)
            elif flg and lis[i][j] % 2 == 1:
                ans.append([res[0], res[1], i+1, j+1])
                res = []
                flg = not flg
print(len(ans))
for a in ans:
    print(*a)


Measured memory_bytes: 76636
#include <stdio.h>
 int main()
{ long long a,b,x,d;
 scanf("%lld%lld%lld",&a,&b,&x);
 long long i;
 if(a>=b){
 i=a;
 a=b;
 b=i;
 }
 long long c;
 if (a%x==0)
 {
 c=a/x;
 }
 else 
 {
 c=a/x+1;
}
 d=b/x;
 long long w=d-c+1;
 printf("%lld",w);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n][3];
  for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
       cin>>a[i][j];
  for(int i=1;i<n;i++)
  {
      	a[i][0]=a[i][0]+max(a[i-1][1],a[i-1][2]);
        a[i][2]=a[i][2]+max(a[i-1][0],a[i-1][1]);
        a[i][1]=a[i][1]+max(a[i-1][0],a[i-1][2]);
 //       cout<<a[i][0]<<" "<<a[i][1]<<" "<<a[i][2]<<endl;
  }
  int ma=a[n-1][0];
  ma=max(a[n-1][1],ma);
  ma=max(a[n-1][2],ma);
  cout<<ma<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a , b;
    cin >> a >> b;
    int ans = a * b;
    if(ans%2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::string S;
  std::cin >> S;

  std::vector<i64> groups;
  if (S.front() == '0') groups.push_back(0);
  i64 combo = 0;
  char prev_c = S.front();
  for (const char& c : S) {
    if (prev_c == c) {
      ++combo;
    } else {
      groups.push_back(combo);
      combo = 1;
    }
    prev_c = c;
  }
  groups.push_back(combo);
  if (S.back() == '0') groups.push_back(0);

  i64 answer;
  if (2 * K + 1 > static_cast<i64>(groups.size())) {
    answer = N;
  } else {
    answer = 0;
    for (i64 i = 0; i + 2 * K < static_cast<i64>(groups.size()); i += 2) {
      answer = std::max(answer, std::accumulate(groups.begin() + i, groups.begin() + (i + 2 * K + 1), static_cast<i64>(0)));
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w; cin >> h >> w;
  REP(i,h) REP(j,w){
    string s;
    cin >> s;
    if(s=="snuke"){
      cout << char('A'+j) << i+1 << endl;
      return 0;
    }
  }

  return 0;
}


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

int main() 
{
    long N,K;
    cin>>N>>K;

    vector<long>H;
    for (long i = 0; i < N; i++)
    {
        int h;
        cin>>h;
        H.push_back(h);
    }
    
    sort(H.begin(),H.end());

    while (K>0&&!H.empty())
    {
        H.pop_back();
        --K;
    }
    

    long ans=0;
    for (auto&h:H)
    {
        ans+=h;
    }
    

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 5268
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(5*1e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int from, to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/


signed main() {
	int h, w;
	cin >> h >> w;
	int ans = inf;
	//横3つ
	if (h % 3 == 0) {
		cout << 0 << endl;
		endre;
	}
	else {
		ans = min(ans, w);
	}
	//縦3つ
	if (w % 3 == 0) {
		cout << 0 << endl;
		endre;
	}
	else {
		ans = min(ans, h);
	}
	//横2つ、縦1つ
	rep(i, w + 1) {
		int cnt = i * h;
		if (h % 2 == 0) {
			ans = min(ans, abs(cnt - (h / 2)*(w - i)));
		}
		else {
			ans = min(ans, abs(max(cnt, (h / 2 + 1)*(w - i)) - min(cnt, (h / 2)*(w - i))));
		}
	}
	//横1つ、縦2つ
	rep(i, h + 1) {
		int cnt = i * w;
		if (w % 2 == 0) {
			ans = min(ans, abs(cnt - (w / 2)*(h - i)));
		}
		else {
			ans = min(ans, abs(max(cnt, (w / 2 + 1)*(h - i)) - min(cnt, (w / 2)*(h - i))));
		}
	}
	cout << ans << endl;
	endre;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

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

    int subans = n%500;
    
    if(subans > a) {
        cout << "No" << '\n';
    }
    else {
        cout << "Yes" << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
dic={}
ans=0
pen=0
for i in range(m):
    p,s=input().split()
    if p not in dic.keys():
        dic[p]={}
    if s=='AC':
        dic[p][s]=1
    if 'AC' not in dic[p].keys():
        if 'WA' not in dic[p].keys():
            dic[p][s]=0
        dic[p][s]+=1

for key in dic.keys():
    if 'AC' in dic[key].keys():
        ans+=1
        if 'WA' in dic[key].keys():
            pen+=dic[key]['WA']

print(str(ans)+' '+str(pen))


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

int main() {
    int a, b, t;
    cin >> a >> b >> t;
    int ans = 0, time = 0;
    while (time <= t) {
        time += a;
        ans += b;
    }
    cout << ans-b << endl;
    return 0;
}

Measured memory_bytes: 256