akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
int a[N][N],ci[N],ls[N];
int n;
struct node{
    int u,v,w;
    node(int u=0,int v=0,int w=0):u(u),v(v),w(w){}
};
int main(){
    cin >> n;
    for(int i=1;i<=n;++i){
        for(int j=1;j<n;++j){
            cin >> a[i][j];
        }
        ci[i] = 1;  ls[i] = 0;
    }
    int sign = 0;
    int r =0;
    queue<node> q;
    node cur;
    for(int i=1;i<=n;++i){  // 第一轮
        if(ls[i]==1)    continue;
        int  to = a[i][1];
        if(a[to][1]==i){
            ls[to] = 1; ls[i] = 1;
            q.push({i,to,1});
        }
    }
    while(!q.empty()){
        cur = q.front();    q.pop();    r = cur.w;
// cout << cur.u << ' ' << cur.v << ' ' << cur.w << endl;
        ci[cur.u]++; ci[cur.v]++;
        int to = a[cur.u][ci[cur.u]];
        if(a[to][ci[to]]==cur.u && ls[to]<=cur.w){
            ls[to] = cur.w+1;   ls[cur.u] = cur.w+1;
            q.push(node{cur.u,to,cur.w+1});
        }
        to = a[cur.v][ci[cur.v]];
        if(a[to][ci[to]]==cur.v && ls[to]<=cur.w){
            ls[to] = cur.w+1;   ls[cur.v] = cur.w+1;
            q.push(node{cur.v,to,cur.w+1});
        }
    }
    for(int i=1;i<=n;++i){
        if(ci[i]!=n){
            sign = 1;break;
        }
    }
    if(sign)   cout << -1 << endl;
    else cout << r << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
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;}
template<class T> T gcd(T a, T b){return b?GCD(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/GCD(a,b);}

int num(char a,char b,char c){
    return (a-'0')*100+(b-'0')*10+(c-'0');
}

int main(){
    string s; cin >> s;
    int sz = s.size();
    int ans = 1000;

    rep(i,sz-2){
        chmin(ans,abs(num(s[i],s[i+1],s[i+2])-753));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb emplace_back
#define pob pop_back()
#define ff first
#define ss second
typedef long long int ll;
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define prq priority_queue<ll>
#define psq priority_queue<ll,vector<ll>,greater<ll>>
#define m_p make_pair
#define vcc vector<char>
#define vss vector<string>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t; cin>>t; while(t--)
ll dp[3005][3005];
void cal(string s, string t)
{
	for (ll i = 0; i <= s.length(); i++)
	{
		for (ll j = 0; j <= t.length(); j++)
		{
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else
			{
				if (s[i - 1] == t[j - 1])
					dp[i][j] = dp[i - 1][j - 1] + 1;
				else
				{
					if (dp[i - 1][j] > dp[i][j - 1])
						dp[i][j] = dp[i - 1][j];
					else
						dp[i][j] = dp[i][j - 1];
				}
			}
		}
	}
}
main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, i, j, k;
	string s, t, ans = "";
	cin >> s >> t;
	cal(s, t);
	i = s.length(); j = t.length();
	while (i != 0 && j != 0)
	{
		if (dp[i][j] == dp[i][j - 1])
			j--;
		else if (dp[i][j] == dp[i - 1][j])
			i--;
		else
		{ans += s[i - 1]; i--; j--;}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;
				

				
int main(){
	vector<int>v[100001];
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int arr[100001];
	bool arr2[100001];
	for(int i=0;i<100001;i++){
		arr[i]=-1;
		arr2[i]=false;
	}
	arr2[1]=true;
	queue<int>que;
	que.push(1);
	while(!que.empty()){
		int cur=que.front();
		que.pop();
		for(int i=0;i<v[cur].size();i++){
			if(!arr2[v[cur][i]]){
				arr2[v[cur][i]]=true;
				arr[v[cur][i]]=cur;
				que.push(v[cur][i]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(!arr2[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++)cout<<arr[i]<<endl;
	
  return 0;
}

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

using namespace std;

int main(void) {
    for (int i = 0; i < 5; i++) {
        int tmp;
        cin >> tmp;
        if (tmp == 0)
            cout << i+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int x[4], y[4];
	cin >> x[0] >> y[0] >> x[1] >> y[1];

	int dx, dy;
	dx = abs(x[0] - x[1]);
	dy = abs(y[0] - y[1]);

	if (y[1] - y[0] >= 0) {
		x[2] = x[1] - dy;
		x[3] = x[0] - dy;
	}
	else {
		x[2] = x[1] + dy;
		x[3] = x[0] + dy;
	}

	if (x[1] - x[0] >= 0) {
		y[2] = y[1] + dx;
		y[3] = y[0] + dx;
	}
	else {
		y[2] = y[1] - dx;
		y[3] = y[0] - dx;
	}

	cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll X, K; cin >> X >> K;
  ll r[K+1]; FOR(i,1,K+1) cin >> r[i];
  r[0] = 0;
  ll Q; cin >> Q;
  ll mx = X, mn = 0;
  int j = 1;
  ll d = 0;
  FOR(i,0,Q) {
    ll t, a; cin >> t >> a;
    while(j <= K && r[j] <= t) {
      if(j % 2 == 1) {
        mx = max(0LL, mx - (r[j] - r[j-1]));
        mn = max(0LL, mn - (r[j] - r[j-1]));
        d -= (r[j] - r[j-1]);
      } else {
        mx = min(X, mx + (r[j] - r[j-1]));
        mn = min(X, mn + (r[j] - r[j-1]));
        d += (r[j] - r[j-1]);
      }
      j++;
    }
    ll dd = min(mx, max(mn, a + d)) + (j % 2 == 1 ? - (t - r[j-1]) : (t - r[j-1]));
    cout << max(min(dd, X), 0LL) << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b,ans[4]={};
  for(int i=0; i<3; i++) {
    cin >> a >> b;
    a--,b--;
    ans[a]++,ans[b]++;
  }
  cout << (ans[0]<3&&ans[1]<3&&ans[2]<3&&ans[3]<3?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

vector<int> bfs(vector<bool> &used, priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que, vector<vector<int> > &neigh, vector<int> &n_neigh, priority_queue<int, vector<int>, greater<int> > cvec){
    vector<int> ans((int) cvec.size(), 0);
    while((int) que.size() > 0){
        int vertex=que.top().second;
        que.pop();
        if(used[vertex]==true){
            continue;
        }

        used[vertex]=true;
        ans[vertex]=cvec.top();
        cvec.pop();
        
        for(int i=0; i<(int) neigh[vertex].size(); i++){
            int next = neigh[vertex][i];
            n_neigh[next]--;
            que.push(make_pair(n_neigh[next], next));
        }
    }
    return ans;
}

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int> > neigh(N, vector<int>(0));
    vector<int> n_neigh(N,0);
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;b--;
        neigh[a].push_back(b);
        neigh[b].push_back(a);
        n_neigh[a]++;
        n_neigh[b]++;
    }

    priority_queue<int, vector<int>, greater<int> > cvec;
    int sum_=0;
    int max_=0;
    for(int i=0; i<N; i++){
        int c;
        cin >> c;
        cvec.push(c);
        sum_+=c;
        max_=max(max_,c);
    }
    sum_-=max_;

    vector<bool> used(N,false);

    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    for(int i=0; i<N; i++){
        if(n_neigh[i]==1){
            que.push(make_pair(1, i));
        }
    }

    vector<int> ans = bfs(used, que, neigh, n_neigh, cvec);
    cout << sum_ << endl;
    cout_vec(ans);

}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;
	int cnt = 0;
	ll ans = 0;
	for (int i = S.size() - 1; i >= 0; i--) {
		if (S[i] == 'W') cnt++;
		else ans += cnt;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

const int N = 3000;

array<array<double, N>, N> dp;

int main()
{
    int n;
    cin >> n;
    vector<double> ps(n);
    for (auto& p : ps)
    {
        cin >> p;
    }
    for (auto& v : dp)
    {
        fill(v.begin(), v.end(), 0);
    }

    dp[0][0] = 1.0;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = dp[i - 1][0] * (1 - ps[i - 1]);
        for (int j = 1; j <= i; j++)
        {
            dp[i][j] = dp[i - 1][j - 1] * ps[i - 1] + dp[i - 1][j] * (1 - ps[i - 1]);
        }
    }
    double ans = 0;
    for (int i = n / 2 + 1; i <= n; i++)
    {
        ans += dp[n][i];
    }
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 70528
import itertools
N = int(input())
x = [list(map(int,input().split())) for _ in range(N)]
# print(list(itertools.combinations(x,2)))
a = sum(((p-r)**2 + (q-s)**2 ) **0.5 for [(p,q),(r,s) ]in itertools.combinations(x,2))

print(2*a/N)

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int H, W, h, w;

int main() {
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

template<int N>
struct sieve {
	bool s[N];
	constexpr sieve() : s() {
		for (int i = 0; i < N; i++)
			s[i] = true;
		for (int i = 4; i < N; i += 2)
			s[i] = false;
		for (int i = 9; i < N; i += 6)
			s[i] = false;
		for (int i = 6, e = sqrt(N); i <= e; i += 6) {
			for (int j : {i - 1, i + 1})
				if (s[j])
					for (int k = j * j; k < N; k += j)
						s[k] = false;
		}
	}
};

template<int N>
struct twin {
	int t[N/10], l;
	constexpr twin() : t(), l(1) {
		sieve<N> s;
		t[0] = 5;
		for (int i = 0; i < N; i++)
			if (s.s[i - 2] && s.s[i])
				t[l++] = i;
	}
};

int main() {
	enum {N = 10001};
	twin<N> t;
	for (int n; (n = in());) {
		auto r = upper_bound(t.t, t.t + t.l, n) - 1;
		outl(*r - 2, ' ', *r);
	}
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  
  if(n % 2 == 0) cout << n/2 << endl;
  else cout << n/2 + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    int tmp = 1;
    while(tmp<=n){
        tmp*=2;
    }
    co(tmp/2);
}

Measured memory_bytes: 256
n=int(input())
A = [0]
A.extend([int(i) for i in input().split()])
d1 = {}
d2 = {}
for i in range(1, n+1):
	u = A[i] + i
	v = A[i] - i
	d1[u] = d1.get(u,0)+1
	d2[v] = d2.get(v,0)+1

# ~ print(d1)
# ~ print(d2)
	
ans = 0

for e in d1:
	ans += d1[e] * d2.get(-e,0)
	
print(ans)


Measured memory_bytes: 53220
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

typedef long long ll;

#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789

using namespace std;
 

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

ll N;
ll A;
ll B;
ll C;
ll D;
bool flag = 0;
ll K;
ll jdg;
ll top;
ll down;

int main(){
	
	cin>>N>>A>>B>>C>>D;
	
	K = D-C;
	jdg = B-A;
	if( jdg < 0 ) jdg *= -1;
	
	//cout<<jdg<<endl;
	
	top = 0;
	down = 0;
	
	flag = 0;
	
	ll num;
	
	if( N % 2 == 0 ){
		for( ll i = 1; i <= N-1; i++ ){
			//cout<<flag<<endl;
			top += D;
			down += C;
			num = (N-i)/2;
			if( i % 2 ){
				//printf("%lld %lld>=%lld>=%lld\n",i, top+K*num, jdg, down-K*num);
				if( (top+K*num) >= jdg && jdg >= (down-K*num) ) flag = 1;
			}
		}		
	}
	else{
		for( ll i = 0; i <= N-1; i++ ){
			//cout<<flag<<endl;
			if( i ){
				top += D;
				down += C;
			}
			num = (N-i)/2;
			//cout<<num<<endl;
			if( i % 2 == 0 ){
			//printf("%lld %lld>=%lld>=%lld\n",i, top+K*num, jdg, down-K*num);
				if( (top+K*num) >= jdg && jdg >= (down-K*num) ) flag = 1;
			}
		}
	}
	
	if( flag ) puts("YES");
	else{     puts("NO");}
	
	return 0;

}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

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

int main(){
	int c=0;
	in(n);
	repp(i, n)
		c += i;
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
import heapq
n, m, s, t = map(int, input().split())
node = [False] * n # 訪問済み
gyen = [[] for i in range(n)]
gsnu = [[] for i in range(n)]

for i in range(m):
    u, v, a, b = map(int, input().split())
    u-=1; v-=1
    gyen[u].append((a, v))
    gyen[v].append((a, u))
    gsnu[u].append((b, v))
    gsnu[v].append((b, u))

distyen = [float('inf')] * n
distsnu = [float('inf')] * n

# yenのダイクストラ、sから
distyen[s-1] = 0
node[s-1] = True
q = []
for e in gyen[s-1]:
    heapq.heappush(q, e)

while q:
    cost, v = heapq.heappop(q)
    if node[v]:
        continue
    node[v] = True
    distyen[v] = cost
    for e in gyen[v]:
        nextcost, to = e
        heapq.heappush(q, (cost+nextcost, to))

node = [False] * n
distsnu[t-1] = 0
node[t-1] = True
q = []
for e in gsnu[t-1]:
    heapq.heappush(q, e)
while q:
    cost, v = heapq.heappop(q)
    if node[v]:
        continue
    distsnu[v] = cost
    node[v] = True
    for e in gsnu[v]:
        nextcost, to = e
        heapq.heappush(q, (cost+nextcost, to))

ans = []
for i in range(n-1, -1, -1):
    if i == n-1:
        ans.append(pow(10, 15) - distyen[i] - distsnu[i])
    else:
        ans.append(max(ans[-1], pow(10, 15) - distyen[i] - distsnu[i]))
for i in ans[::-1]:
    print(i)
    






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

int main(){
  string s;
  cin>>s;
  int count=0;
  int max=0;
  for(int i=0;i<3;i++){
  	if(s[i]=='S') count=0;
    else count++;
    if(max<count) max=count;
  }
  cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <forward_list>
#include <utility>
#include <algorithm>
#include <cstdio>

using namespace std;

#define MAX 100000

int cnt;
int pre[MAX];
int low[MAX];
vector<pair<int,int>> ans;

class EDGE{
public:
    int v;
    int w;
    EDGE(int vin,int win):v(vin),w(win){;}
};

class Graph{
public:
    int V;
    int E;
    vector<forward_list<int>> adj_list;
    void addedge(int v,int w);
    void BridgeR(EDGE e);
    Graph(int v,int e):V(v),E(e){adj_list.resize(v);}
};

void Graph::addedge(int v,int w){
    adj_list[v].push_front(w);
    adj_list[w].push_front(v);
}

void Graph::BridgeR(EDGE e){
    pre[e.w] = cnt++;
    low[e.w] = pre[e.w];
    int t;
    for(auto n = adj_list[e.w].cbegin();n != adj_list[e.w].cend();++n){
        t = *n;
        if(pre[t] == -1){
            BridgeR(EDGE(e.w,t));
            if(low[t] < low[e.w]) low[e.w] = low[t];
            if(low[t] == pre[t]) {
                if(t > e.w) ans.push_back(make_pair(e.w,t));
                else ans.push_back(make_pair(t,e.w));
            }
        }
        else if(t != e.v){
            low[e.w] = min(pre[t],low[e.w]);
        }
    }
}

void solution(Graph &G){
    cnt = 0;
    for(int i = 0; i < G.V;i++){
        if(pre[i] == -1){
            G.BridgeR(EDGE(i,i));
        }
    }
}

int main(){
    int V,E,s,t;
    scanf("%d %d",&V,&E);
    Graph G(V,E);
    for(int i = 0; i < E;i++){
        scanf("%d %d",&s,&t);
        G.addedge(s,t);
    }

    for(int i = 0;i < V;i++){
        pre[i] = -1;
        low[i] = -1;
    }

    solution(G);
    sort(ans.begin(),ans.end());
    for(auto &a:ans){
        printf("%d %d\n",a.first,a.second);
    }
}



Measured memory_bytes: 7116
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#define llong long long
using namespace std;

const int N = 1e6;
const int P = 998244353;
llong a[N+3],aa[N+3],f[N+3];
int pri[N+3];
bool isp[N+3];
int mu[N+3];
llong inv[N+3];
int n,np;
llong ans;

void EulerSieve()
{
	isp[1] = true; mu[1] = 1;
	for(int i=2; i<=N; i++)
	{
		if(isp[i]==false) {np++; pri[np] = i; mu[i] = -1;}
		for(int j=1; j<=np && i*pri[j]<=N; j++)
		{
			isp[i*pri[j]] = true;
			if(i%pri[j]==0) {mu[i*pri[j]] = 0; break;}
			mu[i*pri[j]] = -mu[i];
		}
	}
}

int main()
{
	EulerSieve();
	inv[1] = 1; for(int i=2; i<=N; i++) {inv[i] = (P-P/i)*inv[P%i]%P;}
	for(int i=1; i<=N; i++)
	{
		for(int j=1; j*i<=N; j++)
		{
			f[i*j] = (f[i*j]+inv[j]*(mu[i]+P))%P;
		}
	}
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {int x; scanf("%d",&x); a[x] += x;}
	for(int i=1; i<=N; i++)
	{
		for(int j=1; j*i<=N; j++)
		{
			aa[i] = (aa[i]+a[j*i])%P;
		}
	}
	for(int i=1; i<=N; i++)
	{
		llong tmp = f[i]*aa[i]%P*aa[i]%P;
		ans = (ans+tmp)%P;
	}
	for(int i=1; i<=N; i++) {ans = (ans-a[i]%P+P)%P;}
	ans = ans*inv[2]%P;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 38272
#include <iostream>
#include <unordered_map>

using namespace std;
using ll=long long;
#define UO unordered_map
#define FOR(i, N) for(ll i = 0; i < N; ++i)

int main(){
  ll n, m, x;
  cin>>n>>m>>x;
  if(n+m >=x && n<= x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


int main() {
    fast

    int n,d,a;
    cin>>n>>d>>a;

    vector<pair<long long ,long long >>arr(n);

    for(int i=0;i<n;i++){
        cin>>arr[i].first>>arr[i].second;
    }
    sort(arr.begin(),arr.end());
    vector<long long>pref(n+1);
    int i=0;
    int j=0;
    long long ans=0;
    for(int i=0;i<n;i++){

        while(j<n && arr[i].first+2*d>=arr[j].first)
        j++;

        long long need=max((arr[i].second-pref[i]*a+a-1)/a,0LL);
        ans+=need;
        pref[i]+=need;
        pref[j]-=need;
        pref[i+1]+=pref[i];


    }
    cout<<ans<<endl;



	return 0;
}


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

typedef long long LL;

const int OO = 1e9;
const int MOD = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	double x = a[0];
	for (int i = 1; i < n; ++i) {
		x = (x + a[i]) / 2;
	}
	cout.precision(5);
	cout << fixed;	
	cout << x << '\n';
}

int32_t main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// #endif

	// clock_t begin = clock();

	solve();

	// clock_t end = clock();
	// cerr << "\nELAPSED TIME: " << (double) (end - begin) / CLOCKS_PER_SEC;

	return 0;
}


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


int main(){
    int n, k;
    ll a = 0;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    for(int i = 0; i < n-k;i++){
        a += h[i];
    }
    cout << a << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
const int MOD = 1000000007;

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 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll n,k;
	cin>>n>>k;
	k=min(n,k);
	ll ans=0;
	 COMinit();
	for(ll i=0;i<=k;i++){
		ll cnt1=COM(n,i);
		ll cnt2=COM(n-i-1+i,i);
		ans+=cnt1*cnt2;
		ans%=inf;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 12160
Sd=input().strip()
T=input().strip()
S=None
for i in range(len(Sd)-len(T),-1,-1):
    sub=Sd[i:i+len(T)]
    for t,s in zip(T,sub):
        if s!="?" and s!=t:
            break
    else:
        S=Sd[:i]+T+Sd[i+len(T):]
        break
print(S.replace("?","a") if S else "UNRESTORABLE")

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll n,ans=0;
  cin >> n;
  if (n==1) {
    cout << 0 << endl;
    return 0;
  }
  if (n==2) {
    cout << 1 << endl;
    return 0;
  }
  for (ll i = 1; i <= n/2; i++) {
    ll j = n-i;
    if (j!=i)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 100000
#define MOD 1000000007
#define MAX_BIT 35
int main()
{
    long long int n,i;
    scanf("%lld",&n);
    long long int ans=0;
    long long int d,temp,c=0;
    for(i=1;i*i<=(n-1);i++)
    {
        if((n-1)%i==0)
        {
            c++;
            if(i*i!=(n-1)) c++;
        }
    }
    //printf("L1 done!\n");
    ans=ans+c-1;
    for(i=1;i*i<=n;i++)
    {
        //printf("i=%lld\n",i);
        if(n%i) continue;
        temp=n;
        d=i;
        while(d>1&&temp%d==0)
        {
            temp=temp/d;
        }
        if(temp%d==1) ans++;
        if(i*i==n) continue;
        temp=n;
        d=n/i;
        while(d>1&&temp%d==0)
        {
            temp=temp/d;
        }
        if(temp%d==1) ans++;

    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<math.h>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const ll N= 1e8;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 2; i*i  <= n;i++)
    {
        ll cnt = 0;
        ll z = 1;
        while(n%i==0)
        {
            n /= i;
            cnt++;
            if(cnt>=z)
            {
                cnt = 0;
                z++;
                ans++;
            }
        }
    }
    if(n!=1)
        ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3644
class uf_tree():

    def __init__(self,n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

    def indep(self):
        dep =0
        for i in range(self.n):
            if i == self.par[i]:
                dep += 1

        return dep

    def unite(self,x,y):
        if self.root(x) == self.root(y):
            return
        else:
            rootx = self.root(x)
            rooty = self.root(y)
            if self.rank[rootx] < self.rank[rooty]:
                self.par[rootx] = rooty
            else:
                self.par[rooty] = rootx
                if self.rank[rootx] == self.rank[rooty]:
                    self.rank[rootx] += 1
    def root(self,i):
        if self.par[i] == i:
            return i
        else:
            self.par[i] = self.root(self.par[i])
            return self.par[i]

    def same(self,x,y):
        return self.root(x) == self.root(y)

def kruscal(n,edge_arr):
    edge_arr.sort(key=lambda x:x[2])
    ans = []
    tree = uf_tree(n)
    for e in edge_arr:
        s = e[0]-1
        g = e[1]-1
        if tree.same(s,g):
            continue
        else:
            ans.append(e)
            tree.unite(s,g)
    return ans

p = []
edge = []
n = int(input())
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y,i+1])

p.sort(key = lambda x:x[0])
for i in range(n-1):
    cost = min(abs(p[i+1][0]-p[i][0]),abs(p[i+1][1]-p[i][1]))
    edge.append([p[i][2],p[i+1][2],cost])

p.sort(key = lambda x:x[1])
for i in range(n-1):
    cost = min(abs(p[i+1][0]-p[i][0]),abs(p[i+1][1]-p[i][1]))
    edge.append([p[i][2],p[i+1][2],cost])

ans = kruscal(n,edge)
tot = 0
for e in ans:
    tot += e[2]
print(tot)

Measured memory_bytes: 55196
def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

print(solve())


Measured memory_bytes: 13976
N = int(input())
A = input()
Ar = A[::-1]
i = 0
j = 0
res = 0
while True:
    x = A[i:-1].find("W")
    y = Ar[j:-1].find("R")
    if x == -1 or y == -1:
        break
    i += x
    j += y
    if i+j >= N:
        break
    else:
        res += 1
    i+= 1
    j+= 1
print(res)
    

Measured memory_bytes: 9640
import math
N = int(input())
A = list(map(int, input().split()))

G = []
nodes = [0]*(N+1)
nodes[0] = 1
for i in range(N):
    nodes[i+1] = nodes[i]*2

if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    exit(0)

ans = 0
node = 1 - A[0]
nodes = [0 for i in range(N)]
nodes[0] = 1 - A[0]  # 深さi-1で、葉でない頂点の個数の最小値、最大値

# 可能性の判定 + 深さNの確定
for i in range(1, N+1):
    if i == N:
        if math.ceil(A[i]/2) > nodes[i-1]:
            print(-1)
            exit(0)
        else:
            continue
    else:
        # 自分の深さが可能かの判定
        if nodes[i-1] * 2 >= A[i]:
            nodes[i] = nodes[i-1] * 2 - A[i]
        else:
            print(-1)
            exit(0)
ans += A[i]
prev = A[-1]
for i in range(N-1, -1, -1):
    # その深さでできる最大値
    prev = min(nodes[i], prev) + A[i]
    ans += prev

print(ans)


Measured memory_bytes: 671720
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/23 11:33:49 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	string	s;
	cin >> s;
	vector<int>	V(3);
	rep(i, s.size())
	{
		if (s.at(i) == 'a')
			V.at(0)++;
		else if (s.at(i) == 'b')
			V.at(1)++;
		else
			V.at(2)++;
	}
	sort(V.begin(), V.end());
	if (V.at(2) - V.at(0) <= 1)
		cout << "YES" << endl;
	else
	{
		cout << "NO" << endl;
	}

}
// END

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


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

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

    lint n, k, ans=1;
    cin>>n>>k;
    rep(i, n){
        if(k>pow(2, i))ans*=2;
        else ans += k;
    }
    co(ans);
}

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

int main(){
  string s;
  long long k;
  cin>>s>>k;
  for(int i=0;i<k;i++){
    if(s[i]!='1'){
      cout<<s[i]<<endl;
      return 0;
    }
  }
  cout<<'1'<<endl;
  return 0;
}
      
  
  


Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

s = input()

if s[0]==s[1] and s[1]==s[2]:
	if s[0] == "R":
		print(3)
	else:
		print(0)
elif s[0]==s[1]:
	if s[0]=="R":
		print(2)
	else:
		print(1)
elif s[1]==s[2]:
	if s[1]=="R":
		print(2)
	else:
		print(1)
else:
	if "R" in s:
		print(1)
	else:
		print(0)

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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;
}

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

using pii = pair<ll, ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

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

    ll n;
    cin >> n;
    const auto a = Read(n);
    ll q;
    cin >> q;
    const auto k = Read(q);
    REP(i, q) {
        cout << lower_bound(ALL(a), k[i]) - a.begin() << endl;
    }
    return 0;
}



Measured memory_bytes: 5196
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=1;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;



int main(){
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

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

int main(){
	LL a,b;
	while(cin >> a >> b){
		LL c = gcd(a,b);
		cout << c << " " << a*b/c << endl;
	}
	return 0;
}

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

int main() { 
  int k;
  string s;
  
  cin >> k >> s;
  int m = s.size();
  //cout << m;
  
  if(m <= k){
    cout << s;
  }else{
    for(int i = 0; i< k;i++){
      cout << s[i];
    }
    cout << "...";
  }

  
}


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

int main()
{
   int a , b;
   cin>>a>>b;
int ans =0;
   for(int i=a;i<=b;i++)
   {
       string temp = to_string(i);
       string temp1 = temp;
       reverse(temp1.begin() , temp1.end());
       if( temp == temp1)
           ans++;
   }
cout<<ans;
}

Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC96_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var h = int.Parse(s[0]);
            var w = int.Parse(s[1]);
            var p = new string[h];
            for (int i = 0; i < h; i++)
            {
                p[i] = Console.ReadLine();
            }
            bool f = true;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    
                    if((p[i][j] == '#')
                        && (i != 0 && p[i-1][j] != '#')
                        && (i != h-1 && p[i+1][j] != '#')
                        && (j != 0 && p[i][j - 1] != '#')
                        && (j != w - 1 && p[i][j+1] != '#'))
                    {
                        f = false;
                    }
                }
            }

            Console.WriteLine(f ? "Yes": "No");
        }
    }
}


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

ll dp[3001][3001][2];

ll f(int i, int j, ll *a)
{
 if(i==j)
 {
     return a[i];
 }
 if(dp[i][j][1]!=-1)
 {
     return dp[i][j][0];
 }
    dp[i][j][0]=max((a[i]-f(i+1, j, a)), (a[j]-f(i, j-1, a)));
    dp[i][j][1]=0;
    return dp[i][j][0];
}

int main()
{
   memset(dp, -1, sizeof(dp));
   int n;
   cin>>n;
   ll a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   cout<<f(0, n-1, a)<<endl;
   return 0;
}



Measured memory_bytes: 144564
s = gets.chomp
t = gets.chomp

if s.size<t.size then
  puts 'UNRESTORABLE'
  exit
end

w = -1
s.size.times{|i|
  f = true
  t.size.times{|j|
    if !(s[i+j]=='?'||s[i+j]==t[j]) then
      f = false
    end
  }
  w = i if f
}

if w==-1 then
  puts 'UNRESTORABLE'
  exit
end

a = ''
s.size.times{|i|
  if w<=i && i<w+t.size then
    a+=t[i-w]
  elsif s[i] == '?' then
    a+='a'
  else
    a+=s[i]
  end
}

puts a

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


Measured memory_bytes: 1024
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,dp[505][505]={},x,y;
  cin >> h >> w;
  string s[505]={};
  for(int i=0; i<h; i++) {
    cin >> s[i];
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      dp[i][j]=inf;
    }
  }
  if(s[0][0]=='.') {
    dp[0][0]=0;
  }
  else {
    dp[0][0]=1;
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(i==0&&j==0) {
        continue;
      }
      else {
        if(i==0) {
          dp[i][j]=min(dp[i][j],dp[i][j-1]+(s[i][j-1]=='.'&&s[i][j]=='#'));
        }
        else if(j==0) {
          dp[i][j]=min(dp[i][j],dp[i-1][j]+(s[i-1][j]=='.'&&s[i][j]=='#'));
        }
        else {
          x=dp[i-1][j]+(s[i][j]=='#'&&s[i-1][j]=='.');
          y=dp[i][j-1]+(s[i][j]=='#'&&s[i][j-1]=='.');
          dp[i][j]=min(x,y);
        }
      }
    }
  }
  cout << dp[h-1][w-1] << endl;
}

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


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

	cin>>a>>b>>k;

	if(b-a<2*k){
		for(int i=a;i<=b;i++)cout<<i<<endl;
		return 0;
	}
	for(int i=0;i<k;i++)cout<<a+i<<endl;
	for(int i=k-1;i>=0;i--)cout<<b-i<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> e(N), w(N), val(N);
    int cnt = 0;
    //各地点までの東を向いている人の数
    rep(i, N){
        if(s[i] == 'E'){
            cnt++;
        }
        e[i] = cnt;
    }
    cnt = 0;
    //各地点までの西を向いている人の数（逆順でみて）
    for(int i = N-1; i >= 0; i--){
        if(s[i] == 'W'){
            cnt++;
        }
        w[i] = cnt;
    }
    rep(i, N) val[i] = N - (e[i] + w[i]); //各地点における向きを変えなければ行けない人の数
    sort(val.begin(), val.end());
    int ans = val[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7156
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;

ll n;
ll a[200005];
ll dp[200005];
ll lastsum[200005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	lastsum[1]=a[1];
	for(int i=3;i<=n;i+=2)
	{
		lastsum[i]=lastsum[i-2]+a[i];
	}
	
	for(int i=2;i<=n;i++)
	{
		if(i%2==0)
		{
			dp[i]=max(dp[i-2]+a[i],lastsum[i-1]);
		}
		else
		{
			dp[i]=max(dp[i-2]+a[i],dp[i-1]);
		}
	}
	
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 8324
// Aizu Vol-1 0161: Sport Meet
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[200], *p;

#define INF 15000

int max1, max2, min1, min2;
int idx1, idx2, idx3, idx4;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int main()
{
	int i, j, n, t, s;
	
	while (1) {
		gets(p = buf);
		if (!(n = getInt())) break;
		min1 = min2 = INF, max1 = max2 = -1;
		for (i = 0; i < n; i++) {
			gets(p = buf);
			t = getInt();
			for (j = s = 0; j < 4; j++) s += 60 * getInt() + getInt();
			if (s > max1) max2 = max1, max1 = s, idx2 = idx1, idx1 = t;
			else if (s > max2) max2 = s, idx2 = t;
			if (s < min1) min2 = min1, min1 = s, idx4 = idx3, idx3 = t;
			else if (s < min2) min2 = s, idx4 = t;
		}
		printf("%d\n%d\n%d\n", idx3, idx4, idx2);
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X;
  int happy=0;
  cin >> X ;
  while (X >= 500){
    X-=500;
    happy+=1000;
  }
  while ( X >= 5 ){
    X-=5;
    happy+=5;
  }
  cout << happy << endl;
}

    
  

Measured memory_bytes: 256
#include<iostream>
 
int main()
{
  int N;
  std::cin >> N;
  
  if(N%2)
  {
   std::cout << ((N/2)+1)/static_cast<double>(N);
  }
  else
  {
    std::cout << (N/2)/static_cast<double>(N);
  }
}

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();
    int sum = a;
    int i = 1;
    if(b == 1) {
    	System.out.println(0);
    	return;
    }
    while(sum < b){
      sum += a-1;
      i++;
    }
    System.out.println(i);
  }
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

int main()
{
    int prime_num[1000001];
    memset(prime_num, 0, 1000001);
    prime_num[2] = 1;
    int ans = 1;
    for(int i = 3; i <= 1000000; i++) {
        if(i % 2 == 0) { 
            prime_num[i] = prime_num[i-1];
            continue;
        }
        bool is_prime = true;
        for(int j = 3; j*j <= i; j++) {
            if(i % j == 0) {
                is_prime = false;
                break;
            }
        }
        if(is_prime) {
            prime_num[i] = prime_num[i-1] + 1;
        } else {
            prime_num[i] = prime_num[i-1];
        }
    }
    int n;
    while(cin >> n) {
        cout << prime_num[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 4648
//
// Created by watemus on 10.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    int n, m;
    cin >> n >> m;
    int x;
    cin >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = INFL;
    for (int mask = 0; mask < (1 << n); mask++) {
        int cur_val = 0;
        vector<int> ta(m);
        for (int i = 0; i < n; i++) {
            if ((1 << i) & mask) {
                cur_val += c[i];
                for (int j = 0; j < m; j++) {
                    ta[j] += a[i][j];
                }
            }
        }
        bool f = false;
        for (int i = 0; i < m; i++) {
            if (ta[i] < x) {
                f = true;
                break;
            }
        }
        if (!f) ans = min(ans, cur_val);
    }
    cout << (ans==INFL ? -1 : ans);
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 3664