akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include<cstdlib>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

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

  vector<pair<int64_t, int64_t>> A;
  rep(i,N){
    int64_t a;
    cin >> a;
    A.push_back(make_pair(a, i));
  }

  vector<pair<int64_t, int64_t>> B;
  B = A;
  sort(A.begin(), A.end());

  vector<pair<int64_t, int64_t>> v;
  int64_t now = A.at(0).first;
  int64_t count = 1;

  for(int64_t i=1; i<N; i++){
    if(A.at(i).first != now){
      v.push_back(make_pair(count, now)); 
      count = 1;
      now = A.at(i).first;
    }else{
      count++;
    }
  }
  v.push_back(make_pair(count, now));

  int64_t zenbu = 0;
  for(int64_t i=0; i<v.size(); i++){
    zenbu += v.at(i).first * max(v.at(i).first-1, int64_t(0)) / 2;
  }

  int64_t withk = 0;
  vector<int64_t> ans(N+1, 0);

  for(int64_t i=0; i<v.size(); i++){
    int64_t k = v.at(i).second;
    ans.at(k) = zenbu - v.at(i).first + 1;
  }

  for(int64_t i=0; i<N; i++){
    int64_t k = B.at(i).first;
    cout << ans.at(k) << endl;
  }
  


  
}

Measured memory_bytes: 12396
#include <stdio.h>
#include <cmath>
#include <vector>
#include <iostream>

using namespace std;


int main(){
  int m,d;
  scanf("%d", &m);
  scanf("%d", &d);
  bool tbl[1000] = {};
  if(d<12||m<4){
    printf("0\n");
    return 0;
  }

  for(int i=4;i<=m;i++){
    tbl[i] = true;
  }

  long counter = 0;

  for(int i=22;i<=d;i++){
    int d1 = i % 10;
    int d10 = (i - d1) / 10;
    if(d1<2||d10<2)
      continue;
    counter = tbl[d1*d10] ? counter+1 : counter;
    //if (tbl[d1*d10]) cout << d10 << d1 << endl;
  }

  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#pragma GCC optimize("Ofast,no-stack-protector") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 
#pragma GCC optimize("unroll-loops") 
#pragma GCC optimize("fast-math")
  
#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
#define vec vector            
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
#define print(x) cout << (x) << endl;
  
#ifdef LOCAL
    #define dbg(x) cerr << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
  
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
  
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i; 
    }
    return str;
}
  
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
  
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();   
    return 0;
}
 
const int INF = 1e18, MAXN = 3e5 + 10;
 
void solve() {
    int n, k;
    cin >> n >> k;
    vec<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    vec<int> s(n + 1);
    s[1] = a[1] % k; 
    for (int i = 1; i <= n; ++i) {
        s[i] = (s[i - 1] + a[i]) % k;
    }
    for (int i = 1; i <= n; ++i) {
        s[i] = (s[i] - i + 10000000 * k) % k;
    }

    map<int, int> cnt;
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        if (i - k >= 0) {
            cnt[s[i - k]]--;
        }
        ans += cnt[s[i] % k];
        cnt[s[i] % k]++;
    }

    
    print(ans);
}   


Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, L;
	cin >> N >> L;
	int f = L;
	int l = L + N - 1;
	int sum = 0;
	REP(i, N)sum += L + i;
	if (f * l <= 0) {
		cout << sum << endl;
	}
	else {
		if (abs(f) >= abs(l)) {
			cout << sum - l << endl;
		}
		else {
			cout << sum - f << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Node {
    int value;
};

int H;
Node heap[250];

int main(void) {

    cin >> H;

    for (int i = 0; i < H; ++i) {
        scanf("%d", &heap[i].value);
    }

    for (int i = 0; i < H; ++i) {
        printf("node %d: key = %d, ", i + 1, heap[i].value);
        if (i != 0) {
            printf("parent key = %d, ", heap[(i - 1) / 2].value);
        }
        if (i * 2 + 1 < H) {
            printf("left key = %d, ", heap[i * 2 + 1].value);
        }
        if (i * 2 + 2 < H) {
            printf("right key = %d, ", heap[i * 2 + 2].value);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1228
from collections import deque

s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    f = [i for i in input().split()]
    if f[0] == '1':
        cnt += 1
    else:
        if f[1] == '1':
            if cnt % 2 == 0:
                ans.appendleft(f[2])
            else:
                ans.append(f[2])
        else:
            if cnt % 2 == 0:
                ans.append(f[2])
            else:
                ans.appendleft(f[2])
if cnt % 2 == 0:
    print(''.join(map(str,ans)))
else:
    ans2 = []
    for i in (reversed(ans)):
        ans2.append(i)
    print(''.join(map(str,ans2)))

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const ll MOD = 1000000007;
const int INF = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i=k; i<=n+1; i++)
    {
        ll res = i*i - i - 1;
        if(i * n < res)
            break;
        ans = (MOD + ans + i*n - res) % MOD;
    }
    cout << ans;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    long double a, b, c;
    cin >> a >> b >> c;
    long double eps = 1.0E-14;
    if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#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=1010;
const ll mod=1e9+7;

char data[310][310];
int outdata[310][310];

int h,w,k;
int cstraw[310];



int main() {
  cin >> h >> w >> k;
  for(int i=0; i<h; i++){
    cstraw[i]=0;
    for(int j=0; j<w; j++){
      cin >> data[i][j]; 
      if(data[i][j]=='#'){cstraw[i]++;}
    }
  } //map road

  int sn=1;
  int ff=0;
  for (int i=0; i<h; i++) { 
    int sc=0;
      
    if(cstraw[i]!=0){
    for (int j=0; j<w; j++) {
        outdata[i][j] = sn;
        if(data[i][j]=='#'){
          sc++;
          if(sc!=cstraw[i]){sn++;}
        }
    }
    if(ff!=0 && cstraw[i]!=0){
        for(int z=ff; 0<z; z--){
          for(int q=0; q<w; q++) { 
            outdata[i-z][q] = outdata[i][q]; 
          }
        }
        ff=0;
    }
    sn++;
      
    } else {
        ff++;
    }      
          

  }
  
  if(ff!=0){
    int lh = h-1-ff;
    for (int i=lh+1; i<h; i++) { 
      for (int j=0; j<w; j++) { 
        outdata[i][j] = outdata[lh][j]; 
      }
    }
  }

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cout << outdata[i][j];
      if(j!=w-1){cout <<" ";}
    }
    cout << endl;
  } //map road
  return 0;
}  


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
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 (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	int n;
	cin >> n;
	queue<int> que[n+10];
	rep(i,n) rep(j,n-1) {
		int a; cin >> a;
		que[i+1].push(a);
	}

	int cnt = 0,ok = 0;
	queue<int> pre;
	rep(i,n) pre.push(i+1);
	while(1){
		int flag = 0,flags[n+10] = {};
		queue<int> tmp;
		while(pre.size()){
			int i = pre.front(); pre.pop();
			if(flags[i]) continue;
			flags[i] = 1;
			if(!que[i].empty()){
				int j = que[i].front();
				if(flags[j]) continue;
				if(!que[j].empty()){
					if(i == que[j].front()){
						que[i].pop();
						que[j].pop();
						tmp.push(i),tmp.push(j);
						//cout << cnt << " " <<  i << " " << j << endl;
						flag = 1;
						flags[j] = 1;
					}
				}
			}
		}
		pre = tmp;
		cnt++;

		// no-judge
		if(!flag) break;
		// ok-judge
		int fin = 1;
		for(int i = 1; i <= n; i++) if(!que[i].empty()) fin = 0;
		if(fin){
			ok = 1;
			break;
		}
	}
	cout << (ok ? cnt : -1) << endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int r,g,b;
    cin>>r>>g>>b;
    int num=100*r+10*g+b;
    if (num%4==0)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int gcd(int s, int t){
  if(s>t)swap(s, t);
  if(s==0)return t;
  else return gcd(s, t%s);
}

int main(){
  int n, k;cin>>n>>k;
  int M=-1, div=-1;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    M=max(M, a);
    if(div==-1)div=a;
    else div=gcd(div, a);
  }
  if(k<=M && k%div==0)cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class A {
	int a, b, h;
public:
	void solve()
	{
		cin >> a >> b >> h;
		cout << ((a + b) * h / 2) << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
k = int(input())
s = 0
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
for i in range(1, 2*k):
    s += (7 * pow(10, i-1, k)) % k
    s %= k
    if s % k == 0:
        print(i)
        exit()
print(-1)

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

#define INF 1e9
using namespace std;

int main() {

    string S; cin >> S;
    int N;
    N = S.length();

    long long ans = 0;

    for (int bit = 0; bit < (1 << N-1); ++bit) { //2^(N-1)のbit全探索
        long long sum = 0;

        long long tmp = S[0] - '0'; //文字列を整数に
        for (int i = 0; i < N-1; ++i) {
            if (bit & (1 << i)) { //+が挿入されたと考える
                sum += tmp;
                tmp = 0;
            }

            tmp = tmp * 10 + S[i+1] - '0';
        }

        sum += tmp; //最後の数が足されていないので足す
        ans += sum;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = 998244353ll;

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<int> v;

int main(void){
	int n,m,p,q,i,j,k;
	ll tmp,ans=0ll;
	bool flag;
	string s,t;
	cin >> n;
	cin >> s;
	t = s;
	for(i=1; i*i<=n; ++i){
		if(n%i){
			continue;
		}
		if(i%2){
			v.push_back(i);
		}
		if(n/i==i){
			continue;
		}
		if((n/i)%2){
			v.push_back(n/i);
		}
	}
	sort(v.begin(),v.end());
	m = v.l_ength();
	vector<ll> w(m,0ll);
	for(i=0; i<m; ++i){
		p = v[i];
		q = n/v[i];
		add_mod(w[i],q*2);
		for(j=0; j<i; ++j){
			if(v[i]%v[j]){
				continue;
			}
			add_mod(w[i],MOD-w[j]);
		}
		tmp = 0ll;
		for(k=0; k<q; ++k){
			mul_mod(tmp,2ll);
			add_mod(tmp,s[k]-'0');
		}
		for(j=0; j<p; ++j){
			for(k=0; k<q; ++k){
				t[j*q+k] = ((j%2)?('0'+'1'-s[k]):s[k]);
			}
		}
		flag = true;
		for(j=0; j<n; ++j){
			if(s[j]<t[j]){
				flag = false;
				break;
			}else if(s[j]>t[j]){
				break;
			}
		}
		if(flag){
			add_mod(tmp,1ll);
		}
		mul_mod(tmp,w[i]);
		add_mod(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 772
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int n;
	int array[3010];
	int ans=0;
	int i;
	
	//データの読み込み
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	for(i=0;i<n;i++){
		ans=ans+array[i];
	}
	
	ans=ans-n;
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
}


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

using namespace std;

int main(void)
{
	int h,w;
	cin >> h >> w;
	string a[h];

	for(int i=1;i<=h;i++)
		cin >> a[i-1];

	int h_black[105]={},w_black[105]={};

	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		{
			if(a[i-1][j-1]=='#')
			{
				h_black[i-1]=1;
				w_black[j-1]=1;
			}
		}

	for(int i=1;i<=h;i++)
	{
		if(h_black[i-1]==1)
		{
			for(int j=1;j<=w;j++)
			{
				if(w_black[j-1]==1)
					cout << a[i-1][j-1];
			}
			cout << endl;
		}
	}
}
			
		

Measured memory_bytes: 256
from math import sqrt
sigma=[]
while True:
	total=0
	nval=0
	n=int(input())
	if n==0:
		break

	score_list=map(float,raw_input().split(" "))

	for i in score_list:
		total+=i

	average=total/n

	for i in score_list:
		nval+=(average-i)**2
	val=nval/n
	sigma.append(sqrt(val))

for i in sigma:
	print i

Measured memory_bytes: 6660
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

def win(c):
  if c=="r":
    return "p"
  elif c=="s":
    return 'r'
  else:
    return 's'
def rew(c):
  if c=='r':
    return r
  elif c=='p':
    return p
  else:
    return s
bef=[""]*k
ans=0
for i in range(n):
  mod=i%k
  hand=t[i]
  wi=win(hand)
  if not bef[mod]==wi:
    ans+=rew(wi)
    bef[mod]=wi
  else:
    bef[mod]=''
  
print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

vector<vector<int>> g;
// ダイクストラ法
// 参照：蟻本　p97
// O(mlogn)
struct edge{int to,cost;};
typedef pair<int,int> P; // firstは最短距離、secondは頂点の番号
 
vector<edge> G[200010];
int d[200010];
int n;
 
void dijkstra(int s){
    priority_queue<P,vector<P>, greater<P>> que;
    fill(d,d+n,INF);
    d[s]=0;
    que.push(P(0,s));
 
    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
 
int main(){
    int k;
    cin>>n>>k;

    rep(i,k){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back({b,1});
        G[b].push_back({a,1});
    }
 
    dijkstra(0);
    
    //cout<<d[n-1]<<endl;
    if(d[n-1]==2) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

}

Measured memory_bytes: 17836
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sort stable_sort
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for (int (i)=(1);(i)<=(x);(i)++)
#define rep2(i,x) for (int (i)=(x);(i)>=(1);(i)--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
using namespace std;
int n,m,i,j,fa[100005],g[18][18],deg[18];
multiset<int> e[100005];
int fnd(int x){
	if (fa[x]==x) return x;
	return fa[x]=fnd(fa[x]);
}
int main(){
	scanf("%d%d",&n,&m);
	if (m<n+2) {puts("No");return 0;}
	rep(i,m){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].insert(y);e[y].insert(x);
		deg[x]++;deg[y]++;
	}
	rep(i,n){
		if (deg[i]&1) {puts("No");return 0;}
	}
	rep(i,n) fa[i]=i;
	rep(i,n){
		if (e[i].size()==2){
			e[*(e[i].begin())].insert(*(e[i].rbegin()));
			e[*(e[i].rbegin())].insert(*(e[i].begin()));
			e[*(e[i].begin())].erase(i);
			e[*(e[i].rbegin())].erase(i); 
			e[i].clear();
		}
	}
	int s=0;
	rep(i,n)foreach(it,e[i]) if (*it>=i){
		s++;
	}
	if (s<6) {puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 15616
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define Temp template<typename T>
#define mem(a,b) memset(a,(b),sizeof(a))
typedef long long LL;
using namespace std;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}

LL n,m;

int main(){
	read(n);read(m);
	printf("%lld\n",abs((n-2)*(m-2)));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<ll,int>
#define ll __int64
//#define ll long long
int n,k;
int a[311111];
int pos[310];
int cnt[310];

void ip(){cout<<"IMPOSSIBLE"<<endl;}
void p(){cout<<"POSSIBLE"<<endl;}
int main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i];

	if(n==1){
		if(a[0]==k)p();
		else ip();
	}
	else {
		sort(a,a+n);
		int sa=a[1]-a[0];
		bool is=1;

		for(int i=1;i<n;i++)if(sa!=a[1]-a[0])is=0;
		if(is){
			rep(i,n){
				if(a[i]==k||a[i]>k&&(a[i]-k)%sa==0){p();return 0;}
			}
			ip();
		}
		else{
			p();
		}
	}

	return 0;
}


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

int main(){
    char s;
    cin >> s;
    if (s == 'A') cout << 'T' << endl;
    else if (s == 'T') cout << 'A' << endl;
    else if (s == 'C') cout << 'G' << endl;
    else cout << 'C' << endl;
}


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

int d[100005];//初始的数 

struct node{
	int b,c;
}a[100005];

int cmp(node x,node y){
	return x.c>y.c;//重载：按照更改的值排序 
}

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	cin>>d[i];
	sort(d,d+n);//升序排列 
	for(int i=0;i<m;i++)
	cin>>a[i].b>>a[i].c;//记录更改的pair 
	sort(a,a+m,cmp);//升序排列更改的pair 
	int tot=0;//遍历pair指针 
	ll count=0;//计数器 
	
	//关键，待研究 
	
	for(int i=0;i<n;i++){//外层循环存入的值，内层循环用pair更改小的值 
		if(d[i]<a[tot].c&&a[tot].b){//找比它小的数 
			count+=a[tot].c;
			a[tot].b--;
		}
		else count+=d[i];
		if(a[tot].b==0){//用光了就下一个 
			if(tot+1<m)
				tot++;
		}
	}
	cout<<count<<endl;
}

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

#define MAXN 100010

int n,ans[MAXN];

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

Measured memory_bytes: 1152
n, m = map(int, input().split())
state = []
for _ in range(m):
  lst = list(map(int, input().split()))
  state.append(lst[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
  total = 0
  for j in range(m):
    cnt = 0
    for s in state[j]:
      s -= 1
      if (i >> s) & 1:
        cnt += 1
    cnt %= 2
    if cnt == p[j]:
      total += 1
  if total == m:
    ans += 1
print(ans)

Measured memory_bytes: 9084
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
	char ch;
	int cnt[26] = {};
	
	while( cin >> ch ){
		ch = tolower(ch);
		if ( isalpha(ch) ){
			cnt[ch-'a']++;
		}
	}
	for ( int i = 0; i < 26; i++ ){
		printf("%c : %d\n", i+'a', cnt[i]);
	}

	return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e5 + 5;
ll n, m, ans, arr[N], cum[N];
map<ll, vector<ll>>mp;
ll zabat(ll a)
{
    a %= m;
    a += m;
    a %= m;
    return a;
}
ll add(ll a, ll b)
{
    a = zabat(a);
    b = zabat(b);
    return zabat(a + b);
}
ll sub(ll a, ll b)
{
    a = zabat(a);
    b = zabat(b);
    return zabat(a - b);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 0;i < n;++i)
    {
        cin >> arr[i];
        arr[i] = zabat(arr[i]);
        cum[i] = arr[i];
        if(i)   cum[i] = add(cum[i], cum[i - 1]);
        ans += !arr[i];
        mp[cum[i]].push_back(i);
    }
    for(int i = 0;i < n;++i)
    {
        ll want = sub(m, arr[i]);
        want = add(want, cum[i]);
        auto &v = mp[want];
        auto it = upper_bound(v.begin(), v.end(), i);
        ans += v.size() - (it - v.begin());
    }
    cout << ans;
    return 0;
}


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

int main() {
    int n;cin>>n;
    vector<pair<int,int>> a[n];
    for (int i=0;i<n-1;i++) {
        int b,c,d;cin>>b>>c>>d;
        a[b-1].push_back({c-1,d});
        a[c-1].push_back({b-1,d});
    }
    ll dist[n]{};
    int vis[n]{};
    queue<int> q;
    q.push(0);
    while (q.size()) {
        int v=q.front();q.pop();
        vis[v]=1;
        for (auto p:a[v])
            if (!vis[p.first]) {
                dist[p.first]=dist[v]+p.second;
                q.push(p.first);
            }
    }
    for (int i=0;i<n;i++)
        cout<<dist[i]%2<<endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){

  ios_base::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  map<string, bool> m;
  char last;
  string s; cin >> s;
  m[s] = 1;
  last = s[s.size()-1];
  for(int i  =1; i <n; i++)
  {
    cin >> s;
    if(s[0] != last || m[s]){
      cout << "No" << nl;
      return 0;
    }
    m[s] = 1;
    last = s[s.size()-1];
  }
  cout << "Yes" << nl;






  return 0;
}



Measured memory_bytes: 3624
N = int(input())
L = list(map(int, input().split())) # len(L) == N

def cond_1(i, j):
  return True if L[i] != L[j] else False

def cond_2(i, j, k):
  return True if L[i]+L[j]>L[k] and L[i]+L[k]>L[j] and L[j]+L[k]>L[i] else False

ret = 0

for i in range(0, N):
  for j in range(i+1, N):
    if cond_1(i, j): # condition 1
      for k in range(j+1, N):
        if cond_1(i, k) and cond_1(j, k): # condition 1
          if cond_2(i, j, k):
            ret += 1

print(ret) 





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

using namespace std;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

void sub()
{
    const auto   H(cin2var<size_t>());
    const auto   W(cin2var<size_t>());
    const auto   A(cin2var<size_t>());
    const auto   B(cin2var<size_t>());
    const string line0(string(A, '1') + string(W - A, '0'));
    const string line1(string(A, '0') + string(W - A, '1'));
    for (size_t i = 0; i < H; ++i) {
        if (i < B) {
            cout << line0 << endl;
        }
        else {
            cout << line1 << endl;
        }
    }
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    sub();
    return 0;
}

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

bool revp2(const pair<ll,ll>&a,const pair<ll,ll>&b){return a.first>b.first;}
bool revp3(const pair<ll,ll>&a,const pair<ll,ll>&b){if(a.first==b.first)return a.second<b.second;
return a.first>b.first;}

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll n,s=0;
    cin>>n;
    ll l1[n+2],l2[n+2];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
    }l1[0]=0,l1[n+1]=0;
    for(int i=1;i<=n;i++){
        if(i<n)l2[i]=abs(l1[i]-l1[i+2]);
        else l2[i]=abs(l1[n]);
        if(i==1||i==n)s+=abs(l1[i]);
        else s+=abs(l1[i]-l1[i-1]);
    }
    s+=abs(l1[n]-l1[n-1]);
    l2[0]=abs(l1[2]);
    //cout<<s<<endl;
    for(int i=1;i<=n;i++){
        cout<<s-abs(l1[i-1]-l1[i])-abs(l1[i]-l1[i+1])+l2[i-1]<<endl;
    }
}


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

vector<int> input(int N){
    int i;
    vector<int> out(N);

    for(i=0;i<N;i++)cin>>out[i];

    return out;
}

int main(){
    int N,i;
    int result=0;
    vector<int> A,B,C;
    cin>>N;
    A=input(N);
    B=input(N);
    C=input(N-1);

    for(i=0;i<N;i++){
        result+=B[A[i]-1];
        if(i>=1){
            if(A[i]-A[i-1]==1){
                result+=C[A[i-1]-1];
            }
        }
    }
    cout<<result<<endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())

t=[0]
x=[0]
y=[0]

for i in range(N):
    ti,xi,yi=map(int, input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)

can=True

for i in range(N):
    dt=t[i+1]-t[i]
    dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i])
    if dt<dist:
        can=False
    if dist%2 != dt%2:
        can=False

if can:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11728
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    map<char, int>mp;
    for(int i=0; i<s.size(); i++)
    {
        mp[s[i]]++;
    }
    int flag=0;
    for(auto it:mp)
    {
        if(mp.size()==2)
        {
            flag=1;
        }
    }

    if(flag==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
s = []
for i in range(m):
    inputs = list(map(int, input().split()))
    k = inputs[0]
    s.append(inputs[1:])

p = list(map(int, input().split()))

res = 0
for i in range(2 ** n):
    flag = True
    bit_i = bin(i)[2:].zfill(n)
    for j in range(m):
        sum_s = 0
        for idx in s[j]:
            sum_s += int(bit_i[idx-1])
        if sum_s % 2 != p[j]:
            flag = False
            break
    if flag:
        res += 1

print(res)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int a[100][100];
	int n,u,k,v;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			a[i][j]=0;
		}
	}
	for(int j=0;j<n;j++){
		cin>>u>>k;
		for(int i=0;i<k;i++){
			cin >>v;
			a[u-1][v-1]=1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout<<a[i][j];
			if(j!=n-1) cout << " ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define itn int
#define f(n) for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int> P;
signed main() {
	string a, b, c;
	char s = 'd';
	cin >> a >> b >> c;
	int x = 0, y = 0, z = 0;
	for (int i = 0;; i++) {
		if (s == 'a' || i == 0) {
			if (x == a.size()) {
				cout << 'A' << endl;
				return 0;
			}
			s = a[x];
			x++;
		}
		if (s == 'b') {
			if (y == b.size()) {
				cout << 'B' << endl;
				return 0;
			}
			s = b[y];
			y++;
		}
		if (s == 'c') {
			if (z == c.size()) {
				cout << 'C' << endl;
				return 0;
			}
			s = c[z];
			z++;
		}
	}
	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := newInputScanner(true, 64)
	H, W := sc.nextInt(), sc.nextInt()
	var answer int
	if H == 1 || W == 1 {
		answer = 1
	} else if H%2 == 0 {
		answer = (H / 2) * W
	} else if W%2 == 0 {
		answer = (H/2)*W + W/2
	} else {
		answer = (H/2)*W + W/2 + 1
	}
	fmt.Println(answer)
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	capacity := sizeInKB * 1024
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	i, e := strconv.Atoi(inputSc.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}


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

int X, N, bil;
bool ada[110];
int ans, diff=200;

int main () {
	cin >> X >> N;
	for(int i=0; i<N; i++) {
		cin >> bil;
		ada[bil] = true;
	}
	for(int i=0; i<=101; i++) {
		if (!ada[i]) {
			if (abs(i-X)<diff) {
				diff = abs(i-X);
				ans = i;
			}
		}
	}
	cout << ans << endl;
}


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

long long mod = 1000000000 + 7;

long long modplus(long long a, long long b){
	long long ans = a + b;
	ans %= mod;
	return ans;
}

long long modminus(long long a, long long b){
	long long ans = a - b;
	ans %= mod;
	if(ans < 0) ans += mod;
	return ans;
}

long long modmul(long long a, long long b){
	long long ans = (a % mod) * (b % mod);
	ans = ((ans % mod) + mod) % mod;
	return ans;
}

int main(){
	int N;
	cin >> N;
	long long A[N];
	long long sum[N];
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	sum[0] = A[0];
	for(int i=1;i<N;i++){
		sum[i] = modplus(A[i], sum[i-1]);
	}
	long long ans = 0;
	for(int i=0;i<N-1;i++){
		ans = modplus(ans,modmul(A[i], 
			modminus(sum[N-1], sum[i])));
	}
	cout << ans << endl;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
  gearup;
  ll h,w; cin >> h >> w;
  if(h % 3 == 0 || w % 3 == 0)out(0);
  else{
    ll res = L_INF;
    rep(j,2){
      swap(h,w);
      rep1(i,h){
        ll area1 = i * w;
        ll rest_h = h - i;
        ll area2 = (rest_h/2) * w;
        ll area3 = h*w - area1 - area2;
        ll ma = max(area1,max(area2,area3));
        ll mi = min(area1,min(area2,area3));
        res = min(res,ma-mi);
      }
      rep1(i,h){
        ll area1 = i * w;
        ll rest_h = h - i;
        ll area2 = rest_h * (w/2);
        ll area3 = h*w - area1 - area2;
        ll ma = max(area1,max(area2,area3));
        ll mi = min(area1,min(area2,area3));
        res = min(res,ma-mi);
      }
    }
    out(res);
  }
}

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

int main(){
  string N;
  cin>>N;
  int sum =0;
  
  if(N.at(0)=='1'){
    sum++;
  }
    if(N.at(1)=='1'){
    sum++;
  }
   if(N.at(2)=='1'){
    sum++;
  }
 
    
    cout<<sum<<endl;
}

Measured memory_bytes: 3588
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		HashSet<Integer> list = new HashSet<Integer>();

		for (int i = 1; i <= K; i++) {
			int A = sc.nextInt();
			for (int j = 1; j <= A; j++) {
				list.add(sc.nextInt());
			}
		}

		System.out.println(N - list.size());

	}

}

Measured memory_bytes: 46188
import sys
sys.setrecursionlimit(10**6)
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
t=[[""for i in range(w)] for j in range(h)]
t[0][0]=(1 if s[0][0]=="#" else 0)
def f(x,y):
    if t[x][y]!="":
        return t[x][y]
    else:
        t[x][y]=min((f(x-1,y)+(s[x][y]=="#" and s[x][y]!=s[x-1][y]) if x>0 else float("INF")),(f(x,y-1)+(s[x][y]=="#" and s[x][y]!=s[x][y-1]) if y>0 else float("INF")))
        return t[x][y]
print(f(h-1,w-1))

Measured memory_bytes: 3316
# include <iostream>
# define MOD 10007
# define MAX_N 1000

int n;
char  ch[MAX_N];
int s[MAX_N];
int dp[MAX_N][8];
int main() {
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> ch[i];
		if (ch[i] == 'J')
			s[i] = 1;
		else if (ch[i] == 'O')
			s[i] = 2;
		else if (ch[i] == 'I')
			s[i] = 4;
	}

	for (int i = 1; i <= 7; ++i) {
		if (i & 1 && i&s[0])
			dp[0][i] = 1;
	}

	for (int i = 1; i < n; ++i) {
		for (int j = 1; j <= 7; ++j) {
			for (int k = 1; k <= 7; ++k) {
				if (j&k&&j&s[i])
					dp[i][j] += dp[i - 1][k] % MOD;
			}
		}
	}
	int res = 0;
	for (int i = 1; i <= 7; ++i) {
		res += dp[n - 1][i] % MOD;
	}
	res %= MOD;
	std::cout << res << std::endl;
	return 0;
}

Measured memory_bytes: 1196
h,w=map(int,input().split())
a=[]
for i in range(h):
  at=list(str(input()))
  a.append(at)
i=0
j=0
t=0
while True:
  if j!=w-1:
    if a[i][j+1]=="#":
      for k in range(i+1,h):
        if a[k][j]=="#":
          t=1
          break
      else:
        j=j+1
  if i!=h-1:
    if a[i+1][j]=="#":
      for k in range(j+1,w):
        if a[i][k]=="#":
          t=1
          break
      else:
        i=i+1
  if t==1:
    print("Impossible")
    break
  elif i==h-1 and j==w-1:
    print("Possible")
    break

Measured memory_bytes: 9040
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
int main() {
	int n=0;
	string src;

	vector<char> ch;

	cin >> n;
	cin >> src;


	int max=0;
	int h = 0;
	string s1, s2;

	for (int i = 1; i < n-1; i++) {
		s1 = src.substr(0, i);
		s2 = src.substr(i, n-1);
		h = 0;
		for (auto e : s1) {
			auto res = find(ch.begin(),ch.end(), e);
			if (s2.find(e)!=string::npos && res==ch.end()) {
				h++;
				ch.push_back(e);
			}
		}
		if (max < h) {
			max = h;
		}
		ch.clear();

	}


	printf("%d",max);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 302;
ll dp[MAXN][MAXN], h[MAXN];
int main()
{
    int n, k; scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    n++;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= k; j++)
        {
            dp[i][j] = 1e16;
            for (int x = 0; x < i; x++) if (j - (i - x - 1) >= 0)
                dp[i][j] = min(dp[i][j], dp[x][j - (i - x - 1)] + max(0ll, h[i] - h[x]));
        }

    ll ans = 1e16;
    for (int i = 0; i <= k; i++) ans = min(ans, dp[n][i]);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int n;
long long h[100001];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	for(int i=n;i>1;i--)
	{
		if(h[i-1]-1>h[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
		else if(h[i-1]-1==h[i])
		{
			h[i-1]--;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**6)
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(N,dtype=int)
for i in range(1, N):
    s=max(0, i-K)
    dp[i] = min(dp[s:i]+abs(h[s:i]-h[i]))
print(dp[-1])

Measured memory_bytes: 22920
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 1000000000;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector <double> a(n);
  for (int i = 0; i < n; i++)
   cin >> a[i];
  ll l = 1, r = 1000000000;
  while (l < r){
    ll mid = (l+r)/2;
    double t = mid;
    ll bn = 0;
    for (int i = 0; i < n; i++){
      bn += ceil(a[i]/t) - 1;
      if (bn > k)
       break;
    }
    if (bn > k)
     l = mid + 1;
    else
     r = mid;
  }
  cout << l;
}

Measured memory_bytes: 4748
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    string s,t;
    
    cin >> s >> t;
    string ans;
    for(int i=0;i<N;i++){
        ans = ans + s[i] + t[i];
    }

    cout << ans <<"\n";

    return 0;
}

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

int main(){
  ll n; cin >> n;
  vector<ll> v;
  ll ans;
  ll m=0;
  rep(i,n){
    ll x; cin >> x;
    v.push_back(x);
    ans+=x*x;
    m=max(m,x);
  }
  rep(j,m){
    ll p=j;
    ll sum=0;
    rep(t,n){
      ll e=v[t-1];
      sum+=(e-p)*(e-p);
    }
    ans=min(ans,sum);
  }
  cout << ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main() {
  ll n,ans;
  ans=0;
  cin >> n;
  rep(i,4)if(DEC(n,10,i)==2)ans++;
  printf("%lld",ans);
}

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(a>=b){
        cout<<"delicious"<<endl;
    }else if(b-a<=x){
        cout<<"safe"<<endl;
    }else{
        cout<<"dangerous"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
str = input()
a = str.split(" ")
n = (int)(a[0])
k = (int)(a[1])
str = input()
before = ""
for ii in range(k-1):
  s = str + str[::-1]
  s1 = s[0:n]
  for i in range(1,n+1):
    s2 = s[i:n+i]
    if(s1>s2):
      s1 = s2
  str = s1[::-1]
  if(before==str):
    break
  before = str

s = str + str[::-1]
s1 = s[0:n]
for i in range(1,n+1):
  s2 = s[i:n+i]
  if(s1>s2):
    s1 = s2
print(s1)



Measured memory_bytes: 3064
let n = read_int ()

let arr = Array.make 100001 0

let rec f i odd even =
  if i = n then (odd, even)
  else
    let j = Scanf.scanf " %d" (fun a -> a) in
    if 0 = arr.(j) then (ignore (arr.(j) <- 1); f (i+1) (odd + 1) even)
    else if 1 = arr.(j) then (ignore (arr.(j) <- 2); f (i + 1) (odd - 1) (even + 1))
    else (ignore (arr.(j) <- 1); f (i + 1) (odd + 1) (even - 1))
    
let odd, even = f 0 0 0

let () = print_int (odd + even / 2 * 2)

Measured memory_bytes: 5376
n = int(input()) 
a = [int(item) for item in input().split()]

mina = min(a)
min_index = a.index(mina)
maxa = max(a)
max_index = a.index(maxa)

if abs(maxa) > abs(mina):
    sign = maxa
    sign_id = max_index
else:
    sign = mina
    sign_id = min_index

print(n + n-1)

if sign >= 0:
    for i in range(n):
        a[i] += sign
        print(sign_id+1, i+1)
    for i in range(n-1):
        a[i+1] += a[i]
        print(i+1, i+2)
else:
    for i in range(n):
        a[i] += sign
        print(sign_id+1, i+1)
    for i in range(n-1):
        a[n-i-2] += a[n-i-1]
        print(n-i, n-i-1)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int x = ReadInt();
        Console.WriteLine(10 - (x / 200));
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}


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

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

  int a,b;
  vector<vector<int>> graph(n+1);
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }

  vector<int> mark(n+1, 0);
  vector<int> canditate;
  canditate.push_back(1);
  while(canditate.size() > 0) {
    int now = canditate.at(0);
    //cout << now << endl;
    for(int i = 0; i < graph.at(now).size(); i++) {
      if (mark.at(graph.at(now).at(i)) == 0) {
        mark.at(graph.at(now).at(i)) = now;
        canditate.push_back(graph.at(now).at(i));
      }
    }
    canditate.erase(canditate.begin());
  }

  for(int i = 2; i <= n; i++) {
    if(mark.at(i) == 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for(int i = 2; i <= n; i++) {
    cout << mark.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 10480
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] h=new long[n];
		for(int i=0; i<n; i++){
			h[i]=sc.nextLong();
		}
		int ans=0;
		int count=0;
		for(int i=0; i<n-1; i++){
			if(h[i]>=h[i+1]){
				count++;
			}else{
				ans=Math.max(ans,count);
				count=0;
			}
		}
		ans=Math.max(ans,count);
		System.out.println(ans);
	}
}


Measured memory_bytes: 50648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i,n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
int main(){
    int n, m, tmp = 0, mod = 1e9+7; sc(n),sc(m);
    vector<int> a(m);
    if (m != 0) for (int i = 0; i < m; i++) sc(a[i]);

    vector<ll> dp(n+1, 1);
    if (m != 0 && a[tmp] == 1) dp[1] = 0, tmp = min(m-1, tmp+1);
    for (int i = 2; i <= n; i++){
        if (m == 0) dp[i] = (dp[i-1] + dp[i-2]) % mod;
        else if (a[tmp] == i) dp[i] = 0, tmp = min(m-1, tmp+1);
        else dp[i] = (dp[i-1] + dp[i-2]) % mod;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
package main

import "fmt"

func main() {
	var abcd string
	fmt.Scan(&abcd)

	len := 3
	count := 0
	for bit := 0; bit < (1 << uint(len)); bit++ {
		count++
		exp := abcd[0:1]
		eval := int(abcd[0] - '0')
		for i := 0; i < len; i++ {
			literal := abcd[i+1 : i+2]
			value := int(abcd[i+1] - '0')
			if (1 & (bit >> uint(i))) == 1 {
				exp += "+" + literal
				eval += value
			} else {
				exp += "-" + abcd[i+1:i+2]
				eval -= value
			}
		}

		if eval == 7 {
			fmt.Printf("%s=7\n", exp)
			return
		}
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(void)
{
	int len,i,j;
	char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	char b[26]={'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C'};
	char s[1001];
	
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len;i++){
		for(j=0;j<26;j++){
			if(s[i]==b[j]){
				s[i]=a[j];
				break;
			}
		}
	}
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 948