akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    string s;
    cin >> s;
    if(s[0]==s[1]&&s[1]==s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int ans = A + B;
  ans = min(ans, B + C);
  ans = min(ans, C + A);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;

using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {

	int N;
	cin >> N;
	
	int res = 0;

	for (int i = 1; i <= N; i++) {
		int count = 0;
		for (int j = 1; j <= i; j++) {
			
			if (i % j == 0 && i % 2 == 1) {
				count++;
			}
		}
		if (count == 8) {
			res++;
		}
	}
	ce(res);
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int a, b;
	char c;
	double rad = M_PI / 2.0, x = 0, y = 0;
	for (cin >> a >> c >> b; a || b; cin >> a >> c >> b) {
		x += a*cos(rad);
		y += a*sin(rad);
		rad -= (b / 180.0 * M_PI);
	}
	cout << int(x) << endl << int(y) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    cout << max(max(A + B, A - B), A * B) << endl;
    return 0;
}
/* 注意すべき点
グローバル以外の配列は初期化すべし
*/

Measured memory_bytes: 256
#include <iostream>
#define N 101
using namespace std;

int a[N][N],b[N][N];
long int c[N][N]={{0}};

int main(){

  int n,m,l;
  cin >> n >> m >> l;

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

  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
      cin >> b[i][j];
    }
  }


  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      for(int k=0;k<m;k++){
        c[i][j] +=a[i][k]*b[k][j];
      }
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
    cout << c[i][j];
    if(j!=l-1) cout << " ";
    }
  cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define ff first
#define ss second
#define tt third
#define q2(n) (n%2)==0
#define vp vector<pair <$$,$$> >
#define vctr vector<$$>
#define in(a) scanf("%lld",&a)
#define out(a) printf("%lld ",a)
#define loop(i,m,p) for ($$ i = m; i < p; i++)
#define loopn(i,m,p) for ($$ i = p-1; i >=m; --i)

using namespace std;


int main()
{


   $$ n;
   cin>>n;
   $$ a[n];
   loop(i,0,n) cin>>a[i];
   $$ sum=0;
   loop(i,0,n-1){
   	loop(j,i+1,n){
   		sum+=(a[i]*a[j]);
   	}
   }
   cout<<sum<<endl;








return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(index, begin, end) for (int (index) = (begin); (index) < (end); (index)++)
#define RE(index, end) REP(index, 0, end)
#define INF INT_MAX / 3
#define DINT(x) printf(#x " = %d\n", x);
#define GETINT(x) scanf("%d", &x)
#define GETLL(x) scanf("%lld", &x)
#define GETSTR(x) scanf("%s", x)

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

struct ie_t
{
	ll pos;
	char dir;
};

int main()
{
	int ie_num, hito_num;
	ll time;
	vector<ie_t> ie;
	vi hito;
	GETINT(ie_num);
	GETLL(time);
	GETINT(hito_num);
	ie.reserve(ie_num);
	hito.reserve(hito_num);
	RE(i, ie_num)
	{
		ll pos;
		int dir;
		GETLL(pos);
		GETINT(dir);
		ie_t temp;
		temp.pos = pos;
		switch (dir)
		{
		case 1:
			temp.dir = 1;
			break;
		case 2:
			temp.dir = -1;
			break;
		}
		ie.push_back(temp);
	}
	RE(i, hito_num)
	{
		int temp;
		GETINT(temp);
		hito.push_back(temp - 1);
	}
	vector<ll> result;
	RE(hito_cur, hito_num)
	{
		int hito_ieidx = hito[hito_cur];
		ie_t hito_ie = ie[hito_ieidx];
		if ((hito_ieidx >= ie_num - 1 && hito_ie.dir == 1) ||
			(hito_ieidx <= 0 && hito_ie.dir == -1))
		{
			result.push_back(hito_ie.pos + hito_ie.dir * time);
			continue;
		}
		int hito_n_ieidx = hito_ieidx + hito_ie.dir;
		ie_t hito_n_ie = ie[hito_n_ieidx];
		bool fin = false;
		while (hito_ie.dir == hito_n_ie.dir)
		{
			if ((hito_n_ieidx >= ie_num - 1 && hito_ie.dir == 1) ||
				(hito_n_ieidx <= 0 && hito_ie.dir == -1))
			{
				result.push_back(hito_ie.pos + hito_ie.dir * time);
				fin = true;
				break;
			}
			if (hito_ie.pos - hito_n_ie.pos >= time &&
				hito_n_ie.pos - hito_ie.pos >= time)
			{
				result.push_back(hito_ie.pos + hito_ie.dir * time);
				fin = true;
				break;
			}
			hito_n_ieidx += hito_ie.dir;
			hito_n_ie = ie[hito_n_ieidx];
		}
		if (fin)
		{
			continue;
		}
		ie_t hito_nprev_ie = ie[hito_n_ieidx - hito_ie.dir];
		ll len = (hito_n_ie.pos + hito_nprev_ie.pos) / 2 - hito_ie.pos;
		if (len * hito_ie.dir > time)
		{
			len = time * hito_ie.dir;
		}
		result.push_back(len + hito_ie.pos);
	}
	RE(i, hito_num)
	{
		printf("%lld\n", result[i]);
	}
	return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vld = vector<ld>; 

int main(void) {
    ll n; 
    while (cin >> n && n) {
        vld x(n), y(n); rep(i, n) cin >> x[i] >> y[i];
        auto d = [&](ll i, ll j) { return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]); };
        ll ret = 1;
        for (int i = 0; i < n-1; i++) {
            for (int j = i+1; j < n; j++) {
                ld dij = d(i, j);
                if (dij >= 4) continue;
                ld x1 = x[i], y1 = y[i], x0 = x[j], y0 = y[j];
                for (auto dir : {1, -1}) {
                    ld xc = x0 + (x1 - x0) / 2.0l + (-(y1 - y0)) * dir 
                        * sqrtl(1.0l - ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) / 4.0l) 
                        / sqrtl((y1 - y0) * (y1 - y0)  + (x1 - x0) * (x1 - x0));
                    ld yc = y0 + (y1 - y0) / 2.0l + (+(x1 - x0)) * dir 
                        * sqrtl(1.0l - ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) / 4.0l) 
                        / sqrtl((y1 - y0) * (y1 - y0)  + (x1 - x0) * (x1 - x0));
//                    cout << x1 << " " << y1 << " " << x0 << " " << y0 << " : " << xc << " " << yc << endl;
                    ll m = 2;
                    rep(k, n) {
                        if (k == i || k == j) continue;
                        if ((xc - x[k]) * (xc - x[k]) + (yc - y[k]) * (yc - y[k]) < 1) 
                            m++;
                    }
                    chmax(ret, m);
                }
            }
        }
        cout << ret << endl;
    }
    return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// constexpr ll INF = 1LL << 60;

struct UnionFind{
  vector<int> par;
  UnionFind(int n): par(n){
    REP(i, n){
      par[i] = i;
    }
  }
  int root(int x){
    if(par[x] == x){
      return x;
    }
    return par[x] = root(par[x]);
  }
  bool same(int a, int b){
    return root(a) == root(b);
  }
  void unite(int a, int b){
    int aroot = root(a);
    int broot = root(b);
    if(aroot == broot) return;
    par[aroot] = broot;
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  UnionFind uf(n);
  REP(i, q){
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0){
      uf.unite(x, y);
    }
    else{
      cout << (uf.same(x, y) ? 1 : 0) << endl;
    }
  }
  return 0;
}




Measured memory_bytes: 3176
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(2,n):
    dp[i]=min(abs(l[i]-l[i-2])+dp[i-2],abs(l[i]-l[i-1])+dp[i-1])
print(dp[-1])

Measured memory_bytes: 13908
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;

const int maxn = 200002;

int n, evenFreq[maxn], oddFreq[maxn], evenMax, oddMax, evenSecondMax, oddSecondMax;

vector<int> evenBest, oddBest, evenSecondBest, oddSecondBest;

int main()
{
	cin >> n;

	int v, maxv = 0, minv = 200000;
	for (int i = 1; i <= n; ++i) {
		cin >> v;

		if (i%2)
			++oddFreq[v];
		else
			++evenFreq[v];

		if (v > maxv)
			maxv = v;
		if (v < minv)
			minv = v;
	}

	for (int i = minv; i <= maxv; ++i) {
		if (evenFreq[i] > evenMax) {
			evenSecondMax = evenMax;
			evenSecondBest = evenBest;

			evenMax = evenFreq[i];
			evenBest = vector<int>(1, i);
		} else if (evenFreq[i] == evenMax) {
			evenBest.push_back(i);
		} else if (evenFreq[i] > evenSecondMax) {
			evenSecondMax = evenFreq[i];
			evenSecondBest = vector<int>(1, i);
		} else if (evenFreq[i] == evenSecondMax)
			evenSecondBest.push_back(i);

		if (oddFreq[i] > oddMax) {
			oddSecondMax = oddMax;
			oddSecondBest = oddBest;
			
			oddMax = oddFreq[i];
			oddBest = vector<int>(1, i);
		} else if (oddFreq[i] == oddMax) {
			oddBest.push_back(i);
		} else if (oddFreq[i] > oddSecondMax) {
			oddSecondMax = oddFreq[i];
			oddSecondBest = vector<int>(1, i);
		} else if (oddFreq[i] == oddSecondMax)
			oddSecondBest.push_back(i);
	}

	int ans = n - evenMax - oddMax;
	if (evenBest.size() == 1 && oddBest.size() == 1 && evenBest[0] == oddBest[0]) {
		
		ans = n - max(evenMax + oddSecondMax, oddMax + evenSecondMax);
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2024
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>

int main(){
    int n,m,x;
    
    while(std::cin >> n >> m){
        
        if(n == 0 && m == 0)
            break;
        
        int flag = 0;
        int num = 0;
        std::vector<int> v;
        std::string line;
    
        std::getline(std::cin, line);
    
        if(std::getline(std::cin, line)){
            std::istringstream ss(line);
            while(ss >> x){
                v.push_back(x);
            }
        }
        
        sort(v.rbegin(),v.rend());
    
        for(int y = 0;y < n;++y){
            ++flag;
            if(flag != m){
                num += v[y];
            }
            else
                flag = 0;
        }
        std::cout << num << std::endl;
    }
}


Measured memory_bytes: 3180
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXH 55
#define MAXW 55
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int H,W, D[MAXH][MAXW] = {}, nextX, nextY;
string G[MAXH];
queue<pii> Q;

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

void bfs(){
    D[0][0] = 1;
    Q.push(pii(0,0));

    while(!Q.empty()){
        pii tmp = Q.front();
        Q.pop();
        int i = tmp.first, j = tmp.second;

        rep(k, 4){
            nextY = j + dy[k];
            nextX = i + dx[k];

            if(nextY < 0 || H <= nextY || nextX < 0 || W <= nextX)
                continue;
            
            // printf("reached (%d, %d)\n", nextX, nextY);

            if(!D[nextY][nextX] && G[nextY][nextX] == '.'){
                D[nextY][nextX] = D[j][i]+1;
                Q.push(pii(nextX, nextY));
            }
        }
    }
}

void solve(){
    bfs();

    if(D[H-1][W-1])
        cout << H*W - D[H-1][W-1] - ans << endl;
    else
        cout << -1 << endl;
}

int main(){
    cin >> H >> W;
    rep(i, H){
        cin >> G[i];
        rep(j, W){
            if(G[i][j] == '#') ans++;
        }
    } 

    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

// MARK: - header
namespace {
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<ull MOD>
struct Mod {
    ull v = 0;
    Mod() {};
    Mod(ull val) : v(val) {}
    operator ull() const {return v;}
    ull operator=(ll x) {return v = x % MOD;}
    ull operator+=(ll x) {return operator=(v + x);}
    ull operator*=(ll x) {return operator=(v * x);}
};
}

// MARK: - answer

ll X, Y, Z, K;
vector<ll> A, B, C;

void input() {
    cin >> X >> Y >> Z >> K;
    A.resize(X);
    for (auto& a : A)
        cin >> a;
    B.resize(Y);
    for (auto& b : B)
        cin >> b;
    C.resize(Z);
    for (auto& c : C)
        cin >> c;
}

bool cut_search(ll p, vector<ll>& sums, bool quick_cut = true) {
    sums = {};
    for (auto a : A) {
        for (auto b : B) {
            for (auto c : C) {
                auto sum = a+b+c;
                if (sum < p)
                    break;
                sums.push_back(sum);
                if (quick_cut and sums.size() >= K)
                    return true;
            }
        }
    }
    return false;
}

void solve() {
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    vector<ll> sums;
    ll l = 0, r = 3e10;
    ll p = 0;
    while (l <= r) {
        ll c = (l+r)/2;
        if (cut_search(c, sums)) {
            p = c;
            l = c + 1;
        } else {
            r = c - 1;
        }
    }
    cut_search(p, sums, false);
    sort(sums.rbegin(), sums.rend());
    for (int i = 0; i < K; i++)
        cout << sums[i] << endl;
}

int main() {
    input();
//    cout << (solve() ? "Yay!" : ":(") << endl;
    solve();
    
    return 0;
}



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

int main(){
    int N;  cin >> N;
    vector<tuple<ll,ll,ll>> S(N);
    for(int i=0; i<N; i++){
        ll A, B;  cin >> A >> B;
        S[i] = make_tuple(A+B,A,B);
    }
    sort(S.begin(), S.end());

    ll ans = 0;
    for(int i=0; i<N; i++){
        int n = N-1-i;
        if(i%2==0){
            ans += get<1>(S[n]);
        }else{
            ans -= get<2>(S[n]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = TEN(9) + 7;

inline ll mod_pow(ll a, ll x, ll m)
{
	if (x == 0) return 1ll;

	ll res = mod_pow(a, x / 2, m);

	res *= res;
	res %= m;

	if (x % 2) {
		res *= a;
		res %= m;
	}

	return res;
}

int N, K;
int counter[100010];

signed main()
{
	cin >> N >> K;

	int ans = 0;

	for (int i = K; i >= 1; --i) {
		counter[i] = mod_pow(K / i, N, mod);
		for (int j = i + i; j <= K; j += i) {
			counter[i] += mod - counter[j];
			counter[i] %= mod;
		}
	}

	for (int i = 1; i <= K; ++i) {
		ans += i * counter[i];
		ans %= mod;
	}

	cout << ans << endl;
}




Measured memory_bytes: 4352
import sys


def count(i, r, value):
    value += rc[i]
    counter[i] = value
    for e in es[i]:
        if e != r:
            count(e, i, value)


if __name__ == "__main__":
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    es = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        es[a-1].append(b-1)
        es[b-1].append(a-1)
    counter = [0]*N
    rc = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        rc[p-1] += x
    count(0, -1, 0)
    print(*counter)


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

int main(){
    int k;
    cin >> k;
    string s;
    rep(i,k){
        s = s  +"ACL";
    }

    cout << s << endl;
}

Measured memory_bytes: 3628
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;

long long int N, M, K, W, H, L, R;

int main() {
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	map<char, int>m;
	for (auto i : s) {
		m[i]++;
	}
	for (char i = 'a'; i <= 'z'; i++) {
		if (!m[i]) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "None\n";
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()), x = Integer.parseInt(sc.next());
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = Integer.parseInt(sc.next());
        }
        int prevD = 0;
        int result = 1;
        while (result != n + 1) {
            int d = prevD + l[result - 1];
            if (d > x) {
                break;
            }
            prevD = d;
            result++;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 21588
package main

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

var in = newIo(bufio.NewScanner(os.Stdin))

func main() {
	var n = in.nextInt()
	print(solve(n))
}

func print(result int) {
	fmt.Println(result)
}

func solve(n int) int {
	return 1110 - n
}

type io struct {
	sc *bufio.Scanner
}

func newIo(sc *bufio.Scanner) *io {
	i := new(io)
	i.sc = sc
	i.sc.Split(bufio.ScanWords)
	return i
}

func (i *io) setSplit(f bufio.SplitFunc) {
	i.sc.Split(f)
}

func (i *io) nextIntSlice(y int, delim string) [][]int {
	result := make([][]int, y)
	for j := 0; j < y; j++ {
		line := i.next()
		result[j] = perseIntSlice(strings.Split(line, delim))
	}
	return result
}

func (i *io) next() string {
	i.sc.Scan()
	return i.sc.Text()
}

func (i *io) nextInt() int {
	return perseInt(i.next())
}

func (i *io) nextLong() int64 {
	return perseLong(i.next())
}

func perseInt(s string) int {
	in, _ := strconv.Atoi(s)
	return in
}

func perseLong(s string) int64 {
	in, _ := strconv.ParseInt(s, 10, 64)
	return in
}

func perseIntSlice(s []string) []int {
	var r = make([]int, len(s))
	for i := 0; i < len(s); i++ {
		r[i] = perseInt(s[i])
	}
	return r
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int d; cin >> d;
	// 監視員は地震のいる木とあとD本みれる
	int a = 2*d+1 ;
	if(n%a ==0){
		cout << n/a<<endl;
		}
		else {
		  cout << n/a + 1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (int i = (a); i >= (b); --i)
#define edge(i, u) for (int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define mod 1000000007
#define ll long long
#define N 100005
#define K 205
#define pb push_back
ll n, x;
inline ll calc (ll x, ll y)
{
    if (x < y) std::swap(x, y);
    if (!y) return -x;
    return calc(y, x % y) + 2 * (x / y) * y;
}
int main ()
{
    scanf("%lld %lld", &n, &x);
    printf("%lld", calc(n - x, x) + n);
    return 0;
}

Measured memory_bytes: 256
// AOJ 2264 Spanning Trees
// 2018.2.1 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, k, m, n2, i, j;

	n = in(), k = in();
	n2 = n >> 1, m = n - (n & 1);
	if (n2 < k) puts("-1");
	else for (i = 0; i < k; i++) {
		for (j = 0; j < n2; j++)
			printf("%d %d\n", 1+(i+j)%m, 1+(m+i-j-1)%m);
		for (j = 0; j < n2-1; j++)
			printf("%d %d\n", 1+(m+i-j-1)%m, 1+(i+j+1)%m);
		if (n & 1) printf("%d %d\n", i+1, n);
		putchar('\n');
	}
	return 0;
}


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

const int N = 1e5 + 5;
typedef long long ll;

int a, b, n, h[N];

bool works(ll x) {
	ll c = b * x;
	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (c >= h[i]) continue;
		cnt += (h[i] - c - 1) / (a - b) + 1;
	}
	return cnt <= x;
}

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> a >> b;
	for (int i = 0; i < n; ++i) cin >> h[i];
	ll lo = 1, hi = 1e18 / b;
	while (lo < hi) {
		ll mid = (lo + hi) / 2;
		if (works(mid)) hi = mid;
		else lo = mid + 1;
	}
	cout << lo << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

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

    int N = sc.nextInt();
    int[] count_array = new int[N+1];
    int[] coins = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049, 279936, 531441};
    int tmp;

    for (int i=0; i <= N; i++) {
      count_array[i] = i;
    }

    for (int i=1; i < coins.length; i++) {
      for (int j=0; j <= N-coins[i]; j++) {
        if (count_array[j+coins[i]] > count_array[j] + 1) {
          count_array[j+coins[i]] = count_array[j] + 1;
        }
      }
    }

    System.out.println(count_array[N]);
  }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const double EPS=1e-8;
const int N=2e5+10;
const ll mod=1e9+7;
inline ll read()
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar()) x=x*10+ch-'0';
   return x*f;
}
ll k;
int main()
{  cin>>k;
   ll sum=7;
   for(int i=1;i<=10000000;i++)
   {   if(sum%k==0)
       {  printf("%d",i);
          return 0;
       }
       sum=sum%k;
       sum=sum*10+7;
   }
   printf("-1");
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,M;
  cin>>N>>M;
  int ans=0;
  if(N==1&&M==1){
    ans=1;
    cout<<ans<<endl;
    return 0;
  }
  if(N==1||M==1){
    if(N==1)ans=M-2;
    if(M==1)ans=N-2;
    cout<<ans<<endl;
    return 0;
  }
  ans=(N-2)*(M-2);
  cout<<ans<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, t;
map<int,int> d;

int main() {
	cin >> n;
	rep(i,n) {
		cin >> t;
		d[t]++;
	}
	cin >> m;
	rep(i,m) {
		cin >> t;
		if (!d[t]) {
			cout << "NO" << ln;
			return 0;
		}
		d[t]--;
	}
	cout << "YES" << ln;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int ans=0;
  REP(i,A+1){
    REP(j,B+1){
      REP(k,C+1){
        int sum;
        sum=500*i+100*j+50*k;
        if(sum==X)ans++;
      }
    }
  }
  P(ans);
  return 0;
}



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

/***Crazy Macros***/
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define reu(i,a,b) for (ll i = (a); i <= (b); ++i)
#define red(i,a,b) for (ll i = (a); i >= (b); --i)
typedef int64_t ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll inf = 1e18;
const ll mod = 998244353;

/***Graph Variables***/
vector<vi> adj;
vector<vi> radj;
vi visited;
vi level;

/***Common Functions***/
ll inp() {ll x; cin >> x; return x;}
string inpStr() {string x; cin >> x; return x;}

ll power(ll a, ll b) {
    a %= mod;
    ll res = 1;
    reu(i, 0, log2(b)) {
        if (b & (1<<i)) res = (res*a) % mod;
        a = (a*a) % mod;
    }
    return res;
}
ll gcd(ll a, ll b) {
    while (b > 0) {ll tmp = a%b; a = b; b = tmp;}
    return a;
}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}

void file_io(string in, string out) {
    freopen(in.c_str(), "r", stdin);
    freopen(out.c_str(), "w", stdout);
}
/***Main Code***/
bool pal(string s, ll b, ll e) {
    reu(i, b, (b+e)/2)
        if (s[i] != s[b+e-i]) return false;
    return true;
}
int main()
{
    fast_io();
    ll L = inp();
    double res = L*L*L/(3.0*3.0*3.0);
    cout << setprecision(7) << fixed << res;
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4.1")

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

const int mod = (int)1e9 + 7;

void add (int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

void sub (int &a, int b)
{
    a -= b;
    if (a < 0)
        a += mod;
}

int mult (int a, int b)
{
    return (ll)a * b % mod;
}

int n;
vii a, b;

bool read ()
{
    if (!(cin >> n))
        return false;

    a = b = vii(n);
    forn (i, n)
    {
        cin >> a[i].fst >> b[i].fst;
        a[i].snd = b[i].snd = i;
    }

    return true;
}

const ll inf = ll(1e18);

ll solve ()
{
    sort(all(a));
    sort(all(b));

    mt19937_64 rng (228);
    vll value (n);
    forn (i, n)
        value[i] = rng() % (1LL << 60);

    ll hsh_a, hsh_b = 0;
    ll sum_b = 0LL, sum_a = 0;
    forn (i, n)
        sum_b += b[i].fst;

    ll ans = inf;
    ford (take_b, n + 1)
    {
        const int take_a = n - take_b;

        if (take_a == 0 || take_b == 0 || hsh_a != hsh_b)
            ans = min(ans, sum_a + sum_b);
        else
        {
            ans = min(ans, sum_a + sum_b + b[take_b].fst - b[take_b - 1].fst);
            ans = min(ans, sum_a + sum_b + a[take_a].fst - a[take_a - 1].fst);
        }

        if (take_b > 0)
        {
            sum_b -= b[take_b - 1].fst;
            hsh_b ^= value[b[take_b - 1].snd];
        }
        if (take_a < n)
        {
            sum_a += a[take_a].fst;
            hsh_a ^= value[a[take_a].snd];
        }
    }

    return ans;
}

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
    {
        auto ans = solve();
        cout << ans << endl;
    }

    return 0;
}


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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[,] abc = new int[N,3];

        for (int i = 0; i<N; i++ ) {
            abc[i,0] = cin.nextInt();
            abc[i,1] = cin.nextInt();
            abc[i,2] = cin.nextInt();
        }

        int[,] DP = new int[N+1,3];
        for (int i=1; i<=N; i++) {
            for (int j = 0; j<3; j++) {
                DP[i, (j+1)%3] = Math.Max(DP[i, (j+1)%3], DP[i-1, j] + abc[i-1, (j+1)%3]);
                DP[i, (j+2)%3] = Math.Max(DP[i, (j+2)%3], DP[i-1, j] + abc[i-1, (j+2)%3]);
            }
        }

        Console.WriteLine(Math.Max(DP[N, 0], Math.Max(DP[N,1], DP[N,2])));
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 17344
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>s) {
		ll ans = 0, p=0;
		REP(i, s.size()) {
			if(s[i]=='W') {
				ans+=i-p;
				p++;
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 720
#N個のりんごの数　L:味の基準
N, L = map(int, input().split())

#普通のアップルパイの味
nomal_sum = 0
for number in range(1,N+1):
  nomal_sum = nomal_sum + (L + number -1)
#print("普通のアップルパイ",nomal_sum)
  
#一つ欠けたアップルパイのパターンを作る
#lost_sum = 0
#for number in range(1,N+1):
#  if number == 1:
#    print("1だよ")
#  else:
#    lost_sum = lost_sum + (L + number -1)
#print(lost_sum)

#一つ欠けたアップルパイのリストをつくる
list = []
lost_sum = 0
for number in range(1,N+1):
  for number2 in range(1,N+1):
    if number != number2:
      lost_sum = lost_sum + (L + number2 -1)
  list.insert(number, lost_sum)
  lost_sum = 0
#print("list",list)

# 差の絶対値を取る
minimal1 = 100000
ans = 0
for list_aji in list:
  #print("list_aji",list_aji)
  #print("minimal1",minimal1)
  #print("abs(list_aji - nomal_sum)",abs(list_aji - nomal_sum))
  if minimal1 >= abs(list_aji - nomal_sum):
    minimal1 = abs(list_aji - nomal_sum)
    ans = list_aji
print(ans)

Measured memory_bytes: 3064
h, w = gets.split.map(&:to_i)
f = h.times.map{gets.chomp}
rmv_t = "."*w
f2 = f.delete_if{|s| s==rmv_t}.map(&:chars).transpose
f3 = f2.delete_if{|t| t.all?{|c| c==?.}}.transpose.map(&:join)
puts f3

Measured memory_bytes: 2428
N,K=map(int,input().split())
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp)
print(ans)

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

X = int(N // 1.08)

if int(X*1.08) == N:
    print(X)
elif int((X-1)*1.08) == N:
    print(X-1)
elif int((X+1)*1.08) == N:
    print(X+1)
else:
    print(":(")

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < s.size(); i++) {
      s[i] = s[i] + n;
  }
  for (int i = 0; i < s.size(); i++) {
      if(s[i] > 'Z') {
        s[i] = s[i] - 'Z';
        s[i] = 'A' + s[i] - 1;
      }
  }
  cout << s;
  return 0;
}

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

string s, ans;

int main() {
  cin >> s;
  rep (i, 3) ans += s[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstring>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	if (a - 2 * b > 0) {
		cout << a - 2 * b;
	}
	else {
		cout << 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int solve(int ,int);

int A[2000];
int n;
int main() {
  int i;
  int m;
  int j;
  int q;
  int mi[2000];
  

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }
  for(i=0;i<q;i++){
    if(solve(0,mi[i])==1) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int solve(int i,int mi){

  int res;
  if(mi==0) return 1;
  if(i>=n) return 0;

  res= solve(i+1,mi) || solve(i+1,mi-A[i]);
  return res;
}

Measured memory_bytes: 588
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const ll inf=1e18;
const int MAX_N=55;
const int MAX_L=35;
ll ans=inf;
int n,len[MAX_N];
ll c[MAX_N],dp[MAX_N][MAX_L][2];
char s[MAX_N][MAX_L];
ll dfs(int id,int pos,int dir)
{
	if(pos>len[id]) return dp[id][pos][dir]=0;
	if(~dp[id][pos][dir]) return dp[id][pos][dir];
	ll &tmp=dp[id][pos][dir];
	tmp=inf;
	bool flag=true;
	if(!dir){ for(int st=pos,ed=len[id];st<ed;st++,ed--)if(s[id][st]!=s[id][ed]){ flag=false; break; } } 	
	else{ for(int st=pos,ed=1;st>ed;st--,ed++)if(s[id][st]!=s[id][ed]){ flag=false; break; } } 
	if(flag) return dp[id][pos][dir]=0;
	repi(i,1,n){
		flag=true;
		int j,k;
		if(!dir){
			for(j=pos,k=len[i];j<=len[id]&&k>=1;j++,k--)if(s[id][j]!=s[i][k]){ flag=false; break; }
			if(flag) tmp=min(tmp,c[i]+((k<1)?dfs(id,j,0):dfs(i,k,1)));
		}
		else{
			for(j=pos,k=1;j>=1&&k<=len[i];j--,k++)if(s[id][j]!=s[i][k]){ flag=false; break; }
			if(flag) tmp=min(tmp,c[i]+((j<1)?dfs(i,k,0):dfs(id,j,1)));
		}
	}
	return tmp;
}
int main()
{
	si(n); memset(dp,-1,sizeof(dp));
	repi(i,1,n) ss(s[i]+1),sl(c[i]),len[i]=strlen(s[i]+1);
	repi(i,1,n) ans=min(ans,c[i]+dfs(i,1,0));
	printf("%lld\n",(ans==inf)?-1:ans);
	return 0;
}


Measured memory_bytes: 3864
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

DIV = 10**9+7

def mod_inv(a,mod = DIV):
    return pow(a,mod-2,mod)

def ncr(n,r, mod =DIV):
	r = min(r,n-r)
	ret = 1
	for i in range(1,r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * pow(i, mod-2, mod) % mod
	return ret


def main():
    N, M,K = ints_raw()
    ans = 0
    for d in range(1,N):
        ans =(ans+d*(N-d)*M*M)%DIV
    for d in range(1,M):
        ans =(ans+d*(M-d)*N*N)%DIV
    return (ans*ncr(N*M-2,K-2))%DIV
print(main())


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

typedef long long LL;
const int MOD = 1000000007;

int main(){
    int n;
    while(cin >> n){
        vector<string> s(n);
        REP(i, n) cin >> s[i];
        array<LL, 222> dp = {};
        dp[0] = 1;
        int down = 0;
        int eq = 0;
        int up = 0;
        for(int i = 0; i < n; i++) {
            //REP(i, 10) cout << dp[i] << " "; cout << endl;
            if(s[i] == "-") {
                eq++;
                continue;
            }

            if(s[i] == "D") {
                for(int j = 0; j <= n; j++) {
                    int rest = i - eq - up - j;
                    //printf("i = %d eq = %d up = %d j = %d rest = %d dp[j] = %lld\n", i, eq, up, j, rest, dp[j]);
                    if(rest > 0) {
                        dp[j] *= rest;
                        dp[j] %= MOD;
                    } else {
                        dp[j] = 0;
                    }
                }
            }

            array<LL, 222> ndp = {};
            for(int j = 0; j <= n; j++) {
                int rest = down - j;
                if(rest >= 1) {
                    ndp[j + 1] += dp[j] * rest;
                    ndp[j + 1] %= MOD;
                }
                ndp[j] += dp[j];
                ndp[j] %= MOD;
            }

            if(s[i] == "U") down++;
            if(s[i] == "D") up++;
            dp = ndp;
        }
        //REP(i, 10) cout << dp[i] << " "; cout << endl;
        cout << dp[down] << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

const int MAX=510000;
long long fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
long long COM(int n,int k){
    if(n<k) return 0;
    if(n<0 or k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
} 
ll pow_mod(ll x,ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
//O(r)
ll combination_mod(ll n,ll r){
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    ll b=pow_mod(fact_mod(r),mod-2);
    return (a%mod)*(b%mod)%mod;
}
ll inv_mod(ll n){
    return pow_mod(n,mod-2);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n,k;cin>>n>>k;
    ll ans=0;
    ll dp[k+1];
    for(int i=1;i<=k;i++){
        ll pat=pow_mod(k/i,n);
        ll t=i;
        for(int j=1;j*j<=i;j++)if(i%j==0){
            ll x=j,y=i/j;
            if(x!=i) t-=dp[x];
            if(y!=x and y!=i) t-=dp[y];
        }
        dp[i]=t;
        t%=mod;
        ans+=t*pat%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string w;
    cin >> w;
    vector<int> Cnt(1000, 0);
    int l = w.size();
    rep(i, l) {
        Cnt[w[i]]++;
    }

    bool ans = true;
    for(int x : Cnt) {
        if(x % 2 != 0) ans = false;
    } 
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

  


vector<int> linear_sieve(const int UPBD) {
  vector<int> primes, last_prime(UPBD, 0);
  for (int p = 2; p < UPBD; ++p) {
    if (not last_prime[p]) primes.push_back(p), last_prime[p] = p;
    for (int j = 0; primes[j] * p < UPBD; ++j) {
      last_prime[primes[j] * p] = primes[j];
      if (p % primes[j] == 0) break;
    }
  }
  return last_prime;
}


 

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
  int n; 
  vector<int> sieve = linear_sieve(1.3e6);
  vector<int> lp(sieve.size()), np(sieve.size());
  for (int i = 2, p = 2; i < sieve.size(); ++i) {
    if (sieve[i] == i) p = i;
    lp[i] = p;
  }
  for (int i = sieve.size() - 1, p = -1; i > 0; --i) {
    if (sieve[i] == i) p = i;
    np[i] = p;
  }
  while (cin >> n and n) {
    cout << np[n] - lp[n] << '\n';
  }
}



Measured memory_bytes: 18124
n = int(input())
h = list(map(int, input().split()))

memo = [10**9] * n
memo[0] = 0

for i in range(1, n):
  memo[i] = min(memo[i], memo[i-1] + abs(h[i] - h[i-1]))
  if i > 1:
    memo[i] = min(memo[i], memo[i-2] + abs(h[i] - h[i-2]))

print(memo[-1])

Measured memory_bytes: 20636
/*
 * a.cc:
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<iomanip>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

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

  if(N==1){
    cout<<"Hello World"<<endl;
  }

  else {
    int a,b;
    cin>>a>>b;

    cout<<a+b<<endl;
  }
}

  


Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

string s, t, u;
int a, b;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> s >> t >> a >> b >> u;	
	if( s == u )
	{
		--a;
	}
	else
	{
		--b;
	}
	cout << a << " " << b << "\n";
	return 0;
}

Measured memory_bytes: 256
PROGRAM-ID.                      ABC_045_A.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 a       PIC 9(3).
    01 b       PIC 9(3).
    01 h       PIC 9(5).
    01 ZS      PIC Z(6).
    01 DUMMY   PIC X(1).
    01 ans     PIC X(5).

PROCEDURE                        DIVISION.
    ACCEPT a.
    ACCEPT b.
    ACCEPT h.

    ADD a TO b.
    MULTIPLY b BY h.
    DIVIDE 2 INTO h.

    MOVE h TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 636