akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left
from bisect import bisect_right



n,m=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
S=[0]*(n+1)
for i in range(1,n+1):
    S[i]=S[i-1]+A[i-1]

def solve(x):
    case=0
    for i in range(n):
        case+=n-bisect_right(A,x-A[i]-1)
    return case

right=2*A[-1]+1
left=0
         
while abs(right-left)>1:
    mid=(right+left)//2
    if solve(mid)>=m:
        left=mid
    else:
        right=mid
    
Kijun=left
ans=0
for i in range(n):
    case=n-bisect_right(A,Kijun-A[i]-1)
    ans+=case*A[i]+(S[n]-S[n-case])
    
ans-=(solve(Kijun)-m)*Kijun
print(ans)

Measured memory_bytes: 55704
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

template<typename T>
struct BIT{
private:
  vector<T> A;
  const int n;
  
public:
  BIT(int _n) : A(_n+1,0), n(_n){}
  
  T sum(int i){
    T s=0;
    while(i>0){
      s+=A[i];
      i-=i&-i;
    }
    return s;
  }
  
  T sum(int i,int j){
    return sum(j)-sum(i-1);
  }
  
  void add(int i,T x){
    while(i<=n){
      A[i]+=x;
      i+=i&-i;
    }
  } 
};

int main(){
  int n,q;
  cin>>n>>q;
  
  ll c,x,y;
  BIT<ll> bit(n);
  
  rep(i,n){
    cin>>x;
    bit.add(i+1,x);
  }
  
  rep(i,q){
    cin>>c>>x>>y;
    if(c==0) bit.add(x+1,y);
    else cout<<bit.sum(x+1,y)<<endl;
  }
   
  return 0;
}

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

int s,l;
vector<string> strls;
int main (){
    string str;
    cin>>s>>l;
    for(int i=0;i<s;i++){
        cin>>str;
        strls.push_back(str);
    }
    sort(strls.begin(),strls.end());
    for(int i=0;i<s;i++){
        cout<<strls[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
n, y = list(map(int, input().split()))
for i in range(0, n + 1):
    for j in range(0, n + 1):
        if 0 <= (n - i - j) <= n:
            if y == 10000 * i + 5000 * j + 1000 * (n - i - j):
                print(i, j, n - i - j)
                exit()
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

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

typedef long long LL;

int main() {
    LL n;
    cin>>n;

    vector<pair<LL, int> > dvs;//配对<质数, 幂次>

    //质因数分解
    for (LL i=2; i*i<=n; i++) {
        if (0==n%i) {
            dvs.push_back(make_pair(i, 0));
            while (0==n%i) {
                dvs.back().second++;
                n /= i;
            }
        }
    }
    if (n>1) {
        dvs.push_back(make_pair(n, 1));
    }

    //遍历
    int ans = 0;
    for (pair<LL, int> &p : dvs) {
        int i=sqrt(p.second*2);
        if (i*(i+1)>p.second*2) {
            i--;
        }
        ans += i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define mp  make_pair
#define ls  (n<<1)
#define rs  (ls|1)
using namespace std;

typedef pair <int,int>  PII;
int n,m,t[800010],tag[800010],ans;
PII a[200010];

void build(int n,int l,int r)
{
	if (l==r)  t[n]=l-m-1;
	else
		{
			int mid=(l+r)>>1;
			build(ls,l,mid),build(rs,mid+1,r);
			t[n]=max(t[ls],t[rs]);
		}
}

void modify(int n,int l,int r,int L,int R)
{
	if ((L<=l)&&(r<=R))  t[n]++,tag[n]++;
	else
		{
			int mid=(l+r)>>1;
			if (L<=mid)  modify(ls,l,mid,L,R);
			if (mid<R)  modify(rs,mid+1,r,L,R);
			t[n]=max(t[ls],t[rs])+tag[n];
		}
}

int ask(int n,int l,int r,int L,int R)
{
	if ((L<=l)&&(r<=R))  return t[n];
	else
		{
			int mid=(l+r)>>1;
			if (mid>=R)  return ask(ls,l,mid,L,R)+tag[n];
			if (L>mid)  return ask(rs,mid+1,r,L,R)+tag[n];
			return max(ask(ls,l,mid,L,R),ask(rs,mid+1,r,L,R))+tag[n];
		}
}

void work()
{
	scanf("%d %d",&n,&m),ans=max(0,n-m);
	for (int i=1,l,r; i<=n; i++)
		scanf("%d %d",&l,&r),a[i]=mp(l,r);
	sort(a+1,a+n+1);
	build(1,1,m+1);
	for (int i=1; i<=n; i++)
		{
			modify(1,1,m+1,1,a[i].second);
			ans=max(ans,ask(1,1,m+1,a[i].first+1,m+1)-a[i].first);
		}
	printf("%d",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 7040
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
///////////////////////////


int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll pos[n+1];
    rep(i,0,n-1){
        pos[a[i]]=i;
    }
    vector<ll>idx;
    rep(i,0,n-1)idx.pb(a[i]);
    sort(idx.rbegin(),idx.rend());
    set<ll>s;
    ll l1[n+1],l2[n+1],r1[n+1],r2[n+1];
    rep(i,1,n){
        l2[i]=inf;r2[i]=-inf;
        l1[i]=0;r1[i]=0;
    }
    for(auto val:idx){
        s.insert(pos[val]);
        auto itr=s.lower_bound(pos[val]);
        ll laspos=*itr;
        ll newpos;
        if(itr==s.begin()){
            newpos=-1;
            l1[val]=(laspos-newpos);
        }else{
            itr--;
            newpos=*itr;
            l1[val]=laspos-newpos;
            laspos=newpos;
            if(itr==s.begin())newpos=-1;
            else {itr--;newpos=*itr;}
            l2[val]=laspos-newpos;
        }
        itr=s.lower_bound(pos[val]);
        laspos=*itr;
        itr++;
        if(itr==s.end()){
            newpos=n;
            r1[val]=newpos-laspos;
        }else{
            newpos=*itr;
            r1[val]=newpos-laspos;
            laspos=newpos;
            itr++;
            if(itr==s.end())newpos=n;
            else newpos=*itr;
            r2[val]=newpos-laspos;
        }
    }
    /*
    rep(i,1,n){
        cout<<l1[i]<<" "<<l2[i]<<" "<<r1[i]<<" "<<r2[i]<<endl;
    }*/
    ll ans=0;
    rep(i,1,n){
        if(r2[i]!=-inf){
            ans+=i*l1[i]*r2[i];
        }
        if(l2[i]!=inf){
            ans+=i*r1[i]*l2[i];
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 10484
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, m, k;
llint c[100005];
UnionFind uf(200005);
vector<E> vec;

int main(void)
{
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++) cin >> c[i];
	
	llint u, v, w;
	for(int i = 1; i <= m; i++){
		cin >> u >> v >> w;
		if(c[u] > 0) u = c[u]+n;
		if(c[v] > 0) v = c[v]+n;
		vec.push_back(E(w, P(u, v)));
	}
	sort(vec.begin(), vec.end());
	
	llint cnt = 0, ans = 0;
	for(int i = 0; i < vec.size(); i++){
		w = vec[i].first, u = vec[i].second.first, v = vec[i].second.second;
		if(uf.same(u, v)) continue;
		if(cnt >= k-1) break;
		ans += w, cnt++;
		uf.unite(u, v);
	}
	if(cnt < k-1) ans = -1;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6516
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let iter = buf.split_whitespace();
    let mut v: Vec<T> = Vec::new();
    for i in iter {
        v.push(i.parse().ok().unwrap());
    }
    v
}

fn main() {
    let n:usize = procon_read()[0];
    let mut v:Vec<u64> = procon_read();
    v.sort();
    let mut cnt:u64 = 0;
    if n < 3 {
        
    }else{
        for i in 0..(n-2) {
            for j in (i+1)..(n-1) {
                for k in (j+1)..n {
                    if v[i] != v[j] && v[j] != v[k] && v[i] + v[j] > v[k] {
                        cnt += 1;
                    }
                }
            }
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 2076
t=input()
for j in range(t):
    n=input()
    L=map(int,raw_input().split())
    mi,ma=0,0
    for i in range(len(L)-1):
        if L[i]>L[i+1]:
            mi=min(mi,L[i+1]-L[i])
        else:
            ma=max(ma,L[i+1]-L[i])
    print ma,-mi

Measured memory_bytes: 4244
package main

import (
	"fmt"
	"math"
)

const (
	INTEREST float64 = 0.05
	DEBT     int     = 100000
)

func main() {
	var x int
	interestDebt := DEBT
	fmt.Scanf("%d", &x)
	for i := 0; i < x; i++ {
		interestCalc := MakeCalcInterest(float64(interestDebt)) + int(interestDebt)
		interestDebt = RoundUp(float64(interestCalc))
	}
	fmt.Printf("%d\n", interestDebt)
}

func MakeCalcInterest(x float64) int {
	return int((x * INTEREST))
}

func RoundUp(x float64) int {
	return int(math.Ceil(x*0.001) * 1000)
}



Measured memory_bytes: 1124
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Text.RegularExpressions;

namespace Yuzuki
{
    class Yukari
    {
        public static void Main(string[] args)
        {
            Regex regex = new Regex(@"^(hi)+$");
            Console.WriteLine(regex.IsMatch(Console.ReadLine()) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 15948
eval"N,K,S,T,*A,C=#{`tr ' 
' ,`}[1]*51"
A.select!{1>~_1&S|_1&~T}
C.map{$*<<C[K]-1
t=0
C.map!{t+t=_1}}
p (S..T).sum{|u|~u&S|u&~T<1?A.map{_1&u}.tally.sum{$*[_2]}*(1-('%b'.%u-S).count(?1)%2*2):0}

Measured memory_bytes: 14636
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=5e5+10;

int main()
{
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll ans=max(max(a*c,a*d),max(b*c,b*d));
	if((a<=0&&b>=0)||(c<=0&&d>=0)) cout<<max(ans,ll(0));
	else cout<<ans;
	return 0;	
} 

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  char tmp = a.at(0);
  int d=1,e=0,f=0;
  while((d<a.size()&&tmp=='a')||(e<b.size()&&tmp=='b')||(f<c.size()&&tmp=='c')){
    if(tmp=='a'){
      tmp = a.at(d);
      d++;
    }
    else if(tmp == 'b'){
      tmp = b.at(e);
      e++;
    }
    else{
      tmp = c.at(f);
      f++;
    }
  }
  cout << char(tmp-32) << endl;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())

mod = 998244353

def inved(a):
    x, y, u, v, k, l = 1, 0, 0, 1, a, mod
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % mod
fact = [1 for _ in range(N+M+1)]
invf = [1 for _ in range(N+M+1)]
for i in range(N+M):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(N+M, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
MM = [1 for _ in range(N+1)]
for i in range(1, N+1):
    MM[i] = ((MM[i-1] * (M - 1)) % mod)
S = (MM[N-1] * M) % mod
for i in range(K):
    S += (((fact[N-1] * invf[i+1] * invf[N-i-2]) % mod) * (M * MM[N-i-2])) % mod
    S %= mod
print(S)

Measured memory_bytes: 48600
#include<cstdio>
#include<cstring>
char a[10010]; 
bool c,f;
int main() {
    scanf("%s", a);
    for(int i=0; i<strlen(a); i++) {
        if(a[i]=='C') c=true;
        if(a[i]=='F'&&c==true) f=true; 
    }
    if(f==true) printf("Yes\n"); 
    else printf("No\n");
    return 0;
}

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

typedef long long ll;

#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
const ll MAX = 1e6;
/* end defineing */

signed main()
{
    ll n, x;
    ll a[100000];
    cin >> n >> x;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int sum = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i - 1] + a[i] > x)
        {
            sum += (a[i - 1] + a[i] - x);
            a[i] = max(0LL, x - a[i - 1]);
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 1024
A,B,H,M = map(int,input().split())
import math
minute = 6 * M
hour = 30 * (H + M / 60)
a = abs(minute - hour)
degree = min(a, 360 - a)
rad = math.radians(degree)
cosa = math.cos(rad)
C = A ** 2 + B ** 2 - 2 * A * B * cosa
print(C ** 0.5)

Measured memory_bytes: 9428
S = str(input())

a=0
b=0
c=0
if S[0]=='A':
    a=1

cnt=0
for i in S[2:-1]:
    if i=='C':
        cnt+=1
if cnt==1:
    b=1

s=S[1:]
s=s.replace('C','')
if s.islower()==True:
    c=1

if a==1 and b==1 and c==1:
    print('AC')
else:
    print('WA')

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

int main(){
	int n;
	cin>>n;
	vector<int> v;
	if(n==0){
		cout<<0;
		return 0;
	}
	for(long long i=-2;n!=0;i*=(-2)){
		if(n%llabs(i)==0) v.push_back(0);
		else{
			v.push_back(1);
			n+=i/2;
		}
	}
	for(int i=v.size()-1;i>=0;i--) cout<<v[i];
	return 0;
}


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

string s, t, ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> s >> t;
}

void solve(){
    ans = t + s;
}

void out(){
    cout << ans;
}


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

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  int order = 0;
  vector<string> adding(2, "");
  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      order = 1 - order;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        adding[1- order] += c;
      } else {
        adding[order] += c;
      }
    }
  }
  S += adding[0];
  reverse(adding[1].begin(), adding[1].end());
  S = adding[1] + S;
  if (order == 1) {
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  {
    for(int j=0;j<vertex;j++) {
      if(graph[start][j]<INF/2 && graph[j][j]<0) {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
      }
    }
  }
  
  for(int i=0;i<vertex;i++) {
    if(graph[start][i]>=INF/2) {
      cout << "INF" << endl;
    } else {
      cout << graph[start][i] << endl;
    }
  }
  return 0;
}
 
inline int fastmin(int a, int b) {
  return (((a-b)>>31)&(a-b))+b;
}

int mymin_slow(int a, int b) __attribute__((noinline));
int mymin_slow(int a, int b) {
  int t;
  if (a < b) {
    t = a;
  } else {
    t = b;
  }
  return t;
}
 
void check()
{
  for(int k=0;k<vertex;k++) {
    for(int i=0;i<vertex;i++) {
      int gik= graph[i][k];
      for(int j=0;j<vertex;j++) {
        graph[i][j]= fastmin(graph[i][j], gik+graph[k][j]);
      }
    }
  }
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
        {
          if(i==j)
            {
              graph[i][j]=0;
            }
          /*else
            {
            graph[i][j]=INF;
            }*/
        }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
    dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
      {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
      }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
      for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }  
      cout << endl;    
      }*/
   
 
}

Measured memory_bytes: 5300
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " " ;
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define setBits(n) __builtin_popcountll(n)
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int n;
    cin >> n;
    vi in(n);
    for(auto &i : in) cin >> i;
    int cnt = 0, num = 1;
    for(int i = 0; i < n; i++) {
    	if(in[i] == num) num++;
    	else cnt++;
    }
    if(cnt == 0 and num == 1) cout << -1 << endl;
    else if(cnt <= n - 1) cout << cnt << endl;
    else cout << -1 << endl;
}
  
int32_t main() {
 
    FAST;

   
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 4780
#include<stdio.h>
int main(void)
{
	int h,w,i,j,flg,b[101][101],x;
	char a[101][101];
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",a[i]);
	}
	for(i=0;i<h;i++){
		flg=0;
		x=0;
		for(j=0;j<w;j++){
			if(a[i][j]=='c'){
				b[i][j]=0;
				flg=1;
			}	
			if(flg==1&&j+1<=w){
				if(a[i][j+1]=='.'){
					x++;
					b[i][j+1]=x;
				}
				else if(a[i][j+1]=='c'){
					b[i][j+1]=0;
					x=0;
				}
			}
			if(flg==0){
				b[i][j]=-1;
			}	
		}
	}
		
	for(i=0;i<h;i++){
		printf("%d",b[i][0]);
		for(j=1;j<w;j++){
			printf(" %d",b[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2696
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int H=Integer.parseInt(sc.next());
int W=Integer.parseInt(sc.next());
char[][] s=new char[H][W]; 
    for (int i = 0; i < H; i++) {
        String p=sc.next();
        for (int j = 0; j < W; j++) {
            if (p.charAt(j)=='.') {
                s[i][j]='0';
            }else{
            s[i][j]='#';
            }
        }
    }
int[] dx={-1,-1,-1,0,0,1,1,1};
int[] dy={-1,0,1,1,-1,-1,0,1};
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if(s[i][j]=='#'){
                for (int k = 0; k <8; k++) {
                   if(0<=i+dy[k]&&i+dy[k]<H&&0<=j+dx[k]&&j+dx[k]<W){
                       if(s[i+dy[k]][j+dx[k]]!='#')s[i+dy[k]][j+dx[k]]++;
                   }
                }
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            out.print(s[i][j]);
        }out.println();
    }
}
}

Measured memory_bytes: 23636
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}
for i in range(6):
 f=[d[int(j)]for j in m[i]];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t==1])


Measured memory_bytes: 5604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using ll=long long;
using namespace std;

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

    vector<int> A(N);
    vector<int> B(N);
    pair<int,int> ss={0,1};
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
        if(ss.first*B[i]<ss.second*A[i]){
            ss={A[i],B[i]};
        }
    }

    vector<int> dp(H+1,-1);
    dp[0]=0;
    for(int i=1;i<H+1;i++){
        dp[i]=dp[i-1]+B[0];
        for(int j=0;j<N;j++){
            if(i<A[j]){
                if(dp[i]>dp[0]+B[j]){
                    dp[i]=dp[0]+B[j];
                }
            }else{
                if(dp[i]>dp[i-A[j]]+B[j]){
                    dp[i]=dp[i-A[j]]+B[j];
                }
            }
        }
    }

    cout<<dp[H]<<endl;

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
  using namespace std;
using namespace __gnu_pbds;
  #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define double long double
  #define all(v) v.begin(),v.end()
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const double PI = acos(-1);
  const int N = 200005;
  int mod = 1e9 + 7;
     
 
    vector<int> adj[N];
    bool vis1[N];
    bool vis2[N];
    int dist1[N];
    int dist2[N];
 
    void bfs1(int s)
    {
        queue<int> q;
        q.push(s);
        dist1[s] = 0;
        while(!q.empty())
        {
          int k = q.front();
          q.pop();
 
          for(auto i:adj[k])
          {
            if(!vis1[i])
            {
              vis1[i] = true;
              dist1[i] = dist1[k] + 1;
              q.push(i);
            }
          }
        }
    }
    void bfs2(int s)
    {
        queue<int> q;
        q.push(s);
        dist2[s] = 0;
        while(!q.empty())
        {
          int k = q.front();
          q.pop();
 
          for(auto i:adj[k])
          {
            if(!vis2[i])
            {
              vis2[i] = true;
              dist2[i] = dist2[k] + 1;
              q.push(i);
            }
          }
        }
    }
 
int32_t main()
{
       
    int n,u,v;
    cin >> n >> u >> v;
 
    rep(i,1,n-1)
    {
      int x,y;
      cin >> x >> y;
      adj[x].PB(y);
      adj[y].PB(x);
 
    }
 
    
 
    bfs1(u);
    bfs2(v);
    dist1[u] = 0;
    dist2[v] = 0;
 
 
    int ans = 0;
 
    rep(i,1,n)
    {
 
      if(dist1[i]<dist2[i])
      {
        ans = max(dist2[i]-1,ans);
      }
    }
 
 
 
    cout << ans ;
 
   return 0;
}       

Measured memory_bytes: 13900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    ll c=0, c0=0, res=0;
    rep(i, n){
        cin >> a[i];
        c += a[i]<0;
        c0 += a[i]==0;
        a[i] = abs(a[i]);
        res += a[i];
    }
    sort(ALL(a));
    if(c%2 && !c0) res -= 2*a[0];
    cout << res << endl;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define INF 1e+9
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int a[200000];

int main(void){
    int N; cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];

    ll x = a[0], y = accumulate(a + 1, a + N, 0LL);
    ll res = abs(x - y);
    for(int i = 1; i < N - 1; i++){
        x += a[i]; y -= a[i];
        res = min(res, abs(x - y));
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const string w[] = { "the", "this", "that" };

string decoded_letter (string s, int m )
{
	int n = s.length();
	rep (i, n ){
		if (s[i] == ' ' || s[i] == ',' || s[i] == '.' ) continue;
		s[i] = (char)(((int)(s[i] - 'a') + m ) % 26 + 'a');
	} // end rep

	return s; 
}

bool is_include (string s )
{
	int n = s.length();
	rep (i, n ){
		if (s[i] == ',' || s[i] == '.' ) s[i] = ' ';
	} // end rep

	stringstream ss (s );
	string t = "";
	while (ss >> t ){
		rep (i, sizeof (w )/sizeof (w[0] ) ){
			if (t == w[i] ){
				return true;
			} // end if
		} // end rep
	} // end while

	return false;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.CC", "r", stdin );
	string str = "";
	while (getline (cin, str ) ){
		string decode = "";
		rep (i, 26 ){	// secret number
			decode = decoded_letter (str, i );
			if (is_include (decode ) ){
				break;
			} // end if
		} // end rep
		cout << decode << endl;		
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K;
  cin >> N >> K;
  long ans = 0;
  for(long i = K; i <= N + 1; i++){
    ans += (N + N - i + 1) * i / 2 - (0 + i - 1)  * i / 2 + 1;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int a,b;
        cin>>a>>b;
        if (a != 1 && b != 1)
        {
            cout<<1;
        }
        if (a != 2 && b != 2)
        {
            cout<<2;
        }
        if (a != 3 && b != 3)
        {
            cout<<3;
        }
        
        return 0;
    }

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


using namespace std;

int main(void){
    // Your code here!
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
def main():
    A, B, C = [input() for _ in range(3)]
    cards = [A, B, C]
    players = ['a', 'b', 'c']
    turn = 'a'
    cnt = 0
    while True:
        for i in range(3):
            if turn == players[i]:
                if len(cards[i]) == 0:
                    print(players[i].upper())
                    return
                else:
                    turn = cards[i][0]
                    cards[i] = cards[i][1:]
        cnt += 1


main()


Measured memory_bytes: 3064
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if(op == "?"):
        break
    elif(op == "+"):
        print(a+b)
    elif(op == "-"):
        print(a-b)
    elif(op == "*"):
        print(a*b)
    elif(op == "/"):
        print(a//b)

Measured memory_bytes: 7636
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.State              (StateT (..), runStateT)
import           Data.Attoparsec.ByteString.Char8 (isSpace)
import qualified Data.ByteString.Char8            as B
import qualified Data.ByteString.Unsafe           as B
import qualified Data.Vector                      as V

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  s <- getLine
  lrs <- V.unfoldrN q parseInt2 <$> B.getContents
  mapM_ print $ solve n q s lrs

solve :: Int -> Int -> String -> V.Vector (Int, Int) -> V.Vector Int
solve _ _  s lrs = V.map (\(l, r) -> xs V.! (r - 1) - xs V.! (l - 1)) lrs
  where s' = V.fromList s
        xs = V.scanl' (\x (c1, c2) -> x + (if c1 == 'A' && c2 == 'C' then 1 else 0)) 0 (V.zip s' (V.tail s'))

parseInt :: B.ByteString -> Maybe (Int, B.ByteString)
parseInt = B.readInt . B.dropWhile isSpace

parseInt2 :: B.ByteString -> Maybe ((Int, Int), B.ByteString)
parseInt2 = runStateT $
  (,) <$> StateT parseInt
  <*> StateT (B.readInt . B.unsafeTail)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//使う前にCOMinit
//最大に注意！！！！！！！！！！！！！！！

int main() {
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans1=0;
    rep(i,n){
        ll num1=n-i;
        ans1+=num1*i*m*m;
        ans1%=MOD;
    }
    rep(i,m){
        ll num2=m-i;
        ans1+=num2*i*n*n;
        ans1%=MOD;
    }
    COMinit();
    if(n*m==2)cout<<ans1<<endl;
    else{
        ll ans=ans1*COM(n*m-2,k-2);
        ans%=MOD;
        cout<<ans<<endl;
    }

    

    return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;


int main() {
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;

  int W_s = r,H_s = r;
  W -= r;
  H -= r;
  if(W_s <= x && x <= W && H_s <= y && y <= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>
int x;
int myexp(int b, int p){
    int ans = 1;
    for(int i = 0; i < p; i++) ans *= b;
    return ans;
}
int main(void){
    // Your code here!
    scanf("%d",&x);
    if(x == 1){ puts("1"); return 0;}
    
    int max = 0;
    for(int b = 2; b < x; b++){
        for(int p = 2; myexp(b,p) <= x; p++){
            if(max < myexp(b,p)) max = myexp(b,p);
        }
    }
    printf("%d",max);
}


Measured memory_bytes: 128
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		long a = sc.nextLong();
		long b = sc.nextLong();
 
		if(b==a){
            System.out.println(a+b);
		}else if (b%a==0l){
		    System.out.println(a+b);

		}else{
            System.out.println(b-a);
		    
		}
	}
}

Measured memory_bytes: 23764
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

Bsize = 1000

def Mo_argsort(LR):
    L = LR[:, 0]
    R = LR[:, 1]
    key1 = L // Bsize
    key2 = np.where(key1 & 1, -R, R)
    key = (key1 << 32) + key2
    return np.argsort(key)

def main(A, LR):
    N = len(A)
    Q = len(LR)
    ind = Mo_argsort(LR)
    count = np.zeros(N + 1, np.int64)
    ans = 0

    def add(x):
        nonlocal ans
        if not count[x]:
            ans += 1
        count[x] += 1

    def rem(x):
        nonlocal ans
        count[x] -= 1
        if not count[x]:
            ans -= 1

    answers = np.empty(Q, np.int64)
    nl, nr = 0, 0
    for i in ind:
        l, r = LR[i]
        l -= 1
        # 区間 [l, r) に対する計算
        while nl > l:
            nl -= 1
            add(A[nl])
        while nr < r:
            add(A[nr])
            nr += 1
        while nl < l:
            rem(A[nl])
            nl += 1
        while nr > r:
            nr -= 1
            rem(A[nr])
        #  答を求めて ans[i] に格納する
        answers[i] = ans
    return answers

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    Mo_argsort = cc_export(Mo_argsort, (i8[:,:],))
    main = cc_export(main, (i8[:], i8[:, :]))
    cc.compile()

from my_module import main

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)
LR = np.array(read().split(), np.int64).reshape(Q, 2)

ans = main(A, LR)
print('\n'.join(map(str, ans.tolist())))


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int INT_INF = 999999999;
const static llong INF = 1LL << 60;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int h, n;

    cin >> h >> n;

    vector <pii> v(n);

    for(int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        v[i] = mp(a, b);
    }

    vi dp(h + 1, INT_MAX);
    dp[0] = 0;

    for(int i = 0; i <= h; i++)
    {
        for(int j = 0; j < n; j++)
        {
            dp[i] = min(dp[i], dp[((i - v[j].fi < 0) ? (0) : (i - v[j].fi))] + v[j].se);
        }
    }

    cout << dp[h] << '\n';


    return 0;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int N;
  string s;
  cin >> N >> s;

  if (N % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  string a = s.substr(0, N / 2);
  string b = s.substr(N / 2, N / 2);

  if (a == b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define ll long long
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
const ll mod=1e9+7;
#define maxn 300005
int main()
{
	int a,b;
	cin>>a>>b;
	int x=25*a-20*b;
	int vv=inf;
	int f=0;
	for(int i=0;i<25;i++)
	{
		for(int j=0;j<10;j++)
		{
			int t=2*j-i;
			if(t==x)
			{
				vv=min(vv,j);
				f=1;
			}
		}
	}
	if(f==0)
	cout<<-1<<endl;
	else
	{
		int ans=10*b+vv;
		cout<<ans<<endl;
	}
}

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

using namespace std;

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

    string S;
    cin >> S;

    if (S.length() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

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

	int densya = a * n;

	int ans = min(densya, b);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
using Node = pair<string, int>; // left: 0, right: 1

long long solve() {
    int N; 
    cin >> N;
    vector<string> S(N);
    vector<long long> C(N);
    for (int i = 0; i < N; ++i) cin >> S[i] >> C[i];

    long long res = INF;
    map<Node, long long> dp;
    priority_queue<pair<long long, Node>,
        vector<pair<long long, Node>>, greater<pair<long long, Node>>> que;

    auto func = [&](const string &left, const string &right) {
        int i = (int)left.size()-1, j = 0;
        while (true) {
            if (i == -1 || j == (int)right.size()) break;
            if (left[i] != right[j]) return Node("", -1);
            --i, ++j;
        }
        if (left.size() >= right.size()) {
            string res = left.substr(0, (int)left.size() - (int)right.size());
            return Node(res, 0);
        }
        else {
            string res = right.substr((int)left.size());
            return Node(res, 1);
        }
    };
    auto relax = [&](const string &left, const string &right, long long cost) {
        auto v = func(left, right);
        if (v.second == -1) return;
        if (v.first == "") chmin(res, cost);
        else {
            que.push(make_pair(cost, v));
            if (dp.count(v)) chmin(dp[v], cost);
            else dp[v] = cost;
        }
    };
    
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= S[i].size(); ++j) {
            string left = S[i].substr(0, j), right = S[i].substr(j);
            relax(left, right, C[i]);
        }
        for (int j = 0; j < S[i].size(); ++j) {
            string left = S[i].substr(0, j), right = S[i].substr(j+1);
            relax(left, right, C[i]);
        }
    }
    while (!que.empty()) {
        auto tmp = que.top(); que.pop();
        long long dist = tmp.first;
        string cur = tmp.second.first;
        int type = tmp.second.second;
        if (dist > dp[Node(cur, type)]) continue;
        for (int i = 0; i < N; ++i) {
            if (type == 0) relax(cur, S[i], dist + C[i]);
            else relax(S[i], cur, dist + C[i]);
        }
    }
    return res < INF ? res : -1;
}

int main() {
    cout << solve() << endl;
}

Measured memory_bytes: 3700
n = int(input())
a = list(map(int,input().split()))
a_abs = [0]*n
is_minus = [0]*n

for i in range(n):
    if a[i] >= 0:
        a_abs[i] = a[i]
    else:
        a_abs[i] = -1 * a[i]
        is_minus[i] = 1

a_abs.sort()
if sum(is_minus) % 2 == 0:
    ans = sum(a_abs)
else:
    ans = sum(a_abs) - 2*a_abs[0]

print(ans)

Measured memory_bytes: 86872
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	ll X,FF,F;
	cin >> X;

	FF = X / 500;
	F = X - (500*FF);
	F = F / 5;
	cout << FF*1000 + F*5 << endl;

}

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

int h, w, k, z, ans=1e9, c[15];
string a[15];

bool f(int j) {
	int i, id=0, fl=0;
	for(i=0; i<h; i++) {
		c[id] += a[i][j]=='1';
		if(c[id]>k) fl = 1;
		if(z>>i & 1) id++;
	}
	return fl;
}

int main() {
	int i, j, cnt, re;
	cin >> h >> w >> k;
	for(i=0; i<h; i++) cin >> a[i];
	for(z=0; z<1<<h-1; z++) {
		memset(c, 0, sizeof(c));
		cnt = __builtin_popcount(z);
		re = 0;
		for(j=0; j<w; j++) {
			if(f(j)) {
				cnt++;
				memset(c, 0, sizeof(c));
				re = f(j);
			}
		}
		if(!re) ans = min(ans, cnt);
	}
	cout << ans;
	return 0;
}

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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define pi pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int> >
#define vll vector<pair<int,int> >
#define pb push_back
#define mp make_pair
#define qi queue<int>

const ll mod=1e9+7;
#define MAX 100000

template<typename T> void max_self(T &x,T y) { x = max(x,y); }
template<typename T> void min_self(T &x,T y) { x = min(x,y); }

ll solve(ll a,ll b,ll c){

    if(b==0) return 1;
    else if(b%2==0) return solve(((a%c)*(a%c))%c,b/2,c)%c;
    else return ((a%c)*(solve(((a%c)*(a%c))%c,b/2,c)%c))%c;
}

int main(){

    std::ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n,k;
    cin>>n>>k;

    int arr[n];
    FOR(i,0,n) cin>>arr[i];

    bool dp[k+1];
    memset(dp,false,sizeof(dp));

    FOR(i,0,k+1){
        FOR(j,0,n){
            if(i>=arr[j] && dp[i-arr[j]] == false) dp[i] = true;
        }
    }

    if(dp[k] == true) cout<<"First";
    else cout<<"Second";
    return 0;
}


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

int main(){
  int H,W,A,B;
  cin >> H >> W >> A >> B;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      int x=0;
      if(i<=B){
        x ++;
      }
      if(j<=A){
        x ++;
      }
      cout << (x%2);
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair 
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9;
const ll MAX = 1e5+10;
const ll inf = 1e18+7;

int main(){
	fastio;
	string s;
	cin>>s;
	if(*s.rbegin()=='s') s+="es";
	else s.pb('s');
	cout<<s<<"\n";
    return 0; 
}

Measured memory_bytes: 3612