akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};
use std::collections::HashMap;
use std::collections::HashSet;

fn main() {
    let n: i64 = read();
    let k: i64 = read();
    let r: i64 = read();
    let s: i64 = read();
    let p: i64 = read();
    let t: String = read();
    let mut ans = 0;
    // let mut vec: Vec<Vec<char>> = vec![vec![]; k as usize];
    let mut dist: HashMap<i64, Vec<char>> = HashMap::new();

    for (i, v) in t.chars().enumerate() {
        let key = (i as i64 + 1) % k;
        if dist.contains_key(&key) {
            let current = dist.get_mut(&key).unwrap();
            current.push(v);
        } else {
            dist.insert(key, vec![v]);
        }
    }

    for (k, v) in dist.iter() {
        let mut prev = '#';
        for i in v {
            if (*i == prev) {
                prev = '#'
            } else {
                match *i {
                    'r' => ans += p,
                    's' => ans += r,
                    'p' => ans += s,
                    _ => (),
                };
                prev = *i;
            }
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 17512
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

const int maxn = 100*1000+5;

int n, a[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a+i);
    std::sort(a, a+n);
    std::reverse(a, a+n);
    int i = 0;
    while (i < n) {
        int j = i;
        while (j+1 < n && a[i] == a[j+1]) j++;
        int lo = i - a[i];
        if (i == 0 || (i-1 - a[i-1]) % 2 == lo % 2) {
            if (lo == 0) {
                printf("First\n");
                return 0;
            }
        }
        int hi;
        if (j+1 < n) hi = j+1 - a[j+1] - 1;
        else hi = 1e9;
        if (lo <= 0 && hi >= 0) {
            if ((j - a[j]) % 2) printf("Second\n");
            else printf("First\n");
            return 0;
        }
        i = j+1;
    }
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;

int main() {
    int s1, a1, s2, a2;
    cin >> s1 >> a1 >> s2 >> a2;
    int t1 = s2 / a1;
    int t2 = s1 / a2;

    if(s2 % a1 != 0) {t1++;}
    if(s1 % a2 != 0) {t2++;}

    if(t1 <= t2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

#define rep(i,m,n) for(int i=(m);i<=(n);i++)
#define mer(i,m,n) for(int i=(m);i>=(n);--i)

#define MOD 1000000007
//#define MOD 998244353
//#define MAX

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<long long int> vll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<char> vc;
vector<string> vs;


int main() {
	int N;
	cin >>N;
	v.resize(N+1,0);
	ll ans = 0;
	rep(i,1,N){
		cin >>v[i];
		if(v[i]<v[i-1]){
			ans += v[i-1] - v[i];
			v[i] = v[i-1];
		}
	}
	cout << ans << '\n';
	return 0;
}


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

using namespace std;

typedef long long int ll;
const ll MOD = (ll)1e9 + 7;
const int MAX = 2020;
vector<int> fact,invf;

ll pwr(ll a, ll n){
	if(n==0) return 1;
	ll q = pwr(a,n/2);
	q = q * q % MOD;
	if(n&1) q = q * a % MOD;
	return q; 
}
ll inv(ll a){
	return pwr(a,MOD-2);
}

ll add(ll a, ll b){
	a += b;
	if(a >= MOD)
		a -= MOD;
	return a;	
}

ll mul(ll a, ll b){
	return a * b % MOD;
}

void init(){
	fact.resize(MAX);
	invf.resize(MAX);
	fact[0] = 1;
	for(int i = 1; i < MAX; i++){
		fact[i] = mul(fact[i-1],i); 
	}
	invf[MAX-1] = inv(fact[MAX-1]);
	for(int i = MAX-2; i >= 0; i--){
		invf[i] = mul(invf[i+1],i+1);
	}
}
ll C(int n, int k){
	if(k > n || n < 0 || k < 0) return 0;
	return mul(fact[n], mul(invf[n-k],invf[k]));
}


int main(){
	init();
	ll res = 0;
	ll S; cin >> S;
	for(int i = 1; i <= S; i++){
		ll take = 3 * i;
		ll remS = S - take;
		ll tmp = C(remS+i-1,i-1);
		//cout << tmp << "\n";
		res = add(res,tmp);
	}
	cout << res << "\n";
	return 0;
}


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

int main(){
	int n,h;
    cin>> h >> n;
    int a[n];
    long long sum = 0;
    for(int i = 0 ; i < n ; i++)cin>>a[i], sum+=a[i];
    if(sum>=h)cout<<"Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 640
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))
    cnt=0
    for i in range(n):
        while a[i]%2==0:
            a[i]//=2
            cnt+=1
    
    print(cnt)

if __name__=="__main__":
    main()

Measured memory_bytes: 4084
x = 'KIHBR'
T = []
for i in range(1<<6):
    t = ''
    for j in range(6):
        if i&(1<<j) and j != 1 and j != 2:
            t += 'A'
        if j != 5:
            t += x[j]
    T.append(t)
S = input()
if S in T:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define MAX 200005
vector<ll> v[MAX];
ll par[MAX];
bitset<MAX> vis;
void dfs()
{
    par[1]=1;
    deque<ll> dq;
    dq.push_back(1);
    vis[1]=1;
    while(!dq.empty())
    {
        int node =dq[0];
        dq.pop_front();
        for(int i=0;i<v[node].size();i++){
            if(vis[v[node][i]]) continue;
            vis[v[node][i]]=1;
            par[v[node][i]]=node;
            dq.push_back(v[node][i]);
        }
    }
}
void solve()
{
	 ll n,m; cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        ll a, b;
         cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs();
            cnt++;
            ll mid=cnt;
            cnt+=10;
            cnt+=10;
            cnt+=10;
            cnt=mid;
        }
        if(cnt>1) { cout<<"No"<<endl; return;} 
        
    }
    vector<ll>va;

    	for(int i=0;i<5;i++)
    		va.pb(1);
         cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++) cout<<par[i]<<endl;
        cout<<endl;
}
int main()
{
    fast;
   solve();
}

Measured memory_bytes: 15320
#include <stdio.h>
int main(void){
  double a,b,c,d;
  int c1=0,c2=0;
  while(scanf("%lf,%lf,%lf",&a,&b,&c)!=EOF){
    d=c/2;
    if(a*a+b*b==c*c)
      c1++;
    else if(a==b&&a+b>c)
	    c2++;
  }
  printf("%d\n%d\n",c1,c2);
  return 0;
}

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

#define ll long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define F first
#define S second

void solve() {

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("manish.txt", "r", stdin);
	freopen("ps.txt", "w", stdout);
#endif
	int t;
	t = 1;
	while (t--) {
		ll n, x, t;
		cin >> n >> x >> t;

		if (n % x == 0) {
			cout << (n / x)*t;
		}
		else {
			cout << ((n / x) + 1)*t << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n;
int a[N],gs1[N],gs2[N];
struct node{
    int k,v;
}e1[N],e2[N];
bool cmp(node a,node b){
    return a.v>b.v;
}
int main()
{
    scanf("%d",&n);
    int cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i+=2)gs1[a[i]]++;
    for(int i=2;i<=n;i+=2)gs2[a[i]]++;
    for(int i=1;i<=1e5;i++){
        if(gs1[i])e1[++cnt1].k=i,e1[cnt1].v=gs1[i];
        if(gs2[i])e2[++cnt2].k=i,e2[cnt2].v=gs2[i];
    }
    sort(e1+1,e1+cnt1+1,cmp);sort(e2+1,e2+1+cnt2,cmp);
    if(e1[1].k!=e2[1].k){
        cout<<(n/2-e1[1].v)+(n/2-e2[1].v)<<endl;
    }else{
        cout<<min((n/2-e1[1].v)+(n/2-e2[2].v),(n/2-e1[2].v)+(n/2-e2[1].v))<<endl;
    }
}


Measured memory_bytes: 2176
//# pragma GCC optimize ("O2")
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<climits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<iomanip>
#include<sstream>
#define out(i,a,now) for(int i=a.be[now],to=a.v[i];i;i=a.ne[i],to=a.v[i])
#define fo(i,a,b) for(i=a;i<=b;i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define mp(a,b) make_pair(a,b)
#define qk(x) memset(x,0,sizeof(x))
#define RG register
#define gs(x) (tr[tr[x].f].son[1]==x)
#define lb(x) (x&(-x))
#define mid ((l+r)>>1)
#ifdef Mogician
#endif
using namespace std;
typedef long long LL;
typedef double DB;
template <class T> void cmax(T &a,T b)
{
    a=max(a,b);
}
template <class T> void cmin(T &a,T b)
{
    a=min(a,b);
}
template <class T> void swp(T &a,T &b)
{
	T temp=a; a=b; b=temp;
}
int main()
{
	LL ans=0,n,m,i;
	scanf("%lld",&n);
	scanf("%lld%lld",&m,&ans);
	m--;
	fo(i,1,n)
	{
		LL v;
		scanf("%lld",&v);
		ans+=(m/v)+1;
	}
	printf("%lld",ans);
}

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

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

char s[100][101];

signed main() {
	int A, B;
	cin >> A >> B;
	--A; --B;
	for(int i = 0; i < 50; ++i) {
		for(int j = 0; j < 100; ++j) {
			s[i][j] = '#';
			s[i + 50][j] = '.';
		}
	}
	for(int i = 1; i < 49; i += 2) {
		for(int j = 1; j < 99; j += 2) {
			if(A > 0) {
				s[i][j] = '.';
				--A;
			} 
			if(B > 0) {
				s[i + 50][j] = '#';
				--B;
			}
		}
	}
	cout << 100 << " " << 100 << endl;
	for(int i = 0; i < 100; ++i) cout << s[i] << endl;
	return 0;
}


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

using namespace std;
bool isSquare(int n){
	
	if(sqrt(static_cast<double>(n))==floor(static_cast<double>(sqrt(n)))) return true;
	else return false;
	}

int main(){
	int a,b;
	cin>>a>>b;
	string word = "";
	word += to_string(a)+to_string(b);
	int d = stoi(word);
	
	(isSquare(d))? cout<<"Yes" : cout<<"No";
	return 0;
	}


Measured memory_bytes: 256
def solve():
    n, a, b = read()
    result = think(n, a, b)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return list(map(int, read_line().split()[:n]))


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, a, b):
    subsum = 0
    for i in range(1, n + 1):
        if satisfies_condition(i, a, b):
            subsum += i
    return subsum


def satisfies_condition(i, a, b):
    return a <= sum(map(int, list(str(i)))) <= b


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 41196
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,m,x;
    cin >> n >> m >> x;
    vi a(n),b(n+1,0);
    rep(i,m) {
        cin >> a.at(i);
        b.at(a.at(i))=1;
    }
    int64_t left=0, right=0;
    for(int i=0; i<n+1; i++){
        if(i<x){
            if(b.at(i)) left++;
        }
        if(i>x){
            if(b.at(i)) right++;
        }
    }
    cout << min(right, left) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >>n;
  vector<int> t(n);
  for(int i;i<n;i++){
    cin >>t[i];
  }
  cin >> m;
  for(int i;i<m;i++){
    int p,x;
    cin >> p >> x;
    int k= accumulate(t.begin(),t.end(),0);
    cout << k-t[p-1]+x <<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

double dist(vector<int> x, vector<int> y, int n, int p) {
  double s = 0;
  for(int i=0; i<n; i++) {
    int d = abs(x[i] - y[i]);
    s += pow(d, p);
  }
  s = pow(s, 1.0 / p);

  return s;
}

int main() {
  int n;
  vector<int> x, y;
  double res = 0;
  
  cin >> n;
  for(int i=0; i<n; i++) {
    int temp;
    cin >> temp;
    x.push_back(temp);
  }
  for(int i=0; i<n; i++) {
    int temp;
    cin >> temp;
    y.push_back(temp);
  }

  res = dist(x, y, n, 1);
  cout << to_string(res) << endl;
  res = dist(x, y, n, 2);
  cout << to_string(res) << endl;
  res = dist(x, y, n, 3);
  cout << to_string(res) << endl;

  double d_max = 0;
  for(int i=0; i<n; i++) {
    double d;
    d = abs(x[i] - y[i]);
    if(d > d_max) {
      d_max = d;
    }
  }
  cout << to_string(d_max) << endl;
    
  return 0;
}


Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;

const long long MOD = 5;
const string YES = "YES";
const string NO = "NO";
#define judge(f) cout<<(f?YES:NO)<<"\n";

void solve(long long A, long long B, long long C){
    ll i=2, sum=0, init=0;
    bool flg=false;
    init = A%B;
    sum = A;
    while (1)
    {
        // sum += A*i;
        sum += A;
        if (sum%B == C)
        {
            flg = true;
            break;
        } else if (sum%B == init) {
            flg = false;
            break;
        }
        // i++;
    }
    judge(flg);
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define MOD (ll) (1e9+7)
int main()
{
   ll n,k;
   cin>>n>>k;
   ll ans = (ll)(floor(log(n)/log(k)) + 1);
   cout<<ans<<"\n";
}

Measured memory_bytes: 3808
#include <stdio.h>
#define det(A) (A.a*A.d-A.b*A.c)

/* A Point In A TriangleÌÜÜ */

struct matrix{ double a, b, c, d; };
struct vector{ double a, b; };

struct vector multi(struct matrix x, struct vector y){
	struct vector res;
	res.a=x.a*y.a+x.b*y.b,
	res.b=x.c*y.a+x.d*y.b;
	return res;
}

struct matrix inv(struct matrix x){
	struct matrix res;
	res.a=x.d/det(x), res.b=-x.b/det(x),
	res.c=-x.c/det(x), res.d=x.a/det(x);
	return res;
}

int main(int argc, char *argv[]){
     struct vector a, p, x;
     struct matrix A;
     
     while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
		  &A.a,&A.c,&a.a,&a.b,&A.b,&A.d,&p.a,&p.b)){
	  p.a-=a.a, p.b-=a.b, A.a-=a.a, A.b-=a.a, A.c-=a.b, A.d-=a.b;
	  x = multi(inv(A),p);
	  
	  if(x.a<0 || x.b<0 || x.a+x.b<=1) puts("NO");
	  else puts("YES");
     }

     return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  string s1=s.substr(0, 2);
  string s2=s.substr(2, 2);
  int x=stoi(s1);
  int y=stoi(s2);
  
  int p=0;
  bool z;
  if(1<=x && x<=12){
    p++;
    z=true;
  }
  if(1<=y && y<=12){
    p++;
    z=false;
  }
  if(p==2) cout << "AMBIGUOUS" <<endl;
  else if(p==1 && z) cout << "MMYY" <<endl;
  else if(p==1 && !z) cout << "YYMM" <<endl;
  else cout << "NA" <<endl;
}

Measured memory_bytes: 256
using System;
namespace q1
{
  class q2
  {
    static void Main()
    {
      int a=int.Parse(Console.ReadLine());
      int b=a%10;
      if(b==3)
      {
        Console.WriteLine("bon");
      }
      else if(b==0||b==1||b==6||b==8)
      {
        Console.WriteLine("pon");
      }
      else
      {
        Console.WriteLine("hon");
      }
    }
  }
}


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

int main() {
  int N, max = 0, sum = 0, index = 0;
  int p[12];

  std::cin >> N;
  for(int i=0; i<N; ++i)
    std::cin >> p[i];

  for(int i=0; i<N; ++i) {
    if(max < p[i]) {
      max = p[i];
      index = i;
    }
  }

  for(int i=0; i<N; ++i) {
    if(index==i) sum += p[i]/2;
    else sum += p[i];
  }

  std::cout << sum << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;
const ll MOD = 1e9 +7;
ll a[200010], acum[200010];

ll mod(ll a) {
	return ((a % MOD) + MOD) % MOD;
}

int main() {
	optimizar_io
	int n;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		acum[i] = a[i];
	}
	for (int i = 1; i < n; i++) acum[i] = mod(acum[i] + acum[i - 1]);
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ll tmp = mod(acum[n - 1] - acum[i - 1]);
		tmp = mod(tmp * a[i - 1]);
		ans = mod(ans + tmp);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 6716
N = int(input())
H = list(map(int, input().split()))

C = [0]*N
C[0], C[1] = 0, abs(H[1]-H[0])
for i in range(2, N):
    C[i] = min(C[i-2] + abs(H[i]-H[i-2]), C[i-1] + abs(H[i]-H[i-1]))
print(C[N-1])


Measured memory_bytes: 13980
//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test(t) int t;cin>>t;while(t--)
#define forn(i,f,n) for(int i=f;i<f+n;i++)
#define rforn(i,l,n) for(int i=l;i>l-n;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
 
const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p,ll mod)
{
	if(p==0) return 1;
	ll z=powN(a,p/2,mod);
	z=(z*z)%mod;
	if(p%2) z=(z*a)%mod;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{		
	Sieve();
	int x;
	cin>>x;
	for(int i=x;i<MAX;i++)
	{
		if(is_prime[i]) {cout<<i<<endl;break;}
	}
}

Measured memory_bytes: 384
n = input()
a = list(map(int,input().split()))
ans = 1
t = False

for i in a:
  if i == 0:
    ans = 0
    t = True

if t != True:
  for i in a:
    ans *=i
    if ans>10**18:
      ans = -1
      break
    
print(ans)

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

int n,x,sum;
bitset<4000005>s;

int main(){
	s[0]=1;scanf("%d",&n);while(n--){
		scanf("%d",&x);sum+=x;
		s|=s<<x;
	}
	for(register int i=(sum+1)/2;i<=sum;i++)
		if(s[i]){printf("%d\n",i);return 0;}
}

Measured memory_bytes: 5272
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;




signed main()
{
	vector<int> all = { 105,135,165,189,195 };
	int x;
	cin >> x;

	int ans = 0;
	for (auto i : all)
	{
		if (i <= x)
		{
			ans++;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

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

    ll c = a * (n / (a + b));
    ll d = n % (a + b);
    ll e = min(a,d);
    print(c + e);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

int x, a, b;

int main(){

    cin >> x >> a >> b;

    x = x - a;

    cout << x%b;


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 256
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, wl, cnt[27] = { 0 };
	string w;

	cin >> w;
	wl = w.length();

	for (i; i < wl; i++)	cnt[w[i] - 'a']++;

	for (i = 0; i < 27; i++) {
		if (cnt[i] % 2) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define MOD 1000000007
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int x;
    int ans = 0;
	cin >> x;
    vector<int> vec(x);
    vector<int> vec2(x);
    for(int i=0; i<x; i++){
      cin >> vec.at(i);
    }
    for(int i=0; i<x; i += 2){
      vec2.push_back(vec.at(i));
    }
    int y = vec2.size();
    for(int i=0; i<y; i++){
      if(vec2.at(i)%2 != 0){
        ans++;
      }
    }
    cout << ans;
  
}

Measured memory_bytes: 3652
N,D=map(int,input().split())
X=[0]*(N+1)
Y=[0]*(N+1)
ans=int(0)
for i in range(N):
    X[i],Y[i]=map(int,input().split())
for i in range(N):
    if X[i]**2+Y[i]**2<=D**2:
        ans+=1
print(ans)


Measured memory_bytes: 24704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[110000];
int b[110000];
int c[110000];
int main()
{
    long long sm=0,zj=0,xm=0;
    long long ff=0;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);

    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
    }
    sort(c,c+n);
    for(int i=0;i<n;i++)
    {
        while(a[sm]<b[i]&&sm<n)
            sm++;
        while(c[zj]<=b[i]&&zj<n)
        {
            zj++;
        }
        ff=ff+(sm*(n-zj));
    }
    printf("%lld\n",ff);
    return 0;
}


Measured memory_bytes: 1408
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

#[fastout]
fn main() {
   input! {
      n: usize,
      mut h: usize,
      ab: [(usize, usize); n]
   }
   let mut a = 0;
   let mut b = vec![0; n];
   for i in 0..n {
      a = std::cmp::max(a, ab[i].0);
      b[i] = ab[i].1;
   }
   b.sort_by(|a, b| b.cmp(a));

   let mut ans = (h - 1) / a + 1;
   let mut count = 0;
   for i in 0..n {
      if h <= b[i] {
         ans = std::cmp::min(ans, count + 1);
         break;
      }
      count += 1;
      h -= b[i];
      ans = std::cmp::min(ans, count + (h - 1) / a + 1);
   }
   println!("{}", ans);
}


Measured memory_bytes: 6772
a=""
b=[]
a=input()
for x in a:
    b.append(x)

if b[0]==b[1] and b[0]==b[2]:
    print("No")
elif b[0]==b[1]:
    if b[2]==b[3]:
        print("Yes")
    else:
        print("No")
else:
    if b[0]==b[2] and b[1]==b[3]:
        print("Yes")
    elif b[0]==b[3] and b[1]==b[2]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
// Loop
#define REP(i, a, b) for(int(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(int(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)


int main(void) {
	int n, k;
	cin >> n >> k;
	vi a(n), b(n);
	rep(i, n) { cin >> a[i]; }
	rep(step, min(k, 100)) {
		b.assign(n, 0);
		rep(i, n) {
			int l = max(0, i - a[i]);
			int r = min(i + a[i], n - 1);
			b[l]++;
			if(r + 1 < n) {
				b[r + 1]--;
			}
		}
		REP(i, 1, n) { b[i] += b[i - 1]; }
		rep(i, n) { a[i] = b[i]; }
	}
	rep(i, n) { cout << a[i] << " "; }
	cout << endl;

	return 0;
}

Measured memory_bytes: 4848
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, k, q, a;

	cin >> n >> k >> q;

	vector<ll> v(n, 0);

	REP(i, q) {
		cin >> a;
		v[a - 1]++;
	}

	REP(i, n) {
		if (k - q + v[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1408
#include <iostream>
#include <stack>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;
#define endl "\n"
typedef long long Int;
int main() {
    ios::sync_with_stdio(false);
    Int N,M;
    cin>>N>>M;
    vector<pair<Int,Int>>p(N);
    for(int i=0;i<N;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p.begin(),p.end());
    Int ans = 0;
    
    for(int i=0;i<N;i++){
        Int buy = min(M,p[i].second);
        ans+=(Int)buy*p[i].first;
        M-=buy;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void) {
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h/2.0 << endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

typedef long long ll;
#define pb push_back

#define rep(i, n) for (int i=0;i<(n);++i)
#define rep2(i, s, n) for (int i=s;i<(n);++i)
#define INF (1e9)

class Edge{
public:
    int u, v, cost;
    Edge(int u, int v, int cost):
        u(u), v(v), cost(cost) {}
    bool operator < (const Edge& e) const {
        return cost != e.cost ? cost > e.cost : // for min-priority queue
            u != e.u ? u < e.u : v < e.v;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void dfs(Graph& G, int u, vector<bool>& visited)
{
    visited[u] = true;
    for(auto e:G[u]) if(!visited[e.v]) dfs(G, e.v, visited);
}

void dfs(vector<vector <int> >&G, int u, vector<bool>& visited)
{
    int V = G.size();
    visited[u] = true;
    rep(i,V) if(G[u][i] == 1 && !visited[i]) dfs(G, i, visited);  
}

int main()
{
    int V,E;cin>>V>>E;
    //Graph G(V);
    vector<vector <int> > G(V, vector<int>(V, 0));
    rep(i,E) {
        int u,v;cin>>u>>v;
        u--;v--;
        //G[u].pb(Edge(u,v));
        //G[v].pb(Edge(v,u));
        G[u][v] = 1;
        G[v][u] = 1;
    }

    int cnt = 0;
    rep(k,V) {
        rep2(l, k+1, V) {
            if (G[k][l] == 0) continue;
            
            G[k][l] = 0, G[l][k] = 0;
            vector<bool> visited(V,false);
            dfs(G, 0, visited);
            rep(j,V) if(!visited[j]) {cnt++; break;}
            G[k][l] = 1, G[l][k] = 1;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
n, k, *a = map(int, open(0).read().split())
m = INF = float("inf")
for i in range(n - k + 1):
    l, r = a[i], a[i + k - 1]
    c = abs(r-l)
    m = min(m, min(abs(l) + c, abs(r) + c))
print(m)

Measured memory_bytes: 14052
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  if(N%2==0)cout<<N/2-1<<endl;
  else cout<<N/2<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static PrintStream o = System.out;
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();
		if (s > w) {
			o.println("safe");
		} else {
			o.println("unsafe");
		}
	}
}

Measured memory_bytes: 35736
N,Q = input().split()
N,Q = int(N),int(Q)
S = input()
l,r = [],[]
for i in range(Q):
    l_,r_ = input().split()
    l_,r_ = int(l_)-1,int(r_)-1
    l.append(l_)
    r.append(r_)
    
A = [0]
sum_ = 0
for i in range(1,N):
    if(S[i-1]=="A" and S[i]=="C"):
        sum_ += 1
    A.append(sum_)

for i in range(Q):
    if(l[i]==0):
        num = r[i]
        print(A[r[i]])
    else:
        sa = A[r[i]]-A[l[i]]
        print(sa)

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

int main()
{
	stack<int> s1;
	stack<pair<int, int> > s2;
	
	char ch;
	int sum =0;
	for(int i=0 ; cin >> ch;i++)
	{
		if(ch=='\\') s1.push(i);
		else if(ch =='/' && s1.size() >0)
		{
			int j  = s1.top(); s1.pop();
			sum += i-j;
			int a = i-j;
			while(s2.size() > 0 &&  s2.top().first > j)
			{
				a+=s2.top().second; s2.pop();
			}
			s2.push(make_pair(j,a));			
		}
	}
	
	vector<int> ans;
	while(s2.size()>0){ans.push_back(s2.top().second); s2.pop();}
	reverse(ans.begin(),ans.end());
	cout << sum<<endl;
	cout<<ans.size();
	for(int i =0; i<ans.size();i++)
		cout <<" "<<ans[i];
	cout << endl;
}

Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>

using namespace std;

int main(){

    long long A, B, r, GCD;
    cin >> A >> B;

    // 最大公約数を求める
    if (A < B) swap(A, B);
    r = A % B;
    while(r != 0){
        A = B;
        B = r;
        r = A % B;
    }
    GCD = B;

    // cout << "GCD : " << GCD << endl;

    // GCD を素因数分解する
    vector<int> common_divisor;
    bool add = false;
    common_divisor.emplace_back(1);
    while (GCD % 2 == 0){
        GCD = GCD / 2;
        if (!add) common_divisor.emplace_back(2);
        add = true;
        // cout << "i: " << 2 << ", GCD: " << GCD << endl;
    }
    add = false;
    for (int i = 3; i <= (int)sqrt(GCD); i = i+2){
        while (GCD % i == 0){
            GCD = GCD / i;
            if (!add) common_divisor.emplace_back(i);
            add = true;
            // cout << "i: " << i << ", GCD: " << GCD << endl;
        }
        add = false;
    }
    if (GCD != 1) common_divisor.emplace_back(GCD);

    cout << common_divisor.size() << endl;
    // for (int i = 0; i < common_divisor.size(); i++){
    //     cout << common_divisor[i] << " ";
    // }



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+10;
char s[N];
int main() {
	scanf("%s",s+1);
	int n = strlen(s+1);
	if (s[1]=='0'||s[n]=='1') return puts("-1"),0;
	REP(i,1,n) if (s[i]=='1'&&s[n-i]=='0') return puts("-1"),0;
	int rt = 1;
	REP(i,2,n) {
		printf("%d %d\n",rt,i);
		if (s[i-1]=='1') rt = i;
	}
}








Measured memory_bytes: 1536
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)


Measured memory_bytes: 14472
#include <iostream>
using namespace std;
#define MOD 1000000007

int main()
{
    long long n, k;
    long long mem[200005];

    cin >> n >> k;
    long long min = 0, max = 0;
    for (int i = 0; i <= n; ++i)
    {
        min += i % MOD;
        max += (n - i) % MOD;
        mem[i] = (max - min + 1) % MOD;
    }

    long long ans = 0;
    for (int i = k - 1; i <= n; ++i)
        ans += mem[i] % MOD;
    cout << ans % MOD << endl;
}

Measured memory_bytes: 5128
while True:
  try:
    hit=0
    brow=0
    a = map(int,raw_input().split())
    a1,b1,c1,d1 = a[0],a[1],a[2],a[3]
    b = map(int,raw_input().split())
    a2,b2,c2,d2 = b[0],b[1],b[2],b[3]
    for c in range(4):
      if a[c] == b[c]: hit +=1
      for d in range(4):
        if a[c]==b[d]:
          if c == d:
            break
          brow += 1

    print hit,brow
  except EOFError:
    break

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

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

    bool all_even = true;
    for (int i = 0; i < N; i++) {
        int a_i;
        cin >> a_i;
        all_even &= a_i % 2 == 0;
    }

    if (all_even) {
        cout << "second" << endl;
    } else {
        cout << "first" << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Yuekis' Audio Room
 */
public class Main {

	public static int R = 100;
	public static int T = 30;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		br.readLine(); //skip first line.

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int r = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int t = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			int[] _r = new int[2];
			int[] _t = new int[2];

			if (r % R == 0) {
				_r[0] = r / R;
			} else {
				_r[0] = r / R;
				_r[1] = r / R + 1;
			}

			if (t % T == 0) {
				_t[0] = t / T * 5;
			} else {
				_t[0] = t / T * 5;
				_t[1] = (t / T + 1) * 5;
			}

			int[] _rt = new int[4];
			_rt[0] = _r[0] + _t[0];
			_rt[1] = _t[1] > 0 ? _r[0] + _t[1] : 0;
			_rt[2] = _r[1] > 0 ? _r[1] + _t[0] : 0;
			_rt[3] = _r[1] > 0 && _t[1] > 0 ? _r[1] + _t[1] : 0;

			Arrays.sort(_rt);
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < 4; i++) {
				if (_rt[i] > 0) {
					if (i > 0 && _rt[i - 1] > 0) {
						sb.append(" ");
					}
					sb.append(_rt[i]);
				}
			}
			System.out.println(sb);

		} // end while
	} // end main
}

Measured memory_bytes: 24300
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  v=LI()

  ans=0
  for i in range(k):
    if i+1<n:
      for l in range(i+1):
        r=i-l
  
        _ans=0
        _v=[]
        for x in range(l+1):
          _ans+=v[x]
          _v.append(v[x])
        for x in range(r):
          _ans+=v[n-x-1]
          _v.append(v[n-x-1])

        _v.sort()
        for j in range(min(len(_v),k-i-1)):
          if _v[j]<0:
            _ans-=_v[j]
          else:
            break
        # print(_v,l,r,_ans)
        ans=max(ans,_ans)
    else:
      _v=v.sort()
      _ans=sum(v)
      _k=n-k-1
      for j in range(_k):
        if _v[j]<0:
          _ans-=_v[j]
        else:
          break
      ans=max(ans,_ans)

  return ans

# main()
print(main())


Measured memory_bytes: 10696
import java.io.BufferedReader;
import java.io.InputStreamReader;
//ツつスツつセツづ個スツタツッツク
//public class Problem0013_SwitchingRailroadCars {
public class Main {
	public static void main(String[] args) {
		try {
		//	Problem0013_SwitchingRailroadCars test = new Problem0013_SwitchingRailroadCars();
		//	Main test = new Main();
			
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String line;
			CarStack stack = new CarStack();
			while((line = reader.readLine()) != null) {
				try {
					int number = Integer.parseInt(line);
					if(number == 0) {
						System.out.println(stack.pop());	//nullツづ債考ツ猟カツつオツづ按つ「
					} else {
						stack.push(new Car(number));
					}
				} catch(NumberFormatException e) {
					break;
				}
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}
class CarStack {
	private Car lastCar;
	
	CarStack() {
		lastCar = null;
	}
	void push(Car car) {
		if(lastCar != null) {
			car.setPrevious(lastCar);
			lastCar = car;
		} else {
			lastCar = car;
		}
	}
	Car pop() {
		if(lastCar != null) {
			Car result = lastCar;
			lastCar = lastCar.getPrevious();
			
			return result;
		} else {
			return null;
		}
	}
}
class Car {
	private int number;
	private Car previousCar;
	
	Car(int number) {
		this.number = number;
		previousCar = null;
	}
	Car getPrevious() {
		return previousCar;
	}
	void setPrevious(Car car) {
		previousCar = car;
	}
	@Override
	public String toString() {
		return Integer.toString(number);
	}
}

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

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i<s.size(); i++){
        if(s[i] == '1'){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 256
from collections import deque
n=int(input())
x = deque(int(i) for i in input().split())
x.appendleft(0)
x.append(0)

d1=[]
d2=[]
for i in range(0,len(x)-1):
    d1.append(abs(x[i+1]-x[i]))
for i in range(0,len(x)-2):
    d2.append(abs(x[i+2]-x[i]))
d1sum=sum(d1)

for i in range(0,i+1):
    ans = d1sum + d2[i] - d1[i] -d1[i+1]
    print(ans)


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


int main(){
   int n;
  cin>>n;
  set<string> s;
  vector<string> a(n);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,n){
    s.insert(a[i]);
  }
  
  cout<<s.size()<<endl;
  
}
  


Measured memory_bytes: 25000
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<climits>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define MAXN 1000
#define INF 0x3f3f3f3f
int n,len,x[MAXN+5],y[MAXN+5],d[35];
void Print(int X,int Y){
	for(int i=1;i<=len;i++){
		if(abs(X)>abs(Y)){
			if(X>0) putchar('R'),X-=d[i];
			else putchar('L'),X+=d[i];
		}
		else{
			if(Y>0) putchar('U'),Y-=d[i];
			else putchar('D'),Y+=d[i];
		}
	}
	puts("");
	return ;
}
int main(){
	bool f[2]={0};
	n=read();
	for(int i=1;i<=n;i++)
		x[i]=read(),y[i]=read(),f[(x[i]+y[i])%2]=1;
	if(f[0]&&f[1]){
		puts("-1");
		return 0;
	}
	for(int i=30;i+1;i--)
		d[++len]=(1<<i);
	if(f[0]) d[++len]=1;
	printf("%d\n",len);
	for(int i=1;i<len;i++)
		printf("%d ",d[i]);
	printf("%d\n",d[len]);
	for(int i=1;i<=n;i++)
		Print(x[i],y[i]);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    for i in range(10):
        n = 10 * (B + i * 0.1)
        if 0 <= n * 0.08 - A < 1:
            print(int(n))
            return
    else:
        print(-1)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define arr array
#define _min(a) *min_element(a.begin(), a.end());
#define _max(a) *max_element(a.begin(), a.end());
#define _sort(x) sort(x.begin(), x.end())
#define _rsort(x) sort(x.rbegin(), x.rend())
#define _reverse(x) reverse(x.begin(), x.end())
#define _debug(x) cout << #x << " = " << x << endl;
#define debug(x, y) cout << #x " = " << x << " " << #y << " = " << y << endl;
#define _lower_bound(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()
#define _upper_bound(a, x) upper_bound(a.begin(), a.end(), x) - a.begin()
typedef long long ll;
using namespace std;

void solve() {	
	int x, y; cin >> x >> y;
	cout << max(x, y) + max(max(x, y) - 1, min(x, y)) << endl;
}   

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

    // int t; cin >> t;
    // while(t--) 
        solve();
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>

using namespace std;

typedef long long LL;

int main() {
  string s = "CODEFESTIVAL2016";
  string s1;
  cin >> s1;
  int ans = 0;
  for (int i = 0; i < s.length(); i += 1) {
    if (s1[i] != s[i]) {
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  int n = s.size();
  bool flag = false;
  if (n & 1) flag = true;
  bool same = false;
  if (s[0] == s[n - 1]) same = true;

  cout << ((flag ^ same) ? "First" : "Second") << endl;
  


  
  return 0;
}

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

using namespace std;

int main()
{
    int n,m,a[1100],p=0;
    scanf("%d %d",&n,&m);
    int i,t=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);t=t+a[i];
    }
    if(t==m)
    {
        printf("%d\n",n);return 0;
    }
    else {
        sort(a,a+n);
        if(t<m)
           { int x=a[0];
               m=m-t;m=m/x;
             n=n+m;
             printf("%d\n",n);
             return 0;
           }
        else
           {
               for(i=0;i<n;i++)
               {
                   p=p+a[i];
                   if(p>m)
                   {
                       printf("%d\n",i);return 0;
                   }
               }
           }
    }

    return 0;
}


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

int main() {
  int D,G;
  cin >> D >> G;
  G /= 100;
  vector<int> P(D),C(D);
  for(int i=0;i<D;i++){
    cin >> P[i] >> C[i];
    C[i] /= 100;
  }
  
  int ans = 10000;
  for(int i=0;i<(1<<D);i++){
    bitset<10> B(i);
    int score=0,solve=0,x=-1;
    
    for(int i=0;i<D;i++){
      if(B.test(i)){
        solve += P[i];
        score += (i+1)*P[i] + C[i];
      }
      else x = i;
    }
    
    if(score>=G) ans = min(ans,solve);
    else{
      if((x+1)*P[x] >= G-score){
        solve += (G-score) / (x+1);
        if((G-score)%(x+1)!=0) ++solve;
        ans = min(ans,solve);
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int t[102]={0},v[102]={0},i,j,n;
  double x=0,f[40001];
  scanf("%d",&n);
  for(i=1;i<=n;i++){scanf("%d",&t[i]);t[i]+=t[i]+t[i-1];}t[n+1]=t[n];
  for(i=1;i<=n;i++)scanf("%d",&v[i]);
  for(i=0;i<=t[n];i++){
    f[i]=i*2<t[n]?(double)i/2.0:(double)(t[n]-i)/2.0;
    for(j=1;j<=n;j++){
      if(i<t[j-1])f[i]=f[i]<(double)v[j]+(t[j-1]-i)/2.0?f[i]:(double)v[j]+(t[j-1]-i)/2.0;
      else if(i>t[j])f[i]=f[i]<(double)v[j]+(i-t[j])/2.0?f[i]:(double)v[j]+(i-t[j])/2.0;
      else f[i]=f[i]<v[j]?f[i]:v[j];

    }
  }
  for(i=0;i<t[n];i++){x+=(f[i]+f[i+1])/4;}
  printf("%lf",x);
}


Measured memory_bytes: 2016