akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vector<ll> ans(201, 0);
    rep(i, n){
        ll a; cin >> a;
        for(ll j=-100; j<=100; j++){
            ans[j+100] += (j-a)*(j-a);
        }
    }
    ll minv = INFLL;
    rep(i, ans.size()) chmin(minv, ans[i]);
    cout << minv << endl;
}

Measured memory_bytes: 256
import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d, directed=False):
        """
        #0-indexedでなくてもよいことに注意
        #u = from, v = to, d = cost
        #directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.e[u].append([v, d])
            self.e[v].append([u, d])
        else:
            self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def Dijkstra_search(self, s):
        """
        #0-indexedでなくてもよいことに注意
        #:param s: 始点
        #:return: 始点から各点までの最短経路と最短経路を求めるのに必要なprev
        """
        d = collections.defaultdict(lambda: float('inf'))
        prev = collections.defaultdict(lambda: None)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    prev[uv] = u
                    heapq.heappush(q, (vd, uv))

        return d, prev

    def getDijkstraShortestPath(self, start, goal):
        _, prev = self.Dijkstra_search(start)
        shortestPath = []
        node = goal
        while node is not None:
            shortestPath.append(node)
            node = prev[node]
        return shortestPath[::-1]


N, M = map(int, input().split())
islands = Dijkstra()
for _ in range(M):
    a, b = map(int, input().split())
    islands.add(a, b, 1)

dis = islands.Dijkstra_search(1)[0][N]

if dis > 2:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 171516
#include <cstdio>

int n;
int s[15];
int s_new[15];
int count[105];





int main() {
  while(scanf("%d", &n), n) {
    // input
    for (int i=0; i<n; i++) {
      scanf("%d", &s[i]);
    }

    int loop_count = 0;

    // calc
    while (1) {
      loop_count++;
      
      for (int i=1; i<=100; i++) {
	count[i] = 0;
      }
      for (int i=0; i<n; i++) {
	count[s[i]]++;
    }
      for (int i=0; i<n; i++) {
	s_new[i] = count[s[i]];
      }
      int k;
      for (k=0; k<n; k++) {
	if (s[k] != s_new[k])
	  break;
      }


      // output
      if (k == n) {
	printf("%d\n", loop_count-1);
	printf("%d", s[0]);
	for (int j=1; j<n; j++) {
	  printf(" %d", s[j]);
	}
	printf("\n");
	break;
      }

      // copy
      for (int j=0; j<n; j++) {
	s[j] = s_new[j];
      }
    }
   
  }
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s,t;
	cin >> s >> t;
	int n=(int)s.length(), m=(int)t.length();
	int dp[n+1][m+1];
	for(int i=0; i<=n; i++)for(int j=0; j<=m; j++)dp[i][j]=0;
	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(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]);
		}
	}
	 /*
	for(int i=0; i<=n; i++){
		for(int j=0; j<=m; j++){
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}
	// */
	string ans = "";
	int i=n,j=m;
	while(i!=0&&j!=0){
		if(i-1>=0&&dp[i-1][j]==dp[i][j]){
			i--;
		}else if(j-1>=0&&dp[i][j-1]==dp[i][j]){
			j--;
		}else{
			ans += s[i-1];
			i--; j--;
		}
	}
	reverse(all(ans));
	cout << ans << endl;
}	
/* Benq's
	stuff you should look for
	* ll, int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;string s,t;
	cin>>n>>s>>t;
	for(ll i=0;i<n;i++){
		cout << s[i]<<t[i];
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
n, m, l = map(int, input().split())
 
INF = float("INF")
 
d = [[INF] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
 
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
 
for i in range(n):
    for j in range(n):
        if i == j:
            continue
 
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = INF
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
 
# print()
# print(*d, sep='\n')
 
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
 
    if d[s][t] == INF:
        print(-1)
    else:
        print(d[s][t]-1)

Measured memory_bytes: 80476
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,k,cnt = 0;
    cin >> n >> k;
    while(n) {
        n /= k;
        cnt ++;
    }
    cout << cnt ;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;  
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;
struct Res { int basecost; int xlim; vector<int> xreduce; }; 

int n;
int val[MAXN];

void upd(Res &res,int x,int cost) {
	if(x>res.xlim) return;
	x=max(x,0);
	if(cost>=res.basecost) return;
	if(x==0) {
		while(SZ(res.xreduce)>0&&cost<res.basecost) --res.basecost,res.xreduce.erase(res.xreduce.begin());
		res.basecost=cost;
	} else {
		int delta=res.basecost-cost;
		REP(i,delta) if(i<SZ(res.xreduce)) res.xreduce[i]=min(res.xreduce[i],x); else res.xreduce.PB(x);
	}
}

// decrease x costs one, increasing y=lim-x costs one
Res calc(Res cur,int val) {
	Res ret; ret.basecost=INT_MAX,ret.xlim=val,ret.xreduce.clear();
	for(int idx=-1;idx<SZ(cur.xreduce);++idx) {
		int cx=idx==-1?0:cur.xreduce[idx],ccost=cur.basecost-(idx+1);
		// !increase x -> nx>=x, !increase y -> nx>=val-(cur.xlim-cx)
		// no constraint on x or y
		upd(ret,0,ccost+2);
		// no constraint on x, !increase y
		upd(ret,val-(cur.xlim-cx),ccost+1);
		// !decrease x, no constraint on y
		upd(ret,cx,ccost+1);
		// !decrease x, !increase y
		upd(ret,max(cx,val-(cur.xlim-cx)),ccost);
	}
	return ret;
}

int solve() {
	Res res; res.basecost=0,res.xlim=0,res.xreduce.clear();
	REP(i,n) {
		res=calc(res,val[i]);
		//printf("after %d: basecost=%d xlim=%d",i,res.basecost,res.xlim); REPSZ(k,res.xreduce) printf(" %d:%d",res.xreduce[k],res.basecost-k-1); puts("");
	}
	res=calc(res,0);
	//printf("final: basecost=%d xlim=%d",res.basecost,res.xlim); REPSZ(k,res.xreduce) printf(" %d:%d",res.xreduce[k],res.basecost-k-1); puts("");
	return res.basecost;
}

void run() {
	scanf("%d",&n);
	REP(i,n) scanf("%d",&val[i]);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 1024
/*
 * DATE : 2017-06-18
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
    register char c = getchar();x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar());
    if(c=='-'){neg = 1;c = getchar();}
    for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/
const int N = 1001;

string str;
int func(char c)
{
    int ret = 0;
    string now = str;
    set<int> s;
    for(int i = 0; i < now.size(); i ++ )s.insert(now[i]);
    if(s.size()==1) return 0;
    s.clear();
    while(1) {
        string nxt ;
        for(int i = 0; i < now.length() - 1; i ++) {
            if(now[i] == c || now[i+1] == c) nxt.push_back(c);
            else nxt.push_back(now[i]);
        }
        ret ++;
        set<int> s;
        for(int i = 0 ; i < nxt.size(); i ++ ) s.insert(nxt[i]);
        if(s.size()==1) break;
        now = nxt;
//        db(now);
    }
    return ret;
}
int main()
{

    cin >> str;
    int ans = 1e8;
    for(int i= 'a'; i <='z' ; i ++) {
        ans = min(ans,func(i));
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int ile[256];

int main()
{
    string s; cin >> s;
    int n = sz(s);
    LL res = 0;
    for(int i = 0; i < n; i++)
    {
        res += i - ile[s[i]];
        ile[s[i]]++;
    }
    cout << res + 1 << "\n";
    return 0;
}


Measured memory_bytes: 644
N = int(input())
s = list(input() for i in range(N))
M = int(input())
t = list(input() for i in range(M))

s_set = list(set(s))
ans = 0
for name in s_set:
    count = s.count(name) - t.count(name)
    ans = max(count, ans)

print(ans)


Measured memory_bytes: 3188
n = int(input())
a_list = sorted([int(x) for x in input().split()])
ans = a_list.pop()
n -= 2
while n > 0:
    a = a_list.pop()
    ans += a
    n -= 1
    if n > 0:
        ans += a
        n -= 1
print(ans)

Measured memory_bytes: 31556
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int table[1001] = {0};
    table[1] = 1;
    rrep(i, 2, 1001) {
        int tmp = i;
        while (1) {
            if (tmp * i > 1000) break;
            tmp *= i;
            table[tmp] = 1;
        }
    }
    int x; cin >> x;
    for (int i = x; i >= 1; --i) {
        if (table[i]) {cout << i << endl; return 0;}
    }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
 
int main()
{
  int g[100][100];
  int n;
  
  for(int i=0; i<100; i++)
    {
      for(int j=0; j<100; j++)
	{
	  g[i][j]=0;
        }
    }
  
  cin>>n;

  int x,y,z;
    
  for(int i=0; i<n; i++)
    {
      cin>>x>>y;
      for(int j=0; j<y; j++)
	{
	  cin>>z;
	  g[x-1][z-1]=1;
        }
    }
  
  for(int i=0; i<n; i++)
    {
      for(int j=0; j<n; j++)
	{
	  if(j!=0) cout<<" ";
	  cout<<g[i][j];
        }
      cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k;
int main(){
	cin>>n>>k;
	if(n==0&&k==0)return puts("0 0")&0;
	if(n==0)return puts("-1")&0;
	if(n==1&&k==0)return puts("0 0 1 1")&0;
	if(n==1)return puts("-1")&0;
	if((1<<n)<=k)return puts("-1")&0;
	for(int i=0;i<(1<<n);i++)if(i!=k)cout<<i<<" ";
	cout<<k<<" ";
	for(int i=(1<<n)-1;i>=0;i--)if(i!=k)cout<<i<<" ";
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>

using namespace std;

typedef long long ll;



int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        x = max(a, x);
    }
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        y = min(a, y);
    }
    if (x >= y)
        cout << "War";
    else
        cout << "No War";
    return 0;
}
















Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int x,a,b;
    cin>>x>>a>>b;
    if(a>=b){
      cout<<"delicious"<<endl;
    }else if(a+x>=b){
      cout<<"safe"<<endl;
    }else if(a+x<b){
      cout<<"dangerous"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define db double
#define inf 0x3f3f3f3f
using namespace std;

const int N=5e5+10,mod=1e9+7;

int main(){
	int n;
	ll a,b,c=0;
	cin>>n>>a>>b;
	for(int i=3;i<=n;i++) {
		ll x;
		cin>>x;
		c^=x;
	}
	ll s=a+b,d=s-c,ans=d/2;
	bool f=true;
	if((d&1)||d<0||ans>a||(ans&c)) f=false;
	if (f) {
		for(ll i=(1ll<<61);i;i>>=1) {
			if((i&c)&&ans+i<=a) 
				ans+=i;
		} 
		if(ans) cout<<a-ans<<endl;
		else cout<<-1<<endl;
	}
	else {
		cout<<-1<<endl;
	}
	
}

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define exist(c, x) find(all(c), x) != (c).end()
#define mp(a, b) make_pair(a, b)
const int inf = 1 << 28;
const int dx[][9] = {{-2, -1, -1, 0, 0, 0, 1, 1, 2}, {-2, -1, -1,  0,  0,  0,  1,  1,  2}},
          dy[][9] = {{ 1,  1,  2, 1, 2, 3, 1, 2, 1}, {-1, -1, -2, -1, -2, -3, -1, -2, -1}};

int w, h;
vector<vector<int> > cost;

inline bool inrect(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

int solve(){
    vector<vector<vector<int> > > mem(h, vector<vector<int> >(w, vector<int>(2, inf)));
    auto comp = [&](const pair<int, int> &a, const pair<int, int> &b){
        int ax = a.first / 100, ay = a.first % 100, bx = b.first / 100, by = b.first % 100;
        return mem[bx][by][b.second] < mem[ax][ay][a.second];
    };
    priority_queue<pair<int, int>, vector<pair<int, int> >, decltype(comp)> q(comp);
    vector<int> T;
    rep(j, w){
        if(cost[0][j] == 0)T.push_back(j);
        if(cost[h-1][j] == -1){
            rep(foot, 2){
                mem[h-1][j][foot] = 0;
                q.push(mp((h-1) * 100 + j, foot));
            }
        }
    }
    while(!q.empty()){
        pair<int, int> p = q.top(); q.pop();
        if(exist(T, p.first))continue;
        int x = p.first / 100, y = p.first % 100;
        rep(k, 9){
            int nx = x + dx[p.second][k], ny = y + dy[p.second][k];
            if(inrect(nx, ny) && 0 <= cost[nx][ny] && mem[nx][ny][p.second^1] == inf){
                mem[nx][ny][p.second^1] = mem[x][y][p.second] + cost[nx][ny];
                q.push(mp(nx * 100 + ny, p.second ^ 1));
            }
        }
    }
    int res = inf;
    for(auto t: T)rep(k, 2)res = min(res, mem[0][t][k]);
    return res == inf? -1: res;
}

int main(){
    while(cin >> w >> h, w|h){
        cin.ignore();
        cost.assign(h, vector<int>(w, 0));
        rep(i, h){
            string in;
            getline(cin, in);
            in.erase(remove_if(all(in), [](char c){return c == ' ';}), in.end());
            rep(j, w)cost[i][j] = in[j] == 'X'? -2: in[j] == 'S'? -1: in[j] == 'T'? 0: in[j] - '0';
        }
        cout << solve() << '\n';
    }
    return 0;
}

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

class Dice{
    public:
    int face[6];
    Dice(int *x){
    for(int i=0;i<6;i++){
        face[i]=x[i];
    }
    }
void roll_N(){
    int a=face[0],b=face[1],c=face[5],d=face[4];
    face[0]=b;face[1]=c;face[5]=d;face[4]=a;
}
void roll_W(){
    int a=face[0],b=face[2],c=face[5],d=face[3];
    face[0]=b;face[2]=c;face[5]=d;face[3]=a;
}
void roll_S(){
    int a=face[0],b=face[4],c=face[5],d=face[1];
    face[0]=b;face[4]=c;face[5]=d;face[1]=a;
}
void roll_E(){
    int a=face[0],b=face[3],c=face[5],d=face[2];
    face[0]=b;face[3]=c;face[5]=d;face[2]=a;
}
void roll_(){
    int a=face[1],b=face[2],c=face[4],d=face[3];
    face[1]=d;face[2]=a;face[4]=b;face[3]=c;
}
int answer(){
    return face[0];
}
};

int judge(int *x,int *y){
    int flg=0;
    for(int i=0;i<6;i++){
        if(x[i]==y[i]){flg+=1;}
    }
    if(flg==6){return true;}
    else{return false;}
}

int judge2(Dice x,Dice y){
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                if(judge(x.face,y.face)){
                    return 1;
                }
                y.roll_();
            }
        y.roll_E();
        }
    y.roll_N();
    }
    return 0;
}

int main(){
    int n;
    cin>>n;
    int x[n][6];
    for(int i=0;i<n;i++){
        for(int j=0;j<6;j++){
            cin>>x[i][j];
        }
    }
    int flg=0;
    for(int i=0;i<n-1;i++){
        if(flg==1)break;
        for(int j=i+1;j<n;j++){
            if(flg==1)break;
            Dice dx(x[i]),dy(x[j]);
            if(judge2(dx,dy)){
                flg=1;
                cout<<"No"<<endl;
            }
        }
    }
    if(flg==0)cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    vector<int> per(m);
    set<int> s;
    vector<int> same(m);
    for(int i = 0; i < n; i++)
    {
        int cand = x[i] % m;
        if(s.insert(x[i]).second == false)
        {
            same[cand]++;
            s.erase(s.find(x[i]));
        }
        per[cand]++;
    }
    int ans = 0;
    for(int i = 0; i <= m/2; i++)
    {
        if(i == 0 || (m%2==0 && i == m/2))
        {
            int l = per[i];
            ans += l/2;
            continue;
        }
        int l = per[i];
        int r = per[m-i];
        if(l > r)
        {
            ans += r;
            l -= r;
            ans += min(same[i], l / 2);
        }
        else
        {
            ans += l;
            r -= l;
            ans += min(same[m-i], r/2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6144
a, b, c, x, y = map(int, input().split())
m = min(x, y)
ans = m * min(a + b, c * 2)

if x == m:
    ans += min(c * 2, b) * (y - m)
else:
    ans += min(c * 2, a) * (x - m)

print(ans)

Measured memory_bytes: 3060
/**
*    author:  Dooloper
*    created: 29.08.2020 20:44:47
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  double d,t,s;
  cin >> d >> t >> s;
  if(d/s <= t) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

int main () {
    int a,b;
    cin >> a >> b;
    if (a+a-1 > a+b and a+a-1 > b+b-1){
        cout << a+a-1;
    } else if (a+b > a+a-1 and a+b > b+b-1){
        cout << a+b;
    } else if (b+b-1 > a+b and b+b-1 > a+a-1){
        cout << b+b-1;
    } else if (a+a-1 == a+b){
        cout << a+b;
    } else if (b+b-1 == a+a-1){
        cout << b+b-1;
    } else {
        cout << a+b;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int lcm(int a, int b) { return (a / gcd(a, b) * b); }

signed main()
{
    int N;
    bool flag = false;
    cin >> N;
    
    for(int i = max(N / 4 * 3, 1LL); i <= 3500; i++) {
        for(int j = 1; j <= 3500; j++) {
            int nume = 4, deno = N;
            int lc = lcm(i, deno);
            int val = nume * (lc / deno) - lc / i;
            int div = gcd(lc, val);
            lc /= div, val /= div;

            deno = lc, nume = val;
            lc = lcm(j, deno);
            val = nume * (lc / deno) - lc / j;
            div = gcd(lc, val);
            val /= div, lc /= div;
            if(lc < 0) continue;
            if(val == 1) {
                flag = true;
                cout << i << " " << j << " " << lc << endl;
                break;
            }
        }
        if(flag) break;
    }

    return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    bool f=1;
    REP(i,1,n){
        if(a[i]==a[i-1])f=0;
    }
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;
using sl = signed long;
using sll = signed long long;
using ll = long long;

int main(int argc, char *argv[])
{
	int N, M;
	priority_queue<ll> PQ;
	cin >> N >> M;
	for(int i = 0; i< N ;i++){
		ll tmp;
		cin >> tmp;
		PQ.push(tmp);
	}

	for(int i=0;i<M;i++){
		ll top = PQ.top();
		PQ.pop();
		PQ.push(top/2);
	}

	ll ans =0;
	for(int i=0;i<N;i++){
		ans += PQ.top();
		PQ.pop();
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include <algorithm>
#include <math.h>

int main(){
  int d,n;
  std::cin >> d >> n;
  int c =pow(100,d);
  if(n==100){
    std::cout<< c*100+c << std::endl;
  }else{
    std::cout<< c+(n-1)*c << std::endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

int n,T;
void solve(){
  cin >> n >> T;
  llint c[n],t[n];
  for(int i=0;i<n;i++){
    cin >> c[i] >> t[i];
  }
  llint mn=inf;
  for(int i=0;i<n;i++){
    if(t[i]<=T){
      if(mn>c[i]){
        mn=c[i];
      }
    }
  }
  if(mn==inf)cout << "TLE" << endl;
  else cout << mn << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
 
using namespace std;
 
#define MAX 1050
 
char S[MAX][MAX];
int K[MAX];
 
void print(int N){
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < K[i] ; j++){
	    if(S[i][j] == '.'){
		cout << " ";
	    }else{
		cout << S[i][j];
	    }
	}
	cout << endl;
    }
}
 
int main(){
    int N;
    string str;
 
    while(cin >> N,N){
	for(int i = 0 ; i < N ; i++){
	    cin >> str; K[i] = str.size();
	    for(int j = 0 ; j < K[i] ; j++){
		S[i][j] = str[j];
	    }
	}
 
	for(int i = 1 ; i < N ; i++){
	    for(int j = 0 ; j < K[i]-1 ; j++){
		if(islower(S[i][j+1])){
		    S[i][j] = '+';
		    break;
		}
	    }
	}
	for(int i = 1 ; i < N ; i++){
	    for(int j = 0 ; j < K[i] ; j++){
		if(S[i][j] == '+'){
		    for(int k = i-1 ; k > 0 ; k--){
			if(S[k][j] != '.') break;
			S[k][j] = '|';
		    }
		}
	    }
	}
	print(N);
    }
    return 0;
}

Measured memory_bytes: 4192
A = []
A << STDIN.gets.split(' ').map{|s|s.to_i}
A << STDIN.gets.split(' ').map{|s|s.to_i}
A << STDIN.gets.split(' ').map{|s|s.to_i}
N = STDIN.gets.to_i
B = []
while line = STDIN.gets
  B << line.to_i
end

bingo = Array.new(3, -1).map{|a| Array.new(3, -1)}
0.upto(2) do |i|
  0.upto(2) do |j|
#    puts "i:#{i} j:#{j}"
    unless B.delete(A[i][j]).nil?
      bingo[i][j] = 1
    end
  end
end

ans = false
0.upto(2) do |i|
  # line
  unless bingo[i].include?(-1)
    ans = true
  end
  # 列
  unless [bingo[0][i], bingo[1][i], bingo[2][i]].include?(-1)
    ans = true
  end
end

unless [bingo[0][0], bingo[1][1], bingo[2][2]].include?(-1)
  ans = true
end
unless [bingo[0][2], bingo[1][1], bingo[2][0]].include?(-1)
  ans = true
end

if ans
  puts 'Yes'
else
  puts 'No'
end



Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;


/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */

int main() {
	int n, p, c = 0;
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> p;
		if (p != i)c++;
	}
	YES(c <= 2);
}

Measured memory_bytes: 256
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)             \
    do {                         \
        cout << #args << " -> "; \
        err(args);               \
    } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
    std::cout << a << ' ';
    err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &... args) {
    for (auto &v : arg)
        std::cout << v << ' ';
    err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII   = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD   = 1000000007;
const int MAXN  = 200005;

void run() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    while(b<=a && k>0) b*=2, k--;
    while(c<=b && k>0) c*=2, k--;
    if(a<b && b<c) cout << "Yes" << endl;
    else cout << "No" << endl; 
}

// Debug Input Redirection
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    run();
}


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



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  ll ans = 0;
  
  for(ll i = 1; i <= sqrt(n) +1; i++) {
    if(i*i <= n)
      ans = i*i;
  }
  
  cout << ans << "\n";

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll ans=0;
    for(ll i=k;i<=n+1LL;++i){
        ll mi = i*(i-1LL)/2LL;
        ll ma = (n-i+1+n)*i/2LL;
        ans += ma-mi+1;
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
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(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;
	debug("debug test\n");
	vector<vint> a(3, vint(3));
	rep(i, 3){
		rep(j, 3){
			cin>>a[i][j];
		}
	}
	rep(i, 2){
		if(a[i][0]-a[i+1][0] != a[i][1]-a[i+1][1] || a[i][1]-a[i+1][1] != a[i][2]-a[i+1][2] ){
			cout << "No" << endl;
			return 0;
		}
		if(a[0][i]-a[0][i+1] != a[1][i]-a[1][i+1] || a[0][i]-a[0][i+1] != a[2][i]-a[2][i+1]  ){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;


int main(){
  long long int a,b,c;
  cin>>a>>b>>c;
  long long int d= c-b-a;
  
  if(d>0 && d*d > 4*a*b){
      cout<<"Yes";
  }
  else{
      cout<<"No";
  }
  return 0;
}
 

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString as BSW
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
lcsTable2 :: BS.ByteString -> BS.ByteString -> UArray (Int,Int) Word16
lcsTable2 s t = runSTUArray $ do
  let !m = BS.length s
      !n = BS.length t
  arr <- newArray ((0,0),(m,n)) 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BSW.index s i
    forM_ [n-1,n-2..0] $ \ !j -> do
      let !y = BSW.index t j
      if x == y
        then do l2 <- readArray arr (i+1, j+1)
                writeArray arr (i,j) (l2 + 1)
        else do l0 <- readArray arr (i+1, j)
                l1 <- readArray arr (i, j+1)
                writeArray arr (i,j) (max l0 l1)
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable2 s t
      !m = BS.length s
      !n = BS.length t
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | table ! (i+1,j) >= table ! (i,j+1) = reconY y (i+1) j
                  | otherwise = reconX x i (j+1)
        where x = BS.index s i
              y = BS.index t j
      reconX !x !i !j | j >= n = Nothing
                      | x == y = let !i' = i+1 ; !j' = j+1
                                 in Just (x, (i', j'))
                      | table ! (i+1,j) >= table ! (i,j+1) = reconY y (i+1) j
                      | otherwise = reconX x i (j+1)
        where y = BS.index t j
      reconY !y !i !j | i >= m = Nothing
                      | x == y = let !i' = i+1 ; !j' = j+1
                                 in Just (x, (i', j'))
                      | table ! (i+1,j) >= table ! (i,j+1) = reconY y (i+1) j
                      | otherwise = reconX x i (j+1)
        where x = BS.index s i
      (result, _) = BS.unfoldrN (fromIntegral $ table ! (0,0)) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


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

int main(){
	int n, max1, max2, a[5001];

	while( cin >> n , n ){
		for(int i=0 ; i<n ; i++){
			cin >> a[i] ;
		}
		max1 = a[0];

		for(int i=0 ; i<n ; i++){
			int sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max1 = max( max1 , sum );
			}
		}
		cout << max1 << endl;
	}
}

Measured memory_bytes: 1176
#include <iostream>
#include <set>
#include <string>

using namespace std;

string reverse(string str){
    int length = str.size();
    string ret("");
    for (int i = 0; i < length; i++) { ret += str[length-i-1]; }
    return ret;
}

int main(){
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string str; cin >> str;
        set<string> s;
        s.insert(str);
        for (int j = 1; j < str.size(); j++) {
            string a = str.substr(0, j);
            string b = str.substr(j);
            string ra = reverse(a);
            string rb = reverse(b);
            s.insert(a+rb);
            s.insert(ra+b);
            s.insert(ra+rb);
            s.insert(b+a);
            s.insert(b+ra);
            s.insert(rb+a);
            s.insert(rb+ra);
        }
        cout << s.size() << endl;
    }
    

    return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i,h) {
    vector<int> done(w);
    rep(j,w) {
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while (j+l < w) {
        if (s[i][j+l] == '#') break;
        ++l;
      }
      rep(k,l) {
        cnt[i][j+k] += l;
        done[j+k] = 1;
      }
    }
  }
  rep(j,w) {
    vector<int> done(h);
    rep(i,h) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while (i+l < h) {
        if (s[i+l][j] == '#') break;
        ++l;
      }
      rep(k,l) {
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w) ans = max(ans, cnt[i][j]-1);
  cout << ans << endl;
  return 0;
}    


Measured memory_bytes: 20096
#include <iostream>

#define N 1000000

using namespace std;

int min(int a,int b){
	if(a>=b)return b;
	else return a;
}

int main(){


	int *data;
	int *data2;
	data = new int[N];
	data2= new int[N];
	int *square;
	int squareLength=0;

	int *square2;
	int square2Length=0;

	square = new int[N];
	square2= new int[N];

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

	for(int i=1;i*(i+1)*(i+2)/6 <=N;i++){
		data[i*(i+1)*(i+2)/6]=1;
		square[squareLength]=i*(i+1)*(i+2)/6;
		squareLength++;
		if((i*(i+1)*(i+2)/6 %2)==1){
			data2[i*(i+1)*(i+2)/6]=1;
			square2[square2Length]=i*(i+1)*(i+2)/6;
			square2Length++;
		}
	}

/*
	for(int i=0;i<squareLength;i++){
		cout<<square[i]<<endl;
	}
*/
	for(int i=1;i<N;i++){
		for(int j=0;j<squareLength;j++){
			if(i-square[j]<0)continue;
			data[i] = min(data[i],data[i-square[j]]+1);
		}
		for(int j=0;j<square2Length;j++){
			if(i-square2[j]<0)continue;
			data2[i] = min(data2[i],data2[i-square2[j]]+1);
		}
	}

	int n;
	while(cin>>n){
		if(n==0)break;

		cout<<data[n]<<" "<<data2[n]<<endl;

	}

	return 0;

}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, c;
ll a[200005];
ll b[200005];
ll const BAD = 1e9+7;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; i++){
		cin >> c;
		a[i] = c;
		b[i] = c; 
		}
		sort(a, a+n);
		for (ll i = 0; i < n; i++){
			if (b[i] == a[n-1]){
				cout << a[n-2] << '\n';
				}else {
					cout << a[n-1] << '\n';}
			
			}
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
int gcd(int x, int y){
	if(y==0) return x;
	return gcd(y,x%y);
}

int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	vi l(n),r(n);
	l[0] = a[0];
	r[n-1] = a[n-1];
	rep2(i,1,n){ 
		l[i] = gcd(l[i-1],a[i]);
		r[n-i-1] = gcd(r[n-i],a[n-1-i]);
	}
	int ans = 0;
	ans = max(ans,r[1]);
	ans = max(ans,l[n-2]);
	rep2(i,1,n-1) ans = max(ans,gcd(l[i-1],r[i+1]));
	cout << ans << endl;
}




Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int n;
    cin >> n;
    vector<pll> a(n),sum(n);

    for(int i = 0;i < n;i++){
        cin >> a[i].first >> a[i].second;
        sum[i].first = a[i].first + a[i].second;
        sum[i].second = i;
    }
    sort(sum.begin(),sum.end(),greater<pll>());

    ll a_sum = 0,b_sum = 0;

    for(int i = 0;i < n;i++){
        if(i%2 == 0){
            a_sum += a[sum[i].second].first;
        }else{
            b_sum += a[sum[i].second].second;
        }
    }
    cout << a_sum - b_sum << endl;

    return 0;
}

Measured memory_bytes: 3328
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[2010][4010];
int main() {
    int N; cin >> N;
    vector< tuple<int, int, int, int> > mus(N);
    for(int i=0; i<N; i++) {
        int R, A, W, T; cin >> R >> A >> W >> T;
        mus[i] = make_tuple(R, A, W, T);
    }

    sort(mus.begin(), mus.end(), [&](auto a, auto b) {
            int AR, AA, AW, AT; tie(AR, AA, AW, AT) = a;
            int BR, BA, BW, BT; tie(BR, BA, BW, BT) = b;
            return AR + AT > BR + BT;
        });

    fill(dp[0], dp[N+1], -INF);
    dp[0][4001] = 0;
    for(int i=0; i<N; i++) {
        int R, A, W, T; tie(R, A, W, T) = mus[i];
        int tmp[4010]; fill(tmp, tmp + 4010, -INF);
        for(int j=0; j<=4005; j++) {
            if(dp[i][j] == -INF) continue;
            // 使わない
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

            // 使う
            if(R >= j) continue;
            int t = min(T, j - R);
            tmp[t] = max(tmp[t], dp[i][j] + A);
        }
        for(int j=4005; j>=0; j--) {
            dp[i+1][j] = max(dp[i+1][j], tmp[j]);
            if(tmp[j] == -INF or j - R <= 0) continue;
            tmp[j - R] = max(tmp[j - R], tmp[j] + W);
        }
    }

    cout << *max_element(dp[N], dp[N] + 4005) << endl;
    return 0;
}



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

int N, M, Q;
vector<long long> a, b, c, d;

long long score(const vector<int> &A) {
  long long res = 0;
  for (int i = 0; i < Q; i++)
    if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
  return res;
}

long long dfs(vector<int> &A) {
  if (A.size() == N) {
    return score(A);
  }
  long long res = 0;
  int prev_last = (A.empty() ? 0 : A.back());
  for (int add = prev_last; add < M; add++) {
    A.push_back(add);
    res = max(res, dfs(A));
    A.pop_back();
  }
  return res;
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);

  for (int q = 0; q < Q; q++) {
    cin >> a[q] >> b[q] >> c[q] >> d[q];
    --a[q], --b[q];
  }
  vector<int> A;
  cout << dfs(A) << endl;
}

Measured memory_bytes: 3616