akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
#define downint greater<int>()
#define downchar greater<char>()
#define downstring greater<string>()
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a,ll mod){
  return modpow(a,mod-2,mod);
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,tmp,key,value;
  int a[LIMIT2]={0};
  map<ll,ll> b[LIMIT1];
  map<ll,ll> l;
  char s[LIMIT1];
  
  cin >> n;
  rep(i,n) cin >> a[i];
  
  rep(i,n){
    tmp = (ll)a[i];
    m = (ll)sqrtl(tmp);
    for(j=2;j<=m;j++){
      while(tmp%j==0){
        b[i][j]++;
        tmp /= j;
      }
    }
    if(tmp>=2) b[i][tmp]++;
    for (auto x : b[i]){
      key = x.first;
      value = x.second;
      l[key] = max(l[key],value);
    }
  }
  tmp = 1;
  for(auto x : l){
    key = x.first;
    value = x.second;
    tmp = (tmp * modpow(key,value,MOD1))%MOD1;
  }
  rep(i,n){
    result += (tmp*modinv(a[i],MOD1))%MOD1;
    result %= MOD1;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 14720
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 1505; 
using namespace std;

int n, m, cnt[N], sum[N][N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	n = read <int> (), m = read <int> (), n = (1 << n) - 1, m = (1 << m) - 1; 
	for(int i = 1; i <= n; i++) cnt[i] = cnt[i >> 1] + (i & 1); 
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) sum[i][j] = cnt[i & j] & 1; 
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
			printf("%d", sum[i][j] ^ sum[i - 1][j] ^ sum[i][j - 1] ^ sum[i - 1][j - 1]);
		puts(""); 
	}
	return 0; 
}


Measured memory_bytes: 9560
#D
N = int(input())
A = list(map(int,input().split()))

price=1000 #現金
stock=0 #株数
for n in range(N-1):
    next_ = n+1
    
    if A[n] < A[next_]: #買い
        if price >= A[n]:#買える場合
            stock = price//A[n]
            price = price - A[n]*stock
        
    elif A[n] > A[next_]: #売り
        price = price + A[n]*stock
        stock = 0
        
price = price + A[-1]*stock
stock = 0
print(price)

Measured memory_bytes: 9204
//
//AtCoder Beginner Contest 178
//D
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

const int mod = 1000000007;

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

    ll dp[2010];
    dp[0]=1;

    REP(i,s+1){
        if(i >= 3) dp[i] = dp[i-1] + dp[i-3];
        dp[i]%=mod;
    }
    cout << dp[s] << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,ex=0;cin>>h;
  while(h>=(1ll<<ex))ex++;

  assert(h<(1ll<<ex));

  cout<<(1ll<<ex)-1<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
(d,g),*a=$<.map{|s|s.split.map &:to_i}
p (0..1023).map{|b|n=e=0;s=g;a.map{|p,c|e+=100;b&1>0?(n+=p;s-=p*e+c):Q=p*E=e;b/=2};Q ? s>Q ? 1e4:s>0?n--s/E: n: n}.min

Measured memory_bytes: 2300
# include <iostream>
using namespace std;
int f[110];
int main()
{
	int n;
	cin>>n;
	int d;
	for(int i=0;i<n;i++)
	{
		cin>>d;
		f[d]++;
	}
	int ans=0;
	for(int i=1;i<=110;i++)
	{
		if(f[i]!=0)
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n)){
        char ss[100005]={'\0'};
        scanf("%s",ss);
        int ans=1;
        for(int i=1;i<n;i++){
            if(ss[i]!=ss[i-1]){
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,n,p,x,a;
	a=-1;
	x=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>p;
		if(p>a) a=p;
		x=x+p;
	}
	x=x-a/2;
	cout<<x<<endl;
	return 0;
}

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

#define ll long long
#define F first
#define S second

const int mod = 1000000007;
const int M = 100005;

int main() {
	int T = 1;
	// cin>>T;
	while(T--)
	{
		int n;	cin>>n;
		int k;	cin>>k;
		vector<int> v(n);
		for(int i=0; i<n; i++)	cin>>v[i];
		
		vector<int> dp(n);
		
		dp[0] = 0;
		
		for(int i=1; i<n; i++)
		{
			int mini = INT_MAX;
			for(int j=i-1; (j>=0 && j>=i-k); j--)
			{
				mini = min(mini, dp[j]+abs(v[i]-v[j]));
			}
			dp[i] = mini;
		}
		
		cout<<dp[n-1];
	}
	return 0;
}

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

int main(){
        int n, i, j, minj, buffer, num_s = 0;
        int *array;

        scanf("%d", &n);

        array = (int *)malloc(n * sizeof(int));

        for(i = 0 ; i < n ; i++){
                scanf("%d", &array[i]);
        }

        for(i = 0 ; i < n ; i++){
                minj = i;
                for(j = i ; j < n ; j++){
                        if(array[j] < array[minj]){
                                minj = j;
                        }
                }
                if(minj != i){
                        buffer = array[minj];
                        array[minj] = array[i];
                        array[i] = buffer;
                        num_s++;
                }
        }

        for(i = 0 ; i < n ; i++){
                printf("%d", array[i]);
                if(i + 1 != n)printf(" ");
        }
        printf("\n");

        printf("%d\n", num_s);

        return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)

// for debug macro
bool global_debug_flag = true;
#define DEBUG(val) \
  if (global_debug_flag) cout << #val << " = " << val << endl

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  c *= 2;
  int ans = 5000 * 100000 + 5000 * 100000;
  REP(i, 100001) {
    int rest_a = max(0, x - i);
    int rest_b = max(0, y - i);
    ans = min(ans, c * i + rest_a * a + rest_b * b);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int w = Integer.parseInt(sc.nextLine());
	static int[] res = new int[w];
	static int n = Integer.parseInt(sc.nextLine());
	static ArrayList<HorizLine> hL = new ArrayList<HorizLine>();

	public static void main(String[] args) {
		setHorizLine();
		drawLot();
	}

	private static void drawLot() {
		for (int i = 1; i <= w; i++) {
			int p = i;
			for (int j = 0; j < n; j++) {
					if (p == hL.get(j).getPointL() ) {
						p = hL.get(j).getPointR();
					} else if (p == hL.get(j).getPointR()) {
						p = hL.get(j).getPointL();
					}
			}

			res[p - 1] = i;
		}

		for (int i = 0; i < w; i++) {
			System.out.println(res[i]);
		}

	}

	private static void setHorizLine() {
		for (int i = 0; i < n; i++) {
			String[] pt = sc.nextLine().split(",");
			hL.add(new HorizLine( Integer.parseInt(pt[0]), Integer.parseInt(pt[1]) ));
		}

	}



}

 class HorizLine {
	private int pointL;
	private int pointR;

	HorizLine(int pointL, int pointR) {
		this.pointL = pointL;
		this.pointR = pointR;
	}

	public int getPointL() {
		return pointL;
	}
	public int getPointR() {
		return pointR;
	}
	public void setPointL(int pointL) {
		this.pointL = pointL;
	}
	public void setPointR(int pointR) {
		this.pointR = pointR;
	}


}


Measured memory_bytes: 26008
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    
    list<int> List;
            string S;
    for(int i = 0; i < N; i++){

        int X;
        cin >> S;
        
        // 入力・指定する数字を消すとき
        if(S.size() <= 6){
            cin >> X;
            
            // 入力するとき
            if(S[0] == 'i'){ List.push_front(X); }
            
            // 指定する数字を消すとき
            else{
                list<int>::iterator kasu_Posi = List.begin();
                while(kasu_Posi != List.end()){
                    if(*kasu_Posi == X){
                        List.erase(kasu_Posi);
                        break;
                    }
                    kasu_Posi++;
                }
            }
        }
        
        // 先頭を消すとき
        else if(S[6] == 'F'){ List.pop_front(); }
        
        // 最後尾を消すとき
        else{ List.pop_back(); }
    }
    
    // 出力する
    int i = 0;
    list<int>::iterator ans;
    for(ans = List.begin(); ans != List.end(); ans++){
        if(i++) cout << " ";
        cout << *ans;
    }
    cout << endl;
    
}



Measured memory_bytes: 34420
#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 <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}
ll ctoi(char c) {
    if (c == '0')return 0;
    else if (c == '1')return 1;
    else if (c == '2')return 2;
    else if (c == '3')return 3;
    else if (c == '4')return 4;
    else if (c == '5')return 5;
    else if (c == '6')return 6;
    else if (c == '7')return 7;
    else if (c == '8')return 8;
    else if (c == '9')return 9;
    else return -1;
}int main() {
    ll X;
    cin >> X;
    bool ok = false;
    for (ll i = -120; i <= 120; i++) {
        for (ll j = -120; j <= 120; j++) {
            if (pow(i, 5) - pow(j, 5) == X) {
                cout << i << " " << j << endl;
                ok = true;
                break;
            }
        }
        if (ok)break;
    }
}

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

class UnionFind{
private:
  vector<int> v;
  int cnt;
public:
  UnionFind(int n){
    v.resize(n);
    Init();
    cnt = n;
  }
  void Init(){
    for(int i=0,size=v.size();i<size;i++) v[i]=i;
  }
  int Find(int n){
    if(v[n] == n) return n;
    else return (v[n] = Find(v[n]));
  }
  bool Same(int a,int b){
    return (Find(a) == Find(b));
  }
  bool Union(int a,int b){
    if(Same(a,b)) return false;
    v[Find(a)] = Find(v[b]);
    cnt--;
    return true;
  }
  int getCnt(){ return cnt; }
};

struct Edge{
  int a,b,c;
  Edge(int aa,int bb,int cc):a(aa),b(bb),c(cc){}
};

bool operator<(Edge e1,Edge e2){
  return (e1.c < e2.c);
}

int Kruskal(vector<Edge> &Edges,vector<bool> &active,UnionFind &uf){
  int ans = 0;
  for(int i=0,size=Edges.size();i<size;i++){
    if(active[Edges[i].a] && active[Edges[i].b] && uf.Union(Edges[i].a,Edges[i].b))
      ans += Edges[i].c;
  }
  return ans;
}

bool check(vector<Edge> &e,vector<bool> &a){
  UnionFind uf(a.size());
  for(int i=0,sz=e.size();i<sz;i++){
    if(a[e[i].a] && a[e[i].b]) uf.Union(e[i].a,e[i].b);
  }
  int cnt=0;
  for(int i=0,sz=a.size();i<sz;i++) cnt += !a[i];
  return (cnt + 1 ==  uf.getCnt());  
} 

int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    map<int,vector<int> > ivmap;
    for(int i=0;i<n;i++){
      int h;
      cin>>h;
      ivmap[h].push_back(i);
    }
    vector<vector<int> > v;
    for(map<int,vector<int> >::iterator it=ivmap.begin();it!=ivmap.end();it++){
      v.push_back(it->second);
    }
    vector<Edge> Edges;
    Edges.reserve(m);
    for(int i=0;i<m;i++){
      int a,b,c;
      cin>>a>>b>>c;
      a--;
      b--;
      Edges.push_back(Edge(a,b,c));
    }
    sort(Edges.begin(),Edges.end());
    vector<bool> active(n,true);
    int i;
    UnionFind uf(n);
    if(!check(Edges,active)){
      cout<<0<<endl;
    }else{
      for(i=0;i<v.size();i++){
	for(int j=0,sz=v[i].size();j<sz;j++) active[v[i][j]]=false;
	if(!check(Edges,active)) break;
      }
      for(int j=0,sz=v[i].size();j<sz;j++) active[v[i][j]]=true;
      int ans = Kruskal(Edges,active,uf);
      for(i--;i>=0;i--){
	for(int j=0;j<v[i].size();j++) active[v[i][j]]=true;
	ans += Kruskal(Edges,active,uf);
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1500
use proconio::input;
use proconio::marker::Usize1;

struct ToCulc<'a> {
  N: usize,
  M: usize,
  Q: usize,
  A: &'a [(usize, usize, usize, usize)],
  max: usize
}

impl <'a>ToCulc<'a> {
  pub fn culc(&mut self, inner_stack: &mut Vec<usize>) {
    if inner_stack.len() == self.N + 1 {
      let mut temp = 0;
      for j in self.A.iter() {
        if inner_stack[j.1] - inner_stack[j.0] == j.2 {
          temp += j.3;
        }
      }
      self.max = std::cmp::max(self.max, temp);
      return
    }
    
    let last_len = inner_stack.len() - 1;
    while inner_stack[last_len] <= self.M {
      let mut new_stack = inner_stack.clone();
      new_stack.push(*new_stack.last().unwrap());
      self.culc(&mut new_stack);
      inner_stack[last_len] += 1;
    }
  }
}

fn main() {
  input! {
    N: usize,
    M: usize,
    Q: usize,
    A: [(Usize1, Usize1, usize, usize);Q]
  }
  
  let mut to_culc = ToCulc {
    N, M, Q, A: &A, max: 0
  };
  
  let mut stack: Vec<usize> = vec![1];
  to_culc.culc(&mut stack);
  
  println!("{}", to_culc.max);
}

Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <string>

int main(int argc, char **argv)
{
        int num = 0, diff = 0;
        std::string answer = "Yes";
        std::vector<int> hight;
        std::cin >> num;
        for(int i = 0; i < num; i++)
        {
                int hightBuff;
                std::cin >> hightBuff;
                hight.push_back(hightBuff);
        }
        hight[0]--;
        for(int i = 1;i < num; i++)
        {
                if(hight[i-1]<hight[i])
                {
                        hight[i]--;
                }
                else if(hight[i-1] > hight[i])
                {
                        answer = "No";
                        break;
                }
        }
        std::cout << answer << std::endl;
        return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define up(j,k,i) for(ld i=j;i<k;i+=0.5)
#define down(j,k,i) for(ld i=j;i>k;i-=0.5)
#define M 1000000007
#define pp(n) printf("%lld\n",ll(n))
#define ps(n) printf("%lld ",ll(n))
#define pd(x,y) printf("%lld %lld\n",ll(x),ll(y))
#define is(n) scanf("%lld",&n)
#define inf LLONG_MAX
#define id(n,m) scanf("%lld%lld",&n,&m)
#define it(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define pb push_back
#define F first
#define S second
#define pll pair<ll,ll> 
#define db cout<<"######\n"
#define null(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,255,sizeof(a))
typedef long double ld;
typedef long long int ll;
using namespace std;
ll i,j,k,z,n,m,sum,ans,x,y,maxm=0,minm=inf; bool flag;
map<ld,ld> lim,a; ll t[20005];ld v[20005];
int main()
{
	is(n); ld ans=0;
	
	for(int i=1;i<=n;i++)
	cin>>t[i],t[i]+=t[i-1];
	
	for(int i=1;i<=n;i++)
	cin>>v[i];
	
	for(int i=1;i<=n;i++)
	{
		lim[t[i-1]]=min(lim[t[i-1]],v[i]);
	
		up(t[i-1]+0.5,t[i]+0.5,j)
		lim[j]=v[i];
		
		
	}
	
	up(0.5,t[n]+0.5,i)
	{
		a[i]=min(a[i-0.5]+0.5,lim[i]);
	}
	
	a[t[n]]=0;
	
	down(t[n]-0.5,0,i)
	{
		a[i]=min(a[i+0.5]+0.5,a[i]);
	}
	
	
	
	up(0.5,t[n]+0.5,i)
	{
		if(a[i]>a[i-0.5])
		ans+=(a[i-0.5]+a[i])/4;
		else
		if(a[i]<a[i-0.5])
		ans+=(a[i-0.5]+a[i])/4;
		else
		ans+=a[i]/2;
		
		//cout<<i<<" "<<a[i]<<" "<<ans<<endl;
	}
	
	printf("%0.9LF",ans);
		
		
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    int k = 0;
    for (int i = 0; i < n; i++)
    {
        if (p[i] != i + 1)
        {
            k += 1;
        }
    }

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


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b;
    char op;
    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if(op=='?'){
            break;
    	}else if(op=='+'){
    	    printf("%d\n", a+b);
    	}else if(op=='-'){
    	    printf("%d\n", a-b);
    	}else if(op=='*'){
    	    printf("%d\n", a*b);
    	}else if(op=='/'){
    	    printf("%d\n", a/b);
        }
    }
    return 0;
}


Measured memory_bytes: 2040
import numpy as np
import sys
line = sys.stdin.readline

H, W = map(int, line().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
left = np.zeros((H + 2, W + 2), np.int32)
right = np.zeros((H + 2, W + 2), np.int32)
up = np.zeros((H + 2, W + 2), np.int32)
down = np.zeros((H + 2, W + 2), np.int32)

# 下方向に照らせるマスの数（自分の場所含む）
down[H] = grid[H]
for i in range(H, 0, -1):
    down[i - 1] = (down[i] + 1) * grid[i - 1]

up[1] = grid[1]
for i in range(1, H):
    up[i + 1] = (up[i] + 1) * grid[i + 1]

right[:, W] = grid[:, W]
for i in range(W, 0, -1):
    right[:, i - 1] = (right[:, i] + 1) * grid[:, i - 1]

left[:, 1] = grid[:, 1]
for i in range(1, W):
    left[:, i + 1] = (left[:, i] + 1) * grid[:, i + 1]

answer = (left + right + up + down - 3) * grid
print(np.max(answer))

Measured memory_bytes: 126100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    // 整数の入力
    int N,x,y;
    cin >> N;

    x = 800 * N;
    y = 200 * (int)(N / 15);

  	cout << x -y << endl;
    return 0;
}

Measured memory_bytes: 256
from functools import reduce
from operator import itemgetter

N, M = map(int, input().split())
a, b = (
    zip(*(map(int, input().split()) for _ in range(M))) if M else
    ((), ())
)

# bについてソートし、橋を取り除く必要があれば可能な限り東の橋を取り除く
ans, _ = reduce(
    lambda acc, q: (
        (acc[0] + 1, q[1]) if q[0] >= acc[1] else
        acc
    ),
    sorted(zip(a, b), key=itemgetter(1)),
    (0, 0)
)

print(ans)


Measured memory_bytes: 58088
from math import atan,degrees
a,b,x = map(int,input().split())
s = a**2
if x>=s*b/2:
  k = 2*x/s-b
  print(degrees(atan((b-k)/a)))
else:
  i = 2*x/a/b
  print(degrees(atan(b/i)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//桁数
int f(ll x) {
   int keta = 0;
   while(x > 0) {
       x /= 10;
       keta++;
   }
    return keta;
}

//約数列挙
vll d;
void divisor(ll n) {
   for(ll i = 1; i * i <= n; i++) {
       if(n % i == 0) {
           d.push_back(i);
           if(i * i != n) d.push_back(n / i);
       }
   }
   sort(all(d));
   return;
}

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

    divisor(n);

    int ans = 114514;
    rep(i, d.size()) {
        int tmp = max(f(d[i]), f(d[d.size() - 1 - i]));
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int mem[301][301][301];
string a;
int dp(int x, int y, int z){

  if(x>y)
    return 0;

  if(mem[x][y][z]!=-1)
    return mem[x][y][z];

  int res=0;
  if(a[x]==a[y]){
    if(x==y)
      res=max(max( 1+dp(x+1,y-1, z), dp(x+1, y, z)), dp(x, y-1, z));
    else
      res=max(max( 2+dp(x+1,y-1, z), dp(x+1, y, z)), dp(x, y-1, z));
  }
  else{
    if(x==y){
      if(z>0)
        res=max(max( 1+dp(x+1,y-1, z-1), dp(x+1, y, z)), dp(x, y-1, z));
      else
        res=max(dp(x+1, y, z), dp(x, y-1, z));
    }
    else{
      if(z>0)
        res=max(max( 2+dp(x+1,y-1, z-1), dp(x+1, y, z)), dp(x, y-1, z));
      else
        res=max( dp(x+1, y, z), dp(x, y-1, z));
    }
  }
//  cout<<x<<" "<<y<<" "<<z<<"=="<<res<<endl;
  mem[x][y][z]=res;
  return res;
}

int main(){
  int k;
  while(cin>>a>>k){
    memset(mem, -1, sizeof mem);
    int ans, n;
    n=a.size();
    --n;
    ans=dp(0, n, k);
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 106752
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	string s;
	cin >> n >> s;
	vi east(n + 1, 0), west(n + 1, 0);
	rep(i, 0, n) {
		if (s[i] == 'E') {
			east[i + 1] = east[i] + 1;
			west[i + 1] = west[i];
		}
		else {
			west[i + 1] = west[i] + 1;
			east[i + 1] = east[i];
		}
	}
	int ans = INF;
	rep2(i, 0, n) {
		ans = min(ans, west[i] + (east[n] - east[i]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){

    long N;
    std::cin >> N;
    long A[100000]={};
    for(long i=0; i<N; i++){
        std::cin >> A[i];
    }
    long Q;
    std::cin >> Q;
    long B[100000]={};
    long C[100000]={};
    for(long i=0; i<Q; i++){
        std::cin >> B[i] >> C[i];
    }

    long num[100000+1]={};
    for(long i=0; i<100000+1; i++){
        num[i]=0;
    }
    long sum=0;
    for(long i=0; i<N; i++){
        num[A[i]]++;
    }

    for(long i=0; i<100000+1; i++){
        sum+=i*num[i];
    }

    for(long i=0; i<Q; i++)
    {
        sum-=B[i]*num[B[i]];
        sum+=C[i]*num[B[i]];
        num[C[i]]+=num[B[i]];
        num[B[i]]=0;
        std::cout << sum << std::endl;
    }
    return 0;
}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int n,q;cin>>n>>q;
  map<int,int> m;
  for(int i=0;i<n+q;i++){
    int a;cin>>a;m[a]++;
  }
  std::vector<int> ans;
  int c=0;
  for(auto p:m){
    if(p.second==2)ans.push_back(p.first);c++;
  }
  cout<<ans.size()<<" "<<c<<endl;
  for(int p:ans)cout<<p<<endl;
  for(auto p:m)cout<<p.first<<endl;
}



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

using namespace std;

#define sz(a) int(a.size())

const int MOD = 1e9+7;
int res[22][1<<21];
int n, C [22][22];
int dp(int id, int wom) {
	if (id < 0) return 1;
	if (res[id][wom] != -1) return res[id][wom];
	int w = 0;
	for (int j = 0; j < n; j++) {
		if (wom&(1<<j) && C[id][j]) {
			w += dp(id-1, wom^(1<<j));
			if (w >= MOD) w -= MOD;
		}
	}
	return res[id][wom] = w;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cin >> C[i][j];
	}

	memset(res, -1, sizeof(res));
	cout << dp(n-1, (1<<n)-1) << endl;
}


Measured memory_bytes: 180608
#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<stack>
#include<algorithm>
#include<climits>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define vll vector<ll>
#define mii map<ll, ll>
#define debug(x) cerr << #x << " is " << x << "\n";
#define debug1(x, y) cerr << #x << " is " << x << "\n" << #y << " is " << y << "\n";
#define w(x) ll x; cin >> x; while(x--)
#define endl "\n"
#define f first 
#define s second 
#define fo(n) for(ll i = 0LL; i < n; ++i) 
#define setbits(n) __builtin_popcount(n)
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(x.begin(), x.end())
#define pb push_back
#define mk make_pair
#define PERMUTE next_permutation
#define RESET(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
using namespace std;
 
int main(){
    fast
    ll n, m, x, ans = INT_MAX;
    cin >> n >> m >> x;
    vector<ll> c(n, 0);
    vector<vector<ll>> a(n, vector<ll>(m, 0));
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }

    ll all = 1 << n;
    for(int mask = 0; mask < all; ++mask) {
        ll cost = 0;
        vector<ll> here(m);
        fo(n) {
            if((mask >> i) & 1) {
                cost += c[i];
                for(int j = 0; j < m; ++j) {
                    here[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        fo(m) {
            if(!(here[i] >= x)) ok = false; 
        } 
        if(ok) ans = min(ans, cost);
    }
    if(ans == INT_MAX) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }
    
    return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    String[] str = in.readLine().split(" ");
    int[] count = new int[100003];
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(str[i]);
      count[a[i]]++;
      count[a[i]+1]++;
      count[a[i]+2]++;
    }
    in.close();
    
    Arrays.sort(count);
    System.out.println(count[100002]);
  }
}

Measured memory_bytes: 46224
#include <iostream>
#include <cstdio>

using namespace std;

int n, ans;
int a[100005];

int main()
{
    scanf("%d", &n);
    n--;
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n - 1; i++) ans += min(a[i], a[i + 1]);
    printf("%d", ans + a[0] + a[n - 1]);
    return 0;
}


Measured memory_bytes: 256
a,b,ab,x,y=map(int,input().split())
total=0
if a+b>2*ab:
    total+=min(x,y)*2*ab
    if x>y:
        x-=y
        if a>=2*ab:
            total+=2*ab*x
        else:
            total+=a*x
    elif x<y:
        y-=x
        if b>=2*ab:
            total+=2*ab*y
        else:
            total+=b*y
else:
    total+=a*x+b*y
print(total)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int K;
int N;
int ans[1145][1145];

int main() {
  scanf("%d", &K);

  if (K == 1) {
    puts("1\n1");
    return 0;
  }
  
  N = (K/4 + (K%4 != 0))*2;
  assert(N <= 500);

  rep(i, N) {
    rep(j, N) {
      int t = 0;
      if (i%2) t = N;
      int c = t + (i+j)%N;
      if (c >= K) c -= N;
      ans[i][j] = c;
    }
  }
 
  printf("%d\n", N);
  rep(i, N) {
    rep(j, N) {
      printf("%d%c", 1+ans[i][j], " \n"[j == N-1]);
    }
  }
}


Measured memory_bytes: 5248
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N,M;
        Map<String,Integer> list = new HashMap<>();
        N = sc.nextInt();
        for(int a=0;a<N;a++){
            String s = sc.next();
            if(list.containsKey(s)!=true) list.put(s,1);
            else{
                int num = list.get(s)+1;
                list.remove(s);
                list.put(s,num);
            }
        }
        M =sc.nextInt();
        for(int a=0;a<M;a++){
            String s = sc.next();
            if(list.containsKey(s)!=true) list.put(s,1);
            else{
                int num = list.get(s) -1;
                list.remove(s);
                list.put(s,num);
            }
        }
        int price = Collections.max(list.values());
        if(price>0) System.out.println(price);
        else System.out.println(0);
         }
}

Measured memory_bytes: 21844
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

m1 = m2 = m3 = mi = 0
for i in range(n):
    m1 += abs(x[i]-y[i])
    m2 += (x[i]-y[i])**2
    m3 += (abs(x[i]-y[i]))**3
    mi = max([abs(x[i]-y[i]), mi])
print(m1)
print(m2**0.5)
print(m3**(1/3))
print(mi)


Measured memory_bytes: 5648
#include <bits/stdc++.h>
 
using namespace std;
 
#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353
#define PI_2 1.57079632679489661923


int main() {
    ll tt = 1, n, m, l, r, c, i, j, k, w, x, y;
    boost;
    
    // cin >> tt;
    ll ans = 1001;

    for(int _ = 1; _ <= tt; _++) {
        // cout << "Case #" << _ << ": ";
        string s, t;
        cin >> s >> t;
        n = s.size(), r = t.size();

        for(int j = 0; j <= n - r; j++){
            c = 0;
            for(int i = 0; i < r; i++){
                if(s[j+i] != t[i]) c++;
            }
            ans = min(ans, c);
        }

        cout << ans << nl;
    }
}

Measured memory_bytes: 3656
n = int(input())

combi = [[0]]
for i in range(1, n):
    new = []
    for item in combi:
        for t in range(0, max(item) + 2):
            new.append(item + [t])
    combi = new

dicter = {0:"a", 1:"b", 2:"c", 3:"d", 4:"e", 5:"f", 6:"g", 7:"h", 8:"i", 9:"j"}

for i in combi:
    print("".join([dicter[j] for j in i]))


Measured memory_bytes: 77276
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define int int64_t
//#pragma GCC optimize("trapv")
#define float double
#define PI acos(-1);
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a<b;
}
///Solution created by:Ahmadsm2005
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("output.txt","r", stdin);
//iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a,b,h;
cin>>a>>b>>h;
cout<<(h*(a+b)/2);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 3006;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

int n;
int a[MAXN];
int dp[MAXN][MAXN];

int solve(int i, int j, int curr){
	if(i == j){
		return curr * a[i];
	}
	if(dp[i][j] != -1){
		return dp[i][j];
	}
	if(curr > 0){
		return dp[i][j] = max((curr * a[i]) + solve(i+1, j, curr*-1), (curr * a[j]) + solve(i, j-1, curr*-1));
	} else {
		return dp[i][j] =  min((curr * a[i]) + solve(i+1, j, curr*-1), (curr * a[j]) + solve(i, j-1, curr*-1));
	}
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    memset(dp, -1, sizeof(dp));
    FOR(i, 0, n){
    	cin>>a[i];
    }
    cout<<solve(0, n-1, 1)<<endl;
    return 0;
}


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

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

  float num = N;

  if(N % 2 == 0){
    cout << 0.5 << endl;
  }else {
    cout << (N / 2 + 1) / num << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt(),s=sc.nextInt(),ans=0;
		for(int i=0;i<=k;i++) {
			for(int j=0;j<=k;j++) {
				int num=s-i-j;
				if(0<=num&&num<=k)ans++;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23764
n=int(input())
a=list(map(int,input().split()))

a.sort()
if a[0]==0:
  print(0)
  
else:
  s=1
  for i in a:
    s*=i
    if s>10**18:
      print(-1)
      exit()
      
  print(s)
      
  
      

Measured memory_bytes: 21468
s = input()
n = len(s) + 1
v = [0]*n

for i in range(n-1):
    if s[i] == "<":
        v[i+1] = v[i] + 1

for j in range(n-1):
    if s[-j-1] == ">":
        if v[-j-2] <= v[-j-1]:
            v[-j-2] = v[-j-1] + 1

print(sum(v))

Measured memory_bytes: 23380
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  string s; cin >> s ;
  int n=s.size();
  rep(i,n)printf("x");
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;
vi a;

int Ind(int i){
	return (i+n)%n;
}

vvl dp;

ll Rec(int s,int t){
	if(dp[s][t]) return dp[s][t];
	if(s==t) return 0;
	int S=s,T=t;
	int l=a[Ind(s-1)],r=a[t];
	if(l<r) T=Ind(t+1);
	else S=Ind(s-1);
	if(S==T) return 0;
	return dp[s][t]=max(Rec(Ind(S-1),T)+a[Ind(S-1)],Rec(S,Ind(T+1))+a[T]);
}

int main(){
	cin>>n;
	a=vi(n);
	dp=vvl(n,vl(n));
	for(int i=0;i<n;i++) cin>>a[i];
	ll ans=0;
	for(int i=0;i<n;i++) ans=max(ans,Rec(i,Ind(i+1))+a[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 65704
#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
int main(){
	long long k;
	string s;
 
	cin >> k;
	cin >> s;
 
	if(s.size() > k){
		s = s.substr(0,k) + "...";
	}

	cout << s << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void)
{
    int f[11];
    int a,b,c;
    while (scanf("%d%d%d",&a,&b,&c) != EOF) {
        int i, c=0;
        int s = a+b;
        for (i=1; i<=10; ++i) f[i]=0;
        f[a]=f[b]=f[c]=1;
        for (i=1; i<=10; ++i)
            if (!f[i] && a+b+i<=20) c++;
        puts(2*c >= 7 ? "YES" : "NO");
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3],b=0;
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0]==5) b++;
  if(a[1]==5) b++;
  if(a[2]==7) b++;
  if(b==3&&a[0]+a[1]+a[2]==17) cout<<"YES";
  if(b!=3) cout<<"NO";
  cout<<"\n";
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int n,s,i,ave;
    
    while(1){
    int sum=0,max=0,min=0;
    scanf("%d",&n);
    if(n==0) break;
    else{
    for(i=0;i<n;i++)
    {
        scanf("%d",&s);
        if(i==0) min=s;
        sum+=s;
        if(s>max) max=s;
        else if(s<min) min=s;
    }
    ave=(sum-(max+min))/(n-2);
    printf("%d\n",ave);
    }
    }
    return 0;
}



Measured memory_bytes: 1984
// https://atcoder.jp/contests/dp/tasks/dp_h
#include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fored(i, l, r) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout << #x << " " << x << el
#define ri(n) scanf("%d", &n)
#define vec vector
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<char, int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MAXN = 1e5 + 200;
const double PI = acos(-1);
const double EPS = 1e-10;
const int MOD = 1e9 + 7;
int dr[] = {1, -1, 0, 0, 1, -1, -1, 1}; // trick to explore an implicit 2D grid
int dc[] = {0, 0, 1, -1, 1, 1, -1, -1};

int main() {
  int H, W;
  cin >> H >> W;
  int mem[H + 1][W + 1];
  char mat[H + 1][W + 1];
  memset(mem, 0, sizeof(mem));
  for1(i, H) {
    for1(j, W) { cin >> mat[i][j]; }
  }
  mem[1][1] = 1;
  for1(i, H) {
    for1(j, W) {
      if (i != 1 || j != 1)
        mem[i][j] = ((mat[i - 1][j] == '.' ? mem[i - 1][j] : 0) +
		     (mat[i][j - 1] == '.' ? mem[i][j-1] : 0))%MOD;
    }
  }

  cout << mem[H][W] << el;
}


Measured memory_bytes: 5120
/*
 * Welcome to my code!
 * -------------------------------------------- *
 * author : lynmisakura(twitter : @andoreiji11)
 */

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

//Simple Array Input
#define SAI int n;cin >> n;vi a(n);ain(a)
//Simple Graph Input
#define SGI(m) for(int i=0;i<m;i++){int a,b;cin >> a >> b;g[--a].pb(--b);g[b].pb(a);}
//Simple Tree Input
#define STI SGI(n-1)

typedef long long ll;
typedef long long integer;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){
    for(int i=0;i<a.size();i++)cout << a[i] << (i < a.size()-1 ? ' ' : '\n');
}

int ans[110][110];

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

  int h,w;cin >> h >> w;
  int n;cin >> n;
  vector<int> a(n);rep(i,n)cin >> a[i];

  queue<pair<int,int>> Q;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(i % 2 == 0){
        Q.push(mp(i,j));
      }else{
        Q.push(mp(i,w-1-j));
      }
    }
  }

  for(int i = 0;i < n;i++){
    for(int j = 0;j < a[i];j++){
      auto p = Q.front();Q.pop();
      ans[p.first][p.second] = i+1;
    }
  }

  rep(i,h){
    rep(j,w)cout << ans[i][j] << (j < w - 1 ? ' ' : '\n');
  }

  return 0;
}


Measured memory_bytes: 512
n,m=list(map(int,input().split()))
s=input()
a=[0]*(n+1)
a[0]=1

for i in range(1,n+1):
    if s[i]=='1':
        continue
    for j in range(max(0,i-m),i):
        if s[j]=='1':
            continue
        if a[j]>0:
            break
    
    a[i]=i-j

ans=''

cur=n
while cur>0:
    d=a[cur]
    cur-=d
    if d==0:
        print(-1)
        exit(0)

    ans=str(d)+' '+ans

print(ans[:-1])

Measured memory_bytes: 220948
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp(a,b) make_pair(a, b)
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    map<int, int> c;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans = max(ans, ++c[x-1]);
        ans = max(ans, ++c[x]);
        ans = max(ans, ++c[x+1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736