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

const long long INF = 9e18;
const int N = 1e5 + 10;

int x[N][2], y[N][2];
int r, c, n;
vector<pair<int, int>> upper, lower, lb, rb;
bool used[N];

int main() {
    ios::sync_with_stdio(false);
    cin >> r >> c >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i][0] >> y[i][0] >> x[i][1] >> y[i][1];

        int cnt = 0;
        if (x[i][0] == 0 || x[i][0] == r || y[i][0] == 0 || y[i][0] == c) cnt += 1;
        if (x[i][1] == 0 || x[i][1] == r || y[i][1] == 0 || y[i][1] == c) cnt += 1;
        if (cnt != 2) continue;

        if (x[i][0] == 0) {
          upper.push_back({y[i][0], i});
        } else if (y[i][0] == c) {
          rb.push_back({x[i][0], i});
        } else if (x[i][0] == r) {
          lower.push_back({y[i][0], i});
        } else if (y[i][0] == 0) {
          lb.push_back({x[i][0], i});
        }

        if (x[i][1] == 0) {
          upper.push_back({y[i][1], i});
        } else if (y[i][1] == c) {
          rb.push_back({x[i][1], i});
        } else if (x[i][1] == r) {
          lower.push_back({y[i][1], i});
        } else if (y[i][1] == 0) {
          lb.push_back({x[i][1], i});
        }
    }
    // increasing
    sort(upper.begin(), upper.end());
    // increasing
    sort(rb.begin(), rb.end());
    // decreasing
    sort(lower.begin(), lower.end(), greater<pair<int, int>>());
    // decreasing
    sort(lb.begin(), lb.end(), greater<pair<int, int>>());

    bool flag = true;
    stack<int> S;
    for (auto x : upper) {
       //cout << x.first << " 1 " << x.second << endl;
      int id = abs(x.second);
      if (used[id] == 1) {
        if (S.top() == id) {
          S.pop();
        } else {
          flag = false;
        }
      } else {
        used[id] = 1;
        S.push(id);
      }
    }
    for (auto x : rb) {
           // cout << x.first << " 2 " << x.second << endl;

      int id = abs(x.second);
      if (used[id] == 1) {
        if (S.top() == id) {
          S.pop();
        } else {
          flag = false;
        }
      } else {
        used[id] = 1;
        S.push(id);
      }
    }
    for (auto x : lower) {
           //cout << x.first << " 3 " << x.second << endl;

      int id = abs(x.second);
      if (used[id] == 1) {
        if (S.top() == id) {
          S.pop();
        } else {
          flag = false;
        }
      } else {
        used[id] = 1;
        S.push(id);
      }
    }
    for (auto x : lb) {
           //cout << x.first << " 4 " << x.second << endl;

      int id = abs(x.second);
      if (used[id] == 1) {
        if (S.top() == id) {
          S.pop();
        } else {
          flag = false;
        }
      } else {
        used[id] = 1;
        S.push(id);
      }
    }
    if (flag == false) cout << "NO" << endl;
    else cout << "YES" << endl; 
    return 0;
}

// 1 1 2
// 0 0 1 1
// 1 0 0 1

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  vector<vector<int>> a(3, vector<int>(3, 0));
  rep(i, 3){
    rep(j, 3) cin >> a[i][j];
  }
  int n;
  cin >> n;  
  int b;
  rep(i, n){
    cin >> b;
    rep(i, 3){
      rep(j, 3) {
        if(b == a[i][j]) a[i][j] = 0;
      }
    }
  }
  
  int ans = 0;
  if(a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0) ans =1;
  if(a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0) ans =1;
  if(a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0) ans =1;
  if(a[0][0] == 0 && a[1][0] == 0 && a[2][0] == 0) ans =1;
  if(a[0][1] == 0 && a[1][1] == 0 && a[2][1] == 0) ans =1;
  if(a[0][2] == 0 && a[1][2] == 0 && a[2][2] == 0) ans =1;
  if(a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) ans =1;
  if(a[2][0] == 0 && a[1][1] == 0 && a[0][2] == 0) ans =1;
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a+b-1 > n || n > a*b){
        cout << -1 << endl;
        return 0;
    }
    for(int i = 0; i < b; i++){
        cout << b-i << ' ';
    }
    if(a==1) {
        cout << endl;
        return 0;
    }
    int q = (n-b)/(a-1);
    for(int i = q; i >= 1; i--){
        for(int j = 0; j < a-1;j++){
            cout << n-(q-i)*(a-1)-(a-2)+j << ' ';
        }
    }
    for(int i = b+1; i <= n-q*(a-1); i++){
        cout << i << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>

using namespace std;

//マップ探索
void check(int w, int h, int x, int y, int map[20][20], int *ans){

	if(map[x][y] != 0) *ans = *ans + 1;
	if(map[x][y] == 0) return;
	map[x][y] = 0;

	if(x > 0) check(w, h, x - 1, y, map, ans);
	if(x < w - 1) check(w, h, x + 1, y, map, ans);
	if(y > 0) check(w, h, x, y - 1, map, ans);
	if(y < h - 1) check(w, h, x, y + 1, map, ans);

}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {
		//変数宣言
		int w, h ;
		int x, y ;

		int map[20][20];
		cin >> w >> h;

		if( w == 0 && h == 0 ) break;	//終了処理

		//マップ初期化
		for(int i = 0; i < h; i++) {
			string tmp;
			cin >> tmp;
			for(int j = 0; j < w; j++) {
				char ch = tmp.at(j);
				switch(ch) {
					case '.':
						map[j][i] = 1;
						break;
					case '#':
						map[j][i] = 0;
						break;
					case '@':
						x = j;
						y = i;
						map[j][i] = 2;
						break;
				}
			}
		}

		int ans = 0;
		check(w,h,x,y,map,&ans);

		cout << ans << endl;
	}

	
	//while(1){}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> s(n);
    for(int i = 0; i < n; ++i)
        cin >> s[i].first >> s[i].second;

    sort(s.begin(), s.end());

    ll res = 0;
    for(int i = 0; i < n; ++i){
        if(m >= s[i].second){
            res += s[i].first * s[i].second;
            m -= s[i].second;
        }else{
            res += s[i].first * m;
            break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[20005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
string s[2000005];
P p[2000005];
int main() {
	ll n, k;
	cin >> n >> k;
	ll count = 0;
	while (n) {
		n = n / k;
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    if(s[0] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int l,r,d,ans=0;
	cin>>l>>r>>d;
	for(int i=l;i<=r;i++){
		if(i%d==0)ans++;
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000

int d[110][110];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, N) rep(j, N) d[i][j] = INF;
    rep(i, N) d[i][i] = 0;
    int a[100010], b[100010], c[100010];
    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, M) {
        if(d[a[i]][b[i]] != c[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3724
#include <stdio.h>

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

Measured memory_bytes: 580
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define pb              push_back
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
#define read            ZXBs_fast_input
#define write           ZXBs_fast_output
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool write(int x){
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int n, a, b;
	cin >> n >> a >> b;
	cout << (min(a, b)) << " " << (max(0, (a + b - n))) << endl;;
	return 0;
}

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

test_case = {
    "AC": 0,
    "WA": 0,
    "TLE": 0,
    "RE": 0
}

for i in range(N):
    Si = input().rstrip()
    test_case[Si] += 1


print("{} x {}".format("AC", test_case["AC"]))
print("{} x {}".format("WA", test_case["WA"]))
print("{} x {}".format("TLE", test_case["TLE"]))
print("{} x {}".format("RE", test_case["RE"]))


Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, d, x, a[101];
    cin >> n >> d >> x;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += (d - 1) / a[i]+ 1;
    }

    cout << ans + x << endl;

	return 0;
}

Measured memory_bytes: 256
def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N = get_next_int()
    D, X = get_next_ints()
    choco = X + N
    for i in range(N):
        A = get_next_int()
        choco += int((D - 1) / A)
    print(choco)
solve()

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	/*if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;*/
	return ((a.x + 1)*(a.y + 1)) < ((b.x + 1)*(b.y + 1));
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
int ctoi(char a) {
	return (int)a - '0';
}
 //#define int long long
const long long Inf = 4523372036854775807;
const int inf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
H a[100];
bool c[100];
struct A {
	int x, y;
};
bool operator<(A a, A b) { return a.x < b.x; }
A b[100];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i].x >> a[i].y;
	for (int i = 0; i < n; i++)
		cin >> b[i].x >> b[i].y;
	sort(a, a + n);
	sort(b, b + n);
	int ans = 0;
	for (int i = 0; i < n; i++) {//b
		int k = -1;
		for (int j = 0; j < n; j++) {//a
			if (c[j]) continue;
			if (a[j].x < b[i].x&&a[j].y < b[i].y) {
				if (k == -1) k = j;
				else if (a[k].y < a[j].y) k = j;
			}
		}
		if (k >= 0) {
			ans++; c[k] = 1;
		}
	}
	cout << ans << endl;
	getchar(); getchar();
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<string> S(n);
  vector<vector<int>> c(n);
  rep(i, n) {
    cin >> S[i];
    std::sort(S[i].begin(), S[i].end());

    c[i].resize(26, 0);
    rep(j, S[i].size()) {
      int pos = S[i][j] - 'a';
      c[i][pos]++;
    }
  }

  rep(i, 26) {
    int mn = c[0][i];

    rep(j, n) {
      if (mn > c[j][i]) mn = c[j][i];
    }

    if (mn > 0) {
      char al = 'a' + i;
      rep(k, mn) cout << al;
    }
  }

  cout << endl;

  return 0;
}


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    if (fabs(a-b)<=d && fabs(b-c)<=d || fabs(a-c)<=d)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int A, B, M;
vector<int> as, bs;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> A >> B >> M;
  as.resize(A);
  bs.resize(B);
  int ma = 114514;
  int mb = 114514;
  rep(i, A) {
    cin >> as[i];
    MN(ma, as[i]);
  }
  rep(i, B) {
    cin >> bs[i];
    MN(mb, bs[i]);
  }

  int ans = ma + mb;
  rep(i, M) {
    int x, y, c;
    cin >> x >> y >> c;
    --x;
    --y;
    MN(ans, as[x]+bs[y]-c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
// g++ -std=c++17 -O2 -Wall C.cpp -o C

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

ll powmod(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) ret = (ret * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ret;
}

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

    ll n;
    cin >> n;
    ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= MOD;
    ans = (ans + MOD) % MOD;
    cout << ans;
}

Measured memory_bytes: 3600
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String str=sc.next();
			char[] cStr=str.toCharArray();
			int[] iStr=new int[cStr.length];
			for(int i=0;i<cStr.length;i++){
				if(Character.toString(cStr[i]).equals("I")){
					iStr[i]=1;
				}else if(Character.toString(cStr[i]).equals("V")){
					iStr[i]=5;
				}else if(Character.toString(cStr[i]).equals("X")){
					iStr[i]=10;
				}else if(Character.toString(cStr[i]).equals("L")){
					iStr[i]=50;
				}else if(Character.toString(cStr[i]).equals("C")){
					iStr[i]=100;
				}else if(Character.toString(cStr[i]).equals("D")){
					iStr[i]=500;
				}else if(Character.toString(cStr[i]).equals("M")){
					iStr[i]=1000;
				}
			}
			int sum=iStr[iStr.length-1];
			for(int i=iStr.length-2;i>=0;i--){
				if(iStr[i]<iStr[i+1]){
					sum-=iStr[i];
				}else{
					sum+=iStr[i];
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 17232
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int fnd(vector<int> &v,int n)
{
	if(v[0]>n) return -1;
	int hi=sz(v),lo=0;
	while(hi-lo>1)
	{
		int m=(hi+lo)/2;
		if(v[m]>n) hi=m;
		else lo=m;
	}
	return lo;
}

bool cmp(pii a,pii b) { return a.S>b.S; }

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m; cin>>n>>m;
	vector<int> v(n);
	for(auto &i:v) cin>>i;
	sort(all(v));
	vector<pii> q(m);
	for(auto &i:q) cin>>i.F>>i.S;
	sort(all(q),cmp);
	int now=-1,ans=0;
	for(auto &i:q)
	{
		int nnow=min(fnd(v,i.S),now+i.F);
		if(nnow<=now) continue;
		ans+=i.S*(nnow-now);
		now=nnow;
		if(now==n-1) break;
	}
	For(i,now+1,n-1) ans+=v[i];
	cout<<ans<<"\n";
	return 0;
}















Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
using ll = long long;

bool ask(int i) {
  cout << i << endl;
  string s;
  cin >> s;
  if (s == "Vacant") {
    exit(0);
  }
  return s == "Male";
}

bool check(int a, bool av, int b, bool bv) {
  return ((b - a) % 2 == 0 && av != bv) || ((b - a) % 2 == 1 && av == bv);
}

void solve(int s, bool sv, int t, bool tv) {
  for (;;) {
    int m = (s + t) / 2;
    bool mv = ask(m);
    if (check(s, sv, m, mv)) {
      t = m;
      tv = mv;
    } else {
      s = m;
      sv = mv;
    }
  }
}

int main() {
  int N;
  cin >> N;
  bool z = ask(0);
  bool c = ask(N / 2);
  if (check(0, z, N / 2, c)) {
    solve(0, z, N / 2, c);
  } else {
    solve(N / 2, c, N, z);
  }
  return 0;
}


Measured memory_bytes: 852
#include<stdio.h>
int main() {
    long a, b, c;
    scanf("%ld%ld%ld", &a, &b, &c);
    if(4 * a * b < c * c - 2 * c * (a + b) + (a + b) * (a + b) && c - (a + b) > 0) {
        printf("Yes");
    }
    else {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#B

n = int(input())
w = []
sn = []
tn = []
for _ in range(n):
    s = input()
    f = True
    for i in range(len(w)):
        if w[i] == s:
            sn[i] += 1
            f = False
            break
    if f:
        w.append(s)
        sn.append(1)
        tn.append(0)
        
m = int(input())
for _ in range(m):
    t = input()
    f = True
    for i in range(len(w)):
        if w[i] == t:
            tn[i] += 1
            f = False
            break
    if f:
        w.append(t)
        tn.append(1)
        sn.append(0)
        
#print(sn,tn)
        
print(max([sn[i]-tn[i] for i in range(len(w))]+[0]))

Measured memory_bytes: 38512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
  public static void main(String args[]) throws IOException{
   int ans;
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   
   while(true){
   String[] token = br.readLine().split(" ");
    int n = Integer.parseInt(token[0]);      
    int x = Integer.parseInt(token[1]);
    if(n == 0 && x == 0) {break;}
    ans = 0;
    for(int i = 1; i <= n ; i++){
     for(int j = i + 1; j <= n; j++){
      for(int k = j + 1; k <= n; k++){
       if(x==i+j+k){ans++;}
      }//for 
     }//for
    }//for
    System.out.println(ans);
   }//while
 
 }
}

Measured memory_bytes: 24844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	deque<int> deq;
	rep(i, n){
		int in;
		cin >> in;
		auto itr = lower_bound(deq.begin(), deq.end(), in);
		if(deq.size() == 0 || itr == deq.begin()){
			deq.push_front(in);
		}else{
			itr--;
			*itr = in;
		}
	}
	cout << deq.size() << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if( A*B >= A+B ){
        if( A*B >= A-B ){
            printf("%d\n",A*B);
            return 0;
        }else{
            printf("%d\n",A-B);
            return 0;
        }
    }else{
        if( A+B >= A-B ){
            printf("%d\n",A+B);
            return 0;
        }else{
            printf("%d\n",A-B);
            return 0;
        }
    }
}

Measured memory_bytes: 128
package main

import "fmt"
import "strconv"

func main() {
        var n int
        fmt.Scan(&n)
        var ans = 1
        var upper = 1000000000000000000
        for i := 0; i < n; i++ {
                var tmp int
                fmt.Scan(&tmp)
                if tmp == 0 {
                        ans = 0
                        break
                }
                if ans == -1 {
                        continue
                }
                var a = strconv.Itoa(tmp)
                var b = strconv.Itoa(ans)
                ans *= tmp
                if ans == upper {
                        continue
                }
                if len(a)+len(b) > 19 {
                        ans = -1
                        continue
                }
                if ans > upper {
                        ans = -1
                }

        }
        fmt.Print(ans)
}


Measured memory_bytes: 6328
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

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

int h, w;
vector<string>fi;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w; cin >> h >> w;
	fi.resize(h);
	rep(i, h)cin >> fi[i];
	vector<vector<int>>dist(h, vector<int>(w,-1));
	queue<P>que;
	rep(i, h)rep(j, w) {
		if (fi[i][j] == '#') {
			dist[i][j] = 0; que.push(P(i, j));
		}
	}
	while (!que.empty()) {
		auto cur = que.front();
		que.pop();
		rep(dir, 4) {
			int nx = cur.first + dx[dir];
			int ny = cur.second + dy[dir];
			if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
				continue;
			}
			if (dist[nx][ny] == -1) {
				dist[nx][ny] = dist[cur.first][cur.second] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	int ans = 0;
	rep(i, h)rep(j, w) {
		chmax(ans, dist[i][j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 25524
N = gets.to_i
hs = gets.split.map(&:to_i) + [0]
ans = 0
height = 0
while true
  count = 0
  updated = false
  hs.each do |h|
    if height + 1 <= h
      updated = true
      count += 1
    else
      ans += count > 0 ? 1 : 0
      count = 0
    end
  end
  break unless updated
  height += 1
end
puts ans


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

int *counter;

void adpter(const vector<vector<int>>& adp, int index)
{
	for (int i = 0; i < adp[index].size(); i++)
	{
		if (counter[adp[index][i] - 1] > 0) continue;
		counter[adp[index][i] - 1]++;
		adpter(adp, adp[index][i] - 1);
	}
}


int main()
{
	int N;
	int M;
	int *a;
	int *b;
	cin >> N;
	cin >> M;
	a = new int[M];
	b = new int[M];
	for (int i = 0; i < M; i++)
	{
		cin >> a[i];
		cin >> b[i];
	}
	int bridgeCount = 0;
	for (int deleteIndex = 0; deleteIndex < M; deleteIndex++)
	{
		counter = new int[N];
		vector<vector<int>> adp;
		for (int i = 0; i < N; i++)
		{
			adp.push_back(vector<int>());
			counter[i] = 0;
		}
		for (int i = 0; i < M; i++)
		{
			if (i == deleteIndex)
				continue;
			adp[a[i] - 1].push_back(b[i]);
			adp[b[i] - 1].push_back(a[i]);
		}
		
		adpter(adp, 0);

		int answer = 0;
		for (int i = 0; i < N && answer == 0; i++)
		{
			if (counter[i] == 0) answer = 1;
		}
		
		bridgeCount += answer;
	}
	cout << bridgeCount;
	return 0;
}

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

Measured memory_bytes: 1160
N = int(input())
A = [0] * 2
for i in range(2):
  A[i] = list(map(int, input().split()))
candy = A[0][0]
for i in range(N):
  candy += A[1][i]
ans = candy
for i in range(1, N):
  candy = candy + A[0][i] - A[1][i - 1]
  ans = max(ans, candy)
print(ans)


Measured memory_bytes: 3064
A[1000][1000],I[1000],u[999];i,j;d;F=2;main(N){for(scanf("%d",&N);i<N;++i)for(j=0;~j+N;)scanf("%d",A[j++]+i);for(;F&2;i=N)for(++d,F=1;i--;u[i]>d|!j||u[F&=2,--j]>d|A[I[j]][j]+~i||++I[u[i]=u[j]=d+1,++I[i],F=2,j])j=A[I[i]][i];printf("%d",F*d-1);}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(){
  int N;
  map<string,int> rlt;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    rlt[s]++;
  }
  cout << "AC x " << rlt["AC"] << endl;
  cout << "WA x  " << rlt["WA"] << endl;
  cout << "TLE x " << rlt["TLE"] << endl;
  cout << "RE x " << rlt["RE"] << endl;
  return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  int h,w;
  string a[100];
  cin >> h >> w;
  for(int i=0; i<h; i++) cin >>a[i];
  int b[100][100]={0};
 for(int i=0; i<h; i++){
   for(int j=0; j<w; j++){
     if(a[i][j]=='#'){
     	b[i][j]++; b[i][j+1]++; b[i][j+2]++; b[i+1][j]++;
       b[i+1][j+2]++; b[i+2][j]++; b[i+2][j+1]++; b[i+2][j+2]++;
     }
   }
 }
 
  for(int i=0; i<h; i++){
   for(int j=0; j<w; j++){
     if(a[i][j]=='.') cout << b[i+1][j+1];
     else if(a[i][j]=='#') cout <<a[i][j];
     
   }
    cout << endl;
  }
  

  
}

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

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

  vector<string> candidates = {
    "AKIHABARA",
    "KIHABARA",
    "AKIHBARA",
    "AKIHABRA",
    "AKIHABAR",
    "KIHBARA",
    "KIHABRA",
    "KIHABAR",
    "AKIHBRA",
    "AKIHBAR",
    "AKIHABR",
    "AKIHBR",
    "KIHABR",
    "KIHBAR",
    "KIHBRA",
    "KIHBR"
  };

  bool yes = false;
  for(int i=0;i<candidates.size();i++) {
    if(candidates[i] == s) {
      yes = true;
      break;
    }
  }

  cout << (yes ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;

int main() {
	int N;
	cin >> N;
	set<int> A;
	for (int i = 0,a; i < N; i++) {
		cin >> a;
		A.insert(a);
	}
	cout << A.size();
	return 0;
}

Measured memory_bytes: 256
N = int(input())
dict =  {"AC":0,"WA":0,"TLE":0,"RE":0}
count = 0
for i in range(N):
    judge = input()
    if dict.get(judge) is not None:
        dict[judge] += 1
for key in dict.keys():
    print("{} x {}".format(key,dict[key]))

Measured memory_bytes: 9192
n,m = map(int,input().split())
a = set(map(int,input().split()))
dp = [0]+[-float('inf')]*n
f = [0,2,5,5,4,5,6,3,7,6]
for i in range(n+1):
  for j in a:
    F = f[j]
    if F <= i:
      dp[i] = max(dp[i-F]*10+j,dp[i])
print(dp[n])

Measured memory_bytes: 50908
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;

int main(){
    DRI(n);
    set<int>d;
    int sp=0;
    REP(i,n){
        DRI(x);
        if(x<400)d.insert(1);
        else if(x<800)d.insert(2);
        else if(x<1200)d.insert(3);
        else if(x<1600)d.insert(4);
        else if(x<2000)d.insert(8);
        else if(x<2400)d.insert(5);
        else if(x<2800)d.insert(6);
        else if(x<3200)d.insert(7);
        else sp++;
    }
    printf("%d %d\n",max(SZ(d),1),SZ(d)+sp);
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

bool is_prime[2000000];
vector<ll> primes;
bool is_fox_number[11000000];
int cnt[11000000];

void Sieve(){
	fill_n(is_prime,2000000,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<2000000; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j=i*2; j<2000000; j+=i) is_prime[j]=false;
		}
	}
}

void Solve(){
	Sieve();
	ll a,b,l,h;
	cin >> a >> b;
	l=max(a-b,2LL);
	h=a+b+1;

	fill_n(is_fox_number,11000000,true);
	fill_n(cnt,11000000,INF);

	for(auto p:primes){
		ll x=(l+p-1)/p*p;
		if(p*p>h) break;
		while(x<h){
			if(!is_fox_number[x-l]){
				x+=p;
				continue;
			}
			
			ll tmp=x;
			int c=0;
			while(tmp%p==0){
				tmp/=p;
				++c;
			}

			if(c>cnt[x-l]) is_fox_number[x-l]=false;

			cnt[x-l]=c;
			x+=p;
		}
	}

	int ans=0;
	rep(i,0,h-l) ans+=is_fox_number[i];

	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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

  int a,b,c,d;
  bool ab,bc,ca;

int main(){
  cin >> a >> b >> c >> d;
  if(abs(a-b) <= d)
    ab = true;
  if(abs(b-c) <= d)
    bc = true;
  if(abs(c-a) <= d)
    ca = true;
  if(ca || (ab && bc)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}





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

#define PIAR pair<int, int>

struct pos{
    int x;
    int y;
};

int main(){
    int w, h;
    while(cin >> w >> h, w != 0 && h != 0){
        int field[52][52] = {{0}};
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                cin >> field[i][j];
            }
        }

        stack<PIAR> st;
        int island = 0;
        int dx[] = {-1,  0, 1, 0, -1,  1, 1, -1};
        int dy[] = {0 , -1, 0, 1, -1, -1, 1,  1};
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                //島を探す
                if(field[i][j] == 1){
                    st.push(PIAR(i, j));
                    field[i][j] = 0;
                    while(!st.empty()){
                    	int x = st.top().first;
                    	int y = st.top().second;
                        st.pop();
                        for(int k = 0; k < 8; k++){
                            int nextX = x + dx[k];
                            int nextY = y + dy[k];
                            if(field[nextX][nextY] == 1){
                                st.push(PIAR(nextX, nextY));
                                field[nextX][nextY] = 0;
                            }
                        }
                    }
                    island++;
                }

            }
        }

        cout << island << endl;
    }
}

Measured memory_bytes: 1236
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;

class Route{

        private int N ;
        private int M ;
        private int X ;
        ArrayList<Integer> center = new ArrayList<Integer>();
        ArrayList<Integer> chip = new ArrayList<Integer>();


        Route(int n,int m,int x){
                this.N = n;
                this.M = m;
                this.X = x;
        }

        public void addCenter(int a){
                this.center.add(a);
        }
        public void setChip(){
                for(int i=0;i<=this.N;i++){
                        if(this.center.indexOf(i) >= 0){
                                this.chip.add(1);
                        }else if(this.center.indexOf(i) == -1){
                                this.chip.add(0);
                        }
                }
        }

        public int x2zero(){
                int cost = 0;
                for(int i=this.X; i>=0; i--){
                        cost += this.chip.get(i);
                }
                return cost;
        }
        public int x2N(){
                int cost = 0;
                for(int i=this.X; i<=N; i++){
                        cost += this.chip.get(i);
                }
                return cost;
        }

        public int getN(){return this.N;}
        public int getM(){return this.M;}
        public int getX(){return this.X;}


}

class Main{
        public static void main(String args[]){
                Scanner scan = new Scanner(System.in);
                Route route = new Route(scan.nextInt(),scan.nextInt(),scan.nextInt());
                for(int i=0;i<route.getM();i++) route.addCenter(scan.nextInt());
                route.setChip();
                int toZero = route.x2zero();
                int toN = route.x2N();

                System.out.println(Math.min(toZero,toN));

        }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <complex>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")

//#pragma GCC optimize("unroll-loops")
//#define double long double

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 3e5;
const ll inf = 1e16;

ll n, m, k;

ll st2[maxn];

vector <ll> dp(vector <ll> A){
    vector <ll> DP;
//    A.pb(inf);
    DP.resize(n);
    DP[n - 1] = 0;
    ll q;
//    vector <ll> L;
    vector <pll> LAST;
    LAST.pb(mp(n - 1, inf));
//    L.pb(inf);
    for (q = n - 2; q >= 0; q--){
        ll c = 0;
        ll a = A[q], b = A[q + 1];
        while (a > b){
            c++;
            b *= 4;
        }
//        cout << "q c " << q << " " << c << endl;
        if (c == 0){
            DP[q] = DP[q + 1];
            ll c1 = -1;
            ll a1 = A[q + 1], b1 = A[q];
            while (a1 >= b1){
                c1++;
                b1 *= 4;
            }
            LAST.pb(mp(q, c1));
//            L.pb(c1);
//            cout << "DP " <<  q << " " << DP[q] << endl;
            continue;
        }
        ll ans = DP[q + 1];
        ll nc = c;
        ll j = q;
        while (1){
            ll last = LAST[LAST.size() - 1].second;
            ll i = LAST[LAST.size() - 1].first;
            ans = ans + nc * (i - j);
//            cout << nc << " nc" << endl;
            if (last >= nc){
                LAST[LAST.size() - 1].second -= nc;
                break;
            }
            else{
//                if (LAST.size() == 1){
//                    break;
//                }
                nc = nc - last;
                j = i;
//                cout << j << " " << dc << " j dc" << endl;
                LAST.pop_back();
//                L.pop_back();
//                ll dl = L[L.size() - 1];
//                if (LAST.size() == 0){
//                    break;
//                }
//                LAST[LAST.size() - 1].second -= dl;

            }
        }
//        ll last = LAST[LAST.size() - 1].first;
        DP[q] = ans;
//        cout << "DP " <<  q << " " << DP[q] << endl;
    }
    return DP;
}

int main() {
    ll q, w, e, a, b;
//    pyshnapyshnakaa;
    st2[0] = 1;
    vector <ll> A;
    for (q = 1; q < 50; q++){
        st2[q] = st2[q - 1] * 2;
    }
    cin >> n;
    A.resize(n);
    for (q = 0; q < n; q++){
        cin >> A[q];
    }
    vector <ll> DP1 = dp(A);
//    cout << "DP1" << endl;
//    for (q = 0; q < n; q++){
//        cout << DP1[q] << " ";
//    }
//    cout << endl << endl << endl;
    reverse(A.begin(), A.end());
    vector <ll> DP2 = dp(A);
    reverse(DP2.begin(), DP2.end());
//    cout << "DP2" << endl;
//    for (q = 0; q < n; q++){
//        cout << DP2[q] << " ";
//    }
//    cout << endl;
    ll ans = 2 * min(DP1[0], DP2[n - 1] + n);
    for (q = 0; q < n - 1; q++){
        ans = min(ans, 2 * DP1[q + 1] + q + 1 + 2 * DP2[q]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 14052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 505;
const ll INF = (ll)1e18;
ll a[N][N];
ll b[N][N];
ll dp[N][N];
int n;

ll getSum(int l, int r, int x, int y) {
	return a[l][x] + a[r][y] - a[l][y] - a[r][x];
}
ll getCost(int i, int j, int k) {
	return getSum(k, n, i, j) + b[j][k];
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			if (i != j)
				scanf("%lld", &a[i + 1][j + 1]);
			a[i + 1][j + 1] += a[i + 1][j] + a[i][j + 1] - a[i][j];
		}
	for (int len = 1; len <= n; len++) {
		for (int l = 0; l + len <= n; l++) {
			int r = l + len;
			b[l][r] = b[l + 1][r] + getSum(l, l + 1, l, r);
		}
	}
	for (int i = 0; i < n; i++)
		for (int j = i; j <= n; j++)
			dp[i][j] = INF;
	for (int i = 1; i <= n; i++)
		dp[0][i] = b[0][i];
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			for (int k = j + 1; k <= n; k++) {
				dp[j][k] = min(dp[j][k], dp[i][j] + getCost(i, j, k));
			}
	ll ans = INF;
	for (int i = 0; i < n; i++)
		ans = min(ans, dp[i][n]);
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll x; cin >> x;
  ll v = 100;
  int d = 0;
  while (v < x) {
    v += v / 100;
    d++;
  }
  cout << d << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	int n, cnt = 0, input;
	vector<int> vec;
	bool flag = 1;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> input;
		vec.push_back(input);
	}

	while (flag)
	{
		flag = 0;
		for (int i = n - 1; i >= 1; i--)
		{
			if (vec[i] < vec[i - 1])
			{
				swap(vec[i], vec[i - 1]);
				flag = 1;
				cnt++;
			}
		}
	}

	int i = 0;

	for (auto a : vec)
	{
		cout << (i ? " " : "") << a;
		i++;
	}

	cout << endl;

	cout << cnt << endl;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
const int mod = 998244353, L = 128;

int tot;
vector<char> bet;
vector<string> tab;

inline int addMod(int a, int b) {
	return (a += b) >= mod ? a - mod : a;
}

inline ll quickpow(ll base, ll pw) {
	ll ret = 1;
	while (pw) {
		if (pw & 1) ret = ret * base % mod;
		base = base * base % mod, pw >>= 1;
	}
	return ret;
}

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

inline bool cmp(const string &a, const string &b) {
	return a.length() < b.length();
}

inline string merge(const string &a, const string &b) {
	int x;
	string ret, tmp;
	auto l = a.begin(), r = b.begin();
	while (l != a.end() && r != b.end()) {
		tmp = ret;
		tmp.push_back(*r);
		for (auto i = l; i != a.end(); ++i)
			tmp.push_back(*i);
		cout << "? " << tmp << endl;
		read(x);
		if (x + tmp.length() == tot)
			ret.push_back(*r++);
		else
			ret.push_back(*l++);
	}
	while (l != a.end()) ret.push_back(*l++);
	while (r != b.end()) ret.push_back(*r++);
	return ret;
}

int main() {
	int x;
	for (R int i = 'A'; i <= 'Z'; ++i) bet.push_back(i);
	for (R int i = 'a'; i <= 'z'; ++i) bet.push_back(i);
	for (R int i = '0'; i <= '9'; ++i) bet.push_back(i);
	for (auto &v : bet) {
		cout << "? ";
		for (R int i = 1; i <= L; ++i)
			cout << v;
		cout << endl;
		read(x), tot += L - x;
		string s;
		for (R int i = 1; i <= L - x; ++i)
			s.push_back(v);
		tab.emplace_back(s);
	}
	while (tab.size() > 1) {
		sort(tab.begin(), tab.end(), cmp);
		vector<string> tmp;
		auto l = tab.begin(), r = prev(tab.end());
		while (l < r) {
			tmp.push_back(merge(*l, *r));
			++l, --r;
		} 
		if (l == r) tmp.push_back(*l);
		swap(tmp, tab);
	}
	cout << "! " << tab.back() << endl;
	return 0;
}

Measured memory_bytes: 3768
import sys
sys.setrecursionlimit(10 ** 9)

INF = float('inf')

def rec(i: int):
    #if(i==0):print(i,H[i])
    #if(i>=1):print(i,H[i],H[i-1])
    #if(i>=2):print(i,H[i],H[i-2])
    if dp[i] < INF:
        return dp[i]

    if i==0: return 0
    res = INF

    res = min(res, rec(i-1)+abs(H[i]-H[i-1]))

    if i > 1:
        res = min(res,rec(i-2)+abs(H[i]-H[i-2]))

    dp[i] = res
    return dp[i]

N = int(input())
H = list(map(int,input().split()))

dp = [INF] * (N+2)

print(rec(N-1))

#7
#2 9 4 5 1 6 10


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

num =[[0] * 10 for _ in range(10)]

for n in range(1, N+1):
    s = str(n)
    a, b = map(int, [s[0], s[-1]])
    num[a][b] += 1

ans = 0
for a in range(1, 10):
    for b in range(1, 10):
        ans += num[a][b] * num[b][a]

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int N=50;
int n,a[N],b[N],c[N],ans=0;

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
   	if(c=='-')t=-1,c=getchar();
   	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
   	return s*t;
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	scanf("%d",&b[i]);
	for(int i=1;i<n;i++)
	scanf("%d",&c[i]);
	for(int i=1;i<=n;i++)
	ans+=b[a[i]];
	for(int i=2;i<=n;i++)
	if(a[i]-a[i-1]==1)ans+=c[a[i-1]];
	printf("%d\n",ans);
}

Measured memory_bytes: 128