akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
  int a,b;
  while(1)
  {
    scanf("%d %d",&a,&b);
    if(a==0 && b==0)
    {
      break;
    }
    for(int i=0; i<a; i++)
    {
      for(int j=0; j<b; j++)
      {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2068
#include<iostream>
#include<iomanip>
#define pi acos(-1.0)
#include<cmath>
using namespace std;

int main(){
	double r;
	cin >> r;
	cout << setprecision(6) << fixed << r*r*pi << " " << setprecision(6) << fixed << 2*r*pi << endl;
}

Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++) 
const int INF = 100000000;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    rep(i, m) cin >> a[i] >> b[i];
    vector<vector<int>> list(n+1);
    vector<int> ans(n+1, -1);
    vector<int> dist(n+1, INF);
    rep(i, m) {
        list[a[i]].push_back(b[i]);
        list[b[i]].push_back(a[i]);
        ans[a[i]] = b[i];
    }
    //vector<int> fp;
    map<int, int> fp;
    
    dist[1] = 0;
    queue<int> que;
    for(auto i : list[1]) {
        dist[i] = 1;
        ans[i] = 1;
        que.push(i);
    }

    map<int, int> mp;
    while(!que.empty()) {
        int i = que.front();
        que.pop();
        for(int j : list[i]) {
            if(dist[i]+1 < dist[j]) {
                ans[j] = i;
                dist[j] = dist[i]+1;
                que.push(j);
            }
        }
    }

    for(int i = 2; i <= n; i++) {
        if(dist[i] == INF) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for(int i = 2; i <= n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12216
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  if(X<=A){
    cout<<X<<endl;
    return 0;
  }
  if(X<=A+B){
    cout<<A<<endl;
    return 0;
  }
  cout<<A-(X-A-B)<<endl;
  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int main()
{
 long long a,b,c,k;
  cin>>a>>b>>c>>k;
  int t = a-b;
  if(k%2==0)
  {
   cout<<t<<endl;
  }
  else
  {
  cout<<(-1*t)<<endl;  
  }

return 0;
}

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

using namespace std;

const int maxn = 2e5 + 10, mod = 1e9 + 7;
long long a[maxn], dp[maxn], c[maxn], n;

int main()
{
    ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    dp[0] = dp[1] = 1;
    c[a[1]] += dp[0];
    for(int i = 2; i <= n; i++){
        if(a[i] != a[i - 1])
            c[a[i]] += dp[i - 1];
        dp[i] = (c[a[i]] % mod);
    }
    cout << dp[n] % mod;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1000000000;
int main(){
    int h,w,ans=0;
    cin >> h >> w ;
    vector<vector<char>> maze(h,vector<char> (w));
    vector<vector<int>> a(h,vector<int> (w,INF));
    a[0][0] = 0;
    rep(i,h)rep(j,w) cin >> maze[i][j];
    rep(i,h)rep(j,w){
        if(i<h-1){
            if(maze[i+1][j]!=maze[i][j]) a[i+1][j] = min(a[i+1][j],a[i][j]+1);
            else a[i+1][j] = min(a[i+1][j],a[i][j]); 
        }
        if(j<w-1){
             if(maze[i][j+1]!=maze[i][j]) a[i][j+1] = min(a[i][j+1],a[i][j]+1);
             else a[i][j+1] = min(a[i][j+1],a[i][j]);
        }
    }
    if(maze[0][0]=='#') ans++;
    if(maze[h-1][w-1]=='#') ans++;
    cout << (ans+a[h-1][w-1])/2 << endl;
}

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

using namespace std;


int f(vector<int> x) {
    while (x.size() != 1) {
        vector<int> y;
        for (int i = 1; i < x.size() - 1; i++) {
            vector<int> z = {x[i - 1], x[i], x[i + 1]};
            sort(z.begin(), z.end());
            y.push_back(z[1]);
        }
        x = y;
    }
    return x[0];
}

vector<int> g(int n, int x) {
    vector<pair<int, int> > d;

    for (int i = 1; i <= 2 * n - 1; i++) {
        d.push_back({abs(i - x), i});
    }
    sort(d.begin(), d.end());
    deque<int> r;
    for (int i = 0; i < d.size(); i++) {
        if (i & 1) r.push_back(d[i].second );
        else r.push_front(d[i].second);
    }

    return vector<int>(r.begin(), r.end());

}

int main() {
    int N;
    cin >> N;
    int x;
    cin >> x;
    if( x >= 2 && x <= 2 * N - 2 ){
        cout << "Yes" << endl;
        for( auto i : g(N, x)){
            cout << i << endl;
        }
    }else{
        cout << "No" << endl;
    }
}


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

int main() {
  int n, x, m = 0;
  cin >> n >> x;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i, n){
    x -= v[i];
    if(x < 0) break;
    ++m;
  }
  if(m == n && x != 0) --m;
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 高橋くんの夏休みN
		int N = Integer.parseInt(sc.next());
		// 夏休みの宿題M
		int M = Integer.parseInt(sc.next());
      
        int days = 0;
        for (int i=0; i<M; i++) {
          int day = Integer.parseInt(sc.next());
          days += day;
        }
		
		// res が N より大きかったら -1
      	if (days > N) {
          System.out.println("-1");
        } else {
          System.out.println(N-days);
        }
	}
}

Measured memory_bytes: 42348
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

/* //約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}*/


int main() {
  ll N,K,S;
  cin >> N >> K >> S;
  Vl v(N,S);
  REP(i,N) {
    if (K>0) {
      K--;
    }
    else {
      if (S<1e9) v[i] = S+1;
      else v[i] = 1e9-5;
    }
  }

  for (auto i:v) cout << i << ' ';
  cout << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int X, Y, Z, K; cin>>X>>Y>>Z>>K;
  vector<ll> A(X),B(Y),	C(Z);
  REP(i,X) cin>>A[i];
  REP(i,Y) cin>>B[i];
  REP(i,Z) cin>>C[i];
  vector<ll> tmp, work;
  REP(i,X) REP(j,Y) tmp.push_back(A[i]+B[j]);
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());
  int size = min(K, (int)(tmp.size()));
  REP(i,size) REP(j,Z) work.push_back(tmp[i]+C[j]);
  sort(work.begin(), work.end());
  reverse(work.begin(), work.end());
  REP(i,K) cout	<< work[i] << endl;
  return 0;
}


Measured memory_bytes: 43368
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  vector<vector<ll>> c(3,vector<ll>(3)); rep(i,3) rep(j,3) cin>>c[i][j];
  
  vector<int> vec={0,1,2};
  ll sum=0; rep(i,3) sum+=c[i][i];
  do{
    ll ssum=0; rep(i,3) ssum+=c[i][vec[i]];
    if(ssum!=sum) {cout<<"No"<<'\n'; return 0;}
  }while(next_permutation(vec.begin(),vec.end()));
  
  cout<<"Yes"<<'\n';
  
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define llong long long

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 無限大の値
const long long INF = 1LL << 60;


int main(){
    int N, K;
    vector< tuple<llong, llong, llong> > act;

    // i-1日目にある行動(a:0, b:1, c:2)を取った時のi日目までの幸福の最大値
    llong dp[100000][3]; 

    cin >> N;
    llong a,b,c;
    for(int i = 0; i < N; i++){
        cin >> a >> b >> c;
        act.push_back( make_tuple(a,b,c) );
    }

    for(int i = 0; i < N; i++){
        for(int j=0; j<3 ;j++){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = get<0>(act[0]); // 0日目に行動aを取った
    dp[0][1] = get<1>(act[0]); // 0日目に行動bを取った
    dp[0][2] = get<2>(act[0]); // 0日目に行動cを取った
    
    for(int i=1; i<N; i++){
        dp[i][0] = max( dp[i-1][1] + get<0>(act[i]), dp[i-1][2] + get<0>(act[i]) );
        dp[i][1] = max( dp[i-1][0] + get<1>(act[i]), dp[i-1][2] + get<1>(act[i]) );
        dp[i][2] = max( dp[i-1][0] + get<2>(act[i]), dp[i-1][1] + get<2>(act[i]) );
    }

    llong res = 0;
    for(int j=0; j<3 ;j++){
        res = max(res, dp[N-1][j]);
    }

    cout << res << endl;
    
    return 0;
}

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

int main() {
    vector<int> candy(3);
    rep(i, 3) cin >> candy.at(i);
    sort(candy.begin(), candy.end());
    if(candy.at(0) + candy.at(1) == candy.at(2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, w;
ll weight[101], value[101];
ll dp[101010];
int main(){
    cin>>n>>w;
    REP(i, 0, n) cin>>weight[i]>>value[i];
    REP(j, 1, w+1) dp[j]=-1;

    dp[0]=0;
    REP(i, 0, n){
        RREP(j, 0, w){
            if(dp[j]==-1) continue;
            if(j+weight[i]>w) continue;

            dp[j+weight[i]]=max(dp[j+weight[i]], dp[j]+value[i]);
        }
    }

    ll ans=0;
    REP(j, 0, w+1) ans=max(ans, dp[j]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>

using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;

    vector<tuple<int, int, string>> v;

    for(int i=0; i<n; ++i) {
        string city;
        int ptr;
        cin >> city;
        cin >> ptr;
        v.push_back(tuple<int, int, string>(i+1, ptr, city));
    }

    std::sort(v.begin(), v.end(),
    [](const tuple<int, int, string>& a, const tuple<int, int, string>&b ) {
        return get<2>(a) != get<2>(b) ? get<2>(a) < get<2>(b) :
        get<1>(a) > get<1>(b);
    });
    
    for(const auto& t: v) {
        cout << get<0>(t) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
t = sorted(map(int, input().split()))  # 入力のときに N を使う必要はありません
answer = T

for i in range(1, N):
    if t[i-1] + T > t[i]:
        answer += t[i] - t[i-1]
    else:
        answer += T

print(answer)


Measured memory_bytes: 25196
N = int(input())
A = [int(i) for i in input().split()]
A = [A[_] - (_ + 1) for _ in range(N)]
AA = sorted(A)
ans = 0
ans1 = 0
center = N // 2
num = AA[center]

if N % 2 != 0:
    for i in range(N):
        ans += abs(AA[i] - num)
    print(ans)
else:
    center = len(AA) // 2
    for i in range(N):
        ans += abs(AA[i]- num)
        ans1 += abs(AA[i]-(AA[center-1]))
    print(min(ans, ans1))

Measured memory_bytes: 26016
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int dp[305][305][305];
void solve() {
	string s;
	int k;
	cin>>s>>k;
	while(!s.empty()&&s.back()=='0')
		s.pop_back();
	int bak=0;
	vi po;
	for(char i:s)
		if(i=='0') {
			bak++;
		} else
			po.pb(bak);
	k=min(k,sz(po));
	dp[0][0][0]=1;
	fr(i,0,sz(s)-sz(po)) {
		int canmatch=upper_bound(all(po),i)-lower_bound(all(po),i);
		trace(i,canmatch);
		int pool=lower_bound(all(po),i)-po.begin();
		fr(j,pool,sz(po)) {
			fr(kk,0,j) {
				dp[i][j][kk]%=mod;
				fr(l,0,sz(po)-j) {
					dp[i+1][j+l][kk+min(canmatch,l)]+=dp[i][j][kk];
				}
			}
		}
	}
	int ans=0;
	trace(dp[2][1][0],dp[1][2][1],dp[1][1][1],dp[1][1][0]);
//	trace(dp[2][2][2],dp[1][2][2],dp[2][1][1],dp[1][1][1]);
//	trace(dp[2][0][1],dp[2][0][0],dp[2][1][1]);
	trace(k,sz(s)-sz(po),sz(po),po);
	fr(i,sz(po)-k,sz(po)) {
		ans=(ans+dp[sz(s)-sz(po)+1][sz(po)][i])%mod;
		trace(dp[sz(s)-sz(po)+1][sz(po)][i]);
	}
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 57684
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

void solve(){
	
	int n ;
	cin>>n ;
	string s;
	cin>>s ;

	if(s.length()>n){
		string t=s.substr(0,n) ;
		t=t+"..." ;
		cout<<t ;
	}
	else
	{
		cout<<s ;
	}	 

}


int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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

int N,T,A;
int main (){
    cin >> N >> T >> A;
    int best = 99999999;
    int ans = -1;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        int  ave = T * 1000 - x * 6;
        if ( abs( A * 1000 - ave ) < best ) {
            best = abs( A * 1000 - ave);
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int []A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		scan.close();
		Arrays.sort(A);
		System.out.println(A[N - 1] - A[0]);
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n;
	cin >> n;

	vector<int> vs(n + 1);
	FOR_LT(i, 0, n) {
		int v; cin >> v;
		vs[v]++;
	}

	vector<int> ds(n + 1);
	FOR_LE(i, 1, n) {
		ds[vs[i]]++;
	}

	vector<int> kdk(n + 1);
	vector<int> dk(n + 2);

	FOR_LE(k, 1, n) {
		kdk[k] = kdk[k - 1] + k * ds[k];
		dk[k] = dk[k - 1] + ds[k];
	}

	vector<int> fs(n + 2);
	FOR_LE(i, 1, n) {
		fs[i] = (kdk[i] + i*(dk[n] - dk[i])) / i;
	}

	int c = n;
	FOR_LE(v, 1, n) {
		while (c != 0 && fs[c] < v) c--;
		cout << c << endl;
	}

	return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#include <sys/time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldo;
#define endl            "\n"
#define pi              3.1415926535897932384626433832795
#define mod             (ll)1000000007
#define pp              pair<ll,ll>
#define vii             vector<int>
#define vll             vector<ll>
#define vpp             vector<pp>
#define vss             vector<string>
#define pb              push_back
#define pob             pop_back
#define mp              make_pair
#define pf              push_front
#define pof             pop_front
#define eb              emplace_back
#define ff              first
#define ss              second
#define bs(v,x)         binary_search(v.begin(),v.end(),x)
#define ub(v,x)       upper_bound(v.begin(),v.end(),x)
#define lb(v,x)       lower_bound(v.begin(),v.end(),x)
#define print(A,n)      for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n)       for(ll i=0;i<n;++i)cin>>A[i];
#define set(x)          memset(x,0,sizeof(x));
#define Sort(x)         sort(x.begin(),x.end())
#define fast            ios_base::sync_with_stdio(false);cin.tie(NULL);
#define setd(s,s1,S1)   set_difference(s.begin(),s.end(),s1.begin(),s1.end(),inserter(S1,S1.end())); //set and multi set
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(f) for(auto it=f.begin();it!=f.end();it++)cout<<*it<<" ";cout<<endl;


int main()
{
    fast;
    ll L=1;
//    cin>>L;
    while(L--){
        ll n;
        cin>>n;
        cout<<n+n*n+n*n*n<<endl;
    }
    return 0;
}



Measured memory_bytes: 3692
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  string s;
  cin >> s;
  int n = s.length()+1;
  vector<int> adj[n];
  vector<int> adj_in[n];

  for(int i=0;i<n-1;i++){
    if(s[i]=='<'){
      adj[i].push_back(i+1);
      adj_in[i+1].push_back(i);
    }
    else{
      adj[i+1].push_back(i);
      adj_in[i].push_back(i+1);
    }
  }
  vector<int> zero_list;
  int a[n];
  for(int i=0;i<n;i++){
    a[i]=0;
    if(adj_in[i].size() < 1){
      zero_list.push_back(i);
    }
  }

  for(int i=0;i<zero_list.size();i++){
    int r = zero_list[i];
    for(int j=0;j<adj[r].size();j++){
      int r_before = r;
      int next_r = adj[r_before][j];
      a[next_r] = max(a[r_before]+1,a[next_r]);
      r_before = next_r;
      while(adj[r_before].size() != 0){
        int next_r = adj[r_before][0];
        a[next_r] = max(a[r_before]+1,a[next_r]);
        r_before = next_r;
      }
    }
  }

  long long ans = 0;
  for(int i=0;i<n;i++){
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 57348
#include<iostream>
#define int long long
using namespace std;
int solve(int x,int y){
	if(x%y==0){
		return 2*x-y;
	}
	return y*2*(x/y)+solve(y,x%y);
}
signed main(){
	int n,i,j,z;
	cin>>n>>z;
	if(2*z==n){
		cout<<3*n/2;
		return 0;
	}
	if(2*z<n){
		cout<<n+2*z+solve(z,n-2*z);
	}
	else{
		cout<<n+solve(z,n-z);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  int n, k ;
  cin >> n >> k ;
  
  if(n%2==0){
    if(k<=n/2){
      cout << "YES" <<endl ;
    }
    else{
      cout <<"NO"<<endl ;
    }
  }
  else{
    if(k<=n/2+1){
      cout <<"YES"<<endl ;
    }
    else{
      cout << "NO"<<endl ;
    }
  }


  return 0 ;
}




Measured memory_bytes: 256
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 500001; 

// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 

    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 

    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 

        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 

        // If i is equal to r of any query store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                    query(queries[query_counter].r + 1, bit, n)- 
                    query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 

    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 

// driver code 
int main() 
{
    int n,query;
    cin >> n >> query;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    } 
    Query queries[query]; 
    for(int i = 0; i < query; i++){
        cin >> queries[i].l >> queries[i].r;
        queries[i].l--;
        queries[i].r--;
        queries[i].idx = i;
    }
    int q = query;
    sort(queries, queries+q, cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 


Measured memory_bytes: 17360
n = int(input())
a = []
for i in range(2):
    a.append(list(map(int, input().split())))
candy = []
for i in range(n):
    candy_amount = 0
    for j in range(0, i + 1):
        candy_amount = candy_amount + a[0][j]
    for j in range(i, n):
        candy_amount = candy_amount + a[1][j]
    candy.append(candy_amount)
print(max(candy))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n);
	ll sum = 0LL;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	
	ll ans = 1LL << 60;
	ll tmp = 0LL;
	for(int i = 0; i < n - 1; ++i) {
		tmp += a[i];
		ans = min(ans, abs(sum - 2LL * tmp));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4816
def B_Minesweeper(H, W, S):
    def is_bound(x, y, H, W):
        if 0 <= x and x <= W - 1 and 0 <= y and y <= H - 1:
            return True
        else:
            return False

    ans = [[None for i in range(W)] for j in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                ret = 0
                for k in [[i - 1, j - 1], [i - 1, j], [i - 1, j + 1], [i, j - 1], [i, j + 1], [i + 1, j - 1], [i + 1, j], [i + 1, j + 1]]:
                    y = k[0]
                    x = k[1]
                    if is_bound(x, y, H, W):
                        if S[y][x] == '#':
                            ret += 1
                ans[i][j] = str(ret)
            else:
                ans[i][j] = '#'
    for s in ans:
        print(''.join(s))
    return None
  
H,W = [int(i) for i in input().split()]
S = [[i for i in input()] for j in range(H)]
B_Minesweeper(H, W, S)

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


int main()
{
	int n,x,f=0;
	cin >> n;
	while(n)
    {
        f = n%10;
        n /= 10;
        if(f == 7)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 3003;
const int M = 200005;
const int mod = (int) 1e9 + 7;

pii a[N];
int dp[N];

ll f[M], inv[M], finv[M];

void init() {
	f[0] = f[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
	for (int i = 2; i < M; i++) {
		f[i] = (f[i - 1] * i) % mod;
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
		finv[i] = (finv[i - 1] * inv[i]) % mod;
	}
}

ll nCr(ll n, ll r) {
	return (f[n] * ((finv[r] * finv[n - r]) % mod)) % mod;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	init();
	int h, w, n;
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	a[n++] = {h, w};
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		dp[i] = nCr(a[i].first - 1 + a[i].second - 1, a[i].first - 1);
		for (int j = 0; j < i; j++) {
			if (a[j].second <= a[i].second) {
				dp[i] -= dp[j] * nCr(a[i].first - a[j].first + a[i].second - a[j].second, a[i].first - a[j].first) % mod;
				if (dp[i] < 0)
					dp[i] += mod;
			}
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


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


int main(){
  string s;
  int n,ans = 0;
  
  while(true){
    bool on_flag = false;
    bool kataasi = true;
    string s;
    int n,ans = 0;
    
    cin >> n;

    if(n == 0) break;
    
    for(int i=0;i<n;++i){
      cin >> s;

      kataasi = !kataasi;
      
      if(kataasi){
	if(on_flag){
	  if(s == "ld" || s == "rd"){
	    on_flag = false;
	    ++ans;
	  }else{
	    
	  }
	}else{
	  if(s == "lu" || s == "ru"){
	    ++ans;
	    on_flag = true;
	  }else{

	  }
	}
      }
    }

    cout << ans << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    int cnt=0;
    REP2(i, 1, N+1){
        if(i%2==0) continue;
        int cnt_tmp=0;
        REP2(j,1,i+1){
            if(i%j==0) cnt_tmp++;
        } 
        if(cnt_tmp==8) cnt++;
    }
    cout << cnt << endl;

    return 0;
}   

Measured memory_bytes: 256
a,b,c=map(int,input().split())
m=max(a,b,c)
total=a+b+c
x=0
if m%2==0 and total%2==0:
    print((3*m-total)//2)
elif m%2==1 and total%2==1:
    print((3*m-total)//2)
else:
    m=m+1
    print((3*m-total)//2)
    
    

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

int main() {
    long long s, c;
    long long cnt = 0;

    cin >> s >> c;

    if(s > c){
        // 10 2
        cout << c / 2;
    }else if(s * 2 > c){
        // 2 3
        cout << c / 2;
    }else{
        // 2 10
        cnt += s;
        c -= s * 2;
        cnt += c / 4;

        cout << cnt;
    }
}

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

int main () {
  int N;
  cin >> N;
  
  if(N<10){
    cout << "ABC00" << N;
  }
  else if (N<100){
    cout << "ABC0" << N;
  }
  else {
    cout << "ABC" << N;
  }
}
  
  
  

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

int main(){
  int A,B,M;
  cin >> A >> B >> M;
  int a[A];int b[B]; int amin=100001,bmin=100001;
  for(int i=0;i<A;i++){
    cin >> a[i];
    if(a[i]<amin){
      amin=a[i];
    }
  }
  for(int i=0;i<B;i++){
    cin >> b[i];
    if(b[i]<bmin){
      bmin=b[i];
    }
  }
  int x[M]; int y[M]; int c[M];
  for(int i=0;i<M;i++){
    cin >> x[i] >> y[i] >> c[i];
  }
  int summin=amin+bmin;
  int tmpsum=200001;
  for(int i=0;i<M;i++){
    tmpsum=a[x[i]-1]+b[y[i]-1]-c[i];
    if(tmpsum<summin){
      summin=tmpsum;
    }
  }
  cout << summin;
  return 0;
}


Measured memory_bytes: 2176
s=input()
t=input()

dp=[[0 for x in range(len(t)+1)] for x in range(len(s)+1)] 
for i in range(len(s)+1): 
    for j in range(len(t)+1): 
        if i==0 or j==0: 
            dp[i][j] = 0
        elif s[i-1]==t[j-1]: 
            dp[i][j]=dp[i-1][j-1] + 1
        else: 
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]) 
ans=dp[len(s)][len(t)]
lcs=[""]*(ans+1) 
lcs[ans]=""
i=len(s)
j=len(t) 
while i>0 and j>0: 
    if s[i-1]==t[j-1]: 
        lcs[ans-1]=s[i-1] 
        i-=1
        j-=1
        ans-=1
    elif dp[i-1][j]>dp[i][j-1]: 
        i-=1
    else:
        j-=1
print(''.join(lcs))

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

const ll INF = pow(10, 9) + 7;

int main() {
  string s;
  cin >> s;
  int N = s.size();
  vector<int> ans(N);
  bool r =true;//r=trueのときR、falseのときL
  int cnt=0;
  rep(i,N-1){
    if(i==N-2){
      if(r){
        cnt++;
      ans[i+1] += cnt/2 +1;
      ans[i] += cnt-cnt/2;
       break;
      }
      else{
      cnt += 2;
      ans[i-cnt+1] += cnt/2;
      ans[i-cnt+2] += cnt-cnt/2;
      break;
      }
    }
    
    if(s.at(i)==s.at(i+1)) {
      cnt++;
      continue;
    }
    
    if(r){
      cnt++;
      r=false;
      ans[i+1] += cnt/2;
      ans[i] += cnt-cnt/2;
      cnt = 0;
    }
    else{
      cnt++;
      r=true;
      ans[i-cnt] += cnt/2;
      ans[i-cnt+1] += cnt-cnt/2;
      cnt =0;
    }
  }
  rep(i,N) cout << ans[i] << " ";
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int p[256] = {};
    for (int i = 0; i < n; i++) {
        char s[10];
        cin >> s;

        p[s[0]]++;
    }

    string c[4] = { "AC", "WA", "TLE", "RE" };
    for (int i = 0; i < 4; i++) {
        cout << c[i] << " x " << p[c[i][0]] << '\n';
    }

    return 0;
}

Measured memory_bytes: 3660
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @author k
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> inputList = new ArrayList<Integer>();
		// 標準入力より読み取りリストに追加
		inputList.add(sc.nextInt());// 入力A
		inputList.add(sc.nextInt());// 入力B
		inputList.add(sc.nextInt());// 入力C
		// 最大値を取得
		Integer maxNum = Collections.max(inputList);
		inputList.remove(maxNum);
		// 2番目に大きい値を取得
		Integer midNum = Collections.max(inputList);
		inputList.remove(midNum);
		// 結果出力
		System.out.println(maxNum.intValue() * 10 + midNum.intValue() + inputList.get(0).intValue());

		sc.close();
	}

}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  vector <int> v;
  int i,n;
  string a;
  cin>>a;
  n=a.size();
  for(i=0;i<n;i++)
  {
    if(a[i]=='1')
      v.push_back(1);
    if(a[i]=='0')
      v.push_back(0);
    if(a[i]=='B' && v.size()>0)
      v.pop_back();
  }
    
    for(i=0;i<v.size();i++)
      cout<<v[i];
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;


	public static void main(String[] args) {

		long ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		long n = sc.nextLong();


		//-------------------------------------------------------------------------------------

		double k = 100;
		double r = 1.01;

		do {
			k = Math.floor(k * r);
			ans++;
		} while(k < n);

		//-------------------------------------------------------------------------------------

//		for(int i = 0; i < n; i++) {
//			System.out.println(ans[i]);
//		}

//		if(f) {
//			System.out.println("OK");
//		} else {
//			System.out.println("NG");
//		}

		System.out.println(ans);

		sc.close();
	}
}

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

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String[] s = in.nextLine().split(" ");
        int num = new Integer(s[0] + s[1]);
        int sqrt = (int) Math.sqrt(num);
        sqrt *= sqrt;
        if (sqrt == num && num % sqrt == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>

#define fo(i,a,b) for (register int i = a;i <= b;i ++)
#define fd(i,a,b) for (register int i = a;i >= b;i --)
#define wr(a,b) printf("%s = %d\n",a,b)
#define mem(a,b) memset(a,(b),sizeof(a))

using namespace std;

const int N = 100010;

string s;
bool b[N];
int p[N], a[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
   // freopen("in.txt","r",stdin);
    cin >> s;
    int la = 0;
	fo (i,0,s.size() - 2){
		if (s[i] == 'R' && s[i + 1] == 'L') 
		  {
			int fl = 1, j = i - 1;
			while (j >= 0 && !b[j] && s[j] == s[j + 1]) {
			   p[j --] = i + (fl), fl ^= 1, b[j + 1] = 1;
		       //cout << fl << endl;
			  }
			p[i + 1] = i + 1, b[i + 1] = 1;
			p[i] = i, b[i] = 1;
		  }
	}
	fo (i,2,s.size() - 1) {
		if (s[i] == 'L' && s[i - 1] == 'L') {
			p[i] = p[i - 2];
			b[i] = 1;
		}
	}
	
	fo (i,0,s.size() - 1) ++ a[p[i]];
//	fo (i,0,s.size() - 1) cout << p[i] << ' ' ;
//	cout << endl;
	fo (i,0,s.size() - 1) cout << a[i] << ' ' ;
	cout << endl;
	return 0;
}


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

int main(){
  int N,K,Q; cin >> N >> K >> Q;
  int ac[100010]={};
  for(int i=0; i<Q; i++){
    int tmp; cin >> tmp;
    ac[tmp-1]++;
  }
  for(int i=0; i<N; i++){
    if(K>Q-ac[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

int w[301];
int dp[301][301];
int daruma(int n, int i, int j){
    if(dp[i][j]!=-1)    return dp[i][j];
    if(n==1){
        dp[i][j]=0;
    }
    else if(n==2){
        if(abs(w[i]-w[i-1])<=1)   dp[i][j]=2;
        else dp[i][j]=0;
    }
    else{
        int max=0;
        if(n>=4){
            max=daruma(n-2, i-1, j+1);
            if(max==n-2){
                if(abs(w[i]-w[j])<=1)   max+=2;
                else max+=0;
            }
            else max+=0;
        }
        for(int k=j+1; k<i; k++){
            int sum=daruma(k-j+1, k, j)+daruma(i-k, i, k+1);
            if(max<sum) max=sum;
        }
        dp[i][j]=max;
    }
    return dp[i][j];
    
}

int main(void){
    int N;
    while(cin>>N){
        if(N==0)    break;
        for(int i=0; i<N; i++){
            cin>>w[i];
            for(int j=0; j<N; j++){
                dp[i][j]=-1;
            }
        }
        cout << daruma(N, N-1, 0)<<"\n";
        
    }
    
    
}



Measured memory_bytes: 3444
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int K,S,X,Y,Z,ans,cnt = 0;
	scanf("%d%d",&K,&S);
	for(X = 0; X <= K; X++)
	for(Y = 0; Y <= K; Y++)
	{
		ans = S - X - Y;
		if(ans >= 0 && ans <= K)
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

#define MAX_N 100
#define MAX_W 10000
#define SELECTED 1
#define DISCARDED 0

typedef struct { int v, w; } item_t;

int main(int argc, char **argv) {
  int n, w, i, j, vs[MAX_N+1][MAX_W+1];
  item_t is[MAX_N+1];

  scanf("%d %d", &n, &w);
  for (i = 1; i <= n; ++i) scanf("%d %d", &is[i].v, &is[i].w);
  for (i = 0; i <= n; ++i) vs[i][0] = 0;
  for (i = 0; i <= w; ++i) vs[0][i] = 0;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= w; ++j) {
      if (is[i].w > j || vs[i-1][j] > vs[i-1][j-is[i].w] + is[i].v) {
        vs[i][j] = vs[i-1][j];
        continue;
      }
      vs[i][j] = vs[i-1][j-is[i].w] + is[i].v;
    }
  }
  printf("%d\n", vs[n][w]);
}


Measured memory_bytes: 5752
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int64_t> A(N);
  unordered_map<int64_t, int> Amap;
  rep(i, N) {
    cin >> A[i];
    Amap[A[i]]++;
  }

  int answer = 0;
  for (int i = 0; i < N; ++i) {
    bool flag = true;
    for (auto n : divisor(A[i])) {
      if (Amap.count(n)) {
        if (n == A[i] && Amap[n] == 1) {
          continue;
        }
        flag = false;
        break;
      }
    }
    if (flag) ++answer;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 13060
// abc150_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> P(N);
    REP(i, N) cin >> P[i];
    vector<int> Q(N);
    REP(i, N) cin >> Q[i];

    vector<int> A(N);
    iota(ALL(A), 1);

    int a=0, b=0;
    int k = 0;
    do {
        bool same;

        same = true;
        REP(i, N){
            if (A[i] != P[i]) {
                same = false;
                break;
            }
        }
        if (same) a = k;

        same = true;
        REP(i, N){
            if (A[i] != Q[i]) {
                same = false;
                break;
            }
        }
        if (same) b = k;

        k++;

    } while( next_permutation(ALL(A)));


    int ans = abs(a - b);
    print(ans);

    return 0;
}


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

using namespace std;

bool solve(int n, int s, int len, string foo, string bar, char add, char sub) {
  int l = 1, r = n;
  for (int i = len - 1; ~i; --i) {
    if (bar[i] == add) {
      --l;
    } else if (bar[i] == sub) {
      ++r;
    }
    l = max(l, 1);
    r = min(r, n);
    if (foo[i] == add) {
      --r;
    } else if (foo[i] == sub) {
      ++l;
    }
    if (l > r) {
      return false;
    }
  }
  return l <= s && s <= r;
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int r, c, n, x, y;
  string foo, bar;
  cin >> r >> c >> n >> x >> y >> foo >> bar;
  cout << (solve(r, x, n, foo, bar, 'D', 'U') && solve(c, y, n, foo, bar, 'R', 'L') ? "YES" : "NO") << "\n";
  return 0;
}


Measured memory_bytes: 1560
#include <iostream>

using namespace std;

int main()
{
    int i, h, m, s;
    cin >> i;
    h = i / 3600;
    m = i / 60 - h * 60;
    s = i % 60;
    cout << h <<":"<< m << ":" << s << endl;

    return 0;
}



Measured memory_bytes: 3080
import math
def factrize(x):
    f = {}
    if x == 1:
        return f
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp//i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f
p = 10**9+7
N =int(input())
a = factrize(math.factorial(N))
A = list(a.values())
ans =1
for i in A:
  ans = (ans * (i+1)) % p
print(ans)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val hs = readLine()!!.split(' ').map { it.toInt() }

    val dp = Array(n) { Int.MAX_VALUE }

    dp[0] = 0

    (0 until n).forEach { i ->
        (1..k).forEach { j ->
            if (i + j < n) {
                dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(hs[i] - hs[i + j]))
            }
        }
    }

    println(dp.last())
}

Measured memory_bytes: 106920
#include<stdio.h>

int main(){
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		int icp=i,k=0;
		while(icp>0){
			icp/=10;
			k++;
		}
		ans+=k%2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

n=int(input())
l=list(map(int,input().split()))
for i in range(1,n):
    if l[-i]<l[-i-1]:
        if l[-i-1]-l[-i]>1:
            print("No")
            sys.exit()
        else:
            l[-i-1]-=1
print("Yes")

Measured memory_bytes: 14252
a, b = map(int, input().split())
c, d = map(int, input().split())
e, f = map(int, input().split())

for i in range(0,4):
    if i+1 == a or i+1 == b:
        if i+1 == c or i+1 == d:
            if i+1 == e or i+1 == f:
                print("NO")
                exit()

print("YES")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)){
			String[] input = scanner.nextLine().split(" ");
			int a = Integer.valueOf(input[0]);
			int b = Integer.valueOf(input[1]);

			System.out.println((a>2*b)? a-2*b : 0);
		}
	}

}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct node{
	int a,b;
};
node v[N];
int id[N],fa[N];
bool b[N];
int n;
bool cmp(node x,node y){
	return x.b<y.b;
}
bool cmp1(int x,int y){
	return v[x].a<v[y].a;
}
void dfs(int now){
	if (b[now]) return;
	b[now]=1; 
	dfs(fa[now]);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&v[i].a);
	for (int i=1;i<=n;i++) scanf("%d",&v[i].b);
	sort(v+1,v+n+1,cmp);
	for (int i=1;i<=n;i++) id[i]=i;
	sort(id+1,id+n+1,cmp1);
	bool p=1;
	for (int i=1;i<=n;i++) if (v[id[i]].a>v[i].b) {p=0; break;}
	if (!p) {
		puts("No"); return 0;
	} else {
		for (int i=1;i<=n;i++) fa[id[i]]=i;
		for (int i=1;i<=n;i++) b[i]=0;
		int sum=0;
		for (int i=1;i<=n;i++) if (!b[i]) {sum++; dfs(i);}
		if (sum>1) puts("Yes");
		else {
			bool p=0;
			for (int i=2;i<=n;i++) if (v[id[i]].a<=v[i-1].b) {p=1; break;}
			if (p) puts("Yes");
			else puts("No");
		} 
	}
}

Measured memory_bytes: 1920
line = gets.chop.split.map(&:to_f)
a = line
line = gets.chop.split.map(&:to_f)
productPosts = line


productDisplayNum = a[1]
tmp = productDisplayNum

def sum(arr)
  hoge = 0
  arr.each do |i|
    hoge += i;
  end
  return hoge
end

sumPost = sum productPosts
productPosts.each do |postNum|
  if postNum / sumPost >= (1 / (4 * productDisplayNum))
    tmp = tmp - 1;
  end
end

if tmp <= 0
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788