akhauriyash/Code-Regression huggingface dataset:
n, c = map(int, input().split())
xv = [list(map(int, input().split())) for _ in range(n)]

# counter-clockwise
xv2 = []
for x, v in xv:
    xv2.append([c - x, v])
xv2 = xv2[::-1]

ans = 0

cumsum1, cumsum1_2 = [0], [0]
pos = 0
for x, v in xv:
    tmp = cumsum1[-1] + v - (x - pos)
    cumsum1.append(tmp)
    cumsum1_2.append(tmp - x)
    pos = x
    ans = max(ans, tmp)
cumsum1, cumsum1_2 = cumsum1[1:], cumsum1_2[1:]

cumsum2, cumsum2_2 = [0], [0]
pos = 0
for x, v in xv2:
    tmp = cumsum2[-1] + v - (x - pos)
    cumsum2.append(tmp)
    cumsum2_2.append(tmp - x)
    pos = x
    ans = max(ans, tmp)
cumsum2, cumsum2_2 = cumsum2[1:][::-1], cumsum2_2[1:][::-1]

tmpmax = 0
for i in reversed(range(n)):
    ans = max(ans, cumsum1[i] + tmpmax)
    tmpmax = max(tmpmax, cumsum2_2[i])

tmpmax = 0
for i in range(n):
    ans = max(ans, cumsum2[i] + tmpmax)
    tmpmax = max(tmpmax, cumsum1_2[i])

print(ans)


Measured memory_bytes: 93016
#include<bits/stdc++.h>
using namespace std;
int const maxn=1e3+10;
int n,h,w,cou=0,ans=0,disx[4]={0,0,1,-1},disy[4]={1,-1,0,0};
string s[maxn];
struct node{
	int x,y;
	node(int a=0,int b=0):
		x(a),y(b){}  
};
queue <node> q[2];
void work(){
	int sh=h*w;
	bool flag=0,flag2=1;
	if(cou==sh)return ;
	node z;
	int nowx,nowy;
	while(cou<sh){
		while(!q[flag].empty()){
			z=q[flag].front();q[flag].pop();
			for(int i=0;i<4;i++){
				nowx=z.x+disx[i];nowy=z.y+disy[i];
				if(nowx>=0&&nowx<h&&nowy>=0&&nowy<w&&s[nowx][nowy]=='.'){
					s[nowx][nowy]='#';q[flag2].push(node(nowx,nowy));
					cou++;
				}
			}
		}
		ans++;
		flag=!flag;flag2=!flag2;
	}
}
int main(){
	scanf("%d%d",&h,&w);
	node z;
	for(int i=0;i<h;i++){
		cin>>s[i];
		for(int j=0;j<w;j++){
			if(s[i][j]=='#'){
				cou++;
				z.x=i;z.y=j;
				q[0].push(z);
			}
		}
	}
	work();
	cout<<ans<<endl;
	return 0;
}

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

int main(void) {
	int n;
	int a[100000] = { 0 };
	int cnt_four = 0, cnt_two = 0, cnt_one = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 4 == 0)cnt_four++;
		else if (a[i] % 2 == 0)cnt_two++;
		else cnt_one++;
	}
	if (cnt_two) {
		if (cnt_four >= cnt_one) printf("Yes");
		else printf("No");
	}
	else {
		if (cnt_four >= cnt_one - 1)printf("Yes");
		else printf("No");
	}
	return 0;
}


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

const int MAX = 30;

int pow(int a, int b) {
	switch(b) {
		case 0: return 1;
		case 1: return a;
		case 2: return a * a;
	}
	return pow(pow(a, 2), b >> 1) * pow(a, b & 1);
}
int main() {
	int N, M;
	cin >> N >> M;
	int ans = M;
	vector<pair<int, int> > primes;
	for (int i = 2;i < 100000 && M > 1;++ i) {
		if (M % i == 0) {
			primes.push_back(make_pair(i, 0));
			while (M % i == 0) {
				++ primes[primes.size() - 1].second;
				M /= i;
			}
		}
	}
	if (M > 1) primes.push_back(make_pair(M, 1));
	int use[MAX];
	for (int i = 0;i <= primes.size();++ i) use[i] = 0;
	set<int> s;
	while (use[primes.size()] <= 0) {
		int tmp = 1;
		for (int i = 0;i < primes.size();++ i) {
			tmp *= pow(primes[i].first, use[i]);
		}
		s.insert(tmp);
		++ use[0];
		for (int i = 0;i < primes.size() && use[i] > primes[i].second;++ i) {
			use[i] = 0;
			++ use[i + 1];
		}
	}
	cout << ans / *s.upper_bound(N - 1);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、答えはM/N以下になる
答えを仮にxとする
この時、全てのa_iはxの倍数となるので、Mがxで割り切れるならそれが答えとなる
要するに、M/N以下で最大のMの因数を出力すれば良い
言い換えると、N以上の最小のMの因数をMから取り除いた数が答え

さて、N以上の最小のMの因数とは？
Mを素因数分解すると最大でlogM個の素因数が出てくる
そのすべての素因数を列挙し、下から見ていけば良いのでは(lower_bound
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans=0;
  vector<int> v(n);
  vector<int> c(n);
  for(int i=0;i<n;i++) cin >> v.at(i);
  for(int i=0;i<n;i++) cin >> c.at(i);
  
  for(int i=0;i<n;i++){
    int tmp;
    tmp = v.at(i) - c.at(i);
    if (tmp>0) ans+=tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    if (n < 10) {
        cout << r + 100 * (10 - n) << endl;
    } else {
        cout << r << endl;
    }

    return 0;
}

Measured memory_bytes: 764
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		HashMap<String, String> map = new HashMap<>();
		map.put("A", "T");
		map.put("T", "A");
		map.put("C", "G");
		map.put("G", "C");
		out.println(map.get(in.next()));
		
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 20692
//*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
#include <complex>

using namespace std;

typedef long long int lld;

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int x, y;
	cin >> x >> y;

	for (int a = 0; a <= x; a++) {
		int b = x - a;
		if (2 * a + 4 * b == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

//*/ 

Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
int main()
{
    int n, a;
    bool p = true;
    cin >> n;
    for (int i = 0; i < n;i++){
        cin >> a;
        if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0))
        {
            p = false;
        }
    }
    if(p){
        cout << "APPROVED";
    }else{
        cout << "DENIED";
    }

}


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

int main(){
    /*input*/
    int r,g;	cin >> r >> g;
    /*calculatoin*/
    /*output*/
    cout << 2*g-r << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y){

    if(x<y) return gcd(y,x);
    if(y==0) return x;
    return gcd(y,x%y);

}

int main(){

    cin.sync_with_stdio(false);

    long long x,y;

    while(cin >> x >> y){

        long long m = gcd(x,y);

        cout << m << " " << x/m * y << endl;

    }

    return 0;

}

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

using namespace std;

int main() {
    list<int> internal;
    int n;
    cin >> n;
    bool rev = false;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (rev)
            internal.push_front(x);
        else
            internal.push_back(x);
        rev = 1 - rev;
    }
    if (rev) {
        for (int i = 0; i < n; i++) {
            cout << internal.back() << " ";
            internal.pop_back();
        }
    } else {
        for (int i = 0; i < n; i++) {
            cout << internal.front() << " ";
            internal.pop_front();
        }
    }
}

Measured memory_bytes: 9856
package main

import ("fmt"
				"bufio"
				"os"
)


var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	s := nextLine()
	ans := ""
	for _, v := range s {
		if "1" == string(v) {
			ans = ans + "9"
		} else {
			ans = ans + "1"
		}
	}
	fmt.Println(ans)
}

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

#define rep(i,x,y) for(int (i)=(x);i<(y);(i)++)
#define INF 1000000000

int main()
{
  while(true){
    int N,M;
    cin>>N>>M;
    if(N==0&&M==0){
      break;
    }

    vector<int> C,x;
    int temp;
    rep(i,0,M){
      cin>>temp;
      C.push_back(temp);
    }
    rep(i,0,N){
      cin>>temp;
      x.push_back(temp);
    }

    vector<vector<int>> dp(N+1,vector<int>(256,INF));
    dp[0][128]=0;
    rep(i,0,N){
      rep(j,0,256){
        if(dp[i][j]==INF){
          continue;
        }
        rep(k,0,M){
          int yn=j+C[k];
          yn=min(255,yn);
          yn=max(0,yn);
          int sum=(x[i]-yn)*(x[i]-yn);
          dp[i+1][yn]=min(dp[i+1][yn],dp[i][j]+sum);
        }
      }
    }

    int ans=dp[N][0];
    rep(i,0,256){
      ans=min(ans,dp[N][i]);
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 23668
N = int(input())
s = [input() for _ in range(N)]

a = [0] * 5
for i in range(N):
    if s[i][0] == "M":
        a[0] += 1
    elif s[i][0] == "A":
        a[1] += 1
    elif s[i][0] == "R":
        a[2] += 1
    elif s[i][0] == "C":
        a[3] += 1
    elif s[i][0] == "H":
        a[4] += 1

S = 0
for k in range(5):
    for l in range(k + 1, 5):
        for m in range(l + 1, 5):
            S += a[k] * a[l] * a[m]

print(S)

Measured memory_bytes: 9772
use utf8;
use warnings;
use strict;
use feature qw/say/;

chomp(my $n = <>);
my @n = split(//, $n.'');
my $l = 0+$n[-1];
if ($l == 2 || $l == 4 || $l == 5 || $l == 7 || $l == 9) {
    say 'hon';
} elsif ($l == 0 || $l == 1 || $l == 6 || $l == 8) {
    say 'pon';
} else {
    say 'bon';
}

Measured memory_bytes: 5256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 1000009
int main(){
    int n,n2;
    while(cin>>n>>n2,n+n2){
        string s; s=to_string(n);
        int size=(int)s.size();
        rep(i,n2-size) s.push_back('0');
        vi v; v.push_back(stoi(s));
        int count=1;
        while(true){
            sort(s.begin(), s.end(),greater<int>());
            string maxi=s;
            //cout<<maxi<<endl;
            sort(s.begin(), s.end());
            string mini=s;
            //cout<<mini<<endl;
            int a=stoi(maxi);
            int b=stoi(mini);
            rep(i,count){
                if(v[i]==a-b){
                    cout<<i<<" "<<a-b<<" "<<count-i<<endl;
                    goto e;
                }
            }
            v.push_back(a-b);
            s=to_string(a-b);
            rep(j,n2-s.size()){
                s.insert(s.begin(),'0');
            }
            count++;
        }
    e:;
    }
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    char c;
    cin>>c;
    if('A'<=c&&c<='Z'){cout<<'A';}
    else{cout<<'a';}
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int len, fid, dis;
vector < int > edge[maxn];
void dfs(int now, int last, int d = 1){
	if(d > dis){
		dis = d;
		fid = now;
	}
	for(auto &i : edge[now]){
		if(last != i){
			dfs(i, now, d + 1);
		}
	}
}
bool win[maxn];
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> len;
	win[1] = true;
	win[2] = false;
	for(int i = 3;i < maxn;++i)
		(win[i] = !win[i - 1] || !win[i - 2]);
	for(int i = 1;i < len;++i){
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	fid = 1;
	dfs(fid, fid);
	dis = 0;
	dfs(fid, fid);
	if(win[dis]){
		cout << "First\n";
	}
	else{
		cout << "Second\n";
	}
}


Measured memory_bytes: 20736
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;
using ll=long long;
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}

int main() {
ll N;;
cin >> N;
ll a[N],b[N];
ll sabun[N];
ll sum=0;
ll p=0;
FOR(i,0,N-1){
  cin >> a[i];
}

FOR(i,0,N-1){
  cin >>b[i];
  sabun[i]=a[i]-b[i];
  sum = sum+b[i]-a[i];
}

FOR(i,0,N-1){
  while(sabun[i]<0){
    sabun[i]++;
    sabun[i]++;
    p++;
  }
}

if(p>sum){cout<<"No"<<endl;}else{cout<<"Yes"<<endl;}

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, C;
int s[N], t[N], c[N];
int sum[N + N];
int main() {
	scanf("%d%d", &n, &C);
	for (int i = 0; i < n; ++ i) scanf("%d%d%d", &s[i], &t[i], &c[i]);

	for (int i = 0; i < n; ++ i) {
		sum[s[i] * 2 - 1] ^= (1 << c[i] - 1);
		sum[t[i] * 2] ^= (1 << c[i] - 1);
	}
	for (int i = 1; i < N + N; ++ i) sum[i] ^= sum[i - 1];
	int ans = 0;
	for (int i = 0; i < N + N; ++ i) {
		ans = max(ans, __builtin_popcount(sum[i]));
	}

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


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int dp[1000][1000],a,b,c,d[10000],N,lo,li,yu;
double an;
int main(){
    cin>>N>>a>>b>>c;
    for(int i=0;i<N;i++){
        cin>>d[i];
    }
    sort(d,d+N);
    reverse(d,d+N);
    lo=c;li=a;
    yu=lo/li;
    for(int i=0;i<N+1;i++){
        lo+=d[i];
        li+=b;
        yu=max(yu,lo/li);
    }
    cout<<yu<<endl;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int i,a,b,k,c=0;
	cin>>k;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			c++;
		}
	}
	if(c>=1)
	{
		cout<<"OK";
	}
	else
	{
		cout<<"NG";
	}
	return 0;
}

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

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    ll A[1010], B[1010], C[1010];
    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];

    ll D[1000100];
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            D[i * Y + j] = A[i] + B[j];
        }
    }
    sort(D, D + X * Y, greater<ll>());

    ll E[3000100];
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < Z; j++){
            E[i * Z + j] = D[i] + C[j];
        }
    }
    sort(E, E + K * Z, greater<ll>());

    for (int i = 0; i < K; i++){
        printf("%lld\n", E[i]);
    }


}

Measured memory_bytes: 31616
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn anti_division_count(X: i64, C: i64, D: i64) -> i64 {
    let mut n = 0;
    n += X / C;
    n += X / D;
    n -= X / (C / gcd(C, D) * D);

    X - n
}

fn main() {
    let (A, B, C, D) = read!(i64, i64, i64, i64);

    let b = anti_division_count(B, C, D);
    let a = anti_division_count(A - 1, C, D);
    debug!(b, a);

    println!("{}", b - a)
}


Measured memory_bytes: 4352
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math

def resolve():
    A,B=map(int,input().split())
    if A<=8 and B<=8:
        print('Yay!')
    else:
        print(":(")
 
 
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 39408
/**
* I'm sorry I was an Idiot
*/
#include<iostream>
#define ll unsigned long long

using namespace std;

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

int main(){
	ll a,b,c,d;
	cin >> a >> b >> c >> d;

	ll posC = (b/c) - (a/ c);

	if(a % c == 0)
		++posC;

	ll posD = (b/d) - (a/d);
	if(a % d == 0)
		++posD;

	ll lcm = (c*d)/gcd(c,d);
	ll posLC = (b/lcm) - (a/ lcm);
	if(a % lcm == 0)
		++posLC;
	ll ans = posC + posD - posLC;
	//cout << posC << " " << posD << endl;
	//cout << ans << endl;
	ans = (b-a + 1) - ans; 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

int N,M,V,P; 
int pos=0;
int sum=0;
int A[100010];

bool isOK(int index) {
    if (index<=pos) return false;
    int cnt=0;
    int maxr=0;
    rep(i,N){
        if(i<pos) continue;
        else if(i<index){
            cnt+=A[i]-A[index];
            maxr=max(maxr,A[i]-A[index]);
        }
        else break;
    }
    if(min(N-V,index-pos)*M>=cnt && maxr<=M ) return false;
    else return true;
}

int binary_search() {
    int left = -1;
    int right = N;

    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid)) right = mid;
        else left = mid;
    }

    return left;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    cin >> N >> M >> V >> P;
    rep(i,N) cin >> A[i];
    sort(A,A+N,greater<int>());
    
    rep(i,N){
        if(pos!=P-1) {pos++;}
        else {
            break;
        }
    }
    cout << binary_search()+1 << endl;

}


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

int main() {
    string S;
    cin >> S;
    string next;
    if(S == "Sunny") {
        next = "Cloudy";
    }else if(S == "Cloudy") {
        next = "Rainy";
    }else if(S == "Rainy") {
        next = "Sunny";
    }
    cout << next << endl;
    return 0;
}

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

void distance(const int *x, int n, double p)
{
    double sum=0;
    int dec[n];
    for (int i = 0; i < n; i++)
    {
        dec[i] = pow(*x++, p);
        sum += (double)dec[i];
    }
    sum = pow(sum, 1/p);

    cout << sum << endl;
}

int main()
{
    cout<< std::fixed << std::setprecision(6);
    int n;
    cin >> n;
    int x[n], y[n], dec[n];

    for (int i = 0; i < n; i++)
        cin >> x[i];
    for (int i = 0; i < n; i++)
        cin >> y[i];    

    for (int i = 0; i < n; i++)
        dec[i] = abs(x[i] - y[i]);
    
    distance(dec, n, 1);
    distance(dec, n, 2);
    distance(dec, n, 3);

    double mx=0;
    for (int i = 0; i < n; i++)
        mx = fmax(mx, abs(x[i]-y[i]));

    cout << mx << endl;
    

    return 0;
}


Measured memory_bytes: 3444
N, K = map(int, input().split())
mod = int(1e+9 + 7)
p = mod - 2
A = []
while p != 0:
  A = [p%2] + A[:]
  p //= 2
pr1 = 1
pr2 = N - K + 1
key1 = K - 1
key2 = N - K
fact = 1
invi = []
for i in range(1, K+1):
  inv = 1
  for j in range(len(A)):
    if A[j] == 1:
      inv *= fact
      inv %= mod
    if j != len(A)-1:
      inv *= inv
      inv %= mod
  prod = (i * inv * inv * pr1 * pr2) % mod
  print(prod)
  pr1 *= key1
  pr1 %= mod
  pr2 *= key2
  pr2 %= mod
  key1 -= 1
  key1 %= mod
  key2 -= 1
  key2 %= mod
  fact *= i+1
  fact %= mod

Measured memory_bytes: 3316
#include <stdio.h>

#define SIZE 3

int* InputNumber(int* numArr, const int size);
int* Sort(int* numArr, int size);

int main(void) {

    int idx;
    int data[SIZE];

    InputNumber(data, SIZE);
    Sort(data, SIZE);

    for (idx = 0; idx < SIZE - 1; idx++) {
    	printf("%d ", data[idx]);
    }
    printf("%d\n", data[SIZE - 1]);

}

int* InputNumber(int* numArr, const int size) {
	int idx;
	for (idx = 0; idx < size; idx++) {

		do {
			scanf("%d", &numArr[idx]);
		} while (numArr[idx] < 0 || numArr[idx] > 10000);

	}

	return numArr;
}

int* Sort(int* numArr, int size) {

    int i, j;

    for (i = 0; i < size; i++) {
        int sorted = 0;

        for (j = 0; j < size - i - 1; j++) {
            if (*(numArr + j) > *(numArr + j + 1)) {
                int tmp = *(numArr + j);
                *(numArr + j) = *(numArr + j + 1);
                *(numArr + j + 1) = tmp;
                sorted = 1;
            }
        }

        if (!sorted) {
			break;
		}
    }

    return numArr;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long x;
    cin>>x;
    if (x==0)
    {
    	cout<<1<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
bool f(int n){
    set<int> s;
    while(n > 0){
        s.in(n % 10);
        n /= 10;
    }
    if(s.size() == 1) return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    while(!f(n)) n++;
    cout << n;
}

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

int main(int argc, char const *argv[]) {
  char a[4];
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    scanf("%c",&a[i]);
    if (a[i] == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  printf("%d\n",ans );
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<int> ans(n);
  int right,left,location = 0;
  if(s.at(0) == 'R'){
    right = 1;
    left = 0;
  }
  else{
    left = 1;
    right = 0;
  }
  for(int i = 1;i < n;i++){
    if(s.at(i) == 'R'){
      right++;
      if(s.at(i-1) == 'L'){
        if(left % 2 == 0){
          ans.at(location) += left/2;
          ans.at(location-1) += left/2;
        }
        else{
          ans.at(location) += left/2 + 1;
          ans.at(location-1) += left/2;
        }
        right = 1;
        left = 0;
      }
    }
    else{
      left++;
      if(s.at(i-1) == 'R'){
        location = i;
        if(right % 2 == 0){
          ans.at(location) += right/2;
          ans.at(location-1) += right/2;
        }
        else{
          ans.at(location) += right/2;
          ans.at(location-1) += right/2 + 1;
        }
        left = 1;
        right = 0;
      }
      if(i == n-1){
        if(left % 2 == 0){
          ans.at(location) += left/2;
          ans.at(location-1) += left/2;
        }
        else{
          ans.at(location) += left/2 + 1;
          ans.at(location-1) += left/2;
        }
      }
    }
  }
  for(int i = 0;i < n;i++){
    cout << ans.at(i) << ' ';
  }
  cout << ' ' << endl;
}

Measured memory_bytes: 1024
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn main() {
    let mut n: Vec<i32> = read_vec();
    n.sort();
    println!("{} {} {}", n[0], n[1], n[2]);
}



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

int main()
{
    string s, t;
    cin >> s >> t;

    vector<set<int>> ss(26), st(26);

    for (int i = 0; i < s.size(); i++) {
        ss[s[i] - 'a'].insert(t[i] - 'a');
        st[t[i] - 'a'].insert(s[i] - 'a');
    }

    for (int i = 0; i < 26; i++) {
        if (ss[i].size() > 1 || st[i].size() > 1) {
            return cout << "No" << endl, 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 776
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var ab = input[0].split(' ');
    var a = parseInt(ab[0], 10);
    var b = parseInt(ab[1], 10);

    var ans = Math.max(a + b, a - b, a * b);

    if (ans === -0) {
        ans = 0;
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 11596
import java.util.*;

class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  private Scanner sc = new Scanner(System.in);


  private void run() {
    int N = Integer.parseInt(sc.next());
    List<GuideBook> list = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      list.add(new GuideBook(i + 1, sc.next(), Integer.parseInt(sc.next())));
    }
    Comparator<GuideBook> rComparetor = Comparator.comparing(GuideBook::getRestaulant);
    Comparator<GuideBook> pComparetor = Comparator.comparingInt(GuideBook::getPoint).reversed();
    Comparator<GuideBook> comparator = rComparetor.thenComparing(pComparetor);

    list.sort(comparator);

    for (GuideBook guideBook : list) {
      System.out.println(guideBook.getId());
    }
  }
}

class GuideBook {
  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getRestaulant() {
    return restaulant;
  }

  public void setRestaulant(String restaulant) {
    this.restaulant = restaulant;
  }

  public int getPoint() {
    return point;
  }

  public void setPoint(int point) {
    this.point = point;
  }

  public GuideBook(int id, String restaulant, int point) {
    this.id = id;
    this.restaulant = restaulant;
    this.point = point;
  }

  int id;
  String restaulant;
  int point;
}


Measured memory_bytes: 28244
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

  for i in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
map<pii,int> m;
pii p[maxn];
const int mod=1000000007;
set<pii> s;
ll qpow(ll a,ll b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll zero=0;
	rept(i,1,n)
	{
		ll a,b;
		cin>>a>>b;
		if(a||b)
		{
			ll gcd=__gcd(abs(a),abs(b));
			a/=gcd,b/=gcd;
		}
		if(a<0)
		{
			a=-a;
			b=-b;
		}
		if(a==0&&b!=0)
		{
			b=1;
		}
		if(b==0&&a!=0)
		{
			a=1;
		}
		if(a==0&&b==0)
		{
			zero++;
		}
		p[i]=mp(a,b);
		m[p[i]]++;
//		dd(i);dd(a);de(b);
	}
	ll ans=1;
	rept(i,1,n)
	{
		if(p[i].fi==0||p[i].se==0) continue;
		if(s.find(p[i])!=s.end()) continue;
		pii op=mp(-p[i].se,p[i].fi);
		if(op.fi<0)
		{
			op.fi=-op.fi;
			op.se=-op.se;
		}
		s.insert(p[i]);
		s.insert(op);
	//	dd(op.fi);de(op.se);
		ans=ans*(qpow(2,m[op])+qpow(2,m[p[i]])%mod-1+mod)%mod;

	//	dd(i);dd(m[op]);dd(m[p[i]]);de(ans);
	}
//	de(ans);
//	dd(m[mp(0,1)]);de(m[mp(1,0)]);
	ans=ans*(qpow(2,m[mp(0,1)])+qpow(2,m[mp(1,0)])-1+mod)%mod;
//	de(ans);
	ans=(ans-1+mod)%mod;
	ans=(ans+zero)%mod;
	
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 56540
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF pow(10,10)

vector<vector<ll>>dp(3005,vector<ll>(3005,0));

int main(void){
    string s,t; cin >> s >> t;
    s = " " + s;
    t = " " + t;
    for(int i=1;i<s.length();i++){
        for(int j=1;j<t.length();j++){
            if(s[i]==t[j]) dp[i][j] = dp[i-1][j-1] + 1;
            else if(dp[i][j-1]<=dp[i-1][j]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = dp[i][j-1];
        }
    }
    string ans = "";
    ll i = s.length()-1, j = t.length()-1;
    while(ans.length()<dp[s.length()-1][t.length()-1]){
        if(s[i]==t[j]) ans += s[i], i--,j--;
        else if(dp[i][j-1] < dp[i][j]) i--;
        else j--;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 70912
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
 
#define ll long long
 
 
int main() {
  	ll A, B, C, K;
  	cin >> A >> B >> C >> K;
  	ll sum;
  	
  	if(A<K){
      sum+=A;
      if(B<K-A){
      	sum-=K-A-B;
        cout <<sum<<endl;
      }
      else{
        cout <<sum<<endl;
      }
      
    }
  	else{
      cout <<K<<endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define M0D 998244353;

int main(){
  string S;
  int K;
  cin >> K;
  cin >> S;
  if(S.size()>K){
    for(int i=0; i<K; i++) cout << S[i];
    cout << "..." << endl;
  }else{
    for(int i=0; i<S.size(); i++) cout <<  S[i];
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int f=0,x=1;char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')x=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')f=(f<<1)+(f<<3)+ch-'0',ch=getchar();
	return f*x;
} 
int a,b,k,f=0;
int main()
{
	a=read();b=read();k=read();
	for(int i=max(a,b);i>=1;i--)
	{
		if(a%i==0&&b%i==0)
		{
			f++;
			if(f==k)
			{
				printf("%d\n",i);return 0;
			}
		}
	}
}

Measured memory_bytes: 128
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]
c1 = A[0][0]
c2 = sum(A[1])
ans = c1+c2
for i in range(1,N):
  c1 += A[0][i]
  c2 -= A[1][i-1]
  ans = max(ans,c1+c2)
print(ans)

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
 
 
ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
int main(){
    double R;
    cin>>R;
    double ans=0;
    ans = R*2*3.141592653589;
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3788
def power_set(item_lists):

    p_sets = [[]]

    for item in item_lists:
        tmp = []
        for element in p_sets:
            tmp.append(element + [item])
        p_sets.extend(tmp)

    return p_sets



if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    m = list(map(int, input().split()))

    p_set = [sum(l) for l in power_set(A)]

    for m_i in m:

        if m_i in p_set:
            print("yes")
        else:
            print("no")



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

int main(void){
	int N,K;
	int a;
	int s[100];
	int ds[100];
	while(cin>>N>>K,N||K){
	 for(int i=0;i<K;i++)cin>>s[i];
	 for(int i=0;i<K;i++)ds[i]=0;
	 for(int i=0;i<N;i++){
		 for(int j=0;j<K;j++){
			 cin>>a;
			 ds[j]+=a;
		 }
	 }
	 for(int i=0;i<K;i++){
		 if(ds[i]>s[i]){
			 cout<<"No"<<endl;
			 goto ST;
		 }
	 }
	 cout<<"Yes"<<endl;
ST:;
	}
	return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int,h,w,n);
	vector<int> a(n);
	REP(i,n) cin>>a[i];

	vector< vector< int > > ans(h, vector<int>(w,0));
	int id = 0;
	REP(hi,h){
		if (hi % 2 == 0) {
			REP(wi,w){
				if (a[id] <= 0) ++id;
				ans[hi][wi] = id + 1;
				--a[id];
			}
		}else{
			RREP(wi,w){
				if (a[id] <= 0) ++id;
				ans[hi][wi] = id + 1;
				--a[id];
			}
		}
	}

	REP(hi,h){
		bool isFirst = true;
		REP(wi,w){
			if (!isFirst) SP;
			isFirst &= false;
			OUT(ans[hi][wi]);
		}
		BR;
	}
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=NINF;
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
}


return 0;
}





Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e7))
#define MAX_X ((int)(1e6 + 2))
#define pi (2.0*acos(0))
#define M ((ll)(1e9 + 7))
#define NN ((ll)(305))
#define N ((int)(5e5 + 5))
#define eps (0)
#define log 20


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/


typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

char s[N];

int arr[N];

int main()
{
    scanf("%s",s);
    int n = strlen(s);
    arr[n] = 0;
    int mnn = 0;
    memset(arr,-1,sizeof arr);
    for(int i = 0; i<n; i++){
        if(i>0 && i<n && s[i-1]=='>' && s[i]=='<'){
            arr[i] = 0;
        }
        else if(i==0 && s[i]=='<') arr[i] = 0;
        else if(i==n-1 && s[i]=='>') arr[i+1] = 0;
    }

    for(int i = 0; i<=n; i++){
        if(arr[i]==0){
            for(int j = i-1; j>=0; j--){
                if(s[j]=='>') arr[j] = max(arr[j+1]+1,arr[j]);
                else break;
            }

            for(int j = i+1; j<=n; j++){
                if(s[j-1]=='<') max(arr[j] = arr[j-1]+1,arr[j]);
                else break;
            }
        }
    }

    //for(int i = 0; i<=n; i++) cout<<arr[i]<<endl;

    ll sum = 0;
    for(int i = 0; i<=n; i++) sum += arr[i];

    printf("%lld\n",sum);

    return 0;

//    for(int i = n-1; i>=0; i--){
//        if(s[i]=='>') arr[i] = arr[i+1]+1;
//        else arr[i] = arr[i+1]-1;
//
//        mnn = min(mnn,arr[i]);
//    }
//
//    if(mnn<0){
//        for(int i = 0; i<=n; i++){
//            if(arr[i]<0){
//                arr[i] = 0;
//                for(int j = i-1; j>=0; j--){
//                    if(s[j]=='<') break;
//                    arr[j] = arr[j+1]+1;
//                }
//
//                for(int j = i+1; j<=n; j++){
//                    if(s[j-1]=='>') break;
//                    arr[j] = arr[j-1]+1;
//                }
//            }
//        }
//    }
//
//    ll sum = 0;
//    for(int i = )
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef long long ll;

int main(){
	ll N, x;
	cin >> N >> x;
	vector<ll> a(N), cost(N), tmp(N);
	for(int i = 0; i < N; ++i) cin >> a[i];

	ll res = 0;
	for(int i = 0; i < N; ++i){
		cost[i] = a[i];
		res += a[i];
	}
	for(int k = 1; k < N; ++k){
		for(int i = N-1; i >= 0; --i){
			tmp[(i+1)%N] = min(cost[(i+1)%N], cost[i]);
		}
		ll s = 0;
		for(int i = 0; i < N; ++i){
			cost[i] = tmp[i];
			s += cost[i];
		}
		res = min(res, s + k * x);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	long long int a, b, k, c;
	cin >> c;
	if (c == 2) {
		cout << 2;
		return 0;
	}
	for (int i = c; i > 0; i++) {
		for (int j = 2; j < i; j++){
			if (i % j == 0)
			break;
			if (j == i-1) {
				cout << i;
				return 0;
			} 
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int A[100],temp=0,count=0,mini=0,N,i,j;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }
  
  for(i = 0 ; i < N ; i++){
    mini = i;
    for(j = i+1 ; j < N ; j++){
      if(A[j] < A[mini]){
	mini = j;
      }         
    }
    temp = A[i];
    A[i] = A[mini];
    A[mini] = temp;
    if(A[i] != A[mini]) count++;
  }
  
  for(j = 0 ; j < N ; j++){
    printf("%d",A[j]);
    if(j < N-1){
      printf(" ");
    }
  }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while (x->left != NIL) {
    x = x->left;
  }
  
  return x;
  
}

Node treeSearch(Node x, int k){
  
  if (x == NIL || k == x->key) {
    return x;
  }
  
  if (k < x->key) {
    return treeSearch(x->left, k);
  } else {
    return treeSearch(x->right, k);
  }
  
  
}

Node treeSuccessor(Node x){
  Node y;
  
  if (x->right != NIL) {
    return treeMinimum(x->right);
  }
  
  y = x->parent;
  
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  
  return y;
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || z->right == NIL) {
    y = z;
  } else {	
    y = treeSuccessor(z);
  }
  
  if (y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }
  
  if (x != NIL) {
    x->parent = y->parent;
  }
  
  if (y->parent == NIL) {
    root = x;
  } else if (y == y->parent->left) {
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }
  
  if(y != z){
    z->key = y->key;
  }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  z->parent = NIL;

  while(x != NIL){
    y = x;

    if(z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  
  if(y == NIL){
    root = z;
  } else if(z->key < y->key){
    y->left = z;
  } else {
    y->right = z;
  }
  

}


void inorder(Node u){
  
  if(u->left != NIL){
    inorder(u->left);
  }
  
  printf(" %d",u->key);
  
  if(u->right != NIL){
    inorder(u->right);
  }
  
}

void preorder(Node u){

  printf(" %d",u->key);
	
  if(u->left != NIL){
    preorder(u->left);
  }
  
  if(u->right != NIL){
    preorder(u->right);
  }
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}

Measured memory_bytes: 9844
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		println(c + " " + a + " " + b);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
using namespace std;
int main(){
	int w,h;
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	while(true){
	cin>>w>>h;
	if(w==0&&h==0)break;
	string a;
	int s=0;
	int x=1,y=1,z;
	while(true){
		cin>>a;
		if(a=="STOP")break;
		if(a=="RIGHT")s=(s+1)%4;
		if(a=="LEFT")s=(s+3)%4;
		if(a=="FORWARD"){
			cin>>z;
			x+=dx[s]*z,y+=dy[s]*z;
			if(x<1)x=1;if(x>w)x=w;
			if(y<1)y=1;if(y>h)y=h;
		}
		if(a=="BACKWARD"){
			cin>>z;
			x-=dx[s]*z,y-=dy[s]*z;
			if(x<1)x=1;if(x>w)x=w;
			if(y<1)y=1;if(y>h)y=h;
		}
	}
	cout<<x<<" "<<y<<endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;

int main(){
  ll n, k, q;
  cin >> n >> k >> q;
  cin.ignore();
  ll a[n] = {0};
  for (ll i = 0; i < n; i++){
    a[i] = 0;
  }
  ll tmp;
  for (ll i = 0; i < q; i++){
    cin >> tmp;
    --tmp;
    ++a[tmp];
  }
  for (ll i = 0; i < n; i++){
    a[i] = k - q + a[i];
    if(a[i] > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cctype>
#include <map>
#include <algorithm>
#define fr first
#define sc second
#define INF (2 << 28)
using namespace std;

bool ju;
int sx,sy,gx,gy;
int dp[5][5][1001];
typedef pair<int,int> iP;
vector<vector<iP> > d(5);

int dis(int sum,int now,int idx,int next, int i){
  if(sum == 1) return abs(sx - d[next][i].fr) + abs(sy - d[next][i].sc);
  else return abs(d[now][idx].fr - d[next][i].fr) + abs(d[now][idx].sc - d[next][i].sc);
}
		 
int rec(int sum,int now,int idx){
  if(sum == 5) return abs(d[now][idx].fr - gx) + abs(d[now][idx].sc - gy);
  if(dp[sum][now][idx]) return dp[sum][now][idx];
  int ret = INF;
  for(int i = 0 ; i < d[(now + 1) % 5].size() ; i++){
    ret = min(rec(sum+1,(now+1)%5,i) + dis(sum,now,idx,(now+1)%5,i) , ret);
  }

  return dp[sum][now][idx] = ret;
}


int main(){
  int x,y;
  char mas[1001][1001];
  while(cin >> x >> y,x||y){
    for(int i = 0 ; i < y ; i++){
      for(int j = 0 ; j < x ; j++){
	cin >> mas[i][j];
	if(mas[i][j] == 'S') sy = i,sx = j;
	if(mas[i][j] == 'G') gy = i,gx = j;
	if(isdigit(mas[i][j])) d[mas[i][j] - '1'].push_back(iP(j,i));
      }
    }
    
    int mini = INF,ans;
    for(int i = 0 ; i < 5 ; i++){
      memset(dp,0,sizeof(dp));
      int d = rec(1,i,0);
      if(d < mini) mini = d,ans = i+1;
    }
    if(mini == INF) cout << "NA" << endl;
    else cout << ans << " " << mini << endl;
    d.resize(0); d.resize(5);
  }
}

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

int main(){
    int N,a;
    vector<int>b(100002,0);
    scanf("%d",&N);
    rep(i,N)scanf("%d",&a),b[a]++,b[a+1]++,a>0&&b[a-1]++;
    cout<<*max_element(b.begin(),b.end())<<endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=j;i<=k;++i)
#define Forr(i,j,k) for (int i=j;i>=k;--i)
using namespace std;

template<typename T>bool chkmax(T& a,T b) {return a<b?a=b,1:0;}
template<typename T>bool chkmin(T& a,T b) {return a>b?a=b,1:0;}

char s[1000];

int main()
{
	scanf("%s",s);
	int n=strlen(s);
	For (i,0,n-9) printf("%c",s[i]);
	return 0;
}

Measured memory_bytes: 256
A,B,C=(int(x) for x in input().split())

if B==0:
    x=C//A
    if C%A!=0:
        x=x+1
elif A>C:
    x=1
elif C//A<7:
    x=C//A+1
else:
    t=0
    y=A*7
    y=y+B
    z=C%y
    if 0<z<A:
        t=1
    z=z//A
    if z>7:
        t=7-z
    s=C//y
    s=s*7
    x=z+s+t
print(x)


Measured memory_bytes: 5604