akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// (?????????,??????,??????)
struct edge{ int to,cap,rev; };

const int MAX_V = 334; // TODO:initialize
const int F_INF = 1234567; // TODO:initialize
vector<edge> G[MAX_V];
int level[MAX_V]; // s??????????????¢
int iter[MAX_V]; // ???????????§??????????????£??????

void add_edge(int from, int to, int cap){
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,cap,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// ?¢?????????????dfs??§??¢???
int dinic_dfs(int v, int t, int f){
    if(v==t) return f;
    for(int &i=iter[v]; i<G[v].size(); ++i){
        edge &e=G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            int d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// s??????t???????????§???
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dinic_dfs(s,t,F_INF))>0) flow+=f;
    }
}

int main()
{
    int n,m;
    cin >>n >>m;
    vector<int> x(m), y(m);
    rep(i,m)
    {
        cin >>x[i] >>y[i];
        --x[i];
        --y[i];
        add_edge(x[i],y[i],1);
    }

    int S,T;
    cin >>S >>T;
    --S;
    --T;

    cout << max_flow(S,T) << endl;

    vector<int> ans;
    rep(i,m)
    {
        for(const auto &e:G[x[i]])
        {
            if(e.to==y[i] && e.cap==2)
            {
                ans.pb(i);
                break;
            }
        }
    }

    cout << ans.size() << endl;
    rep(i,ans.size()) cout << ans[i]+1 << endl;
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    double r;
    cin >> r;
    cout << fixed << setprecision(10) << 2.0*r*M_PI << endl;

    return 0;
}

Measured memory_bytes: 3784
#include <stdio.h>
int main(){
  int n,i,j, ans = 10e9;
  scanf("%d",&n);
  char dir[n + 10];
  scanf("%s", dir);
  int east[n],west[n];
  for (i = 0; i < n; i++) {east[i] = 0; west[i] = 0;}
  for (i = 0; i < n; i++){
    int cnt = 0;
    if(dir[i] == 'E') east[i]++;
    else if (dir[i] == 'W') west[i]++;
    if(i) {east[i] += east[i - 1];west[i] += west[i-1];}
  }
  for (i = 0; i < n; i++){
    int num;
    if(i) num = west[i - 1] + east[n - 1] - east[i];
    else num = east[n - 1] - east[i];
    if (ans > num) ans = num;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 2816
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long N, M, H,K,W,re;
long long A[200001];
long long C[200001];
bool B[200001] = {};
string S;
set <long long>sll;
bool OK = true;
bool f=false;
vector <long long>vl;

int main() {
	cin >>N>>S;
	M = 0;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] == 'E') {
			M++;
		}
	}
	sll.insert(M);

	for (int i = 1; i < S.size(); i++) {
		if (S[i] == 'E') {
			M--;
		}
		if (S[i-1] == 'W') {
			M++;
		}
		sll.insert(M);
	}

	cout << *sll.begin() << endl;

	return 0;
}


Measured memory_bytes: 14596
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}

ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b != 0){
        ll temp = a / b;
        d = extgcd(b, a - b * temp, y, x);
        y -= temp * x;
    }else{
        x=1;
        y=0;
    }
    return d;
}

int main() {
    cin>>N;
    if(N <= 100){
        reps(k, 1, N + 10){
            if((k * (k + 1) / 2) % N == 0){
                cout<<k<<endl;
                return 0;
            }
        }
    }else{
        ll ans(N | 1), NN(N);
        N *= 2;
        vec prime(0);
        for(ll i = 2; i * i <= N; ++i){
            if(N%i == 0){
                ll elem = 1;
                while(N%i == 0){
                    N /= i;
                    elem *= i;
                }
                prime.push_back(elem);
            }
        }
        if(N != 1) prime.push_back(N);
        N = NN * 2;
        int sz = prime.size();
        rep(s, (1<<sz)){
            ll temp_k(1), x, y, b;
            rep(j, sz) if((s>>j)&1) temp_k *= prime[j];
            if(temp_k == 1 || temp_k == N) continue;
            b = N / temp_k;
            if(temp_k < b) swap(temp_k, b);
            extgcd(temp_k, b, x, y);
            chmin(ans, min(abs(x * temp_k), abs(y * (N / temp_k))));
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3608
X, K, D = (int(x) for x in input().split())

if X > 0:
    div, mod = divmod(X, D)
    if div >= K:
        answer = X - K*D
    else:
        if (K - div)%2 == 0:
            answer = X - div*D
        else:
            answer = abs(X - (div+1)*D)
elif X < 0:
    div, mod = divmod(-X, D)
    if div >= K:
        answer = abs(X + K*D)
    else:
        if (K - div)%2 == 0:
            answer = abs(X + div*D)
        else:
            answer = X + (div+1)*D
else:
    if K%2 == 0:
        answer = 0
    else:
        answer = D

print(answer)


Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  ll i,j,k,l,n,m,c;
  cin>>n>>m>>c;
  ll b[m];
  for(i=0;i<m;i++){
      cin>>b[i];
  }
  ll a[n][m];
  for(i=0;i<n;i++){
      for(j=0;j<m;j++){
          cin>>a[i][j];
      }
  }
  
  ll s=0;
  for(i=0;i<n;i++){
      l=0;
      for(j=0;j<m;j++){
          l+=(a[i][j]*b[j]);
      }
      l+=c;
      if(l>0) s++;
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b,c,T;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b)
		{
			T = a;
			a = b;
			b = T;
		}
	if(b>c)
		{
			T = b;
			b = c;
			c = T;
		}	
	if(a>b)
		{
			T = a;
			a = b;
			b = T;
		}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 2080
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
const int mod=1e9+7;
int n;
bool ok=true;
int a[maxn],cnt[maxn];

int main(){
	scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]),cnt[a[i]]++;
	if(n&1){
		if(cnt[0]!=1)ok=false;
		for(int i=2;i<n;i+=2)if(cnt[i]!=2)ok=false;
	}
	else{
		for(int i=1;i<n;i+=2)if(cnt[i]!=2)ok=false;
	}
	if(!ok)printf("0");
	else{
		int ans=1;
		for(int i=1;i<=n/2;i++)ans=(ll)ans*2LL%mod;
		printf("%d",ans);
	}
	return 0;
}

Measured memory_bytes: 1024
# E - Payment

N = input().strip()

s = 0
carry = 0
five = False
for c in reversed(N):
    x = int(c) + carry
    if x == 5 and not five:
        s += x
        carry = 0
        five = True
    elif x >= 5:
        if five:
            x += 1
        s += 10 - x
        carry = 1
        five = False
    else:
        s += x
        carry = 0
        five = False
s += carry

print(s)


Measured memory_bytes: 52844
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

class Prime
{
	int i, iLimit;
 
public:
	bool isPrime(int a);
};
 
bool Prime::isPrime(int a)
{
	if (a == 1) return false;
 
	iLimit = (int)sqrt(a);
	for (i = 2; i <= iLimit; i++) {
		if (a % i == 0) break;
	}
	if (i == iLimit + 1) {
		return true;
	}
	else {
		return false;
	}
}
 

int main(){
  int x;
  cin >> x;
  bool jud = false;
  Prime p;

  for(int i=x; i<=100003; i++){

    jud = p.isPrime(i);

    if(jud){
      dunk(i);
      break;
    }

  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
     
    int ans = 1;
    while(ans*2 <= n) {
			ans *= 2;
		}
        	System.out.println(ans);
}
}

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

int main() {
	int n;
  	cin>>n;
  
  	int p[n];
  	rep(i,n){cin>>p[i];}
  
  	int ans=0;
  	int max=0;
  	  	
  	for(int i=0;i<n;i++){
    	if(p[i]>max){
        	ans+=max;
          	max=p[i];
        }
      
      	else{
        	ans +=p[i];
        }
    }
  
  cout<<ans+(max/2)<<endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vi dp(100, -1);

int fib(int n) {
    assert(n>=0);
    if (n == 0) return 1;
    if (n == 1) return 1;
    
    if (dp[n] != -1) return dp[n];
    else {
        dp[n-1] = fib(n-1);
        dp[n-2] = fib(n-2);
        return dp[n-1]+dp[n-2];
    }
}

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

    int n;
    cin >> n;
    cout << fib(n) << endl;

    return 0;
}



Measured memory_bytes: 3128
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  int B[N]={0};
  int flag = 0;
  for(int i = N;i>=1;i--){
    REP(j,i){
      if(A[i-1-j]==i-1-j+1){
        FOR(k,i-1-j,i-1){
          A[k]=A[k+1];
        }
        B[i-1]=i-j;
        break;
      }else if(j==i-1){
        flag = 1;
      }
    }
  }

  if(flag == 1){
    cout << -1 << endl;
  }else{
    REP(i,N){
      cout << B[i] << endl;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable PossibleNullReferenceException
// ReSharper disable AssignNullToNotNullAttribute

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var aa = new int[a.Length][];
            for (int i = 0; i < a.Length; ++i)
            {
                aa[i] = new[] {i + 1, a[i]};
            }
            Console.WriteLine(string.Join(" ", aa.OrderBy(tmp => tmp[1]).Select(tmp=>tmp[0]).ToArray()));
        }
    }
}


Measured memory_bytes: 31836
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
int main(){
    int N,M;
    int s[6],c[6],ans[3];
    cin >> N >> M;
    rep(i,M) cin >> s[i] >> c[i];
    rep(i,3) ans[i] = -1;

    rep(i,M){
        s[i] = N - s[i] + 1;
    }
    if (M == 0){
        if (N == 1) cout << 0 << endl;
        if (N == 2) cout << 10 << endl;
        if (N == 3) cout << 100 << endl;
        return 0;
    }
    rep(i,M){
        if ((s[i] == N && c[i] == 0) && N != 1){
            cout << -1 << endl;
            return 0;
        }
        if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i] && ans[s[i] - 1] != 0){
            //cout << "a" << endl;
            cout << -1 << endl;
            return 0;
        }else{
            ans[s[i] - 1] = c[i];
            if (s[i] == 3){
                if(ans[1] == -1) ans[1] = 0;
                if(ans[0] == -1) ans[0] = 0;
            }else if (s[i] == 2){
                if(ans[0] == -1) ans[0] = 0;
            }
        }
    }
    if (N == 1) cout << ans[0] << endl;
    else if (N == 2){
        if (ans[1] == -1) ans[1] = 1;
        cout << ans[1] * 10 + ans[0] << endl;
    }else if (N == 3){
        if (ans[1] == -1) ans[1] = 0;
        if (ans[2] == -1) ans[2] = 1;
        cout << ans[2] * 100 + ans[1] * 10 + ans[0] << endl;
        
    }
    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs'
import {debug} from '../../../util'

const input = fs.readFileSync('/dev/stdin', 'utf8').trim()

const output = (x: string | number | boolean) => console.log(x)
const splitLine = (string: string): string[] => string.split('\n')
const splitBlank = (string: string): string[] => string.split(' ')
const toNumbers = (array: string[]): number[] => array.map(v => Number(v))
const createSerialNumber = (n: number): number[] => [...Array(n).keys()]

// debug(input)

/* ここから */
const [K, S] = splitLine(input)

if (S.length <= +K) {
    output(S)
} else {
    output(S.substr(0, +K) + '...')
}

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

using namespace std;
typedef long long ll;
int N,A;
int a[51];
ll dp[51][51][2501];
int main() {
  cin >> N >> A;

  for(int i = 0; i <  N; i++) cin >> a[i];
  dp[0][0][0] = 1;

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      for(int k = 0; k < 2501; k++) {
	if(dp[i][j][k]) {
	  dp[i+1][j][k] += dp[i][j][k];
	  dp[i+1][j+1][k+a[i]] += dp[i][j][k];
	}
      }
    }
  }
  ll ans = 0;

  for(int i = 1; i <=N; i++) {
    ans += dp[N][i][i*A];
  }
  cout << ans <<endl;
}
    
  
  


Measured memory_bytes: 48128
#include<stdio.h>

#define N 8

#define F 0

#define FN 1
void Queen(int);
void Print(void);

int Q[N][N];
int drop[2*N+1];
int dn[2*N+1];
int r[N];
int c[N];

int main(){
  int i,n;
  int q_c,q_r;
  scanf("%d", &n);

  for(i = 0; i <n; i++){
    scanf("%d%d", &q_r,&q_c);
    Q[q_r][q_c] = FN;
  }
  
  Queen(0);
  return 0;
}
void Queen(int a){
  int i;
  if(a == N){
    Print();
    return;
  }
  for(i = 0;i < N; i++){
    if(c[i] == FN || drop[a+i] == FN || dn[a-i+N-1] == FN)continue;

    r[a] = i;
    c[i] =FN;
    drop[a+i] =FN;
    dn[a-i+N-1] = FN;
    Queen(a+1);
    
    c[i] =F;
    drop[a+i] = F;
    dn[a-i+N-1] = F;
  }

}

void Print(void){
  int i,j;
  for(i = 0; i< N; i++){
    for(j = 0; j < N; j++){
      if(Q[i][j] == FN){
	if(r[i] != j) return;
      }
    }
  }
   for(i = 0; i< N; i++){
    for(j = 0; j < N; j++){
      if(r[i] == j){
	printf("Q");
      }
      else{
	printf(".");
      }
    }
    printf("\n");
   }
}



Measured memory_bytes: 2036
while 1:
    N,T,L,B = map(int,raw_input().split())
    if N == 0: break
    lose = set([int(raw_input()) for i in xrange(L)])
    back = set([int(raw_input()) for i in xrange(B)])
    dp = [[0.]*(N+1) for i in xrange(T+1)]
    dp[0][0] = 1.
    p = 1./6.
    for t in xrange(T):
        for i in xrange(N):
            tt = t-1 if i in lose else t
            for j in xrange(i+1,i+7):
                if j > N: j = N-j%N
                if j in back: j = 0
                dp[t+1][j] += p*dp[tt][i]
        dp[t+1][N] += dp[t][N]
    print "%.6f"%dp[T][N]

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

int main() {
	long long a, b, c, n, m, x;
	cin >> a >> b >> c;
	if(max(a, max(b, c)) == a){
		cout << abs(max(b, c) - a) + abs(min(b, c) - max(b, c)) << endl;
		return 0;
	}else if(max(a, max(b, c)) == b){
		cout << abs(max(a, c) - b) + abs(min(a, c) - max(a, c)) << endl;
		return 0;
	}else{
		cout << abs(max(b, a) - c) + abs(min(b, a) - max(b, a)) << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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

int my_abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int my_abs_B(long long num,long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}



const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> retu(N);
    for (int i = 0; i < N; i++) {
        cin >> retu.at(i);
    }
    bool ok = true;
    sort(retu.begin(), retu.end());
    for (int j = 0; j < N-1; j++) {
        if (retu.at(j) == retu.at(j + 1)) {
            ok = false;
        }
    }

    if (ok) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 1024
w = gets.chomp
h = {}
w.each_char do |c|
  if h.has_key?(c) then
    h[c] = h[c] + 1
  else
    h[c] = 1
  end
end
result = true
h.each do |k,v|
  if v % 2 != 0 then
    result = false
    break;
  end
end
if result then
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll a[500005];
ll bit[500005];
void fill(ll i,ll x)
{
    while(i<=n)
    {
        bit[i]+=x;
        //cout<<i<<" "<<(i&(-i))<<endl;
        i+=i&(-i);
        
    }
   
}
ll query(ll i)
{
    ll s=0;
    while(i>0)
    {
        s+=bit[i];
        i=i-(i&(-i));
    }
    return s;
}
int main()
{
    ll q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    for(ll i=1;i<=n;i++)
    fill(i,a[i]);
    while(q--)
    {
        ll x,l,r;
        cin>>x>>l>>r;
        l++;r++;
        if(x==0)
        {
            fill(l,r-1);
        }
        else
        {
            cout<<query(r-1)-query(l-1)<<endl;
        }
    }
    
    
}

Measured memory_bytes: 12136
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 200010;

ll p[N];
struct Node {
	ll x, h;
} w[N];

inline bool cmp(Node a, Node b)
{
	return a.x < b.x;
}

int main()
{
	ll n, d, a;
	scanf("%lld %lld %lld", &n, &d, &a);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld %lld", &w[i].x, &w[i].h);
	}
	sort(w + 1, w + n + 1, cmp);
	ll l = 1, r = 1;
	d <<= 1;
	ll ans = 0;
	for (; l <= n; ++l) {
		while (r < n && w[r + 1].x - w[l].x <= d) ++r;
		p[l] += p[l - 1];
		w[l].h += p[l] * a;
		if (w[l].h <= 0) continue;
		ans += w[l].h / a + (w[l].h % a != 0);
		p[l] -= w[l].h / a + (w[l].h % a != 0);
		p[r + 1] += w[l].h / a + (w[l].h % a != 0);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

vb is_prime;
void p_ini(int n) {
	is_prime.resize(n, true);
	is_prime[0] = false;
	is_prime[1] = false;
	for (int i = 2; i < n; i++) {
		if (!is_prime[i])
			continue;
		for (int j = i * 2; j < n; j += i)
			is_prime[j] = false;
	}
	return;
}

vl prime_factor(ll n) {
	vl prime_factor_n;
	ll sqrt_n = sqrt(n) + 10;
	p_ini(sqrt_n);
	rep(i, sqrt_n) {
		if (!is_prime[i])
			continue;
		if (n % i == 0) {
			ll count = 0;
			prime_factor_n.push_back(i);
			while (1) {
				n /= i;
				count++;
				if (n % i != 0)
					break;
			}
		}
	}
	if (n > 1)
		prime_factor_n.push_back(n);
	return prime_factor_n;
}

int main() {
	ll N;
	cin >> N;
	vl B = prime_factor(N);
	ll ans = 0;
	rep(i, B.size()) {
		ll p = B[i];
		ll n = 0;
		ll Ntmp = N;
		while (1) {
			if (Ntmp % p != 0)
				break;
			Ntmp /= p;
			n++;
		}
		ll anstmp = 0;
		while (1) {
			if (n - (anstmp + 1) < 0)
				break;
			n -= (anstmp + 1);
			anstmp++;
		}
		ans += anstmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll mod = 1e9 + 7;

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

   int n;
   cin >> n;
   vector <vector <int>> v(n, vector <int> (n));
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
         cin >> v[i][j];
      }
   }

   vector <vector <ll>> dp((1 << n), vector <ll> (n));

   for (int i = 0; i < n; i++) {
      dp[1 << i][0] = v[i][0];
   }
   for (int i = 1; i < n; i++) {
      for (int mask = 0; mask < (1 << n); mask++) {
         if (__builtin_popcount(mask) != i + 1)
            continue;
         for (int j = 0; j < n; j++) {
            if (mask & (1 << j) && v[j][i]) {
               dp[mask][i] += dp[mask ^ (1 << j)][i - 1];
               dp[mask][i] %= mod;
            }
         }
      }
   }

   cout << dp[(1 << n) - 1][n - 1] % mod << '\n';

   return 0;
}

Measured memory_bytes: 411904
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;
int main() {
	while (true) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0)break;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				if ((i + j) % 2 == 0)cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);

  vector<long> ans(N);
  ans.at(0) = 0;
  for (long i = 1; i < N; i++) {
    ans.at(i) = (A.at(i - 1) - ans.at(i - 1) / 2) * 2;
  }

  long rev = (A.at(N - 1) * 2 - ans.at(N - 1)) / 2;

  for (long i = 0; i < N; i++) {
    if (i % 2) ans.at(i) += -rev;
    else ans.at(i) += rev;
  }

  for (auto a : ans) cout << a << "\n";
}

Measured memory_bytes: 2944
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        double L = sc.nextDouble();
	        double a=L/3/3/3*L*L;
	        System.out.println(a);
	 }
}

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

int main(void) {
    int N,M,C;
    cin>>N>>M>>C;
    int B[M];
    for (int i = 0; i < M; i++) cin>>B[i];
    int result = 0;
    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < M; j++) {
            int A;cin>>A;
            sum += A * B[j];
        }
        sum += C;
        if (sum > 0) result++;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  long int n;

  scanf("%ld", &n);
  long int a[n];
  long int count[n];

  for (long int i = 1; i < n; i++)
    scanf("%ld", &a[i]);

  for (long int i = 0; i < n; i++)
    count[i] = 0;

  for (long int i = 1; i < n; i++)
    count[a[i]-1]++;

  for (long int i = 0; i < n; i++)
    printf("%ld\n", count[i]);

  return 0;
}


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define rep(k,dst)    for(int i=k; i<dst;  i++)
#define rep2(k,dst)   for(int j=k; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);

int main(){
    ll n, k; cin >> n >> k;
    ll ans=0;
    vector<ll> h(n);
    rep(0,n) cin >> h[i];

    sort(h.begin(), h.end());
    rep(0,k) h.pop_back();
    rep(0,n-k) ans += h[i];
    cout << ans << endl;
    return 0;
}
/*
3 3
1 7
3 2
1 7
*/


Measured memory_bytes: 4776
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    // dp[l][r][i] := [l, r)が残ってるときの X - Y
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    REP(i, n+1) {
        REP(j, n+1) {
            dp[i][j] = (n - j + i) % 2 ? LINF : -LINF;
        }
        dp[i][i] = 0;
    }

    for (ll rem = 0; rem < n; rem++) {
        for (ll l = 0; l <= n - rem; l++) {
            ll r = l + rem;

            if ((n - rem) % 2) { // taro
                if (l > 0) chmax(dp[l-1][r], dp[l][r] + a[l-1]);
                if (r < n) chmax(dp[l][r+1], dp[l][r] + a[r]);
            } else { // jiro
                if (l > 0) chmin(dp[l-1][r], dp[l][r] - a[l-1]);
                if (r < n) chmin(dp[l][r+1], dp[l][r] - a[r]);
            }

        }
    }
    
    cout << dp[0][n] << endl;
    
    
}

Measured memory_bytes: 72576
import math
n = int(input())
p = {}
for i in range(n):
    x,y = map(int, input().split())
    p[i] = (x, y)
ave = 0
for i in range(n):
    for j in range(i+1,n):
        ave += math.sqrt(abs(p[i][0] - p[j][0])**2 + abs(p[i][1] - p[j][1])**2)
ave /= ((n*(n-1))/2)
total = ave*(n-1)
print(total)

Measured memory_bytes: 3064
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second)
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto &i : a)
#define umap unordered_map
#define fileio(in, out) freopen("in", "r", stdin); freopen("out", "w", stdout)
const int mod = (int)(1e9) + 7;
//endregion

int main() {
    io();
    int n, k, t=0;
    in2(n, k);
    string s;
    in(s);
    fori (i, n-1) {
        if (s[i] == s[i+1]) t++;
    }
    out(min(t+2*k, n-1));
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef long long ll;
typedef pair<ll, ll> pl;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// combinationの計算
const int MAX = 2001;
const int MOD = 1000000007;

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;
} // 二項係数計算

int main(){

  COMinit();

  int N,K;

  cin>>N>>K;

  ll ans;
  int ct=0;

  reps(i,1,min(N-K+2,K+1)){
    ans= (COM(N-K+1,i)*COM(K-1,i-1))%MOD;
    std::cout << ans << '\n';
    ct++;
  }

  while(ct<K){
    std::cout << 0 << '\n';
    ct++;
  }

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

tot = 3 ** N

cnt_odd, cnt_even = 0,0

for i in range(N):
	if A[i] % 2 == 0:
		cnt_even += 1
	else:
		cnt_odd += 1

ans = tot - (2**cnt_even)*(1**cnt_odd)
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] d = new int[n];
        for(int i = 0;i<n;i++){
            d[i] = Integer.parseInt(sc.next());
        }
        int sum = 0;
        for(int i = 0;i<n;i++){
            for(int j = i + 1;j<n;j++){
                sum += d[i] * d[j];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24020
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

ll N, M, X;
vector<ll> C;
vector<vector<ll>> A;

void solve() {
  ll minCost = LINF;

  for (int bit = 0; bit < 1 << N; bit++) {
    ll sumCost = 0;
    vector<ll> l(M, 0);
    rep(i, N) {
      if (bit & (1 << i)) {
        sumCost += C.at(i);
        rep(j, M) { l.at(j) += A.at(i).at(j); }
      }
    }

    if (sumCost >= minCost) continue;

    bool ok = true;
    rep(j, M) {
      if (l.at(j) < X) {
        ok = false;
        break;
      }
    }
    if (ok) {
      minCost = min(minCost, sumCost);
    }
  }

  if (minCost != LINF) {
    cout << minCost << endl;
  } else {
    cout << -1 << endl;
  }
  return;
}

int main() {
  cin >> N >> M >> X;
  C.resize(N);
  A.resize(N);
  rep(i, N) {
    cin >> C.at(i);
    A.at(i).resize(M);
    rep(j, M) { cin >> A.at(i).at(j); }
  }

  solve();

  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<map>
#include<numeric>
#include<cstdio>
#include<iomanip>
#include<algorithm>

using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
	
int r,n;
map<int ,map<int ,double> > biuld;

bool judge(double high)
{
	for(int i = -r;i < r;i++)
	{
		double y = biuld[i][i+1] - high;
		if(y < 0 || i*i + y*y < r*r || (i+1)*(i+1) + y*y < r*r)
			return true;
	}
	return false;
	
}

int main()
{
	cout << setprecision(4) << fixed;
	
	while(cin >> r >> n,r)
	{
		biuld.clear();
		double lx,rx,h;
		REP(i,n)
		{
			cin >> lx >> rx >> h;
			for(int j = lx;j < rx;j++)
			{
				biuld[j][j+1] = max(biuld[j][j+1],h);
			}
		}
		
		double ub = -r,hb = 21;
		REP(i,100)
		{
			double mid = (ub+hb)/2;
			if(judge(mid))hb = mid;
			else ub = mid;
		//	cout << ub << ' ' << hb << endl;
		}
		
		cout << ub + (double)r << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
double a, b, x, c, ans;
int main(){
	scanf("%lf%lf%lf", &a, &b, &x);
	c = 2*x/a/a-b;
	if(c < 0){
		c = 2*x/a/b;
		ans = atan2(b,c) / acos(-1) * 180;
	}else ans = atan2(b-c,a) / acos(-1) * 180;
	printf("%.9f\n", ans);
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
const int N=1e6+11;
int n,m,tot;
int x,y,l=2e5,r=l+1;
int nxt[N],las[N],to[N];
int ans[N],vis[N];
inline void add(int x,int y){
	nxt[++tot]=las[x];
	las[x]=tot;
	to[tot]=y;
}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,m){
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);	
	}
	ans[l]=x,ans[r]=y;
	vis[x]=vis[y]=1;
	while(1){
		int f=0;
		go(x)
			if(!vis[to[e]]){
				x=to[e];
				f=1;
				ans[--l]=x;
				vis[x]=1;
				break;
			}
		if(!f)break;
	}
	while(1){
		int f=0;
		go(y)
			if(!vis[to[e]]){
				y=to[e];
				f=1;
				ans[++r]=y;
				vis[y]=1;
				break;
			}
		if(!f)break;
	}
	printf("%d\n",r-l+1);
	rep(i,l,r)
		printf("%d ",ans[i]);
	puts("");
	return 0;
} 

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

int n;
string s;

int main() {
    cin >> n >> s;
    string ans = "Yes";
    if (n % 2 == 0) {
        rep(i, n / 2) {
            if (s[i] != s[i + n / 2]) ans = "No";
        }
    }
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n,k; cin>>n>>k;
    vector<ll> l(n);
    get(l);
    ll ans = 0;
    for(int a = 0 ; a <=min(n,k); a++){
        for(int b = 0; b + a <=min(n,k); b++){
            vector<ll> take;
            ll sum = 0;
            for(int i = 0; i < a ; i++){
                take.push_back(l[i]);
                sum+=l[i];
            }
            for(int i = 0; i <b; i++){
                take.push_back(l[n-1-i]);
                sum+=l[n-1-i];
            }
            sort(all(take));
            for(int i = 0 ; i < min(k-a-b,(int)take.size()); i++){
                if(take[i]<0)
                    sum-=take[i];
            }
            ans = max(ans, sum);

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){  
  ll n,capa;
  cin >> n >> capa;
  vector<ll> v[4];
  ll w=0;
  rep(i,n){ 
    int a,b; cin>>a>>b;
    if(i==0){w=a;}
    v[a-w].emplace_back(b);
  }
  rep(i,4){sort(v[i].rbegin(),v[i].rend());}

  vector<vector<ll>> r(4, vector<ll>(110,0));
  
  rep(i,4)rep(j,v[i].size()){
    r[i][j+1]=r[i][j]+v[i][j];
  }
  ll a=v[0].size()+1;
  ll b=v[1].size()+1;
  ll c=v[2].size()+1;
  ll d=v[3].size()+1;

  ll ans=0;
  rep(i,a)rep(j,b)rep(k,c)rep(l,d)if(capa>=i*w+j*(w+1)+k*(w+2)+l*(w+3)){
    ll tmp=r[0][i]+r[1][j]+r[2][k]+r[3][l];
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n, m;
vector<vector<int>> M;
int il[3];
vector<int> kol;
bool nope = 0;

void dfs(int x, int k) {
	kol[x] = k;
	DBG(x, k);
	il[k]++;
	for (int y = 0; y < n; y++) {
		if (!M[x][y] or x == y) {
			continue;
		}
		if (kol[y] == k) {
			DBG("Z", x, y);
			nope = 1;
		}
		if (kol[y] == 0) {
			dfs(y, 3 - k);
		}
	}
}

int main() {
	#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	#endif
	cin >> n >> m;
	M.resize(n);
	rep (i, 0, n) {
		M[i].resize(n, 1);
	}
	kol.resize(n);
	rep (i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		M[a][b] = 0;
		M[b][a] = 0;
	}
	vector<pair<int, int>> s;
	rep (i, 0, n) {
		if (kol[i] == 0) {
			il[1] = 0;
			il[2] = 0;
			dfs(i, 1);
			if (nope) {
				cout << "-1";
				return 0;
			}
			s.pb({il[1], il[2]});
		}
	}
	vector<vector<int>> dp(n + 1, vector<int>(n + 1));
	dp[0][0] = 1;
	rep(i, 0, SZ(s)) {
		rep (j, 0, n) {
			if (dp[i][j]) {
				dp[i + 1][j + s[i].ft] = 1;
				dp[i + 1][j + s[i].sd] = 1;
			}
		}
	}
	ll wyn = n * n;
	rep (j, 0, n + 1) {
		if (dp[SZ(s)][j]) {
			wyn = min(wyn, j * (j - 1) / 2 + (n - j) * (n - j - 1) / 2);
		}
	}
	cout << wyn;
}


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

int main(void){
    int h = 0, w = 0; 
    char c[101][101];

    scanf("%d%d", &h, &w);

    for(int i = 0; i < h; i++){
        scanf("%s", c[i]);
    }


    for(int i = 0; i < h; i++){
        printf("%s\n", c[i]);
        printf("%s\n", c[i]);
    }


    return 0;

} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5,mod=1e9+7;
int n,cnt,f[maxn],c[maxn],vis[maxn],pre[maxn];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){scanf("%d",&c[i]);}
	for(int i=1;i<=n;i++){
		if(c[i]!=c[i-1]){cnt++;}
		c[cnt]=c[i];
	}
	for(int i=1;i<=cnt;i++){
		pre[i]=vis[c[i]];
		vis[c[i]]=i;
	}
	f[0]=1;
	for(int i=1;i<=cnt;i++){
		f[i]=f[i-1];
		if(pre[i]){f[i]=(f[i]+f[pre[i]])%mod;}
	}
	printf("%d\n",f[cnt]);
	return 0;
} 

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
template <typename T, typename U>
using P = pair<T,U>;
template <typename T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main(){
  int N,M;
  bool f = true;
  cin >> N;
  vt<int> D(N);
  rep(i,N)  cin >> D[i];
  cin >> M;
  vt<int> T(M);
  rep(i,M)  cin >> T[i];

  sort(D.begin(),D.end());
  sort(T.begin(),T.end());
  if(M > N)
    f = false;
  else
  {
    int d = 0, t = 0;
    do
    {
      if(D[d] < T[t])
        d++;
      else if(D[d] == T[t])
      {
        t++; d++;
      }
      else
      {
        f = false;
        break;
      }
    }while(t < M);
  }

  cout << (f ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<vector<int>> G(n);
    vector<pair<int, int>> vp;

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a, b);
    } 
    
    map<pair<int, int>, int> mp;
    vector<int> cs(n);  // cs[i] : 頂点iとiの親を結ぶ辺の色
    vector<int> used(n);  // used[i] : 頂点iを訪れたかどうか
    queue<int> Q;

    Q.emplace(0);
    used[0] = 1;
    int K = 0;

    while(!Q.empty()) {

        int v = Q.front();
        Q.pop();

        if(K < (int)G[v].size()) {
            K = G[v].size();
        }
        
        int color = 1;
        for(auto u : G[v]) {
            if(used[u]) {
                continue;
            }
            if(color == cs[v]) {
                color++;
            }
            cs[u] = mp[make_pair(u, v)] = mp[make_pair(v, u)] = color++;
            used[u] = 1;
            Q.emplace(u);
        }
    }

    cout << K << "\n";

    for(auto p : vp) {
        cout << mp[p] << "\n";
    }

    return 0;
}

Measured memory_bytes: 20084
t=int(input())
p=t
a,b=[],[]
while(t):
  n, m =map(str, input().split())
  a.append(n)
  b.append(m)
  t-=1
s=str(input())
m,ans=0,0
m=a.index(s)
for i in range(m+1,p):
    ans+=int(b[i])
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "


const int N = 5e3+2;

bitset<N> bl[N], br[N];
int n, k;
void print(bitset<N> bit)
{
  cerr << "bit contains";
  for (int i = 0; i <= k; ++i)
    if (bit[i] == 1)
      cerr << " " << i;
  cerr << endl;
}
int main()
{

  while (~scanf("%d %d", &n, &k))
    {
      vector<int> v;
      for (int i = 0; i < n; ++i)
	{
	  int x;
	  scanf("%d", &x);
	  if (x < k) v.pb(x);
	}
      bl[0].reset();
      bl[0][0] = 1;
      for (int i = 0; i < v.size(); ++i)
	{
	  bl[i+1] = bl[i] | (bl[i] << v[i]);
	}
      br[v.size()+1].reset();
      br[v.size()+1][0] = 1;
      for (int i = int(v.size())-1; i >= 0; --i)
	{
	  br[i+1] = br[i+2] | (br[i+2] << v[i]);
	}
      int ans = v.size();
      for (int i = 0; i < v.size(); ++i)
	{
	  int need = k - v[i];
	  int r = k;
	  //	  cerr << "deal with " << v[i] << " need " << need << endl;
	  //	  print(bl[i]);
	  //	  print(br[i+2]);
	  for (int l = 0; l < k; ++l)
	    if (bl[i][l] == 1)
	      {
		while (r >= 0 && (r+l >= k || br[i+2][r] == 0)) --r;
		if (r == -1)
		  {
		    //		    cerr << "break " << l << " " << r << endl;
		  }
		else if (l + r >= need)
		  {
		    //		    cerr << "elimated by " << l << " and " << r << endl;
		    --ans; break;
		  }
		//		cerr << l << " match with " << r << endl;
	      }
	}
      printf("%d\n", ans);
    }
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
char s[110];

int main()
{
        cin >> s;
        int res = 0;
        int n = strlen(s);
        for(int i = 0; i< n;i++)
        {
                if(s[i] != s[n-1-i])
                        res++;
        }
        cout << res/2<< endl;
}



Measured memory_bytes: 256