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

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int N, M;
  double ans;
  cin >> N;
  M = N/2;
  ans = (double)(N-M)/(double)N;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to; lint cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;
const double Pi = acos(-1.0);

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2, mod) % mod * modpow(fact[r], mod - 2, mod) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

lint xor128() {
	static lint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	lint t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

double dis(D a, D b) {
	double x = a.first - b.first, y = a.second - b.second;
	return sqrt(x * x + y * y);
}

class unionfind {
private:
	int par[2 * 100010], ranks[2 * 100010], sizeth[2 * 100010];
public:
	void init(int n) {
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			ranks[i] = 0;
			sizeth[i] = 1;
		}
	}

	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (ranks[x] < ranks[y]) {
			par[x] = y;
			sizeth[y] += sizeth[x];
		}
		else {
			par[y] = x;
			if (ranks[x] == ranks[y]) ++ranks[x];
			sizeth[x] += sizeth[y];
		}
	}
};

lint n, ans;
lint a[100010];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (i == 0) ans = a[i];
		else ans = gcd(ans, a[i]);
	}
	cout << ans << endl;
}

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

bool equal(map<char, int> m1, map<char, int>m2) {
	for (char c = 'a'; c <= 'w'; c++)
	{
		if (m1[c] != m2[c]) return false;
	}
	for (char c = 'y'; c <= 'z'; c++)
	{
		if (m1[c] != m2[c]) return false;
	}
	return true;
}


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	string s;
	cin >> s;
	
	int l = 0, r = s.size() - 1;
	int ans = 0;
	bool flag = true;
	while (l < r) {
		while (s[l] == 'x') l++;
		while (s[r] == 'x') r--;

		if (s[l] != s[r]) {
			flag = false;
			break;
		}
		l++; r--;
	}

	if (flag) {
		l = 0; r = s.size() - 1;
		while (l < r)
		{
			if (s[l] != s[r]) {
				ans++;
				if (s[l] == 'x') l++;
				else r--;
			}
			else {
				l++; r--;
			}
		}
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}

}



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

	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
c=s.count
r,g,b=c('R'),c('G'),c('B')
t=0
for i in range(n-2):
  for w in range(1,(n-i+1)//2):
    if s[i]+s[i+w]+s[i+w*2] in ('RGB','RBG','GRB','GBR','BRG','BGR'):
        t+=1
print(r*g*b-t)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >>a>>b;
  if(a == 1) a = 14;
  if(b == 1) b = 14;
  if(a < b) cout << "Bob" << endl;
  else if(a == b) cout << "Draw" << endl;
  else if(a > b) cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define szof(x) ((int)x.size())
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii; 
int const INF = (int)1e9+1e3;
ll const INFL = (ll)1e18+1e6;

const int N = 1e5+5;

void solve(){
	int x;
	cin >> x;
	if(x<=599){
		cout << 8 << endl;
		return;
	}
	if(x<=799){
		cout << 7 << endl;
		return;
	}
	if(x<=999){
		cout << 6 << endl;
		return;
	}
	if(x<=1199){
		cout << 5 << endl;
		return;
	}
	if(x<=1399){
		cout << 4 << endl;
		return;
	}
	if(x<=1599){
		cout << 3 << endl;
		return;
	}
	if(x<=1799){
		cout << 2 << endl;
		return;
	}
	if(x<=1999){
		cout << 1 << endl;
		return;
	}
}   	
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    int N,D;cin >> N >> D;
    vector<vector<int>> pos;
    for(int i = 0;i < N;i++){
        vector<int> v;
        for(int j = 0;j < D;j++){
            int b;cin >> b;
            v.push_back(b);
        }
        pos.push_back(v);
    }
    int ans = 0;
    for(int i = 0;i < N-1;i++){
        for(int j = i+1;j < N;j++){
            int sum = 0;
            for(int k = 0;k < D;k++){
                sum += (pos.at(i).at(k) - pos.at(j).at(k))*((pos.at(i).at(k) - pos.at(j).at(k)));
            }
            if(sum == 1){
                ans++;
                continue;
            }
            for(int q = 1;q <= sum;q++){
                if(q*q == sum){
                    ans++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int W,H,a[1000],b[1000];
	int i,j,k,tmp;
	int sum_w = 0;
	int sum_h = 0;
	int result;

	scanf("%d %d", &W, &H);//横、高さ
	for (i = 0; i < W; i++)
	{
		scanf("%d", &a[i]);
		sum_w += a[i];
	}
	for (i = 0; i < H; i++)
	{
		scanf("%d", &b[i]);
		sum_h += b[i];
	}
	if (sum_w != sum_h)
	{
		result = 0;
	}
	//↑縦と横の合計が一致しているかのチェック
	else//↓のアルゴリズムが理解できない
	{
		result = 1;
		for (i = 0; i < W; i++)//横
		{
			for (j = 0; j < H; j++)//高さ
			{
				for (k = j; k < H; k++)
				{
					if (b[j] < b[k])//bを昇順にする？？
					{
						tmp = b[j];
						b[j] = b[k];
						b[k] = tmp;
					}
				}
			}
			for (j = 0; j < H; j++)
			{
				if (a[i] == 0 || b[j] == 0)
				{
					break;
				}
				a[i]--;
				b[j]--;
			}
			if (a[i] > 0)
			{
				result = 0;
				break;
			}
		}
	}
	printf("%d\n", result);
}





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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

//r本再利用されない時、N本から再利用して売れる本数
int rec(int m,int n,int N,int r){
  if(N == 0) return 0;

  int k = N/m * n;//新たに作り出す本数
  r = N%m;//再利用されない本数
  int res = N + k;//売った本数
  
  while(1){
    k = k/m * n;//k本からk/m本再利用
    res += k;
    r += k%m;
    if(k < m){//k本で再利用できなくなったら
      k += r;
      res += rec(m,n,k,r);
    }
  }
}

int main(){
  int X,Y;
  cin >> X >> Y;
  if(X == 1 && Y == 1) cout << 1000000 << endl;
  else if((X == 1 && Y == 2) || X == 2 && Y == 1) cout << 500000 << endl;
  else if((X == 1 && Y == 3) || X == 3 && Y == 1) cout << 400000 << endl;
  else if(X == 2 && Y == 2) cout << 400000 << endl;
  else if((X == 2 && Y == 3) || (X == 3 && Y == 2)) cout << 300000 << endl;
  else if(X == 3 && Y == 3) cout << 200000 << endl;
  else if(X == 1 || Y == 1) cout << 300000 << endl;
  else if(X == 2 || Y == 2) cout << 200000 << endl;
  else if(X == 3 || Y == 3) cout << 100000 << endl;
  else cout << 0 << endl;
}


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

using namespace std;

int main() {

	string s, p;
	cin >> s >> p;

	s =s+s;

	for (int i = 0; i < s.size(); i++) {
		for(int j = 0; j < p.size(); j++) {
			if (s[i+j] != p[j]) { break; }
			if (j == p.size()-1) { cout << "Yes" << endl; return 0; }
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3204
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

////////////////いろいろあるよ//////////////////////////////////
int main(){
	FOR(i,1,6){
      int a;
      cin >> a;
      if(a!=i)cout << i << endl;
    }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> table(H, vector<char>(W));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table.at(i).at(j);
    }
  }

  vector<bool> row(H, false), col(W, false);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (table.at(i).at(j) == '#') {
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    if (row.at(i) == false) {
      continue;
    }
    
    for (int j = 0; j < W; j++) {
      if (col.at(j) == false) {
        continue;
      }

      cout << table.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
std::vector<int> v;
int main() {
	int a,b;
	cin >> a >> b;
	if(a==0||b==0||(a>0&&b<0)||(b>0&&a<0)){
	     
	          cout << "Zero";
	     
	}
	if(a==b){
	     if(a<0){
	          cout << "Negative";
	     }
	     if(a>0){
	          cout << "Positive";
	     }
	     if(a==0){
	          cout << "Zero";
	     }
	}
	else if(a>0&&b>0){
	     cout << "Positive";
	}
	else if(a<0&&b<0){
	   if((b-a+1)%2==0){
	        cout << "Positive";
	   }else{
	        cout << "Negative";
	   }
	}
	return 0;
}


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

int main(){
  constexpr const long long INF = 1e18;
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  const int L = 60;
  vector<vector<int>> C(L,vector<int>(2,0));
  for(auto a : A){
    for(int j = 0; j < 60; ++j){
      int d = (a>>j)&1;
      ++C[j][d];
    }
  }
  vector<long long> dp(2,-INF);
  dp[1] = 0;
  //dp[==K?]
  for(int i = L-1; i >= 0; --i){
    int d = (K>>i)&1;
    vector<long long> dp_(2,-INF);
    for(int j = 0; j < 2; ++j){
      for(int k = 0; k < 2; ++k){
        if(dp[k] < 0) continue;
        if(k and j and !d) continue;
        dp_[k and (d==j)] = max(dp_[k and (d==j)], dp[k]*2+C[i][1-j]);
      }
    }
    dp = dp_;
    //cerr << dp[0] << " " << dp[1] << endl;
  }
  cout << max(dp[0],dp[1]) << endl;
}


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

public class Main {
	public static void main(String args[]){
		int n;
		ArrayList<String> rank;
		int[] score = new int[3];
		Scanner sc = new Scanner(System.in);
		double tmp;
		
		while(true){
			n = sc.nextInt();
			if(n == 0){
				break;
			}
			rank = new ArrayList<String>();
			
			for(int i=0;i<n;i++){
				for(int j=0;j<3;j++){
					score[j] = sc.nextInt();
				}
				
				if(score[0]==100 || score[1]==100 || score[2]==100){
					rank.add("A");
				}else if((score[0]+score[1])/2.0 >= 90){
					rank.add("A");
				}else if((score[0]+score[1]+score[2])/3.0 >= 80){
					rank.add("A");
				}else if((score[0]+score[1]+score[2])/3.0 >= 70){
					rank.add("B");
				}else if((score[0]+score[1]+score[2])/3.0 >= 50){
					if(score[0]>=80 || score[1]>=80){
						rank.add("B");
					}else{
						rank.add("C");
					}
				}else{
					rank.add("C");
				}
			}
			
			for(int i=0;i<n;i++){
				System.out.println(rank.get(i));
			}
		}
		
	}
}

Measured memory_bytes: 28272
#include <stdio.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
typedef struct Card {
    int i;
    int n;
    char c;
} Card;

// retard desu LMAO
void *partition(Card *first, Card *last) {
    Card pivot = *(last - 1);
    Card *p = first - 1;
    for(Card *it = first; it != last - 1; ++it) {
        if(it->n <= pivot.n) {
            p++;
            Card tmp = *p;
            *p = *it;
            *it = tmp;
        }
    }
    Card tmp = *++p;
    *p = pivot;
    *(last - 1) = tmp;
    return p;
}
void quicksort(void *first, void *last, size_t N) {
    if(last - first <= N) return;
    void *mid = partition(first, last);
    quicksort(first, mid, N);
    quicksort(mid, last, N);
}

int main(int argc, char **argv) {
    int n = get_uint();
    Card a[n];
    for(int i = 0; i < n; ++i) {
        a[i].c = getchar_unlocked();
        getchar_unlocked();
        a[i].n = get_uint();
        a[i].i = i;
    }
    quicksort(a, a + n, sizeof(Card));

    int flag = 0;
    for(int i = 1; i < n; ++i) {
        if(a[i].n==a[i-1].n && a[i].i < a[i-1].i){
            flag = 1;
            break;
        }
    }
    puts(flag ? "Not stable" : "Stable");
    for(int i = 0; i < n; ++i) {
        putchar_unlocked(a[i].c), putchar_unlocked(' ');
        put_uint(a[i].n), putchar_unlocked('\n');
    }
    return 0;
}



Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
int n, a;
long long sum[404];
long long dp[404][404];
long long minCost(int left, int right){
	if(left == right) return 0;
	long long& ret = dp[left][right];
	if(ret != -1)	return ret;
	ret = 1e18;
	for(int i = left+1;i<=right;i++){
		ret = min(ret,minCost(left,i-1)+minCost(i,right)+sum[right]-sum[left-1]);
	}
	return ret;
}
int main() {
	cin>>n;
	sum[0] = 0;
	for(int i = 1;i<=n;i++){
		cin>>a;
		sum[i] = sum[i-1]+a*1LL;
	}
	memset(dp,-1,sizeof(dp));
	cout<<minCost(1,n);
	return 0;
}

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

# define F first    
# define S second
      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector

# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
int a, b;

string s;

bool check () {
	if (s[a] != '-')
		return 0;
	for (int i = 0; i < sz(s); i++) {
		if (i == a)	continue;
		if (!isdigit (s[i]))
			return 0;
	}
	return 1;
}	

int main() 
{
  Read_rap (); 
  cin >> a >> b;
  cin >> s;
  cout << (check() ? "Yes" : "No");
     

  return 0;
} 










// Coded by Z..

Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).ok();
    return word.trim().to_string();
}

fn main() {
    let line = get_input();
    let mut split_line = line.split_whitespace();
    let a:u32 = split_line.next().unwrap().parse().unwrap();
    let b:u32 = split_line.next().unwrap().parse().unwrap();

    let ans =
    if a >= 13 {
        b
    } else if 6 <= a && a <= 12 {
        b / 2
    } else {
        0
    };

    println!("{}", ans);
}

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

int main() {
  int N, Y_num;
  cin >> N;
  Y_num = 0;
  
  for (int i = 0; i < N; i++) {
    string Si;
    cin >> Si;
    if (Si == "Y") {
      Y_num++;
    }
  }

  if (Y_num == 0) {
    cout << "Three" << endl;
  }
    
  else {
  cout << "Four" << endl;
  }
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var X = ReadArrayInt();
            var ans = long.MaxValue;
            for (int i = 1; i <= 100; i++)
            {
                var sta = 0L;
                for (int j = 0; j < N; j++)
                {
                    sta += (long)Math.Pow(Math.Abs(X[j] - i), 2);
                }
                if (sta < ans) ans = sta;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int main(void){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);

    int sorted = 0; //どこまでがソート済かの値
    for(int i = 0;i < 3;i++){ //ソート部分
        for (int n = 3;n > sorted;n--){
            if(a[n-1] < a[n]){
                int temp = a[n];
                a[n] = a[n-1];
                a[n-1] = temp;
            }    
        }
    sorted++;
    }

    int ans = 0;
    for(int i = 0;i < 2;i++){
        ans += abs(a[i] - a[i+1]);
    }

    printf("%d",ans);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    ll n;
    cin >> n;
    int mod = 1000000007;
    ll res = 1;
    rep(i,n) {
        res *= (i+1);
        res %= mod;
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx = 1e7 + 7;

ll par[mx];
ll p_u, p_v;

ll find_parent(ll x) {
    if(x == par[x]) return x;

   return par[x] = find_parent(par[x]);
}



void join(ll u, ll v) {

    p_u = find_parent(u);
    p_v = find_parent(v);

   if(p_u == p_v) return;

   par[p_u] = p_v;
}

int main() {
    ll n, q;  cin >> n >> q;
    for(ll i = 0; i < n; i++) par[i] = i;

    while(q--) {
        ll t; cin >> t;
        if(t == 1) {
            ll u, v;  cin >> u >> v;
             p_u = find_parent(u);
             p_v = find_parent(v);
            if(p_u == p_v) cout << 1 << endl;
            else cout << 0 << endl;
        }

        else if( t == 0) {
            ll u, v;  cin >> u >> v;
            join(u, v);
        }
    }

    return 0;
}


Measured memory_bytes: 4932
#! python3
# diceII.py - サイコロを転がす動きをシミュレートするプログラム 今度はトップとフロントが与えられたときの右

def getKeyFromValue(dice, value):
  keys = [k for k, v in dice.items() if v == value]
  if keys:
    return keys[0]
  return None

def initDice(numbers):  # サイコロオブジェクトに値を入れる
    # サイコロオブジェクトを定義, 配列の数値を、各面にわたす
    dice = {'top': numbers[0], 'bottom': numbers[5], 'front': numbers[1],
            'back': numbers[4], 'right': numbers[2], 'left': numbers[3]}
    return dice

def retrunRight(dice, first, second):  # サイコロのトップと前面の2つの値を受け取る
    first = getKeyFromValue(dice, first)
    second = getKeyFromValue(dice, second)
    if first == 'top':
        if second == 'front':
            right = dice['right']
        elif second == 'right':
            right = dice['back']
        elif second == 'back':
            right = dice['left']
        elif second == 'left':
            right = dice['front']
    elif first == 'bottom':
        if second == 'front':
            right = dice['left']
        elif second == 'left':
            right = dice['back']
        elif second == 'back':
            right = dice['right']
        elif second == 'right':
            right = dice['front']
    elif first == 'right':
        if second == 'front':
            right = dice['bottom']
        elif second == 'bottom':
            right = dice['back']
        elif second == 'back':
            right = dice['top']
        elif second == 'top':
            right = dice['front']
    elif first == 'left':
        if second == 'front':
            right = dice['top']
        elif second == 'top':
            right = dice['back']
        elif second == 'back':
            right = dice['bottom']
        elif second == 'bottom':
            right = dice['front']
    elif first == 'front':
        if second == 'top':
            right = dice['left']
        elif second == 'left':
            right = dice['bottom']
        elif second == 'bottom':
            right = dice['right']
        elif second == 'right':
            right = dice['top']
    elif first == 'back':
        if second == 'top':
            right = dice['right']
        elif second == 'right':
            right = dice['bottom']
        elif second == 'bottom':
            right = dice['left']
        elif second == 'left':
            right = dice['top']
    return right


numbers = [int(i) for i in input().split()]
dice = initDice(numbers)
q = int(input())

for i in range(q):
    first, second = [int(i) for i in input().split()]
    right = retrunRight(dice, first,second)
    print(right)


Measured memory_bytes: 5624
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int d, r, a, b;
    double x, y, f;
    cin >> a >> b;
    x = a;
    y = b;
    d = a / b;
    r = a % b;
    f = x / y;
    printf("%d\n %d\n %.8lf\n",d, r, f);
    
    
    
}
    




Measured memory_bytes: 3152
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define MAX ((ll)(2e17+100))
#define MX ((ll)(1e5+100))
#define ARRS ((ll)(2e6+100))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;


ll n,m,x,k,p;
ll a[ARRS];
ll f[2][ARRS];
string s;

int main(){
	cin>>s;
	n=s.size();
	if(s[n-1]=='1'||s[0]=='0'){
		cout<<-1;
		return 0;
	}
	for(int i=0; i<n-1; i++){
		if(s[i]!=s[n-2-i]){
			cout<<-1;
			return 0;
		}
	}
	ll x=2,C=2;
	vector<pair<ll,ll> > pas;
	pas.pb({1,2});
	for(int i=1; i<n-1; i++){
		if(s[i]=='1'){
			pas.pb({x,++C});
			x=C;
		}
		else {
			pas.pb({x,++C});
		}
	}
	for(auto x:pas)
		cout<<x.fr<<" "<<x.sc<<endl;
}


Measured memory_bytes: 3312
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
if n == 1:
    print(0)
    exit()
pfs = factorization(n)

cs = 0
for p, f in pfs:
    c = 0
    for i in range(10**12):
        f -= i
        if f < 0:
            c = i-1
            break
    # print(p,c)
    cs += c
print(cs)

Measured memory_bytes: 9528
n, l = map(int, input().split())
y = []

for i in range(1,n+1):
	y.append(l + i -1)

if 0 in y:
	print(sum(y))
elif sorted(y)[-1] < 0:
	print(sum(sorted(y)[:-1]))
elif sorted(y)[0] > 0:
	print(sum(sorted(y)[1:]))

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;
 
ll modulo(ll a, ll b, ll n){
    long long x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; 
        }
        y = (y*y) % n;
        b /= 2;
    }
    return x % n;
}
 
int main()
{
    SYNC
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n;
    ll k;
    in(n);
    in(k);
    vl h;
    ll temp;
    ll dp[n+1];
    l(i,0,n)
    {
        in(temp);
        h.pb(temp);
    }
    dp[0]=0;
    for(ll i=1;i<=n-1;i++)
    {
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for(ll j=1; j<k; j++)
        {
            if(i>j)
            dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]));
        }
    }
    o(dp[n-1])<<endl;
 
    
 
}


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

int main() {
  string s;
  while(cin >> s) {
    if(s == "#") break;
    int y, m, d;
    cin >> y >> m >> d;
    if(y == 31) {
      if(m >= 5) {
	s = "?";
	y -= 30;
      }
    }
    else if(y > 31) {
      s = "?";
      y -= 30;
    }
    cout << s << " " << y << " " << m << " " << d << endl;
  }
  return 0;
}



Measured memory_bytes: 3160
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input! {
        n: usize,
        v: [(usize, usize, usize); n-1],
    }

    let mut decided = vec![false; n+1];
    let mut visited = vec![false; n+1];
    visited[0] = true;

    //prepare for dfs
    let mut relation = vec![vec![]; n+1];

    // relation[src].push(dst, weight)
    for e in &v {
        relation[e.0].push((e.1, e.2));
        relation[e.1].push((e.0, e.2));
    }

    dfs(1, &relation, &mut decided, &mut visited);

    for e in decided.iter().skip(1) {
        let ans = if *e { 1 } else { 0 };
        println!("{}", ans);
    }    
}

fn dfs(node: usize, relation: &Vec<Vec<(usize, usize)>>, decided: &mut Vec<bool>, visited: &mut Vec<bool>) {
    if !visited.iter().any(|b| !b) {
        return;
    }

    for e in &relation[node] {
        if e.1 % 2 == 0 {
            decided[e.0] = decided[node];
        } else {
            decided[e.0] = !decided[node];
        }
        //println!("{}", e.0);
        if !visited[e.0] {
            visited[e.0] = true;
            dfs(e.0, &relation, decided, visited);
        }
    }
}



Measured memory_bytes: 21884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

template <long long mod>
struct modular {
    long long value;
    modular(long long x = 0) {
        value = x % mod;
        if (value < 0) value += mod;
    }
    modular& operator+=(modular other) {
        if ((value += other.value) >= mod) value -= mod;
        return *this;
    }
    modular& operator-=(modular other) {
        if ((value -= other.value) < 0) value += mod;
        return *this;
    }
    modular& operator*=(modular other) {
        value = value * other.value % mod;
        return *this;
    }
    modular& operator/=(modular other) {
        long long a = 0, b = 1, c = other.value, m = mod;
        while (c != 0) {
            long long t = m / c;
            m -= t * c;
            swap(c, m);
            a -= t * b;
            swap(a, b);
        }
        a %= mod;
        if (a < 0) a += mod;
        value = value * a % mod;
        return *this;
    }
    modular operator-() { return modular(-value); }
    modular operator+(modular rhs) { return modular(*this) += rhs; }
    modular operator-(modular rhs) { return modular(*this) -= rhs; }
    modular operator*(modular rhs) { return modular(*this) *= rhs; }
    modular operator/(modular rhs) { return modular(*this) /= rhs; }
    bool operator==(modular rhs) { return value == rhs.value; }
    bool operator!=(modular rhs) { return value != rhs.value; }
    bool operator<(modular rhs) { return value < rhs.value; }
};
template <long long mod>
string to_string(modular<mod> x) {
    return to_string(x.value);
}
template <long long mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream << x.value;
}
template <long long mod>
istream& operator>>(istream& stream, modular<mod>& x) {
    stream >> x.value;
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream;
};
const long long mod = 998244353LL;
using mint = modular<mod>;

inline mint pw(mint a, long long n) {
    mint res = 1;
    while (n > 0) {
        if (n & 1) {
            res *= a;
        }
        a *= a;
        n >>= 1;
    }
    return res;
}
vector<mint> fact, finv;
inline void cinit(int n) {
    fact.resize(n, 1);
    finv.resize(n, 1);
    for (int i = 2; i < n; i++) {
        fact[i] = fact[i - 1] * i;
    }
    finv[n - 1] /= fact[n - 1];
    for (int i = n - 2; i >= 2; i--) {
        finv[i] = finv[i + 1] * (i + 1);
    }
}
inline mint C(int n, int k) {
    if (n < k || k < 0 || n < 0) return 0;
    return fact[n] * finv[k] * finv[n - k];
}
inline mint H(int n, int k) {
    return C(n + k - 1, k);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    cinit(200000);
    mint ans = 0;
    for (int i = 0; i <= k; i++) {
        ans += C(n - 1, i) * pw(m - 1, n - 1 - i) * m;
    }
    cout << ans << '\n';
    return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string n;
    cin >> n;

    if((n[0] == n[1]) && (n[1] == n[2])) cout << n << endl;
    else{
        int v;
        v = stoi(n);
        while((n[0] != n[1]) || (n[0] != n[2])){
            v++;
            n = to_string(v);
        }
        cout << n << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
 
public class Hello {
    public static void Main() {
      var nums = NumInput();
      int res = (nums[0] * nums[1]);
      if(res%2 == 0) Result("Even");
      else Result("Odd");
        
    }
    static int[] NumInput(){
        var input_line = Console.ReadLine().Split(' ');
        return input_line.Select(int.Parse).ToArray();
    }
    
    static void Result(string text){
        Console.WriteLine( text );
    }   
}

Measured memory_bytes: 13268
#include<iostream>
#include<string>
using namespace std;
int main(){
	string o, e, pass;
	cin >> o >> e;
	int siz = o.size();
	for (int i = 0; i < siz; i++){
		if (i == 0){
			pass = o[i];
		}
		else if (i != 0){
			pass += o[i];
			if (o.size()!=e.size()){
				if (siz - i == 1){
					break;
				}
			}
		}
		pass += e[i];
		
	}
	cout << pass << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int sx, sy, tx, ty;


void print_route(int s, int t, char c)
{
    for (int i = s; i < t; i++) {
        cout << c;
    }
    return;
}


int main()
{
    cin >> sx >> sy >> tx >> ty;
    print_route(sx, tx, 'R');
    print_route(sy, ty, 'U');
    print_route(sx, tx, 'L');
    print_route(sy, ty, 'D');

    cout << 'D';
    print_route(sx, tx + 1, 'R');
    print_route(sy - 1, ty, 'U');
    cout << "LU";
    print_route(sx - 1, tx, 'L');
    print_route(sy, ty + 1, 'D');
    cout << 'R' << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int s;
    string op;
    cin >> s;
    int op1, op2, op3, tmp;
    REP(i, 1, pow(2,3)+1){
        tmp = i;
        if(tmp%2==1){
            op1 = 1;
            op[0] = '+';
        }else{
            op1 = -1;
            op[0] = '-';
        }
        tmp /= 2;
        if(tmp%2==1){
            op2 = 1;
            op[1] = '+';
        }else{
            op2 = -1;
            op[1] = '-';
        }
        tmp /= 2;
        if(tmp%2==1){
            op3 = 1;
            op[2] = '+';
        }else{
            op3 = -1;
            op[2] = '-';
        }
        if(s/1000 + op1 * (s/100)%10 + op2 * (s/10)%10 + op3 * s%10 == 7){
            cout << s/1000 << op[0] << (s/100)%10 << op[1] << (s/10)%10 << op[2] << s%10 << "=7"<< endl;
            return 0;
        }
    }

}


Measured memory_bytes: 256
use proconio::input;
fn main() {
    input!(n: usize);
    input!(a: [usize; n]);
    input!(q: usize);
    let mut query = vec![];
    for _ in 0..q {
        input!(t: (usize, usize));
        query.push(t);
    }

    let mut count = vec![0; 100_000 + 10];
    let mut sum = 0;
    for &e in &a {
        count[e] += 1;
        sum += e;
    }

    for &(b, c) in &query {
        sum = sum - count[b] * b + count[b] * c;
        count[c] += count[b];
        count[b] = 0;
        println!("{}", sum);
    }
}


Measured memory_bytes: 7076
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define NIL NULL
//Node structure
struct Node{
  int key;
  struct Node *parent;
  struct Node *leftc;
  struct Node *rightc;
};
//define Nodepointer
typedef struct Node * Nodepointer;

//root
Nodepointer root;

//function insert   
void insert(int k){
  Nodepointer x,y,z;
  y=NIL;
  x=root;
  //make memory
  z=new struct Node();

  z->key=k;
  z->leftc=NIL;
  z->rightc=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->leftc;
    else x=x->rightc;
  }

  z->parent=y;

  if(y==NIL) root=z;

  else if(z->key<y->key) y->leftc=z;

  else y->rightc=z;


}

//function search
Nodepointer find(Nodepointer now,int data){
  if(now==NIL||data==now->key) return now;
  if(data<now->key) return find(now->leftc,data);
  else return find(now->rightc,data);
}
//print
void inorderprint(Nodepointer now){
  if(now!=NIL){
    inorderprint(now->leftc);
    printf(" %d",now->key);
    inorderprint(now->rightc);
  }
}

void preorderprint(Nodepointer now){
  if(now!=NIL){
    printf(" %d",now->key);
    preorderprint(now->leftc);
    preorderprint(now->rightc);
  }
}


int main(){

  int n,i,j,data;

  char str[10];
  //load n
  scanf("%d",&n);
  //load commnad and key
  for(i=0;i<n;i++){
    scanf("%s",str);
    //insert
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      insert(data);
    }
    //find
    else if(strcmp(str,"find")==0){
      scanf("%d",&data);
      if(find(root,data)!=NIL) printf("yes\n");
      else printf("no\n");
    }
    //print
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int count = 1;
  for (int i = 0;i + 1 < N;i++) {
    if (vec.at(i) != vec.at(i + 1)) {
      count++;
    }
 
  }
  
  cout << count << endl;
  
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 20
#define MOD 1000000007

int H, W;
char S[N_MAX][N_MAX + 1];

int func(int h, int w)
{
	priority_queue<pair<int, pair<int, int> > > pq;
	pq.push(make_pair(0, make_pair(h, w)));

	int dh[] = { 1,-1,0,0 }, dw[] = { 0,0,1,-1 };

	int visit[N_MAX][N_MAX];
	for (int i = 0; i < H; i++) {
		fill(visit[i], visit[i] + W, -1);
	}
	while (!pq.empty()) {
		pair<int, pair<int, int> > cur = pq.top(); pq.pop();
		if (-1 != visit[cur.second.first][cur.second.second]) {
			continue;
		}
		visit[cur.second.first][cur.second.second] = -cur.first;
		for (int i = 0; i < 4; i++) {
			if (0 <= cur.second.first + dh[i] && cur.second.first + dh[i] < H &&
				0 <= cur.second.second + dw[i] && cur.second.second + dw[i] < W)
			{
				if (-1 == visit[cur.second.first + dh[i]][cur.second.second + dw[i]] &&
					'.' == S[cur.second.first + dh[i]][cur.second.second + dw[i]]) {
					pq.push(make_pair(cur.first - 1, make_pair(cur.second.first + dh[i], cur.second.second + dw[i])));
				}
			}
		}
	};

	int ret = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ret = max(ret, visit[i][j]);
		}
	}

	return ret;
}

void solv()
{
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) {
		scanf("%s", S[i]);
	}

	int ret = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if ('.' == S[i][j]) {
				ret = max(ret, func(i, j));
			}
		}
	}

	printf("%d", ret);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = scanner.nextInt();
        List<Integer> hList = Arrays.stream(h).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());

        int max = hList.get(0);

        int count = 0;
        int[] flowers = h;
        for (int i = 0; i < max; i++) {
            StringBuilder builder = new StringBuilder();
            for (int flower : flowers) builder.append(flower > 0 ? String.valueOf(flower).replace("0", "A") : flower);
            count += Arrays.stream(builder.toString().split("0")).filter(s -> !s.trim().equals("")).count();

            for (int j = 0; j < N; j++) {
                if (flowers[j] > 0) flowers[j]--;
            }
        }

        System.out.println(count);
    }

}


Measured memory_bytes: 33108
N = input()
T, A = list(map(int, input().split()))
Hs = list(map(int, input().split()))

last = 99999999999999
lastidx = -1
for idx, h in enumerate(Hs):
  dif = abs(A - (T - 0.006 * h))
  if last > dif:
    last = dif
    lastidx = idx + 1


print(lastidx)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
	vector<int> vec(n);
	rep(i,n){
		cin >> vec[i];
	}
	ll a1 = 0;
	ll sm = vec[0];
	if(sm <= 0){
		a1 += 1-sm;
		sm += 1-sm;
	}
	for(int i=1;i<n;i++){
		if(sm < 0){
			sm += vec[i];
			if(sm <= 0){
				a1 += 1-sm;
				sm += 1-sm;
			}
		}else{
			sm += vec[i];
			if(sm >= 0){
				a1 += sm+1;
				sm -= sm+1;
			}
		}
	}
	ll a2 = 0;
	sm = vec[0];
	if(sm >= 0){
		a2 += 1+sm;
		sm -= 1+sm;
	}
	for(int i=1;i<n;i++){
		if(sm < 0){
			sm += vec[i];
			if(sm <= 0){
				a2 += 1-sm;
				sm += 1-sm;
			}
		}else{
			sm += vec[i];
			if(sm >= 0){
				a2 += sm+1;
				sm -= sm+1;
			}
		}
	}
	cout << min(a1,a2) << endl;
    return 0;
}


Measured memory_bytes: 640