akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

int main() {
    string S;

    cin >> S;
    int count_front = 0;
    int count_back = 0;
    for(int i=0;i< S.size();i+=2) {
        if(S[i] == '0'){
            count_front +=1;
        }
        if(S[i] == '1'){
            count_back +=1;
        }
    }
    for(int i=1;i< S.size();i+=2) {
        if(S[i] == '1'){
            count_front +=1;
        }
        if(S[i] == '0'){
            count_back +=1;
        }
    }
    if (count_front>count_back){
        cout << count_back << endl;
    } else{
        cout << count_front << endl;
    }

    return 0;

}

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

#define int         long long
#define mod         1000000007
#define FAST        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int n;
int compatible[22][22];
int dp[22][(1<<22)];

int solve(int i,int wset){
    if(i == (n+1)){
        if(wset == 0)
            return 1;
        else
            return 0;
    }

    if(dp[i][wset] != -1)
        return dp[i][wset];

    int ans = 0;
    for(int j=0;j<n;j++){
        bool available = (((1<<j)&(wset)) == 0) ? 0 : 1;
        if(available && compatible[i][j]){
            ans = (ans + solve(i+1, (wset^(1<<j)) ) ) % mod;
        }
    }
    dp[i][wset] = ans;

    return ans;
}

int32_t main() {
    FAST;
    cin>>n;
    memset(dp,-1,sizeof(dp));

    for(int i=1;i<=n;i++){
        for(int j=0;j<n;j++){
            cin>>compatible[i][j];
        }
    }
    int x = (1<<n) - 1;
    cout<<solve(1,x);
}


Measured memory_bytes: 721280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void no() {
  cout << -1 << endl;
  exit(0);
}

int main() {
  ll N;
  cin >> N;
  vector<string> s(N);
  vector<vector<ll>> g(N);
  vector<ll> deg(N, 0);
  REP(i, N) {
    cin >> s[i];
    REP(j, N) {
      if (s[i][j] == '1') {
        g[i].push_back(j);
      }
    }
  }

  // start = i
  ll ans = -1;
  REP(i, N) {
    bool ok = true;
    queue<ll> q;
    vector<bool> visited(N, false);
    vector<ll> dist(N, 1);
    q.push(i);
    visited[i] = true;
    while (!q.empty() && ok) {
      ll cv = q.front();
      q.pop();
      FOREACH(nv, g[cv]) {
        if (visited[nv]) {
          if (dist[nv] == dist[cv])
            ok = false;
          else
            continue;
        }
        visited[nv] = true;
        dist[nv] = dist[cv] + 1;
        q.push(nv);
      }
    }
    ll maxi = 0;
    REP(i, N) maxi = max(maxi, dist[i]);
    if (ok) ans = max(ans, maxi);
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	string temp;
	getline(cin, temp);
	stringstream tempss(temp);
	int n, q;
	tempss >> n >> q;
	vector<vector<int>>a(n);
	REP(i, q)
	{
		vector<string>querys;
		getline(cin, temp);
		for (stringstream query(temp); query;)
		{
			query >> temp;
			querys.push_back(temp);
		}
		switch (stoi(querys[0]))
		{
		case 0:
			a[stoi(querys[1])].push_back(stoi(querys[2]));
			break;
		case 1:
			if (a[stoi(querys[1])].size() == 0)cout << endl;
			else
			{
				REP(j, a[stoi(querys[1])].size() - 1)cout << a[stoi(querys[1])][j] << ' ';
				cout << a[stoi(querys[1])].back() << endl;
			}
			break;
		case 2:
			a[stoi(querys[1])].clear();
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 5784
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n;cin>>n;
    vl am(n),a(n);
    rep(i,n){
        int b;
        cin>>b;
        am[i]=i+1-b;
        a[i]=b;
    }
    sort(been(am));
    ll ans =0;
    rep(i,n){
        int sum =0;
        int pu = i+1+a[i];
        sum +=upper_bound(been(am),pu)-lower_bound(been(am),pu);
        ans+=sum;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6428
#include<stdio.h>
int main()
{
  int a,b,c,x,y;
  y=0;
  scanf("%d%d%d",&a,&b,&c);
  for(x=a;x<=b;x++){
    if(c%x==0){y=y+1;}
    else{y=y;}
  }
  printf("%d\n",y);
  return 0;
}

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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h){
    rep(j,w){
      char x;
      cin >> x;
      if(x=='#') a[i][j]=1;
    }
  }
  int n=1;
  rep(i,h+w) n*=2;
  vector<int> b(h+w,0);
  int ans=0;
  rep(_,n){
    int cnt=0;
    rep(i,h){
      rep(j,w){
        if(a[i][j]==1 and b[i]==0 and b[h+j]==0) cnt++;
      }
    }
    if(cnt==k) ans++;
    
    b[0]++;
    rep(i,h+w){
      if(b[i]==2){
        b[i]=0;
        if(i<h+w-1) b[i+1]++;
      }
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

ll ans;
ll a[4], op[3];
char ope[3], b[4];

int main() {
    rep(i,4) cin >> b[i];
    rep(i,4) a[i] = b[i]-'0';

    rep(i,8){
        rep(j,3){
            op[j] = (i>>j)&1;
        }

        ans = a[0];
        rep(j,3){
            if (op[j] == 0){
                ans-=a[j+1];
                ope[j] = '-';
            }
            else {
                ans+=a[j+1];
                ope[j] = '+';
            }
        }

        if (ans == 7){
            cout << a[0];
            rep(j,3){
                cout << ope[j] << a[j+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

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

set<long long> s;

int main()
{
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    long long tmp;
    cin >> tmp;
    if(s.find(tmp) == s.end()){
      s.insert(tmp);
    }else{
      s.erase(tmp);
    }
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 4864
import math
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = [0 for y in range(N)]
for i in range(N):
    x[i] = abs(_x[i] - start)
g = x[0]
for i in range(N):
    g = math.gcd(g,x[i])
print(g)
ans = 1


Measured memory_bytes: 20260
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#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 F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,A[SIZE],B[SIZE];
int main(){
    R(N);
    FOR(i,1,N+1)R(A[i]);
    FOR(i,1,N)R(B[i]);
    LL an=0;
    FOR(i,1,N){
        int v=min(A[i],B[i]);
        an+=v;
        A[i]-=v;
        B[i]-=v;
        
        v=min(A[i+1],B[i]);
        an+=v;
        A[i+1]-=v;
        B[i]-=v;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string.h>

using namespace std;
char S[21][21];
int count = 0;

void a(int i, int j){
	if(S[i][j] == '.'){
		count++;
		S[i][j] = '#';
		a(i - 1, j);
		a(i + 1, j);
		a(i, j + 1);
		a(i, j - 1);
	}
}


int main(){
	while(true){
		memset(S,'#',sizeof(S));
		count = 0;
		int x, y;
		cin >> x >> y;
		if(x == 0 && y == 0){
			break;
		}
		for(int i = 0; i < y; i++){
			for(int j = 0; j < x; j++){
				cin >> S[i][j];
			}
		}

		int startx, starty;
		for(int i = 0; i < y; i++){
			for(int j = 0; j < x; j++){
				if(S[i][j] == '@'){
					startx = j;
					starty = i;
					S[i][j] = '.';
					break;
				}
			}
		}
		a(starty, startx);
		cout << count << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000;
vector<long long> bellman_ford(vector<vector<pair<int, int>>> &E, int s){
    int V = E.size();
    vector<long long> d(V, INF);
    d[s] = 0;
    while (1){
        bool update = false;
        for (int i = 0; i < V; i++){
            for (int j = 0; j < E[i].size(); j++){
                int c = E[i][j].first;
                int v = E[i][j].second;
                if (d[v] > d[i] + c && d[i] != INF){
                    d[v] = d[i] + c;
                    update = true;
                }
            }
        }
        if (!update){
            break;
        }
    }
    return d;
}
int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> E(n);
    for (int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            int v, c;
            cin >> v >> c;
            E[i].push_back(make_pair(c, v));
        }
    }
    vector<long long> d = bellman_ford(E, 0);
    for (int i = 0; i < n; i++){
        cout << i << ' ' << d[i] << endl;
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n;
/******* define variable end *******/
std::vector<ll> sieve(ll n) {
  std::vector<ll> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (ll i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (ll j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}
vl min_factor;
map<ll, ll> factor(ll n) {
  // min_factor は sieve() で得られたものとする
  map<ll, ll> res;
  while (n > 1) {
    res[min_factor[n]]++;
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}
int solve() {
	cin >> n;
	ll ans = 0;
	min_factor = sieve(MAX+5);
	FOR(i, 1, n+1){
		map<ll,ll> pf = factor(i);
		ll times = 1;
		for(auto& [key, value] : pf){
			times *= value + 1;
		}
		ans += times * i;
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 81308
n = int(input())
A = [int(i) for i in input().split()]

INF = 10 ** 18
DP = [[0] * (n - i) for i in range(n)]

csum_ = [0]
for a in A:
    csum_.append(csum_[-1] + a)

def csum(i, j): #[i, j)
    return csum_[j] - csum_[i]

for i in range(1, n):
    for j in range(n-i):
        if i > 1:
            DP[i][j] = min(DP[k][j] + DP[i-k-1][j+k+1] for k in range(0, i))

        DP[i][j] += csum(j, j + i + 1)

print(DP[n-1][0])

Measured memory_bytes: 44252
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vector <int> v[N], temp;
int ch[N],n;
void dfs(int u, int p)
{
    ch[u]=1;
    for(auto to:v[u])
    {
        if(to==p)
        continue;
        dfs(to, u);
        ch[u]+=ch[to];
        //cout<<u<<" "<<to<<" "<<ch[to]<<" "<<n-ch[to]<<"\n";
        temp.pb((ch[to]*(n-ch[to])));
    }
    return;
}
int32_t main()
{
    IOS;
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t;
}

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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

satisfaction = 0
prev = a[0]

for i in a:
  satisfaction +=  b[i-1]

  if i-prev == 1:
    satisfaction += c[i-2]
  prev = i


print(satisfaction)

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

using namespace std;


const int Nmax = 100005;

int  n , m;

long long a[Nmax];

unordered_map < long long , int > M;

int main()
{
    int x;
    long long ans = 0;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
    {
        cin >> x;
        a[i] = a[i - 1] + x;
    }
    for(int i = 1 ; i <= n ; i++)
    {
        a[i] %= m;
        ans += (a[i] == 0);
    }
    for(int i = 1 ; i <= n ; i++)
    {
        ans += M[a[i]];
        ++M[a[i]];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4492
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;
string s;

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

    int x,y;
    x=0;
    int addl=0;
    rep(i,n){
        if(s[i]=='(') x++;
        else if(s[i]==')'){
            if(x>0){
                x--;
            }else{
                addl++;
            }
        }
    }
    string ts ="";
    rep(i,addl) ts.pb('(');
    s = ts + s;


    y=0;
    for(int i=0;i<sz(s);i++){
        if(s[i]=='(') y++;
    }
    x = sz(s) - y*2;
    if(x < 0){
        rep(i,abs(x)) s.pb(')');
    }
    cout << s << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
  int n;
  int d=0;
  string s;
  cin >>n>>s;
  if(n%2==1)cout<<"No";
  else{
    string::iterator it=s.begin();
    for(int i=0;i<n/2;i++){
      if(*it!=*(it+n/2)){
        d=1;
        break;
      }
      it++;
    }
    if(d==0)cout<<"Yes";
    else cout<<"No";
  }
  cout<<endl;
}


Measured memory_bytes: 256
a = int(input())
b = int(a ** 0.5)
c = 0
d = 1
for i in range(2, b + 1):
    c = i
    while True:
        if c <= a:
            c = c * i
        else:
            c = c // i
            d = max(d, c)
            break
print(d)


Measured memory_bytes: 2940
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
using namespace std;
int main(){
	int sx, sy;
	int tx, ty;
	cin >> sx >> sy >> tx >> ty;

	string str = "";
	for (int i = 0; i < ty - sy; ++i) str += "U";
	for (int i = 0; i < tx - sx; ++i) str += "R";
	for (int i = 0; i < ty - sy; ++i) str += "D";
	for (int i = 0; i < tx - sx; ++i) str += "L";
	str += "L";
	for (int i = 0; i < ty - sy + 1; ++i) str += "U";
	for (int i = 0; i < tx - sx + 1; ++i) str += "R";
	str += "DR";
	for (int i = 0; i < ty - sy + 1; ++i) str += "D";
	for (int i = 0; i < tx - sx + 1; ++i) str += "L";
	str += "U";
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,x,y=map(int,input().split())
    x-=1; y-=1
    E1=[[] for _ in range(n)]
    E2=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1; v-=1
        E1[u].append(v)
        E1[v].append(u)
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1; v-=1
        E2[u].append(v)
        E2[v].append(u)

    # E2 において、y-rooted tree とみて、depth,par を計算
    par=[None]*n # x の必勝頂点を判定するのに必要
    par[y]=y
    depth2=[None]*n
    depth2[y]=0
    Q=[y]
    while(Q):
        v=Q.pop()
        for nv in E2[v]:
            if(depth2[nv] is not None): continue
            depth2[nv]=depth2[v]+1
            par[nv]=v
            Q.append(nv)

    # E1の辺で、E2での距離が 3 以上のものは必勝
    win=[0]*n
    for v in range(n):
        for nv in E1[v]:
            if(par[v]==nv or par[nv]==v or par[v]==par[nv] or par[par[v]]==nv or par[par[nv]]==v): continue
            win[nv]=win[v]=1

    # E1 において、x-rooted tree とみて探索
    # depth1 < depth2 -> 以降も探索できる
    # depth1 = depth2 -> そこで捕まる
    ans=depth2[x]
    depth1=[None]*n
    depth1[x]=0
    Q=[x]
    while(Q):
        v=Q.pop()
        if(win[v]): # 探索できる状態 & 必勝頂点にいれば勝ち
            print(-1)
            return
        for nv in E1[v]:
            if(depth1[nv] is not None): continue
            depth1[nv]=depth1[v]+1
            ans=max(ans,depth2[nv])
            if(depth1[nv]<depth2[nv]): Q.append(nv)

    print(2*ans)
resolve()

Measured memory_bytes: 122956
#include<bits/stdc++.h>
#include <ctime>
using namespace std;
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a)
#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define TESTS wez(testow)while(testow--) //for multilple cases problems
#define whileZ int T; getI(T); while(T--) // the same as above
#define getS(x) scanf("%s", x) //get a char* string
#define clr(a,x) memset(a,x,sizeof(a)) //set elements of array to some value
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end()) 
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end()) 
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);//to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
// for debug
inline void pisz(int n) { printf("%d\n",n); }
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
#define MAXN 10000
//for vectors
#define pb push_back
typedef int elem_t;
typedef vector<long long> vll;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
// directions
const int fx[4][2] = {{0,1}, {-1,0}, {0,-1}, {1,0}};
const int fxx[9][2] = {{0,0},{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
const int N = 500;
const ll mod = 1000000007;



int main() 
{IOS
    ll n,x,t;
    cin>>n>>x>>t;
    ll temp = n/x;
    if(n%x!=0)temp++;
    cout<<temp*t<<"\n";


}


Measured memory_bytes: 3632
while s = gets do
  (@n, @s) = s.split().map(&:to_i)
  break if @n == 0 && @s == 0

  @a = Array.new
  @c = 0 

  def solve(i)
    if @a.size == @n
      @c += 1 if @a.inject(:+) == @s
      return
    end 

    (i..9).each { |j| 
      @a.push(j)
      solve(j + 1)
      @a.pop
    }   
  end 

  solve(0)

  puts @c
end

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll w,a,b;
    cin >> w >> a >> b;
    if(abs(a-b) <= w)cout << '0' << endl;
    else cout << abs(max(a,b) - (min(a,b) + w)) << endl;
    return 0;
}

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

int main()
{
	int n,l;
	scanf("%d %d",&n,&l);
	int f,e;
	f=l;e=l+n-1;
	int ans=(f+e)*(e-f+1)/2;
	if(f<=0 && e>=0)
		printf("%d\n",ans);
	else if(f<=0 && e<=0)
		printf("%d\n",ans-e);
	else
		printf("%d\n",ans-f);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
	int a, b, k;
	cin >> a >> b >> k;

	int count = 0;
	for (int i = max(a,b); i != 0; i--) {
		if (a % i == 0 && b % i == 0) {
			count++;
			if (count == k) {
				cout << i << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1046527
#define L 14

char H[M][L];

int char2int(char c) {
  switch (c) {
    case 'A': return 1;
    case 'C': return 2;
    case 'G': return 3;
    case 'T': return 4;
    default: return 0;
  }
}

long long getKey(char str[]) {
  long long ret = 0, p = 1;
  int i;
  for(i = 0; str[i] != '\0'; i++) {
    ret += p * char2int(str[i]);
    p *= 5;
  }
  return ret;
}

int h1(int key) {
  return key % M;
}

int h2(int key) {
  return 1 + (key % (M - 1));
}

int find(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int insert(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], cmd[9];
  for(i = 0; i < M; i++) {
    /* initialize hash */
    H[i][0] = '\0';
  }

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s %s", cmd, str);

    if(cmd[0] == 'i') {
      insert(str);
    } else {
      if(find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}

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

ll five(ll N) {
  N = N / 10;
  ll res = 0;
  while (N != 0) {
    res += N;
    N = N / 5;
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  if (N % 2 == 1) {
    ans = 0;
  }
  else {
    ans = five(N);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main(void) {
	int n;
	cin >> n;
	cout << (n < 1000 ? "ABC" : "ABD") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

void solve()
{	
	double x[2],y[2];
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	cout << pow((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]),0.5) << endl;
	return;
}

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



Measured memory_bytes: 3448
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        int cur = i;
        int c = 0;
        while (cur < k) {
            cur *= 2;
            c++;
        }
        ans += pow(0.5, c);
    }
    cout << setprecision(9) << ans / n << endl;
    return 0;
}


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

int main(){
    using namespace std;
    string S, T, U;
    cin >> S >> S >> T;
    transform(S.begin(), S.end(), T.begin(), back_inserter(U), [](auto a, auto b){cout << a << b; return a;});
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n,i,j,k,d;
    scanf("%d",&n);
    double v[n];
    for(i=0;i<n;i++){
        scanf("%lf",&v[i]);
    }
    for(j=0;j<n-1;j++){
        for(k=1;k<n-j;k++)
        {
            if(v[j]>v[j+k])
        {
            double tmp;
            tmp=v[j];
            v[j]=v[j+k];
            v[j+k]=tmp;
        }
        }
    }
    for(d=0;d<n-1;d++){
        double e;
        e=(v[d]+v[d+1])/2;
        v[d+1]=e;
    }
    printf("%f\n",v[n-1]);
    return 0;
}


Measured memory_bytes: 128
n = gets.to_i

a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

(1...n).each do |i|
  a[i] = a[i] + a[i - 1]
end

(1...n).reverse_each do |i|
  b[i - 1] = b[i] + b[i - 1]
end

puts a.zip(b).map{|c| c.inject(:+)}.max

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true){
            String[] ar = br.readLine().split(" ");
            int x = Integer.parseInt(ar[0]);
            int y = Integer.parseInt(ar[1]);
            int z = Integer.parseInt(ar[2]);
            if(x == -1 && y == -1 && z == -1){
                break;
            }else if(x == -1 || y == -1 || x+y < 30){
                System.out.println("F");
            }else if(x+y >= 80){
                System.out.println("A");
            }else if(x+y >= 65 && x+y < 80){
                System.out.println("B");
            }else if(x+y >= 50 && x+y < 65 || z >= 50){
                System.out.println("C");
            }else{
                System.out.println("D");
            }
        }
    }
}

Measured memory_bytes: 24264
using System;
 
namespace Dice
{
    class Program
    {
        private static bool Eql(string[]x, string[]y)
        {
            var g = true;
            for (int o = 0; o < x.Length; o++)
              if (x[o] != y[o]) g = false;
            return g;
        }
 
        private static string Check(string[]x, string[]y)
        {
            if (Eql(x, y)) return "Yes";
            for (int p = 0; p < 2; p++)
            {
                for(int q = 0; q < 4; q++)
                {
                    string a = x[0], b = x[1], c = x[2],
                           d = x[3], e = x[4], f = x[5];
                    x = p == 0 ? new string[] { e, a, c, d, f, b } :
                                 new string[] { d, b, a, f, e, c };
                    if (Eql(x, y)) return "Yes";
                    var h = x;
                    for(int r = 0; r < 4; r++)
                    {
                        string i = h[0], j = h[1], k = h[2],
                               l = h[3], m = h[4], n = h[5];
                        h = new string[] { i, k, m, j, l, n };
                        if (Eql(h, y)) return "Yes";
                    }
                }
            }
            return "No";
        }
 
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' '),
                     t = Console.ReadLine().Split(' ');
            Console.WriteLine(Check(s, t));
        }
    }
}

Measured memory_bytes: 8944
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x:usize = read();
    let v= primes(x);
    for i in v {
        if i >= x {
            println!("{}", i);
            break;
        }
    }
}

fn primes(n:usize) -> impl Iterator<Item = usize> {
    const START: usize = 2;
    if n < START {
        Vec::new()
    } else {
        let mut is_prime = vec![true; 100005];
        let limit = 100005;
        for i in START..=limit + 1 {
            let mut it = is_prime[i - START..].iter_mut().step_by(i);
            if let Some(true) = it.next() {
                it.for_each(|x| *x = false);
            }
        }
        is_prime
    }
    .into_iter()
    .enumerate()
    .filter_map(|(e, b)| if b { Some(e + START)} else { None })
}

Measured memory_bytes: 2252
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A=LI()
    print("YNeos"[sum(A)/2 not in A::2])
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3444
import sys
n=int(input())
a=[int(input()) for _ in range(n)]
c=set()
s=a[0]
cnt=1
while(1):
    if s==2:
        print(cnt)
        sys.exit()
    if s in c:
        print(-1)
        sys.exit()
    c.add(s)
    s=a[s-1]
    cnt+=1

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

int main(void){
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a >> b >> c;
	while(!(a == -1 && b == -1 && c == -1)){
		if(a == -1 || b == -1){
			cout << "F" << endl;
		}else if(a + b >= 80){
			cout << "A" << endl;
		}else if(a + b >= 65){
			cout << "B" << endl;
		}else if(a + b >= 50){
			cout << "C" << endl;
		}else if(a + b >= 30){
			if(c >= 50){
				cout << "C" << endl;
			}else{
				cout << "D" << endl;
			}
		}else{
			cout << "F" << endl;
		}
		cin >> a >> b >> c;
	}
	return 0;
}

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

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

	int mat[n][m];
	int vec[m], res[n];
	
	int i,k; 
	for (i=0; i<n; i++){
		for (k=0; k<m; k++){
			cin >> mat[i][k];
		}
	}
	for (k=0; k<m; k++){
		cin >> vec[k];
	}
	for (i=0; i<n; i++){
		res[i]=0;
	}

	for (i=0; i<n; i++){
		for (k=0; k<m; k++){
			res[i]+=mat[i][k]*vec[k];
		}
		cout << res[i] <<"\n";
	}		
	
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a;
	int ans = -1;
	int sum = 0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
		sum += x;
	}
	int cur = 0;
	for(int i=0;i<n;i++){
		cur += a[i];
		int cost = abs( sum - 2*cur );
		if( ans == -1 || ans > cost ) ans = cost;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <unordered_set>

using namespace std;

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

  unordered_set<int> mochi_set;

  int di;
  for (int i = 0; i < n; ++i) {
    cin >> di;
    mochi_set.insert(di);
  }

  cout << mochi_set.size() << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
            using namespace std;
         
            int main(){
              int n,temp;
              cin>>n;
              int dp[n];
              vector<int> v;
              for(int i=0;i<n;i++){
              	cin>>temp;
                v.push_back(temp);
                dp[i]=0;
              }
              dp[0]=0;
              dp[1]= abs(v[1]-v[0]);
              for(int i=2;i<n;i++)
                dp[i] = min(dp[i-1]+abs(v[i-1]-v[i]),dp[i-2]+abs(v[i-2]-v[i]));
              cout<<dp[n-1]<<endl;
              return 0;
            }

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	vector<int> b(n);
	if(n % 2 == 0){
		int k = n / 2;
		for(int i = 0; i < n; i += 2) b.at(k++) = a.at(i);
		k = n / 2 - 1;
		for(int i = 1; i < n; i += 2) b.at(k--) = a.at(i);
	}
	else{
		b.at(n / 2) = a.at(0);
		int k = n / 2 + 1;
		for(int i = 1; i < n; i += 2) b.at(k++) = a.at(i);
		k = n / 2 - 1;
		for(int i = 2; i < n; i += 2) b.at(k--) = a.at(i);
	}
	rep(i,n){
		if(i == n - 1) cout << b.at(i) << endl;
		else cout << b.at(i) << " ";
	}
}


Measured memory_bytes: 3712
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		double total = 0;
		for(int T = 0; T<N; T++) {
			String S = sc.nextLine();
			String A[] = S.split(" ");
			double price = Double.parseDouble(A[0]);
			
			if(A[1].equals("BTC")) {
				total += price * 380000.0;		
			}
			else {
				total += price;
			}
		}
		
		System.out.println(total);
		
		
	}

}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N;
vector<Pii> graph[201];
bool used[201];
int way[201][201];
int max_y, min_y, max_x, min_x;

void dfs( int n, int x, int y ) {
  //cout << n << " " << x << " " << y << endl; 
  max_y = max( max_y, y );
  max_x = max( max_x, x );
  min_y = min( min_y, y );
  min_x = min( min_x, x );
  
  if( !used[n] ) {
    used[n] = true;
    for(int i=0; i<graph[n].size(); i++) {
      //cout << 'a' << endl;
      Pii p = graph[n][i];
      int next = p.fr, way = p.sc;

      if( way == 0 ) {
	dfs( next, x-1, y );
      }
      if( way == 1 ) {
	dfs( next, x, y-1 );
      }
      if( way == 2 ) {
	dfs( next, x+1, y );
      }
      if( way == 3 ) {
	dfs( next, x, y+1 );
      }
    }
  }
  
}

main()
{
  while( cin >> N, N ) {
    fill_n(used, 201, false);
    Rep(i, 201) graph[i].clear();
    
    Rep(i, N-1) {
      int n, d;
      cin >> n >> d;
      graph[i+1].pb( Pii(n, d) );
      graph[n].pb( Pii(i+1, (d+2)%4) );
    }

    max_y = max_x = min_y = min_x = 0;
    dfs( 0, 0, 0 );

    cout << max_x - min_x + 1 << " " << max_y - min_y + 1 << endl;							   
  }
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<char> v;
  string temp = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  rep(i, temp.size()) {
    v.push_back(temp[i]);
  }
  ll n;
  cin >> n;
  string s;
  cin >> s;
  deque<char> deq;
  rep(i, s.size()) {
    rep(j, temp.size()) {
      if (s[i] == temp[j]) {
        deq.push_back(temp[j+n]);
        break;
      }
    }
  }
  for(char c: deq) {
    printf("%c", c);
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		System.out.println(lcm(a,b));
	}
	/**
	 * lcm 最小公倍数とは「２つ以上の正の整数に共通な倍数のうち最小のもの」
	 * @param a
	 * @param b
	 * @return
	 */
	static long lcm (int a, int b) {
		int temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}
}

Measured memory_bytes: 21972
N = gets.chomp.to_i
start = [0,0]
points = []
N.times do |i|
  points << gets.chomp.split(" ").map(&:to_i)
end
ans = ""
#元の位置に戻る方法 x+1 x-1, y+1 y-1,x+1 y+1 x-1 y-1,
points.each_with_index do |point,i|
  # point = [3,1,2]
  if i == 0

    if point[0] == point[1] + point[2]
      ans = "Yes"
    else
      ans = "No"
      break
  end
  else
    number = point[0] - points[i-1][0]
    x_move = points[i-1][1] - point[1]
    y_move = points[i-1][2] - point[2]
    if number == x_move + y_move
      ans = "Yes"
    elsif number > x_move + y_move
      if (number - x_move - y_move) % 2 == 0
        ans = "Yes"
      else
        ans = "No"
        break
      end
    else
      ans = "No"
      break
    end
  end
end

puts ans


Measured memory_bytes: 9468
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<string> vs;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	REP(i,s1.size()+s2.size())
	{
		if (i % 2) cout << s2[i / 2];
		else cout << s1[i / 2];
	}
	cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

      String s = sc.next();

      int ans = 0;

      if(s.equals("SUN")){
        ans = 7;
      }
      if(s.equals("MON")){
        ans = 6;
      }
      if(s.equals("TUE")){
        ans = 5;
      }
      if(s.equals("WED")){
        ans = 4;
      }
      if(s.equals("THU")){
        ans = 3;
      }
      if(s.equals("FRI")){
        ans = 2;
      }
      if(s.equals("SAT")){
        ans = 1;
      }


      System.out.println(ans);

    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<ll> as(n),bs(n);
    rep(i,0,n) cin>>as[i];
    rep(i,0,n) cin>>bs[i];
    
    ll x=0,y=0;
    rep(i,0,n){
        ll a=as[i],b=bs[i];
        if(b-a<0) x+=a-b;
        else y+=(b-a)/2;
    }
    cout<<(x<=y ? "Yes" : "No")<<endl;
    //cout<<x<<" "<<y<<endl;
}



Measured memory_bytes: 384