akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;cin>>n;
    vector<ll>a(n),b(n);
    vector<pair<ll, int> > s(n);
    rep(i,n){
        cin>>a[i]>>b[i];
        s[i] = make_pair(a[i]+b[i],i);
    }
    sort(rall(s));
    ll B=0,A=0;
    rep(i,n)B += b[i];
    for(int i = 0; i < n; i += 2){
        A += a[s[i].second];
        B -= b[s[i].second];
    }
    cout << A - B << endl;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  ll N;cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  multiset<ll> s;
  for(ll i=0;i<N;i++){
    ll now = A[i];
    auto itr = s.lower_bound(now);
    if(itr != s.begin()) s.erase(--itr);
    s.insert(now);
  }
  cout << s.size() << endl;;
}

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

using namespace std;

int main(void) {
	long long N;
	cin >> N;
	vector<string> s;
	for(int i = 0; i < N; ++i) {
		string t;
		cin >> t;
		sort(t.begin(), t.end());
		s.push_back(t);
	}
	sort(s.begin(), s.end());
	long long counter = 0;
	long long ans = 0;
	for(int i = 1; i <= N; ++i) {
		if(i != N && s[i] == s[i - 1]) {
			++counter;
		} else {
			ans += counter * (counter + 1) / 2;
			counter = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define ll long long
#define fastIO ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define N 10000


using namespace std;

int n,L[N],x;

inline void init()
{
    ll sum=0,ans=1;
    cin >> n >> x;
    for(int i=0;i<n;++i){
        cin >> L[i];
        sum+=L[i];
        if(sum<=x)
            ++ans;
        else
            break;
    }
    cout << ans << endl;
}

inline void solve()
{

}

int main()
{
    fastIO;

    init();
    solve();

    cout << flush;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x=i,y=n/i*i,z=(y-x)/i+1;
		ans+=(x+y)*z/2;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  
  ll len = A+B;
  ll cnt = N/len*A;
  ll x = N%len;
  if(x<=A) cnt += x;
  else cnt += A;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  int cnt = 0;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] != i + 1) cnt ++;
  }

  if (cnt <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vector<queue<char> > s(3);
  string str;
  rep(i, 3) {
    cin >> str;
    rep(j, str.size()) s[i].push(str[j]);
  }
  
  ll now=0;
  while(1) {
    if(!s[now].size()) break;
    
    char c = s[now].front();
    s[now].pop();
    now = c - 'a';
  }
  cout << char('A' + now) << newl;
  return 0;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[200000];
int main(){
	int n;cin>>n;
	int Min=0,Max=0;
	rep(i,n){
		cin>>a[i];
		if(i==0||a[i]<=a[i-1])Min++;
		Max++;
	}
	cout<<Min<<endl<<Max<<endl;
}


Measured memory_bytes: 3496
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc105_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nums = Console.ReadLine().Split(' ');
            int n = int.Parse(nums[0]);
            int k = int.Parse(nums[1]);

            if(n % k == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int sum(int n) {
	string s = to_string(n);
	int res = 0;
	for (int i = 0; i < s.length(); ++i) {
		res += (s[i] - '0');
	}
 
	return res;
}
 
int main() {
	int n; cin >> n;
 
	if (n % sum(n) == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

int main()
{
    int d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

template <typename T>
class Max_seg_tree {
    vector<T> seg;
    int n;

    // create
    void create(int node, int l, int r, const vector<T>& v) {
        if (l == r)
            seg[node] = v[l];
        else {
            int mid = (l + r) / 2;
            create(node << 1, l, mid, v);
            create(node << 1 | 1, mid + 1, r, v);
            seg[node] = max(seg[node << 1], seg[node << 1 | 1]);
        }
    }

   public:
    // constructor
    Max_seg_tree(const vector<T>& v) {
        n = (int)v.size();
        seg.resize(4 * n);
        create(1, 0, n - 1, v);
    }

    // update element
    void update(int ind, T val, int node = 1, int l = 0, int r = -1) {
        if (r == -1) r += n;

        if (l == r && l == ind)
            seg[node] = val;
        else if (l <= ind && ind <= r) {
            int mid = (l + r) / 2;
            if (ind <= mid)
                update(ind, val, node << 1, l, mid);
            else
                update(ind, val, node << 1 | 1, mid + 1, r);

            seg[node] = max(seg[node << 1], seg[node << 1 | 1]);
        }
    }

    // range query
    T query(int l, int r, int node = 1, int tl = 0, int tr = -1) {
        if (tr == -1) tr += n;

        if (l == tl && r == tr)
            return seg[node];
        else {
            int mid = (tl + tr) / 2;
            if (r <= mid)
                return query(l, r, node << 1, tl, mid);
            else if (l > mid)
                return query(l, r, node << 1 | 1, mid + 1, tr);
            else
                return max(query(l, mid, node << 1, tl, mid), query(mid + 1, r, node << 1 | 1, mid + 1, tr));
        }
    }
};

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

    vector<int> h(n);
    vector<ll> a(n, 0);

    Max_seg_tree<ll> seg(a);

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

    for (int i = n - 1; i >= 0; i--) {
        ll temp = 0;
        if (h[i] + 1 <= n - 1) temp = seg.query(h[i] + 1, n - 1);
        temp += (ll)a[i];
        seg.update(h[i], temp);
        ans = max(ans, temp);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 8832
#include <stdio.h>

int main(void){
	int N,D,X;
	int i;
	scanf("%d",&N);
	scanf("%d",&D);
	scanf("%d",&X);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	int ans=0;
	int d;
	for(i=0;i<N;i++){//人数
		d=1;
		while(d<=D){
			ans++;
			d+=A[i];
		}
	}
	
	ans+=X;
	printf("%d",ans);
	return 0;}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n), sum(n + 1);  // 半開区間の累積和
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + v[i];

  // cout << sum << endl;

  ll ans = INFL;
  for (int i = 2; i <= n - 2; i++) {      // iは全ての真ん中の位置(半開区間的)
    vector<ll> res = {0, INFL, 0, INFL};  // 4つに区切った時のそれぞれの総和を突っ込むvector
    ll left, right;

    // 左側が真に小さくなるギリギリ
    left = 0, right = i;
    while (right - left > 1) {
      ll mid = (left + right) / 2;
      if (sum[mid] < sum[i] - sum[mid])
        left = mid;
      else
        right = mid;
    }

    // 端だった時の場合分けをして、2パターンを整理
    if (0 < left) res[0] = sum[left], res[1] = sum[i] - sum[left];
    if (right < i) {
      if (abs(res[1] - res[0]) > abs(sum[i] - 2 * sum[right]))
        res[0] = sum[right], res[1] = sum[i] - sum[right];
    }

    // ＝＝＝＝＝＝＝＝＝＝＝ 右側 ＝＝＝＝＝＝＝＝＝＝＝＝
    left = i, right = n;
    while (right - left > 1) {
      ll mid = (left + right) / 2;
      if (sum[mid] - sum[i] < sum[n] - sum[mid])
        left = mid;
      else
        right = mid;
    }

    // 端だった時の場合分けをして、2パターンを整理
    if (i < left) res[2] = sum[left] - sum[i], res[3] = sum[n] - sum[left];
    if (right < n) {
      if (abs(res[3] - res[2]) > abs(sum[n] - 2 * sum[right] + sum[i]))
        res[2] = sum[right] - sum[i], res[3] = sum[n] - sum[right];
    }

    // cout << left << " " << right << res << endl;

    ans = min(ans, *max_element(res.begin(), res.end()) - *min_element(res.begin(), res.end()));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        System.out.println(solve(n, h));
    }

    public static String solve(int n, int[] h) {
        int max = h[0];
        for (int i = 1; i < n; i++) {
            int current = h[i];
            if (current <= max - 2) {
                return "No";
            }

            max = Math.max(current, max);
        }
        return "Yes";
    }
}




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

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

    return 0;
}

Measured memory_bytes: 3616
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]
 
N = read()
A = reads()

print(2 * N)
m = min(A)
M = max(A)
if abs(m) <= abs(M):
  I = A.index(M) + 1
  print(I, 1)
  print(I, 1)
  for i in range(1, N):
    print(i, i+1)
    print(i, i+1)
else:
  I = A.index(m) + 1
  print(I, N)
  print(I, N)
  for i in range(N, 1, -1):
    print(i, i-1)
    print(i, i-1)


Measured memory_bytes: 40816
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>
 
#define M_PI       3.14159265358979323846
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
//container util
 
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
int N, P[201010];
int dp[201010];
int main() {
    //cout << fixed << setprecision(8);
 
    cin >> N;
    REP(i, N) cin >> P[i];
 
    int ans = 0;
    REP(i, N) {
        int p = P[i];
        dp[p] = dp[p - 1] + 1;
        ans = max(ans, dp[p]);
    }
    cout << N - ans << endl;
 
 
 
    return 0;
}

Measured memory_bytes: 1920
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 21:06:30 2020

@author: shinba
"""
n,m,x = map(int,input().split())

ca = []
for i in range(n):
    ca.append(list(map(int,input().split())))
    
ans = float("inf")
for i in range(1,2**n):
    s = [0]*(m+1) 
    for j in range(n):
        if (i>>j) & 1:
            s[0] += ca[j][0]
            for k in range(1,m+1):
                s[k] += ca[j][k]
    if s[0] < ans:
        for i in range(1,m+1):
            if s[i] < x:
                break
        else:
            ans = s[0]

if ans == float("inf"):
    print(-1)
else:
    print(ans)
                
            



Measured memory_bytes: 68704
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; ++i)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define PB push_back
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> Point;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#include "gtest/gtest.h"
#pragma comment (lib, "gtest.lib")
#define dump(x) cerr << #x << " = " << (x) << "\n"
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

string str;
//#define severalTestCases

bool input() {
  getline( cin, str );
  return true;
}

string solve(string _str) {
  for ( int i = 0; i < _str.size(); i++ ) {
    if ( 'a' <= _str[ i ] && _str[ i ] <= 'z' ) {
      _str[ i ] += 'A' - 'a';
    }
  }
  return _str;
}

void putsanswer() {
  cout << solve(str) << "\n";
}

int main( int argc, char **argv ) {
#ifndef WIN32
#ifdef severalTestCases
  while ( input() ) {
#else
  input();
  putsanswer();
#endif
#else
  ::testing::InitGoogleTest( &argc, argv );
  return RUN_ALL_TESTS();    // gtest ?????????
#endif
#ifdef severalTestCases
  }
#endif
  return 0;
}

#ifdef WIN32
TEST( testcase, solve ) {
  ASSERT_EQ( "THIS IS A PEN.", solve( "this is a pen." ) );
}
#endif

Measured memory_bytes: 1176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        //変数・リスト宣言・初期化
        List<int> aji = new List<int>();//di の味を記録するリスト
        int output = 0;//味の総和を記録・出力するための変数
        int n = int.Parse(Console.ReadLine());//N ふるまわれる数
        string input_text = Console.ReadLine();//おいしさの入力をstringとして取り込む
        string[] read = input_text.Split(' ');//標準入力用配列

        for (int i = 0; i < n; i++)//input_textを分割して、リストに追加
        {
            aji.Add(int.Parse(read[i]));
        }

        for (int i = 0; i < n; i++)//場合分けで計算
        {
            for (int roop = 0; roop < n; roop++)
            {
                output = output + aji[i] * aji[roop];
            }
        }

        for (int i = 0; i < n; i++)//重複の削除
        {
            output = output - aji[i] * aji[i];
        }
        Console.Write(output / 2);//出力
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    ll n,k;
    cin >> n >> k;
    vector<ll> a(ARRAY_MAX,0),s(ARRAY_MAX,0),t(ARRAY_MAX,0);

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

    for(int i = 1;i <= n;i++){
        s[i] = s[i-1] + a[i];
        t[i] = t[i-1] + max(0LL,a[i]);
    }

    ll maxi = -1;
    for(int i = 0;i < n-k+1;i++){
        
        maxi = max(maxi,max(0LL,s[i+k]-s[i])+ t[n]-t[i+k]+t[i]);
    }

    cout << maxi << endl;


    return 0;
}

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

int main(){
	long long n, a;
	vector<long long> v, u;
	cin >> n;
	for(long long i = 0; i < n; i++){
		cin >> a;
		v.push_back(a);
		u.push_back(a);
	}
	sort(v.begin(), v.end());
	for(long long j = 0; j < n; j++){
		if(v[n/2] <= u[j]){
			cout << v[n/2 - 1] << endl;
		}else{
			cout << v[n/2] << endl;
		}
	}
}

Measured memory_bytes: 6628
#!/usr/bin/env python3

S = input()
T = input()
min_diff_count = float("inf")
for i in range(len(S)):
    if i + len(T) > len(S):
        break
    count = 0
    for j in range(len(T)):
        if S[i + j] != T[j]:
            count += 1
    min_diff_count = min(min_diff_count, count)

# ans = 0 if min_diff_count == float("inf") else min_diff_count
ans = min_diff_count
print(ans)


Measured memory_bytes: 8856
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=2e5+10;
    ll N,K;
    vector<ll>neg,pos;
    ll zero;
    bool check(ll k){
        ll cnt=0;
        if(k>0){
            cnt+=zero*(neg.size()+pos.size());
            cnt+=zero*(zero-1)/2;
            cnt+=(ll)neg.size()*pos.size();
            for(int u=0;u<neg.size();u++){
                ll v=neg[u];
                ll cnd=k%v?k/v+1:k/v;
                cnt+=lower_bound(neg.begin(),neg.begin()+u,cnd)-neg.begin();
            }
            for(int u=0;u<pos.size();u++){
                ll v=pos[u];
                ll cnd=k%v?k/v+1:k/v;
                cnt+=lower_bound(pos.begin(),pos.begin()+u,cnd)-pos.begin();
            }
        }
        else if(k<0){
            k*=-1;
            for(auto v:pos){
                ll cnd=k%v?k/v+1:k/v;
                cnt+=neg.size()-(upper_bound(neg.begin(),neg.end(),k/v)-neg.begin());
            }
        }
        else cnt+=(ll)neg.size()*pos.size();
        return cnt<K;
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N>>K;
        for(int u=0;u<N;u++){
            ll a;
            cin>>a;
            if(a>0)pos.push_back(a);
            else if(a<0)neg.push_back(-a);
            else zero++;
        }
        sort(pos.begin(),pos.end());
        sort(neg.begin(),neg.end());
        ll l=-1e18,r=1e18,ans=-1;
        while(l<=r){
            ll mid=(l+r)>>1;
            if(check(mid)){
                ans=mid;
                l=mid+1;
            }
            else r=mid-1;
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

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

int main()
{
    int a,b,c,k,sum,x=0;
    cin >> a >> b >> c >> k;
    if (k<=a+b) cout << min(a,k) << endl;
    else cout << (a-(k-b-a)) << endl;

}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
  int im;
  Node *ne,*pi;
};

Node *na;

Node* ls(int im){
  Node *ku = na->ne;
  while(ku != na && ku->im !=im){
    ku = ku->ne;
  }
  return ku;
}

void in(){
  na = (Node *)malloc(sizeof(Node));
  na->ne = na;
  na->pi = na;
}

void ep(){
  Node *ku = na->ne;
  int is=0;
  while(1){
    if(ku == na){
      break;
    }
    if(is++ >0){
      printf(" ");
    }
    printf("%d",ku->im);
    ku = ku->ne;
  }
  printf("\n");
}

void dn(Node *A){
  if(A == na){
    return;
  }
  A->pi->ne = A->ne;
  A->ne->pi = A->pi;
  free(A);
}

void df(){
  dn(na->ne);
}


void dl(){
  dn(na->pi);
}

void dk(int im){
  dn(ls(im));
}

void nai(int im){
  Node *X = (Node *)malloc(sizeof(Node));
  X->im = im;

  X->ne = na->ne;
  na->ne->pi = X;
  na->ne =X;
  X->pi = na;
}

int main(){
  int im,num,i;
  int s=0;
  char da[20];
  int p=0,d=0;
  scanf("%d",&num);
  in();
  for(i=0;i<num;i++){
    scanf("%s%d",da,&im);
    if(da[0] == 'i'){
      nai(im);
      p++;
      s++;
    }
    else if(da[0] == 'd'){
      if(strlen(da)>6){
	if(da[6] == 'F'){
	  df();
	}
	else if(da[6] == 'L'){
	  dl();
	}
      }
	else{
	  dk(im);
	  d++;
	}
	s--;
      }
    }

    ep();

    return 0;
  }



Measured memory_bytes: 33848
#include <iostream>
#include <cmath>

int main () {
  int n; std::cin >> n;
  long long x = 1, y = 1;
  for (int i = 0; i < n; ++i) {
    int p, q; std::cin >> p >> q;
    long long cur1 = std::ceil ((long double) x / p);
    long long cur2 = std::ceil ((long double) y / q);
    x = p * std::max (cur1, cur2), y = q * std::max (cur1, cur2);
  }
  std::cout << x + y << "\n";
  return 0;
}

Measured memory_bytes: 256
#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
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
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(6);
    solve();    
    return 0;
}
 
const int MOD = 998244353, MAXN = 5000 + 10, INF = 1e18 + 10, BASE = 37; 
 
void solve() {
    int n;
    cin >> n;
    vec<pii> p(n);
    cin >> p;

    vec<int> a, b;
    for (int i = 0; i < n; ++i) {
        a.pb(p[i].x);
        b.pb(p[i].y);
    }

    sort(all(a));
    sort(all(b));

    if (n % 2 == 0) {
        double x = ((double)a[n / 2] + a[n / 2 - 1]) / 2;
        double y = ((double)b[n / 2] + b[n / 2 - 1]) / 2;
        int res = (int)((y - x) * 2) + 1;
        cout << res << endl;
    }
    else {
        cout << b[n / 2] - a[n / 2] + 1 << endl;
    }
}

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

#define MAXN 100005

using namespace std;

int K, dist[MAXN];
queue<pair<int, int>> q;

int main() {
    cin >> K;
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    q.push(make_pair(1, 0));
    while (!q.empty()) {
        int cur, cost;
        tie(cur, cost) = q.front();
        q.pop();

        int n1 = (cur * 10) % K, n2 = (cur + 1) % K;
        if (n1 < MAXN) {
            if (dist[n1] > cost) {
                dist[n1] = cost;
                q.push(make_pair(n1, cost));
            }
        }

        if (n2 < MAXN) {
            if (dist[n2] > cost + 1) {
                dist[n2] = cost + 1;
                q.push(make_pair(n2, cost + 1));
            }
        }
    }

    cout << dist[0] + 1 << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;

const ll M = 1000000007;
 
int main(){
    string L; cin >> L;
    ll n = sz(L);
    ll dp[n+1][2];
    dp[0][1] = 1;
    dp[0][0] = 1;
    dp[1][0] = 2;
    dp[1][1] = 1;
    rep(i, 2, n+1){
        if(L[i-1] == '0'){
            dp[i][0] = (dp[i-1][0])%M;
            dp[i][1] = (3*dp[i-1][1])%M;
        }else{
            dp[i][0] = (2*dp[i-1][0])%M;
            dp[i][1] = (3*dp[i-1][1] + dp[i-1][0])%M;
        }
    }
    ll g = 1;
    if(L[n-1] == '1'){
        g = 2;
    }
    prtl(((dp[n][1])+(dp[n-1][0]*g))%M);
}

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

int N, K, P[5002], C[5002];
long long score[5002][5002];

long long calc(vector<int> &p) {
    const int l = p.size();
    // for (int i = 0; i < l; i++) score[i][0] = 0;
    for (int j = 1; j < l; j++)
        for (int i = 0; i < l; i++) {
            score[p[i]][j] = C[P[p[i]]] + score[P[p[i]]][j-1];
            // cerr << p[i] << " " << j << " " << score[p[i]][j] << endl;
        }

    long long total = 0;
    for (int i : p) total += C[i];
    long long ans = -(1LL<<62);
    for (int j = 1; j < min(K+1, l); j++)
        for (int x : p) {
            long long s = score[x][j];
            if (total > 0 && K - j >= l) s += (K - j) / l * total;
            ans = max(ans, s);
        }
    if (K >= l) ans = max(ans, max(total, K / l * total));

    // cerr << ans << endl;
    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++) cin >> P[i];
    for (int i = 1; i <= N; i++) cin >> C[i];
    vector<bool> done(N+1, false);
    long long ans = -(1LL<<60);
    for (int i = 1; i <= N; i++) {
        if (done[i]) continue;
        vector<int> p;
        p.push_back(i);
        for (int j = P[i]; j != i; j = P[j]) p.push_back(j);
        ans = max(ans, calc(p));
        for (int x : p) done[x] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 198656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a == b && a == c) printf("1\n");
	else if(a == b || b == c || c == a) printf("2\n");
	else printf("3\n");
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	cout << fixed << setprecision(10);
	if (n & 1) cout << (double) (n / 2 + 1) / n;
	else cout << "0.5";
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

#define long long long int
using namespace std;

// @author: pashka

vector<vector<int>> g;
vector<int> first, last;
vector<int> et;

void dfs(int x, int p) {
    first[x] = et.size();
    last[x] = et.size();
    et.push_back(x);
    for (int y : g[x]) {
        if (y == p) continue;
        dfs(y, x);
        last[x] = et.size();
        et.push_back(x);
    }
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    first.resize(n);
    last.resize(n);
    dfs(0, -1);

    vector<vector<int>> pos(n);
    for (int i = 0; i < et.size(); i++) {
        pos[c[et[i]]].push_back(i);
    }

    for (int k = 0; k < n; k++) {
        vector<int> st;
        st.push_back(0);
        int xx = -1;
        vector<int> cc;
        for (int x : pos[k]) {
            st.back() += (x - xx - 2);
            if (x != first[et[x]]) {
                cc.push_back(st.back());
                st.pop_back();
            }
            if (x != last[et[x]]) {
                st.push_back(0);
            }
            xx = x;
        }
        st.back() += (et.size() - xx - 2);
        if (c[0] != k) {
            cc.push_back(st.back());
        }
        long res = (long)n * (n - 1) / 2 + n;
        for (int x : cc) {
            long sz = x / 2 + 1;
//            cout << sz << " ";
            res -= (sz * (sz - 1) / 2 + sz);
        }
//        cout << "\n";
        cout << res << "\n";
    }

    return 0;
}

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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
#define N		1000001
ll cnt;
void solve(){
	int h, w;
	cin>>h>>w;
	int A[h][w];
	rep(i,0,h)
	rep(j,0,w)
	cin>>A[i][j];
	int cnt=0;
	string ans = "";
	rep(i,0,h-1){
	rep(j,0,w){
		if(A[i][j]%2){
			A[i+1][j]++;
			ans += to_string(i+1) + " " + to_string(j+1)+" "+to_string(i+2)+" " +to_string(j+1)+"\n";
			cnt++;
		}
	}
	}
	rep(j,0,w-1){
		if(A[h-1][j]%2){
			A[h-1][j+1]++;
			ans += to_string(h)+" "+to_string(j+1)+" "+to_string(h)+" "+to_string(j+2)+"\n";
			cnt++;
		}
	}
	cout<<cnt<<endl;
	cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5124
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: i64,
    }

    let mut k = 0;

    while n > 1000 * k{
      k += 1;
    }

     println!("{}", 1000 * k -n );
}


Measured memory_bytes: 2148
N, K, L = map(int,input().split())
 
road = [i for i in range(N)]
rail = [i for i in range(N)]
rank = [0 for i in range(N)]
 
def find(a, U):
  if a == U[a]:
    return a
  else:
    par = find(U[a], U)
    U[a] = par
    return par
  
for i in range(K):
  p, q = map(int,input().split())
  p -= 1
  q -= 1  
  a = find(p, road)
  b = find(q, road)
 
  road[a] = b
  
for i in range(L):
  p, q = map(int,input().split())
  p -= 1
  q -= 1  
  a = find(p, rail)
  b = find(q, rail)
 
  rail[a] = b
  
for i in range(N):
  #print(road, rail)
  road[i] = find(road[i],road)
  rail[i] = find(rail[i],rail)
  
rr = [(road[i], rail[i]) for i in range(N)]
D = {}
for r in rr:
  if not r in D:
    D[r] = 1
  else:
    D[r] += 1
#print(road,rail)
#print(D)
 
for i in range(N):
  print(D[(road[i],rail[i])])

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

int x[100000], m[100000];

int main() {
	int n;
	scanf("%d", &n);
	f(i, 0, n) {
		int t;
		scanf("%d", &t);
		x[i] = m[i] = t;
	}
	sort(m, m + n);
	f(i, 0, n)x[i] = lower_bound(m, m + n, x[i]) - m;
	int an = 0;
	for (int i = 0; i < n; i += 2)if (x[i] & 1)++an;
	printf("%d", an);
}

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

#define LL long long
set<string> st;
map<string , int> mp;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n, mx=0; cin >> n; 
    while(n--) {
        string s; cin >> s;
        mp[s]++;
        mx = max(mx, mp[s]);
    }    

    for(auto x : mp) if(x.second == mx) st.insert(x.first);
    for(auto x : st) cout << x << '\n';
}

Measured memory_bytes: 34876
#include <bits/stdc++.h>
using namespace std;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
int main (){
  int i;
  int n,m;
  cin>>n>>m;
  int cnt=0,a;
  for(i=0;i<m;i++){
    cin>>a;
    cnt+=a;
  }
  if(n-cnt<0){
    cout<<-1<<endl;
  }
  else
  {
    cout<<n-cnt<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 10**9

int main() {
    ll n,x,ans;
    cin >> n >> x;
    vector<ll> A(n);
    rep(i,n){
        cin >> A.at(i);
    }
    if (A.at(0) > x){
        ans = A.at(0)-x;
        A.at(0) = x;
    }
    else{
        ans = 0;
    }
    rep(i,n-1){
        if (A.at(i)+A.at(i+1) > x){
            ans += (A.at(i)+A.at(i+1))-x;
            A.at(i+1) -= ((A.at(i)+A.at(i+1)-x));
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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; }

void Main(){
    int N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];
    ll ans = 0, mx = A[0];
    REP(i,N-1){
        if(A[i+1] < mx){
            ans += mx-A[i+1];
        }
        else chmax(mx, A[i+1]);
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n;
	cin >> n;
	vector<P> v;
	rep(i,n){
		int a,b;
		cin >> a >> b;
		v.push_back(make_pair(b,a));
	}
	sort(all(v));
	ll now = 0,flag = 1;
	for(int i = 0; i < n; i++){
		if(now+v[i].second <= v[i].first){
			now += v[i].second;
		}else flag = 0;
	}

	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxS=1e5+5;
vector<pair<int,int> > v[maxS];
string toStr(int x)
{
        string str1;
        str1=to_string(x);
                        int t1=6-str1.size();
                        for(int i=0;i<t1;i++)
                        {
                                str1='0'+str1;
                        }
        return str1;
}
int main()
{
        int n,m;
        cin>>n>>m;
        string s[m];
        for(int i=0;i<m;i++)
        {
                int p,y;
                cin>>p>>y;
                v[p].push_back(make_pair(y,i));
        }
        for(int i=0;i<=n;i++)
        {
                sort(v[i].begin(),v[i].end());
        }
        for(int i=0;i<=n;i++)
        {
                for(int j=0;j<v[i].size();j++)
                {
                        int x=i;
                        string str1="",str2="";
                        str1=toStr(x);
                        int y=j+1;
                        str2=toStr(y);
                        string str=str1+str2;
                        s[v[i][j].second]=str;
                }
        }
        for(int i=0;i<m;i++)
        {
                cout<<s[i]<<endl;
        }
        // string st;
        // st=st+(char)(2);
        // cout<<st;
}

Measured memory_bytes: 12416
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vectorl vector<long long>
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	int r = a % b;
	return gcd(b, r);
}
int squ(int x) {
	return x * x;
}
int di(vectorl x, vectorl y, int i, int j) {
	return squ(x[i] - x[j]) + squ(y[i] - y[j]);
}
int mmin(int &a, int b) {
	a = min(a, b);
	return a;
}
int mmax(int &a, int b) {
	a = max(a, b);
	return a;
}
int dan(int fg, int tg, int fr, int tr, vector<vectorl> &it, vector<vectorl> &su) {
	return abs(it[fg][fr] - it[tg][tr])*(su[fg][fr] + su[tg][tr]);
}
signed main() {
	int n, m;
	cin >> n >> m;
	while(n!=0){
	int max = 2000000 * 200+1;
	vector<vector<vectorl> > dp(n, vector<vectorl>(m+2, vectorl(10, max)));
	vectorl ze(10, 0);
	vector<vectorl> it(n, vectorl(10));
	vector<vectorl> su(n, vectorl(10));
	vectorl k(n);
	for (int i = 0; i < n; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> it[i][j] >> su[i][j];
		}
	}
	dp[0][0] = ze;
	dp[1][1] = ze;
	for (int i = 0; i < k[0]; i++) {
		for (int j = 0; j < k[1]; j++) {
			mmin(dp[1][0][j], abs(it[0][i] - it[1][j])*(su[0][i] + su[1][j]));
		}
	}
	for (int i = 2; i < n; i++) {
		for (int j = 0; j <= m; j++) {
			for (int f = 0; f < k[i-1]; f++) {
				for (int t = 0; t < k[i]; t++) {
					mmin(dp[i][j][t], dp[i-1][j][f] + dan(i - 1, i, f, t,it,su));
				}
			}
			for (int f = 0; f < k[i - 2];f++) {
				for (int t = 0; t < k[i]; t++) {
					mmin(dp[i][j+1][t], dp[i - 2][j][f] + dan(i - 2, i, f, t, it, su));
				}
			}
		}
	}
	int ans = max;
	for (int j = 0; j <= m; j++) {
		for (int f = 0; f < k[n - 1]; f++) {
			mmin(ans, dp[n - 1][j][f]);
		}
		if (j < m) {
			for (int f = 0; f < k[n - 2]; f++) {
				mmin(ans, dp[n - 2][j][f]);
			}
		}
	}
	cout << ans << endl;
	cin >> n >> m;
	}
}



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

#define int long long

typedef long long ll;
typedef long double ld;

using namespace std;

const int INF = 1e9;
const int maxn = 110;
const int mod = 1e9+7;

string s;
int n, k;

signed main()
{
    cin>> s >> k; n = s.size();

    if(s[0] == s[n-1])
    {
        ll ans = 0;
        int x = 0, s1 = 0, s2 = 0;
        for(int i = 1; i < n; i++){
            if(s[i] != s[i-1] && x != 0)
                ans += (i-x)/2;
            if(s[i] != s[i-1]){
                if(x == 0)
                    s1 = i-x;
                x = i;
            }
        }
        s2 = n-x;
        if(x == 0)
            return cout<< (k*n)/2, 0;
        ans *= k;
        ans += s1/2 + s2/2;
        ans += (1ll * ((s1+s2)/2)) * (k-1);
        return cout<< ans, 0;
    }

    ll ans = 0;
    int x = 0;
    for(int i = 1; i < n; i++)
        if(s[i] != s[i-1]){
            ans += (i-x)/2;
            x = i;
        }
    ans += (n-x)/2;
    cout<< ans * k;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll n;
    cin >> n;
    ll sum[n], sum2[n];
    for(ll i = 0; i < n; i++){
        ll b; cin >> b;
        if(i==0) sum[i] = b;
        else sum[i] = sum[i-1]+b;
    }
    for(ll i = 0; i < n; i++)
        sum2[i] = sum[i];
    ll ans = 0, total = 0, count = 0;
    if(sum[0]>=0) total = -sum[0]-1;
    ans = abs(total);
    sum[0]+=total;
    for(ll i = 1; i < n; i++){
        ll now = sum[i]+total;
        count = 0;
        if(i%2!=0 && now<=0){
            count = abs(now)+1;
            total += count;
        }
        if(i%2==0 && now>=0){
            count = abs(now)+1;
            total -= count;
        }
        if(i%2!=0 && sum[i]==0){
            count=1;
            total++;
        }
        if(i%2==0 && sum[i]==0){
            count=1;
            total--;
        }
        ans += count;
    }
    ll check = ans;
    total = 0; ans = 0;
    if(sum2[0]<=0) total = abs(sum2[0])+1;
    ans=abs(total);
    for(ll i = 1; i < n; i++){
        ll now = sum2[i]+total;
        count = 0;
        if(i%2!=0 && now>=0){
            count = abs(now)+1;
            total -= count;
        }
        if(i%2==0 && now<=0){
            count = abs(now)+1;
            total += count;
        }
        if(i%2!=0 && sum2[i]==0){
            count=1;
            total--;
        }
        if(i%2==0 && sum2[i]==0){
            count=1;
            total++;
        }
        ans += count;
    }
    check = min(check, ans);
    cout << check << endl;
    return 0;
}


Measured memory_bytes: 1792
s = list(input())

idx_a = []
idx_z = []

for idx in range(len(s)):
    if s[idx] == "A":
        idx_a.append(idx)
    elif s[idx] == "Z":
        idx_z.append(idx)

ans = idx_z[-1] - idx_a[0] + 1
print(ans)


Measured memory_bytes: 12600