akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    string S;
    cin >> S;
    S[M - 1] += 32;
    cout << S << endl;
}

Measured memory_bytes: 3640
//8-D
//文字列関数で探し易くするために、検索対象となる文字列 s を加工してみましょう。
//String s を String s にくっつける！！！！！

import java.util.Scanner;

class Main {
    public static void main(String [] args){
    	
    	Scanner sc = new Scanner(System.in);
    	
    	String s = sc.next();//判定される
    	String p = sc.next();//判定する
    	
    	//入力された判定される側を同じ物どおしでくっつける
    	//問題のサンプルだと　vanceknowledtoad  なので
    	//vanceknowledtoad　＋　vanceknowledtoad　= vanceknowledtoadvanceknowledtoad
    	//簡単に判定できる！ただしリングだけに通用する。
    	s = s.concat(s);
    	
    	//indexOfで判定して文字がなければ -1 がかえってくる。
        int num = s.indexOf(p);
         
        if(num != -1){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 26256
#include <bits/stdc++.h>
    using namespace std;
     
    int A[100005];
     
    int main(){
    	int n; cin>>n;
    	int ai = -1;
    	for (int i = 0; i<n; i++){
    		cin>>A[i];
    		ai = max(ai,A[i]);
    	}
     
    	int aj = ai;
    	for (int i = 0; i<n; i++){
    		if (A[i]!=ai){
    			int d = abs((ai-2*A[i])/2);
    			int bd = abs((ai-2*aj)/2);
    			//cout<<i<<" "<<d<<" "<<bd<<"\n";
    			if (d<=bd){
    				aj = A[i];
    			}
    		}
    	}
    	cout<<ai<<" "<<aj<<"\n";
    }

Measured memory_bytes: 640
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut k: i64,
        a: [i64; n],
    }

    let mut looped = vec![false; n];
    looped[0] = true;
    let mut go: i64 = 1;
    let mut count = 0;
    let mut loopstart = 0;
    let mut past = k;
    loop {
        go = a[(go - 1) as usize];
        count += 1;
        if looped[(go - 1) as usize] == true {
            // ここでループに入ったことを検知
            if go != loopstart {
                loopstart = go;
            }
            break
        }
        looped[(go - 1) as usize] = true;
    }

    go = 1;
    loop {
        if go == loopstart {
            break;
        }
        go = a[(go - 1) as usize];
        k -= 1;
        count -= 1;
    }
    if k < 0{
        go = 1;
        for _ in 0..past {
            go = a[(go - 1) as usize];
        }
        println!("{}", go);
    } else {
        go = loopstart;
        for _ in 0..k % count {
            go = a[(go - 1) as usize];
        }
        println!("{}", go);
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string S; cin >> S;
	int a, z;
	for(int i = 0; i < S.size(); i++) {
		if(S[i] == 'A') {
			a = i;
			break;
		}
	}
	for(int j = S.size() - 1; j >= 0; j--) {
		if(S[j] == 'Z') {
			z = j;
			break;
		}
	}
	int ans = z - a + 1;
	cout << ans << endl;
	return 0;
}

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

int main(){
        int n; //yomu card no kazu                                             

        int i,j,k;
        char m;
        int r;
        char mark[4];
        mark[0] = 'S';
        mark[1] = 'H';
        mark[2] = 'C';
        mark[3] = 'D';

        int rank[13];
        for( i = 0; i < 13; i++)
        {
                rank[i] = i+1;
        }
        int cnt[4][13] = {};

        cin >> n;
        for(k = 0; k<n; k++)
        {
                cin >> m >> r;
                for(i = 0; i < 4; i++){
                        if(mark[i]==m) cnt[i][r-1]=1;
                        }
        }
        for(i = 0; i<4; i++){
                for(j=0; j<13; j++){
                        if(cnt[i][j] == 0) cout << mark[i] << " " << rank[j] <\
< endl;
                }
        }

        return 0;
}

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

int main()
{
    int i, len, w;
    char str[1010];
    scanf("%s", str);
    scanf("%d", &w);
    len = strlen(str);
    for(i = 0; i < len; i += w)
        printf("%c", str[i]);
    printf("\n");
    return 0;
}


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

#define ll long long
#define endl "\n"

void solve(){
	int n; cin>>n;
	string s;
	cin>>s;
	if(s.length() <= n){
		cout<<s<<endl;
	}else{
		for(int i = 0; i<n; i++){
			cout<<s[i];
		}
		cout<<"..."<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//int t; cin>>t;
	//while(t--){
		solve();
	//}
	return 0;
}


Measured memory_bytes: 3648
import           Control.Applicative
import           Control.Monad
import           Data.List

main :: IO ()
main = do
  a:b:c:_ <- (map read . words) <$> getLine
  putStrLn $ compareThreeInt a b c

compareThreeInt :: Int -> Int -> Int -> String
compareThreeInt a b c =
  if a < b && b < c
    then "Yes"
    else "No"

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


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

  int l;
  cin>>l;
  int a[l];
  rep(i,l) cin>>a[i];
  int dp[l][5];
  dp[0][0] = a[0]; dp[0][4] = a[0];
  if(a[0] == 0) {
    dp[0][1] = 2;
    dp[0][2] = 1;
    dp[0][3] = 2;
  } else {
    dp[0][1] = a[0] % 2;
    dp[0][2] = (a[0] + 1) % 2;
    dp[0][3] = a[0] % 2;
  }
  FOR(i, 1, l) {
    dp[i][0] = a[i]; dp[i][4] = a[i];
    if(a[i] == 0) {
      dp[i][1] = 2;
      dp[i][2] = 1;
      dp[i][3] = 2;
    } else {
      dp[i][1] = a[i] % 2;
      dp[i][2] = (a[i] + 1) % 2;
      dp[i][3] = a[i] % 2;
    }
    dp[i][0] = dp[i-1][0] + dp[i][0];
    dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + dp[i][1];
    dp[i][2] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2]}) + dp[i][2];
    dp[i][3] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3]}) + dp[i][3];
    dp[i][4] = min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4]}) + dp[i][4];
  }
  cout << min({dp[l-1][0], dp[l-1][1], dp[l-1][2], dp[l-1][3], dp[l-1][4]}) << endl;

  return 0;
}


Measured memory_bytes: 9728
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;

int main(){
  int q,c,a,n;
  int cnt=0;
  cin >> q;
  for(int i=0;i<q;i++){
    cnt=0;
    cin >> c >> a >> n;
    for(int j= n;j>0;j--){
      if(a >= 1 && c >= 1){
        cnt++;
        n--;
        a--;
        c--;
      }
    }
    for(int j = a;j>0;j--){
      if(c >= 2){
        cnt++;
        a--;
        c-=2;
      }
    }
    for(int j=c;j>=3;j-=3){
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>a(n,0),b(n,0);
    for(int i=0;i<n;i++)
    {
     cin>>a[i];
     b[i]=a[i];
    }
    sort(b.begin(),b.end());
    for(int i=0;i<n;i++)
    {
      if(a[i]!=b[n-1])
      cout<<b[n-1]<<endl;
      else
      cout<<b[n-2]<<endl;
    }
    return 0;
}


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

using namespace std;

#define pii pair<int, int>
#define fi first
#define se second
#define REP(i, a, n) for (register int i = a, _n = n; i <= _n; ++i)
#define DREP(i, a, n) for (register int i = a, _n = n; i >= _n; --i)
#define FOR(i, a, n) for (register int i = a, _n = n; i < _n; ++i)
#define EREP(i, a) for (register int i = first[a]; i; i = edge[i].nxt)
#define debug(x) cout << #x << " = " << x << endl

char IO;
inline int rd () {
	int res = 0;
	while ((IO = getchar()) && (IO < '0' || IO > '9'));
	while (IO >= '0' && IO <= '9') 
		res = (res << 1) + (res << 3) + (IO ^ 48), IO = getchar();
	return res;
}

int n, d;
int a[200005];
int main () {
	n = rd();
	int fi = -1, se = -1;

	REP (i, 1, n) {
		a[i] = rd();
		if (a[i] > fi) se = fi, fi = a[i];
		else if (a[i] > se) se = a[i];
	}

	REP (i, 1, n) {
		if (a[i] == fi) printf ("%d\n", se);
		else printf ("%d\n", fi);
	}
	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int T[60];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        T[--a]++;
        T[--b]++;
    }
    REP(i, N)
    {
        cout << T[i] << endl;
    }
    return 0;
}

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

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

  int count1 = 0;
  for(int i = 0; i < S.size(); i++)
  {
    if(i % 2 == 0){
      if(S.at(i) == '0')continue;
      count1++;
    }else{
      if(S.at(i) == '1')continue;
      count1++;
    }

  }

  
  int count2 = 0;
  for(int i = 0; i < S.size(); i++)
  {
    if(i % 2 == 0){
      if(S.at(i) == '1')continue;
      count2++;
    }else{
      if(S.at(i) == '0')continue;
      count2++;
    }

  }

  
  if (count1 <= count2) {
    cout << count1 << endl;
  }else{
    cout << count2 << endl;
  }

  return 0;

}


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

int main(){
  int l, r;
  cin >> l >> r;
  if(r-l >= 2019){cout << 0 << endl; return 0;}
  l %= 2019;
  r %= 2019;
  if(l>r){cout << 0 << endl; return 0;}
  int ans = 2020;
  for(int i=l; i<r; ++i){
    for(int j=i+1; j<=r; ++j){
      int ijmod= (i*j) % 2019;
      ans = min(ans, ijmod);
    }
  }
  cout << ans << endl;
}

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

using namespace std;

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

int n;
char str[310][310];

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

    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%s",str[i]);
    int c = 0;
    for (k=0;k<n;k++) {
        int fl = 1;
        for (i=0;i<n;i++) {
            for (j=0;j<n;j++) {
                if (str[i][(j+k)%n]!=str[j][(i+k)%n]) fl = 0;
            }
        }
        c += fl;
    }
    printf("%d\n",c*n);

    return 0;
}


Measured memory_bytes: 384
from itertools import combinations_with_replacement
combinations_with_replacement
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for i in range(q)]
ans=0
for A in combinations_with_replacement(range(m),n):
  p=0
  for i in range(q):
    a,b,c,d=abcd[i]
    if A[b-1]-A[a-1]==c:
      p+=d
  ans=max(ans,p)
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
 
struct item
{
	int w, v;
};

ll knapsack(vector <item> &v, int n, int w)
{
	ll dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	dp[0][v[0].w]=v[0].v;
	forr(i,1,n)
	{
		forn(j,w+1)
		{
			dp[i][j]=dp[i-1][j];
			if(j-v[i].w < 0) continue;
			dp[i][j]=max(dp[i][j],dp[i-1][j-v[i].w]+v[i].v);
		}
	}
	ll ans = 0;
	forn(i,w+1) ans=max(ans,dp[n-1][i]);
	return ans;
	
}
 
int main()
{ 
	FIN;
	
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif
	
	int n, w;
	cin >> n >> w;
	vector <item> v(n);
	forn(i,n) cin >> v[i].w >> v[i].v;
	cout << knapsack(v,n,w) << endl;
	return 0;
}


Measured memory_bytes: 79232
import java.util.Scanner;

class Point{
	int x;
	int y;
	Point(int x, int y){
		this.x = x;
		this.y = y;
	}
	static double dist(Point a, Point b) {
		return Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
	}
}

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		double sumdist = 0;

		Point[] point = new Point[n]; //それぞれの街のポイント

		for(int i = 0; i < n; i++) {
			point[i] = new Point(stdIn.nextInt(),stdIn.nextInt());
		}
	
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				sumdist += Point.dist(point[i], point[j]);
			}
		}
		
		System.out.println((sumdist*2/n));


	}

}


Measured memory_bytes: 21844
// 解説pdfの方針に沿った解答
// 参考： http://agc005.contest.atcoder.jp/submissions/904878

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

const int N = 1234567;

int pr[N]; // 数列のi番目の数値から左に辿り、最初により小さい数値があるindex
int ne[N]; // 数列のi番目の数値から右に辿り、最初により小さい数値があるindex
int pos[N];  // 数値xがある数列のindexを保持

int main() {
    int N;
    cin >> N;
    FOR(i, 1, N + 1) {
        int a;
        cin >> a;
        pos[a] = i;
    }
    REP(i, N+2) {
        pr[i] = i - 1;
        ne[i] = i + 1;
    }

    long long ans = 0;
    for (int i = N; i >= 1; i--) {
        // j: 数値iがある数列のindex
        int j = pos[i];
        // 数値i * 数値iが最小値となるような部分配列の数
        ans += i * 1LL * (j - pr[j]) * (ne[j] - j);

        // 例えば以下の数列で、今 数値i = 4, j = 5とする。
        //  数列 .. 3 7 8 4 9 2
        //   idx    2 3 4 5 6 7
        //  このとき、pr[5] = 2, ne[5] = 7。
        // 数値4を処理し終わった後は、数値4にとってのne, prを使ってテーブルを更新。
        // この場合、数値3にとってのneは、数値4にとってのneと等しくなる。
        // また、    数値2にとってのprは、数値4にとってのneと等しくなる。
        // 式で書くと ne[2] = ne[7], pr[7] = pr[7]となる。

        pr[ne[j]] = pr[j];
        ne[pr[j]] = ne[j];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2560
# coding: utf-8

line=input().split()
K=int(line[0])
A=int(line[1])
B=int(line[2])

b_rate=B-A

i=0

if K<=A:
    print(A+1)
    exit(0)

sum=A
K-=A-1

if b_rate>2 and K>=2:
    sum+=K//2*b_rate
    if K%2==1:
        sum+=1
else:
    sum+=K
print(sum)


Measured memory_bytes: 3060
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long llong;
using namespace std;



int main() {
	int r, c;
	int A[101][101];
	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < r; i++) {
		A[i][c] = 0;
		for (int j = 0; j < c; j++) {
			A[i][c] += A[i][j];
		}
	}
	for (int j = 0; j <= c; j++) {
		A[r][j] = 0;
		for (int i = 0; i < r; i++) {
			A[r][j] += A[i][j];
		}
	}
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			cout << A[i][j];
			if (j != c)cout << " ";
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] p = sc.nextIntArray(n);
    int count = 0;
    for (int i = 1; i < n - 1; i++) {
      if (p[i - 1] < p[i] && p[i] < p[i + 1]) count++;
      else if (p[i + 1] < p[i] && p[i] < p[i - 1]) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21332
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- U.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getLine
    putStr.unlines.map show $ solve n xs

solve :: Int -> U.Vector Int -> [Int]
solve n xs = go . (0:) . U.toList $ U.snoc xs 0
  where
    !total = U.sum.U.zipWith(\x y->abs(x-y)) (U.snoc xs 0) $ U.cons 0 xs
    go :: [Int] -> [Int]
    go (x:y:z:xs) = res : go (y:z:xs)
      where
        res = total + abs(x-z) - (abs(x-y) + abs(y-z))
    go _ = []


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

using namespace std;

int main(){
	string s;
	cin >> s;
	int arr[26];
	memset(arr,0,sizeof(arr));
	for(int i = 0; i < s.size(); i++){
		arr[s[i]-'a']++;;
	}
	if(s.size() < 26){
		for(int i = 0; i < 26; i++){
			if(!arr[i]) return cout << s << (char)(i + 'a'),0;
		}
	}
	else{
		int pos = s.size()-2;
		arr[s[pos+1]-'a']--;
		while(1){
			if(pos < 0) break;
			for(char a = s[pos] + 1; a <= 'z'; a++){
				if(!arr[a - 'a']) return cout << s.substr(0,pos) << a,0;
			}
			arr[s[pos]-'a']--;
			pos--;
		}	
	}
	cout << -1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    vector<int> w(10);
    vector<int> k(10);
    REP(i,10){
	cin >> w[i];
    }
    REP(i,10){
	cin >> k[i];
    }
    sort(RALL(w));
    sort(RALL(k));
    printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
    return 0;
}

Measured memory_bytes: 1176
from sys import stderr, setrecursionlimit
from collections import Counter
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = Counter(getints())
debug(a)
ans = 0

for k, v in a.items():
    if v - k >= 0:
        ans += v - k
    else:
        ans += v
    
print(ans)



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

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


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

    if(N==1&&M==0){
        cout << 0 << endl;
        return 0;
    }

    vector<int> s(M),c(M);
    vector<int> num(N);
    rep(i,N) num[i]=-1;
    //num[0]=0;
    

    rep(i,M){
        cin >> s[i] >> c[i];
    }

    

    rep(i,M){
        if(num[s.at(i)-1] == -1 || num[s.at(i)-1] == c.at(i)){
            num[s.at(i)-1] = c.at(i);
        }else{
            cout << -1 << endl;
            return 0;
        }

    }

    if(num[0]==0){
        if(N!=1){
        cout << -1 << endl;
        return 0;
        }
    }else if(num[0]==-1){
        num[0]=1;
    }

    

    rep(i,N){
        if(num[i]==-1) num[i] = 0;
        cout << num[i];
    } 

    

    cout << '\n';

}

Measured memory_bytes: 3584
def main():
    N = int(input())
    P = list(int(input()) for _ in range(N))
    
    dp = [0] * (N + 1)
    for i in range(N-1,-1,-1):
        if P[i] == N:
            dp[P[i]] = 1
            continue
        if dp[P[i] + 1] == 0:
            dp[P[i]] = 1
        else:
            dp[P[i]] = dp[P[i] + 1] + 1
    print(N - max(dp))


if __name__ == "__main__":
    main()

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

int main() {
	int n, mn = INT_MAX;
	cin >> n;
	vector<int> w (n + 1,0);
	for(int i = 1; i <= n; i++){
		cin >> w[i];
		w[i] += w[i - 1];
	}
	for(int i = 1; i < n; i++){
		int dif = w[i] - (w[n] - w[i]);
		if(mn > abs(dif)) mn = abs(dif);
	}
	cout << mn << "\n";
	return 0;
}


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

using i64 = long long int;

int main(){
    int n, k;
    cin >> n >> k;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
    }

    cout << (n - 2) / (k - 1) + 1 << endl;

    return 0;
}


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

int main() {
	int num;
	cin >> num;
	int ret = 0;
	if (num % 10 != 0) {
		while (num != 0) {
			ret += num % 10;
			num /= 10;
		}
	}
	else {
		while (num % 10 == 0 && num != 1) {
			num /= 10;
		}
		if (num == 1) {
			ret = 10;
		}
		else {
			if (num % 10 != 0) {
				while (num != 0) {
					ret += num % 10;
					num /= 10;
				}
			}
		}
		
	}
	cout << ret;
	return 0;
		
}

Measured memory_bytes: 256
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
#define N 514
int n , x[ N ] , a[ N * N ];
void init(){
  n = getint();
  for( int i = 1 ; i <= n ; i ++ )
    x[ i ] = getint();
}
void solve(){
  vector< pair<int,int> > v;
  for( int i = 1 ; i <= n ; i ++ )
    v.push_back( { x[ i ] , i } );
  sort( v.begin() , v.end() );
  int ptr = 1;
  for( auto i : v ){
    int who = i.second;
    if( a[ x[ who ] ] ){
      puts( "No" );
      Bye;
    }
    a[ x[ who ] ] = who;
    int nd = who - 1;
    while( nd -- ){
      while( ptr < x[ who ] && a[ ptr ] ) ptr ++;
      if( ptr >= x[ who ] ){
        puts( "No" );
        Bye;
      }
      a[ ptr ] = who;
    }
  }
  for( auto i : v ){
    int who = i.second;
    int nd = n - who;
    while( nd -- ){
      while( ptr <= n * n && a[ ptr ] ) ptr ++;
      if( ptr > n * n || ptr <= x[ who ] ){
        puts( "No" );
        Bye;
      }
      a[ ptr ] = who;
    }
  }
  puts( "Yes" );
  for( int i = 1 ; i <= n * n ; i ++ )
    printf( "%d%c" , a[ i ] , " \n"[ i == n * n ] );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 2176
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
total=0
t=[[T[i] for i in range(k,N,K)] for k in range(K)]
def janken(x):
  if x=='p':
  	return S
  elif x=='r':
    return  P
  else:
  	return R

def janken_hand(x):
  if x=='p':
  	return 's'
  elif x=='r':
    return  'p'
  else:
  	return 'r' 


for k in range(K):
  value=janken(t[k][0])
  memory = [0]*len(t[k])
  memory[0] = janken_hand(t[k][0])
  
  for i in range(1,len(t[k])):
    if t[k][i]!=t[k][i-1]:
      value +=janken(t[k][i])
      memory[i] = janken_hand(t[k][i])
    elif memory[i-1] != janken_hand(t[k][i]):
      value +=janken(t[k][i])
      memory[i] = janken_hand(t[k][i])
    else:
      if janken_hand(t[k][i]) == 's':
        memory[i] = 'p'
      if janken_hand(t[k][i]) == 'r':
        memory[i] = 's'
      else:
        memory[i] = 'r'
  #print(t[k])
  #print(memory)
  #print(value)
  total += value
print(total)

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

#define int long long

const int N = 10 + 5;
int n, m, ar[N], a[N];
vector <int> adj[N];
set <int> st;

void add(int msk) {
	memset(a, 0, sizeof a);
	int res = 0, u = 0, num = 0;
	while (msk) {
		if (msk & 1)
			a[u] = 1;
		u++;
		msk /= 2;
	}
	for (int i = 0; i < m; i++) {
		int cnt = 0;
		for (int j : adj[i])
			if (a[j])
				cnt++;
		if ((cnt & 1) == ar[i])
			num++;
	}
	if (num < m)
		return;
	for (int i = 0; i < n; i++)
		if (a[i])
			res += (1LL << i);
	if (num == m)
		st.insert(res);
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x;
		for (int j = 0; j < x; j++) {
			cin >> y;
			y--;
			adj[i].push_back(y);
		}
	}
	for (int i = 0; i < m; i++)
		cin >> ar[i];
	
	for (int msk = 0; msk < (1LL << n); msk++)
		add(msk);
	cout << st.size();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,k,m;
string s,t;

int main() {
  cin >> n >> m;
  cout << (1900*m+100*(n-m))*pow(2,m) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, H, W;
        cin >> N >> H >> W;
        int ans = 0;
        rep(i, 0, N) {
            int h = (cin >> h, h);
            int w = (cin >> w, w);
            if(h >= H && w >= W) ans++;
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;

int N ;
long long sum[200005] ;

long long calc( int p1 , int p2 , int p3 ){
	long long Mx = max( max( sum[p1] , sum[p2] - sum[p1] ) ,
						max( sum[p3] - sum[p2] , sum[N] - sum[p3] ) ) ;
	long long Mn = min( min( sum[p1] , sum[p2] - sum[p1] ) ,
						min( sum[p3] - sum[p2] , sum[N] - sum[p3] ) ) ;
	return Mx - Mn ;
}

int getPos( int lf , int rg ){
	int mid , rt = lf ;
	long long cs = ( sum[rg] + sum[lf-1] ) >> 1 ;
	rg -- ;
	while( lf <= rg ){
		mid = ( lf + rg ) >> 1 ;
		if( sum[mid] <= cs )
			rt = mid , lf = mid + 1 ;
		else rg = mid - 1 ;
	} return rt ;
}

void solve(){
	long long ans = ( 1LL << 60 ) ;
	for( int i = 2 ; i < N - 1 ; i ++ ){
		int p1 = getPos( 1 , i ) ;
		int p3 = getPos( i + 1 , N ) ;
		ans = min( ans , calc( p1 , i , p3 ) ) ;
		bool c1 = ( p1 != i - 1 ) , c3 = ( p3 != N - 1 ) ;
		if( c1 ) ans = min( ans , calc( p1 + 1 , i , p3 ) ) ;
		if( c3 ) ans = min( ans , calc( p1 , i , p3 + 1 ) ) ;
		if( c1 && c3 ) ans = min( ans , calc( p1 + 1 , i , p3 + 1 ) ) ;
	} printf( "%lld" , ans ) ;
}

int main(){
	scanf( "%d" , &N ) ;
	for( int i = 1 ; i <= N ; i ++ )
		scanf( "%lld" , &sum[i] ) , sum[i] += sum[i-1] ;
	solve() ;
}


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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    vector<pair<int, int>> tasks;
    tasks.reserve(N);
    REP(i, N) {
        int a, b;
        std::cin >> a >> b;
        tasks.emplace_back(b, a);
    }

    SORT(tasks);

    string ans = "Yes";
    ll time = 0;
    REP(i, N) {
        time += tasks[i].second;
        if(tasks[i].first < time) {
            ans = "No";
            break;
        }
    }

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

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if (s=="RRS"||s=="SRR")
		cout<<2<<endl;
	else if (s=="RSR"||s=="SSR"||s=="SRS"||s=="RSS")
		cout<<1<<endl;
	else if (s=="RRR")
		cout<<3<<endl;
	else
		cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 3608
//ABC125 A - 
#include <bits/stdc++.h>
using namespace std;
int64_t calc_gdc(int64_t a,int64_t b)
{
    if (a<b){
        swap(a,b);
    }
	int64_t r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
    return b;
}
int main() {
    int64_t n;
#if LOCAL&0
  	std::ifstream in("input.txt");
  	std::cin.rdbuf(in.rdbuf());
#endif
    cin>>n;
    vector<int64_t> atbl(n);
    for(auto&a:atbl){
		cin >> a;
	}

#if 1
    //外す数を探す
    vector<int64_t> tmp(n);
    tmp[n-1]=atbl[n-1];
    for(int i=n-2;i>=0;--i){
        tmp[i]=calc_gdc(atbl[i],tmp[i+1]);
    }
    vector<int64_t> tmp_st(n);
    tmp_st[0]=atbl[0];
    for (int i=1; i<n;++i) {
        tmp_st[i] = calc_gdc(atbl[i], tmp_st[i-1]);       
    }
    int64_t ans=0;
    for(int skip=0;skip<n;++skip){
        int64_t val;
        if(skip==0){
            val=tmp[1];
        } else if (skip==n-1) {
            val=tmp_st[n-2];
        } else {
			int64_t ll = tmp_st[skip - 1];
			int64_t rr = tmp[skip + 1];
    		val=calc_gdc(ll,rr);
		}
        ans=max(ans,val);
    }
    cout<<ans<<endl;
#else
    //tleする
    int64_t ans=0;
    for(int skip=0;skip<n;++skip){
        bool flag=false;
        int64_t val = -1;
        for(int i=0;i<n;++i){
            if(i==skip) continue;
            if (val<0) {
				val = atbl[i];
			} else {
                val = calc_gdc(val,atbl[i]);
            }
        }
        ans=max(ans,val);
    }
    cout<<ans<<endl;
#endif
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int v[5];
	for (int i = 0; i < 5; i++) cin >> v[i];
	for (int i = 0; i < 5; i++) 
		if (v[i] == 0) {
			cout << i + 1;
			break;
		}
	return 0;
}

Measured memory_bytes: 3640
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/

 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    cin >> a[i];
    int b[n+1]={0};
    for(int i=n;i>=1;i--)
   {
       if(i>n/2)
         b[i] = a[i];
   }
   int k =2;
   int j=n/2 ;
   while(j>=1){
     for(int i=2;i<=n/j;i++)
   {
         b[j]+=b[i*j];
   }
  // if((a[j]==1 && b[j]%2==0) || a[j]==1 && b[j]%2==0))
    b[j] = b[j]%2;
    b[j] = a[j]^b[j];
   k++;
   j--;
   }
//    for(int i=2;i<=n;i++)
//     b[1]+= b[i];
//     if(b[1]%2==a[1])
//     b[1]=0;
//     else
//     b[1]=1;
    int c=0;
    for(int i=1;i<=n;i++)
    if(b[i]==1)
    c++;
    cout<<c<<endl;
    for(int i=1;i<=n;i++)
    if(b[i]==1)
    cout<<i<<" ";
    return 0;
}

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

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    vector<int> a;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    
    int *box = new int[N];
    memset(box, -1, sizeof(int) * N);
    
    int count = 0;
    for (int i = N-1; i >= 0; i--) {
        int rate = i + 1;
        
        int ai = a[i];
        
        int sum = 0;
        for (int j = i + rate; j < N; j += rate) {
            sum += box[j];
        }
        
        if (sum % 2 == ai) {
            box[i] = 0;
        }else {
            box[i] = 1;
            count++;
        }
        
    }
    
    if (count == 0) {
        cout << 0 << endl;
    }else {
        cout << count << endl;
        for (int i = 0; i < N; i++) {
            if (box[i] == 1) {
                cout << (i+1) << " ";
            }
        }
    }
    
    delete[] box;
    return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <algorithm>
int main() {
	int N, A, B;
	std::cin >> N >> A >> B;
	if (N + A >= B)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    string s;
    int ans =0;

    cin >> s;

    for(int i = 1; i < s.length(); i++){
        if(s[i] == s[i-1]){
            if(s[i-1] == '0'){
                s[i] = '1';
                ans++;
            }
            else if(s[i-1] == '1'){
                s[i] = '0';
                ans++;
            }
        }
    }

    cout << ans << endl;
    


}


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

int main() 
{
	int n , q , l , r;
	cin >> n >> q;
	string s;
	cin >> s;
	int a[n] = {0} , temp = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if(s[i]=='C' && s[i-1]=='A')
			temp++;
		a[i] = temp;
	}
	while(q-->0)
	{
		cin >> l >> r;
		cout << a[r-1]-a[l-1] << endl;
	}
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  LL n,l;
  cin >> n >>l;
  LL now;
  LL pre;
  cin >> now;
  for(int i=0;i<n-1;i++){
    pre=now;
    cin >> now;
    if(now+pre>=l){
      cout << "Possible" << endl;
      for(int j=0;j<i;j++){
        cout << j+1 << endl;
      }
      for(int j=n-2;j>=i+1;j--){
        cout << j+1 << endl;
      }
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << "Impossible" << endl;
  return 0;
}


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

int main() {
	int n;
	while(cin>>n){
		vector<int> b(n);
		for(int i=1;i<n;i++){
			b[i]=1;
			for(int j=1;j<i;j++){
				b[i]+=b[j]*2+1;
			}
		}
		
		int ans=n;
		for(int i=0;i<n/2;i++){
			ans+=b[i]*2*2;
		}
		if(n%2==1){
			ans+=2*b[n/2];
		}
		cout<<ans<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 0
n=gets.to_i
a=gets.split.map(&:to_i)
pos=neg=0
max=-1000000000
max_idx=0
min=1000000000
min_idx=0
a.each_with_index{|v,i|
  if max<v
    max=v
    max_idx=i
  end
  if v<min
    min=v
    min_idx=i
  end
}
ans=[]

if min>=0
  1.upto(n-1){|i|ans << [i,i+1]}
elsif max<=0
  n.downto(2){|i|ans << [i,i-1]}
elsif min.abs < max.abs
  1.upto(n){|i|ans << [max_idx+1,i]}
  1.upto(n-1){|i|ans << [i,i+1]}
else
  1.upto(n){|i|ans << [min_idx+1,i]}
  n.downto(2){|i|ans << [i,i-1]}
end

puts ans.size
ans.each{|x|
  puts "%d %d"%x
}

Measured memory_bytes: 1788
from collections import Counter
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    c1 = Counter(s[:i])
    c2 = Counter(s[-(n-i):])
    cnt = 0
    for c in c1:
        if c2[c] > 0:
            cnt += 1
    ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
#define int long long
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
int t1[123456], t2[12345], t3[1234], t4[123], t5[12];
signed main() {
	int n = input(), q = input();
	while (q--) {
		int k = input();
		if (k == 0) {//add
			int s = input(), t = input(), x = input(); s--;
			while (s < t) {
				if (s % 10000 == 0 && s + 10000 <= t) {
					t5[s / 10000] += x;
					s += 10000;
				}
				else if (s % 1000 == 0 && s + 1000 <= t) {
					t4[s / 1000] += x;
					s += 1000;
				}
				else if (s % 100 == 0 && s + 100 <= t) {
					t3[s / 100] += x;
					s += 100;
				}
				else if (s % 10 == 0 && s + 10 <= t) {
					t2[s / 10] += x;
					s += 10;
				}
				else {
					t1[s] += x;
					s++;
				}
			}
		}
		else {//get
			int i = input(); i--;
			cout << t1[i] + t2[i / 10] + t3[i / 100] + t4[i / 1000] + t5[i / 10000] << endl;
		}
	}
}


Measured memory_bytes: 4124
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    string s;
    map<string,int> mp;
    rep(i,n){ 
        cin >> s;
        mp[s]++;
    }

    if(mp["G"] > 0 && mp["W"] > 0 && mp["Y"] > 0 && mp["P"] > 0){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;


int main(){

    ll N;
    cin >> N;
    ll t[111], sum = 0;
    rep1(i, N){
        cin >> t[i];
        sum += t[i];
    }
    ll M;
    cin >> M;
    rep(i, M){
        ll p, x;
        cin >> p >> x;
        cout << sum - t[p] + x << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
es = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    es[a].append(b)
    es[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=1)
q = deque()
q.append(0)
flg = [0]*N
num = [None]*N
i = 0
while len(q):
    v = q.popleft()
    flg[v] = 1
    num[v] = c[i]
    i += 1
    for u in es[v]:
        if flg[u]:
            continue
        q.append(u)
print(sum(c[1:]))
print(*num)




Measured memory_bytes: 52312
#include<stdio.h>
long long h[100000];
long long dp[100000];

	long long n,k;
long long abs(long long a,long long b);
//long long min(long long a,long long b);

long long abs(long long a,long long b)

{
	if(a>b)
	{
		return a-b;
	}
	else
	{
		return b-a;
	}
}
long long cost(long long i)
{
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	else if(i==n-1)
	{
		return 0;
	}
	else
	{
		long long min,j;
		for(j=1;j<=k;j++)
		{
			if(j==1)
			{
				min=abs(h[i],h[i+1])+cost(i+1);
			}
			else if((i+j<=n-1)&&((abs(h[i],h[i+j])+cost(i+j))<min))
			{
				min=abs(h[i],h[i+j])+cost(i+j);
			}
		}
		return dp[i]=min;
	}
}
int main()
{
	scanf("%lld %lld",&n,&k);
	long long i;
	for(i=0;i<n;i++)
	{
		scanf("%Ld",&h[i]);
	}
	for(i=0;i<n;i++)
	{
		dp[i]=-1;
	}
	printf("%Ld\n",cost(0));
	return 0;

}
	


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int a[200009],b[200009];

void solve()
{
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i]>>b[i];
	
	sort(a,a+n);
	sort(b,b+n);
	
	if(n%2==0)
	{
		cout<<b[n/2]+b[n/2-1] - (a[n/2]+a[n/2-1]) + 1;
	}
	else cout<<b[n/2]-a[n/2]+1;
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 5216