akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int d, n;
vector <int> a, e, r;
vector <vector <int>> memo;
const int INF = 1000000000;

void rec(int c = 0, int exp = 0, int end = d) {
	if (memo[exp][end] <= c) return;
	memo[exp][end] = c;

	rep (i, n) {
		if (exp < r[i]) continue;
		rec(c + 1, min(exp + e[i], 100), max(end - a[i], 0));
	}
}

int main() {
	while (cin >> d >> n, d) {
		a = e = r = vector <int> (n);
		rep (i, n) cin >> a[i] >> e[i] >> r[i];
		memo = vector <vector <int>> (105, vector <int> (105, INF));
		rec();
		int ans = INF;
		rep (i, 101) ans = min(ans, memo[i][0]);
		cout << (ans == INF ? "NA" : to_string(ans)) << endl;
	}
	return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;
std::string N;
int main() {
    std::cin >> N;
    int sum = 0;
    EACH(it, N) {
        sum += (int)(*it - '0');
    }
    int X = std::atoi(N.c_str());

    std::cout << (X%sum == 0 ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

template<class T> T umax(T a,T b) {return (a>b?a:b);}
template<class T> T umin(T a,T b) {return (a<b?a:b);}
template<class T,class P> T umax(T a,P b) {return (a>b?a:b);}
template<class T,class P> T umin(T a,P b) {return (a<b?a:b);}

typedef long long int ll;
const int maxn = 1e5+7;
const ll mod = 1e9+7;

bool compare(const pair<ll,ll>& x, const pair<ll,ll>& y) {
    if(x.second == y.second) return x.first < y.first;
    return x.second < y.second;
}

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    cout << n/(a+b)*a + min(n%(a+b),a) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var S = Console.ReadLine().ToCharArray();
			var field = new Stack<Point>();
			var spots = new Stack<Spot>();

			for (int i = 0; i < S.Length; i++)
			{
				var p = new Point { X = i, Type = S[i] };
				if (p.Type == '/')
				{
					if (field.Count != 0)
					{
						var fp = field.Pop();
						var w = 0;
						while (0 < spots.Count && fp.X < spots.Peek().To)
						{
							w += spots.Pop().Amount;
						}

						var sp = new Spot { From = fp.X, To = p.X, Amount = w + p.X - fp.X };
						spots.Push(sp);
					}
				}
				else if (p.Type == '\\')
				{
					field.Push(p);
				}
			}

			System.Console.WriteLine(spots.Sum(s => s.Amount));
			if (spots.Count == 0)
			{
				System.Console.WriteLine($"{spots.Count}");
			}
			else
			{
				System.Console.WriteLine($"{spots.Count} {string.Join(" ", spots.Select(s => s.Amount).Reverse())}");
			}
		}
	}

	class Point
	{
		public int X { get; set; }
		public int Type { get; set; }
	}

	class Spot
	{
		public int From { get; set; }
		public int To { get; set; }
		public int Amount { get; set; }
	}
}



Measured memory_bytes: 20792
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
class JNum{
	static constexpr uint64_t mod = 1000000007;
	uint64_t num;
public:
	JNum(uint64_t x):num(x%mod){}
	JNum operator+(const JNum& j)const{
		return (num + j.num)%mod;
	}
	JNum operator*(const JNum& j)const{
		return (num * j.num)%mod;
	}
	void operator+=(const JNum& j){
		num += j.num;
		num %= mod;
	}
	void operator*=(const JNum& j){
		num *= j.num;
		num %=mod;
	}
	uint64_t out()const{return num;}
};
using namespace std;
template<typename T>
void get(T& t){cin >> t;}
int main(void){
	string str;
	get(str);
	uint64_t cnt[26] = {0};
	for(char c : str)cnt[c - 'a']++;
	uint64_t ans = str.size() * (str.size() - 1) / 2 + 1;
	for(int i=0;i<26;i++)ans -= cnt[i] * (cnt[i] - 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, X = map(int, raw_input().split())


if X > N/2:
    alpha = X = N - X

ans = N
R = N - X
while R and X:
    if R%X == 0:
        ans += X + 2*(R/X - 1)*X
        break
    K = R/X
    ans += 2*K*X
    if R == 1: break
    R, X = X, R%X
print ans


Measured memory_bytes: 4392
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> x(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}

	int min_stamina = INT_MAX;
	for (int p = 1; p <= 100; ++p) {
		int curr = 0;
		for (int i = 0; i < n; ++i) {
			curr += (x[i] - p) * (x[i] - p);
		}

		min_stamina = min(min_stamina, curr);
	}

	cout << min_stamina << "\n";

	return 0;

}

Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
ans=[0]*n
scash=[]
buf=0
for i in range(m):
    s,c=map(int,input().split())
    if s not in scash:
        ans[s-1]+=c
        scash.append(s)
    elif (s in scash) and c!=ans[s-1]:
        buf+=1
        scash.append(s)
if n==1 and ans[0]==0:
    print(0)
    sys.exit()
if buf==0 and ans[0]!=0:
    anstr=[str(num) for num in ans]
    print(''.join(anstr))
elif buf==0 and (1 not in scash):
    ans[0]+=1
    anstr=[str(num) for num in ans]
    print(''.join(anstr))
else:
    print(-1)

Measured memory_bytes: 3064
#include <cstdio>

const int P = 1000000007;

int f(int x, int y) {
	return y ? y & 1 ? (long long)f(x, y ^ 1) * x % P : f((long long)x * x % P, y >> 1) : 1;
}

int main() {
	int L, Lf, Lt, R, Rf, Rt, S;
	int i, n, res = 0;
	scanf("%d", &n);
	L = Lf = R = Rf = 1;
	S = 0;
	Lt = Rt = 10;
	while (1) {
		if (R >= Rt) {
			Rf++;
			Rt *= 10;
		}
		R++;
		S += Rf;
		while (S > n) {
			if (L >= Lt) {
				Lf++;
				Lt *= 10;
			}
			L++;
			S -= Lf;
		}
		if (L >= 10000000) break;
		if (S == n) {
			res++;
			if (L >= Lt) {
				Lf++;
				Lt *= 10;
			}
			L++;
			S -= Lf;
		}
	}
	for (i = R - L; i; i--) {
		if (n % i) res++;
		else {
			res = (res + 9LL * f(10, n / i - 1) - (i - 1) + P) % P;
		}
	}
	printf("%d\n", res % P);
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

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

    vector<int> L(N);
    REP(i, N) L[i] = i+1;

    int a, b;
    int cnt = 0;
    do {
        ++cnt;
        if (L == P) a = cnt;
        if (L == Q) b = cnt;
    } while(next_permutation(L.begin(), L.end()));

    cout << abs(a - b) << endl;
    
}


Measured memory_bytes: 256
x=int(input())

def pow(b,x):
    res=b
    while True:
        if res*b<=x:
            res=res*b
        else:
            break
    return res


ans=1
for i in range(2,x+1):
    if i**2<=x:
        ans=max(ans,pow(i,x))
print(ans)

Measured memory_bytes: 9116
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    vector<int> ansW, ansS;

    for(int i = 0; a * i <= f; ++i){
        for(int j = 0; 100 * a  * i + 100 * b *j <= f; ++j){
            if(i == 0 && j == 0) continue;
            ansW.push_back(100 * a * i + 100 * b * j);
        }
    }

    for(int i = 0; c * i < f; ++i){
        for(int j = 0; c * i + d * j < f; ++j){
            ansS.push_back(c * i + d * j);
        }
    }

    int mx = 0, sum = 0, sumS = 0;

    for(int i = 0; i < ansW.size(); ++i){
        for(int j = 0; j < ansS.size(); ++j){
            if(ansW[i] + ansS[j] > f) continue;
            if(ansS[j]*sum>=(ansW[i]+ansS[j])*sumS){
                if(ansS[j]*(100+e)<=(ansW[i]+ansS[j])*e){
                sum=ansW[i]+ansS[j];
                sumS=ansS[j];
                }
            }
        }
    }
    cout << sum << " " << sumS << endl;
    return 0;
}


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

int f(vector<int>& A, int K, vector<int> &dp){
	if(K==0)
      	return 0;
  	else if(K<0)
      	return 1;
    	
  	if(dp[K] != -1)
      	return dp[K];
  
  	int res = 0;
  
  	for(int i=0;i<A.size();i++) {
      	res = max(res, 1-f(A, K - A[i], dp));
    }
  	
  	dp[K] = res;
  	return dp[K];
}

int main() {
  	int N, K;
  	cin >> N >> K;
  	vector<int> A(N, 0);
  	for(int i = 0 ; i < N ; i++)
      	cin>> A[i];
  	
  	// dp[i] = True if game is winnable by current player 
  	// if there are i stones in the game.
  	vector<int> dp(K+1, -1) ;
  	dp[0] = 0;	// Taro loses if zero stones initially
  
  	if(f(A, K, dp) == 1)
      	cout<<"First";
  	else
      	cout<<"Second";
 	return 0; 
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
#include<cmath>
#include<numeric>

using namespace std;

int main()
{

    int n, l, s, r;

    cin >> n >> l;

    int apple[n];

    r = l;

    for(int i = 0; i < n; i++, l++)
    {
        apple[i] = l;

        if(abs(r) > abs(l))
        {
            r = l;
        }
    }

    for(int i = 0; i < n; i++)
    {

        if(apple[i] == r)
        {
            apple[i] = 0;
            break;
        }
    }

    s = accumulate(apple, apple + n, 0);
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<pair<ll,int>> p(n);
    ll res = 0;
    Rep(i,n){
        cin >> a[i];
        p[i].first = abs(a[i]);
        p[i].second = i;
    }
    int cnt = 0;
    REP(i,n){
        if(a[i]<0){
            cnt++;
        }
    }
    SORT(p);
    if(cnt%2==0){
        ll temp = 0;
        REP(i,n){
            temp += p[i].first;
        }
        res = temp;
    }else{
        ll temp = p[0].first*-1;
        REP(i,n-1){
            temp += p[i+1].first;
        }
        res = temp;
    }
    put(res);
    return 0;
}



Measured memory_bytes: 2560
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795

using namespace std;

void INPUT() 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible ..
*/


const int N = 100005;
ll dp[N];
int v[N];
int n,k;

ll f(int pos)
{
  if(pos == n-1) return 0LL;

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

  ll ans = LLONG_MAX, val, op1;

  fo(i,1,k)
  {
    val = pos + i;
    
    if(val < n)
    {
      op1 = abs(v[val] - v[pos]) + f(val);
      ans = min(ans,op1);
    }
    else break;
  }

  dp[pos] = ans;
  return ans;
}

void solve()
{ 
      cin >> n >> k;

      fo(i,0,n-1) cin >> v[i];

      memset(dp,-1,sizeof(dp));

      cout << f(0) << endl;


}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define LOCAL
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound
#define lowbit(x) x&(-x)
#define testbit(x,i) x&(1<<i)

inline void checkmin(int &x,int y){x=min(x,y);}
inline void checkmax(int &x,int y){x=max(x,y);}

const long long MOD=(long long)1e9+7LL;

long long n;
long long k;

int main() 
{
	#ifndef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>k;
    long long ans=0LL;
    for(long long i=k;i<=n+1;i++)
    {
    	long long mn=i*(i-1)/2LL;
    	long long mx=(n+n-i+1)*i/2LL;
    	ans+=(mx-mn+1LL)%MOD;
    	ans%=MOD; 
	}
	cout<<ans<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    int ans = -1;
    REP(i, n)
    cin >> a[i];
    REP(i, n)
    {
        FOR(j, i, n)
        {
            ans = max(ans, abs(a[i] - a[j]));
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 200010;

typedef pair<int, int> P;

int A[N], n;

inline bool check(int mid) {
	set<P> s;
	for (int i = 2; i <= n; i++) if (A[i] <= A[i - 1]) {
		while (s.size() && s.rbegin() -> first > A[i]) s.erase(*s.rbegin());
		for (int j = A[i]; ; j--) {
			if (!j) return false;
			if (s.size() && j == s.rbegin() -> first) {
				if (s.rbegin() -> second < mid - 1) {
					auto t = *s.rbegin(); s.erase(t), t.second++;
					s.insert(t); break;	
				} else s.erase(*s.rbegin());
			} else {
				if (mid == 1) return false;
				s.insert(P(j, 1)); break;
			}
		} 
	}
	return true;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
	int l = 1, r = n, mid, ans = -1;
	while (l <= r) {
		mid = (l + r) >> 1;
		if (check(mid)) r = mid - 1, ans = mid;
		else l = mid + 1;
	}
	printf("%d\n", ans);
}//

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

int main(void)
{
    int k;
    char s[101]; 
    
    scanf("%d",&k);
    // printf("%d\n",k);
    scanf("%s",s);
    // printf("%s\n",s);

    if (strlen(s)>k){
        for (int i=0;i<k;i++){
            printf("%c",s[i]);
        }
        printf("...");
    }else{
        printf("%s",s);
    }
    printf("\n");


    return 0;
    

}

Measured memory_bytes: 1700
#include<iostream>
#include<vector>
#include<climits>
#include<math.h>

using namespace std;

int main()
{
 	int n;
  	cin >> n;
  
  	vector<vector<int>> weights (n);
  	vector<vector<int>> table (n);
  
  	for(int i = 0; i < n; i++)
    {
     	weights[i] = vector<int>(3);
      	table[i] = vector<int>(3, 0);
    }
  
  	for(vector<int>& current : weights)
    {
      	cin >> current[0] >> current[1] >> current[2];
    }
  
  	for(int i = 0; i < 3; i++)
      table[0][i] = weights[0][i];
  
  	for(int i = 1; i < n; i++)
    {
      	table[i][0] = max(table[i-1][1], table[i-1][2]) + weights[i][0];
        table[i][1] = max(table[i-1][0], table[i-1][2]) + weights[i][1];
        table[i][2] = max(table[i-1][0], table[i-1][1]) + weights[i][2];
    }
  
  	cout << max(max(table[n-1][0], table[n-1][1]), table[n-1][2]);
  	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ull = unsigned long long;
int main() {
	string s;
	cin >> s;
	ull sum = 0;
	for(char ch:s) {
		sum+=ch-'0';
	}
	if(sum%3) {
		cout<<"No";
	} else {
		cout<<"Yes";
	}
	
}


Measured memory_bytes: 3700
#include<stdio.h>
int main(void)
{
   int A[100][100],B[100][100];
   long int C[100][100];
   int i,j,k,n,m,l;
   scanf("%d %d %d",&n,&m,&l);
   for(i=0;i<n;i++){
     for(j=0;j<m;j++){
       scanf("%d",&A[i][j]);
     }
   }
   for(j=0;j<m;j++){
     for(k=0;k<l;k++){
       scanf("%d",&B[j][k]);
     }
   }
   for(i=0;i<n;i++){
     for(k=0;k<l;k++){
       C[i][k]=0;
     }
   }
   for(i=0;i<n;i++){
     for(k=0;k<l;k++){
       for(j=0;j<m;j++){
         C[i][k]+=A[i][j]*B[j][k];
       }
     }
   }
   for(i=0;i<n;i++){
     for(k=0;k<l;k++){
       printf("%ld",C[i][k]);
       if(k!=l-1){
         printf(" ");
       }
       if(k==l-1){
         printf("\n");
       }
     }
   }
   return 0;
}

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

int main(){
    long long x;
    cin >> x;
    long long ret = 0;
    long long money = 100;

    while(true){
        ret += 1;
        money = floor(money * 1.01);
        if(money>=x){
            cout << ret << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e5+5

void solve(){
    string s;
    cin>>s;
    ll cnt=1;
    ll n=s.length();
    ll i=1; 
    string t;
    t.pb(s[0]);
    string temp;
    while(i<n){
        temp.pb(s[i]);
        if(temp != t){
            cnt++;
            t = temp;
            temp.clear();
            
        }
        i++;
    }
    cout<<cnt<<endl;
}

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

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
    
}



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

#define ll long long
#define mx  505
#define mod 1000000009
#define lim 100000000000000000
#define inf 2000000000
#define N 18
#define eps 100000
#define PI acos(-1)

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    string s;cin>>s;

    for(int i=0;i<s.size();i++)
       if(s[i]=='9')s[i]='1';
       else s[i]='9';
    cout<<s<<"\n";   
    return 0;
}


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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)
bool comp(int a, int b){
	return a>b;
}

int main() 
{ 
	JJ;
	int k; string s; cin>>k>>s;
	int n=s.length();
	if(n<=k){
		cout<<s<<endl;
	}
	else{
		FOR(i,0,k)
		cout<<s[i];
		cout<<"..."<<endl;
	}




	return 0;



    
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define maxn 100000
struct Node{
	int a,b;
	bool operator < (const Node &c)const{
		return a<c.a;
	}
}a[maxn+5];
priority_queue<int> p;
int main(){
	int n,m,ans=0;scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d%d",&a[i].a,&a[i].b);
	sort(a,a+n);
	for(int i=1,j=0;i<=m;i++){
		while(j<n&&a[j].a==i)p.push(a[j++].b);
		if(!p.empty()){ans+=p.top();p.pop();}
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 1660
class SegmentTree {
  #a; #op; #n; #e;
  constructor(a,op=Math.min,e=Infinity){
    let n = 1;
    while ( n <= a.length ) n <<= 1;
    this.#a = Array(--n).fill(e).concat(a);
    this.#n = n;
    const l = this.#a.length;
    for ( let i = n-1; i >= 0; i-- ) {
      const x = (l>i+i+1)?this.#a[i+i+1]:e;
      const y = (l>i+i+2)?this.#a[i+i+2]:e;
      this.#a[i] = op( x, y );
    }
    this.#op = op;
    this.#e = e;
  }
  update(i,v){
    const a = this.#a, l = a.length, e = this.#e;
    a[i += this.#n] = v;
    while( i > 0 ) {
      i = i-1 >> 1;
      const x = (l>i+i+1)?a[i+i+1]:e;
      const y = (l>i+i+2)?a[i+i+2]:e;
      a[i] = this.#op( x, y );
    }
  }
  get(l,r) {
    const a = this.#a, e = this.#e, op = this.#op;
    return function q(l,r,x,y,i){
      if ( l <= x && y <= r ) return a[i];
      if ( l >= y || x >= r || a.length <= i) return e;
      return op(
        q(l,r,x,x+y>>1,i+i+1),
        q(l,r,x+y>>1,y,i+i+2)
      );  
    }(l,r,0,this.#n+1,0);
  }
}
console.log((args=>{
  const tmp = args.trim().split`\n`;
  const S = tmp[1].split``.map(v=>1<<(v.charCodeAt()-97)), Q = tmp[2]|0;
  const Query = tmp.slice(3).map(r=>r.split` `);
  const st = new SegmentTree(S,(a,b)=>a|b,0);
  const o = [];
  for ( let i = 0; i < Q; i++ ) {
    const [t,x,y] = Query[i];
    if ( t === '1' ) {
      st.update(x-1,1<<(y.charCodeAt()-97));
    } else {
      const b = st.get(x-1,y|0);
      let c = 0;
      for ( let i = 0; i < 26; i++ ) if ( b&1<<i ) c++;
      o.push(c);
    }
  }
  return o.join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


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

int main(){
    string s1,s2;
    cin >> s1 >> s2;
    //編集距離
    int l,r;
    l = s1.length()+1;
    r = s2.length()+1;
    vector<vector<int> > dp(l);

    
    for(int i = 0 ; i < l ; i++){
        dp[i].resize(r);
        for(int j = 0; j < r ; j++){
            if(i == 0)dp[i][j] = j;
            else if(j == 0)dp[i][j] = i;
            else{
                if(s1[i-1] == s2[j-1]){
                    dp[i][j] = min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]});
                }else{
                    dp[i][j] = min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+1});
                }
            }

        }
    }
    cout << dp[l-1][r-1] << endl;
    return 0;
}


Measured memory_bytes: 6768
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <numeric>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define PB push_back
#define INF 100000000000000000

bool IsPrime(int num)
{
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

/*********************************************************/
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************/
ll gcd( ll m, ll n )
{
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;

  // ユークリッドの方法
  while( m != n )
  {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}//gcd

//*********************************************************
// 最小公倍数（Least Common Multiple）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll lcm( ll m, ll n )
{
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;

  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

/********************************************************/

int main() {
  ll N,H,W;
  cin >> N >> H >> W;
  ll ans = (N-H+1)*(N-W+1);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

string S,T;

bool check_match(string ss) {
	for (int i = 0; i < ss.length(); ++i) {
		if (ss[i] == '?' || ss[i] == T[i]) {
			continue;
		}
		else {
			return false;
		}
	}
	return true;
}

int main(void) {
	cin >> S >> T;
	string res = "UNRESTORABLE";
	int slen = S.length();
	int tlen = T.length();
	if (slen >= tlen) {
		bool find = false;
		for (int i = slen-tlen; !find && i >= 0; --i) {
			string ss = S.substr(i,tlen);
			if (check_match(ss)) {
				find = true;
				res = "";
				int count = 0;
				for (int j = 0; j < slen; ++j) {
					if (j >= i && count < tlen) {
						res += T[count];
						++count;
					}
					else {
						if (S[j] == '?') {
							res += "a";
						}
						else {
							res += S[j];
						}
					}
				}
			}
		}
	}
	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 256
num = gets.strip.to_i
array = gets.strip.split.map(&:to_i)

total = array.inject(0){|r, n| r+= n} - array[0]
sum = 0
num.times do |i|
  sum += (array[i] * total) % (10 ** 9 + 7)
  total -= array[i + 1].to_i
end

puts sum % (10 ** 9 + 7)



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

int main() {
  
  int n;
  cin >> n;
  
  vector<int> a(n),b(n);
  
  for ( int i = 0; i < n; i++)cin >> a[i];  
  for ( int i = 0; i < n; i++)cin >> b[i];
  
  int saidai = 0,goukei,flag = 0;
  
  while(flag < n){
    goukei = 0;
    for ( int i = 0; i <= flag; i++)goukei += a[i];
    for ( int i = flag; i < n; i++) goukei+= b[i];
    saidai = max(saidai,goukei);
    flag++;
  }
  
  cout << saidai << endl; 
  
}

Measured memory_bytes: 3628
#include<stdio.h>
int N,M,A[105][105],B[105],i,j,t;
int main()
{
    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++)
        for(j=0;j<M;j++)
            scanf("%d",&A[i][j]);
    for(i=0;i<M;i++)
        scanf("%d",&B[i]);
    for(i=0;i<N;i++)
    {
        for(j=t=0;j<M;j++)
            t+=A[i][j]*B[j];
        printf("%d\n",t);
    }
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;

int n, a[300000], k;
long long ans, psum, ssum;

int main()
{
//    ifstream cin ("house.in");
//    ofstream cout ("house.out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(25);
    cout.setf(ios_base::fixed);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        a[i] = i;
    }
    for (int i = 0; i < k; i++)
    {
        psum += a[i];
        ssum += a[n - i];
    }
    ans += ssum - psum + 1;
    ans %= base;
    for (int i = k; i <= n; i++)
    {
        psum += a[i];
        ssum += a[n - i];
        ans += ssum - psum + 1;
        ans %= base;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4372
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int a[n];

    rep(i,0,n){
        cin >> a[i];
    }
    
    rep(i,1,m+1){
        rep(j,0,n-1){
            if(a[j] % i > a[j+1] % i){
                swap(a[j],a[j+1]);
            }
        }
    }
    
    rep(i,0,n){
        cout << a[i] << endl;
    }
    return 0;
}


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

signed main(){
  long x;
  cin >> x;
  for(long i = -200; i < 200; i++){
    for(long j = -200; j < 200; j++){
      auto val = (long)pow(i , 5) - (long)pow(j, 5);
      if(val == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

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

int main()
{
  int result = 1;
  string s;
  cin >> s;
  
  for (int i = 0; i < s.size(); i++) {
    if ((i % 2) == 0) { /* (i-1)文字目が奇数 */
      if (s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D') {
        result = 0;
        break;
      }
    }
    else {
      if (s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D') {
        result = 0;
        break;
      }
    }
  }
  
  if (result == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def max_ex(target, iex):
  ret = 0
  i_ret = 0
  for v,i in enumerate(range(len(target))):
    if i == iex:
      continue
    if v > ret:
      ret = v
      i_ret = i
  
  return [ret,i_ret]

n = int(input())
abc = []
dp = []
for i in range(n):
  abc.append(list(map(int, input().split())))
  
  if i == 0:
    dp.append(abc[0])
  else:
    dpa = abc[i][0] + max(dp[i-1][1],dp[i-1][2])
    dpb = abc[i][1] + max(dp[i-1][0],dp[i-1][2])
    dpc = abc[i][2] + max(dp[i-1][0],dp[i-1][1])
    dp.append([dpa,dpb,dpc])
    
print('{}'.format(max(dp[n-1])))


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> f(n+1, INT_MAX);
	f[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0, k = 1; j <= 6; j++, k *= 6)
			if (i >= k) f[i] = min(f[i], f[i-k] + 1);
		for (int j = 0, k = 1; j <= 5; j++, k *= 9)
			if (i >= k) f[i] = min(f[i], f[i-k] + 1);
	}
	cout << f[n] << endl;
	return 0;
}


Measured memory_bytes: 640
def divisor(n):
    result = []
    i = 1
    while True:
        if i * i > n:
            break
        if n % i == 0:
            result.append(i)
            if i != int(n / i):
                result.append(int(n / i))
        i += 1
    return result


def calc(a, b):
    return a * a * a * a * a - b * b * b * b * b


MX = 100000

INF = int(MX**6)


def main():
    X = int(input())
    drs = divisor(X)
    for dr in drs:
        right = MX - dr
        left = -MX
        while right - left > 8:
            bp = int(left + (right - left) / 3)
            bq = int(left + 2 * (right - left) / 3)
            cp = calc(bp + dr, bp)
            cq = calc(bq + dr, bq)
            if cp > cq:
                left = bp
            else:
                right = bq

        mn = INF
        mnb = -2 * MX
        for bi in range(left - 64, right + 64):
            c = calc(bi + dr, bi)
            if mn > c:
                mnb = bi
                mn = c

        left = mnb
        right = MX - dr
        while left <= right:
            b = int((left + right) / 2)
            c = calc(b + dr, b)
            if c == X:
                print(b + dr, b)
                return
            elif c < X:
                left = b + 1
            else:
                right = b - 1

        left = -MX
        right = mnb
        while left <= right:
            b = int((left + right) / 2)
            c = calc(b + dr, b)
            if c == X:
                print(b + dr, b)
                return
            elif c < X:
                left = b + 1
            else:
                right = b - 1


main()


Measured memory_bytes: 63660
#include<stdio.h>
int main(){
char a[100]={0};
char A;
char T;
char G;
char C;
  
A= 'A';
T= 'T';
G= 'G';
C= 'C';
  
scanf("%s",a);
if(a[0]==A){
  printf("%c\n",T);}
if(a[0]==T){
  printf("%c\n",A);}
 if(a[0]==G){
  printf("%c\n",C);}
if(a[0]==C){
  printf("%c\n",G);}
 
 
  return(0);
}

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

int main(){
	// ios::sync_with_stdio(false);
	int N,K; cin>>N>>K;
	vector<int> P(N+1);
	rep(i,N) cin>>P[i+1];
	vector<ll> C(N+1);
	rep(i,N) cin>>C[i+1];


	ll ans = -1e10;
	for(int i=1; i<=N; i++){
		ll score=0;
		ll k = K;
		ll rcheck=i,rcount=0,now=i, rscore=0;
		now = P[i];
		score += C[now];
		k--;
		rcount++;
		ans = max(ans,score);
		while(k>0 && now!=rcheck){
			now = P[now];
			score += C[now];
			ans = max(ans,score);
			k--;
			rcount++;
		}

		if(now==rcheck){
			// cerr << "i:rcount " << i << " " << rcount << endl;
			rscore=score;
			// cerr << "rscore: " << rscore << endl;
			if(rscore<0){
				k = min(rcount, k);
				while(k>0){
					now = P[now];
					score += C[now];
					ans = max(ans,score);
					k--;
				}
				
			}else{
				score += (k/rcount - 1)*rscore;
				k = k%rcount + rcount;
				// cerr << "k: " << k << endl;
				ans = max(ans,score);
				while(k>0){
					now = P[now];
					score += C[now];
					ans = max(ans,score);
					k--;
				}
			}
		}
	}

	cout << ans << endl;	
}


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

namespace TYC
{
	typedef long long ll;
	const int N = 5e5 + 5, mod = 998244353;

	int n, m, Fac[N], Inv[N];

	inline int qpow(int x, int tim)
	{
		int ans = 1;
		for (; tim; tim >>= 1, x = int((ll)x * x % mod))
			if (tim & 1)
				ans = int((ll)ans * x % mod);
		return ans;
	}

	inline int C(const int x, const int y)
	{ return x < y ? 0 : int((ll)Fac[x] * Inv[y] % mod * Inv[x - y] % mod); }

	void work()
	{
		scanf("%d%d", &n, &m);
		if (n < m)
			swap(n, m);
		Fac[0] = 1;
		for (int i = 1; i <= n; i++)
			Fac[i] = int((ll)Fac[i - 1] * i % mod);
		Inv[n] = qpow(Fac[n], mod - 2);
		for (int i = n; i; i--)
			Inv[i - 1] = int((ll)Inv[i] * i % mod);
		int ans = 0;
		for (int r = 0, d = 1; r <= m; r++, d = -d)
			ans = int((ans + (ll)(mod + d) * C(n, r) % mod * C(m, r) % mod * Fac[r] % mod * qpow(m + 1, n - r) % mod * qpow(n + 1, m - r) % mod) % mod);
		printf("%d\n", ans);
	}
}

int main()
{
	TYC::work();
	return 0;
}

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

bool goodx[101],goody[101];

int main(){
  int H,W; cin >> H >> W;
  string board[101];
  for ( int i = 0; i < 101; i++ ) {
    goodx[i] = false;
    goody[i] = false;
  }
  for ( int i = 0; i < H; i++ ) {
    cin >> board[i];
  }
    
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      if ( board[i][j] == '#') {
	goodx[i] = true;
	goody[j] = true;
      }
    }
  }

  
  for ( int i = 0; i < H; i++ ) {
    if ( goodx[i] ) {
      for ( int j = 0; j < W; j++ ) {
	if ( goody[j] ) {
	  cout << board[i][j];
	}
      }
      cout << endl;
    }
  }
  return 0;
}


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

using ll = long long;

const int N = 200005;

int n, m, a[N];
ll b[N], r;

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d", a + i);
        if(i > 1){
            int x = a[i - 1], y = a[i];
            if(x > y) y += m;
            r += (y - x);
            b[x + 2]++;
            b[y + 1] -= (y - x);
            b[y + 2] += (y - x - 1);
        }
    }
    for(int i = 1; i <= 2 * m; i++) b[i] += b[i - 1];
    for(int i = 1; i <= 2 * m; i++) b[i] += b[i - 1];
    for(int i = 1; i <= m; i++) b[i] += b[m + i];
    printf("%lld\n", r - *max_element(b + 1, b + m + 1));
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = n;
    int ptr = 0;
    for(int i = 0; i < n; i++) {
        string p = s.substr(i, n - i);
        bool f = false;
        for(int j = 0; j < n - i; j++) {
            if(p[j] != t[j]) {
                f = true;
                break;
            }
        }
        if(f) continue;
        ptr = max(ptr, n - i);
    }
    ans += n - ptr;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    int N;
    cin >> N;
    int change = N % 1000;
    change = change <= 0 ? 0 : 1000 - change;
    cout << change << endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {

	int N;
	cin >> N;
	vector<int> C(N),S(N),F(N);
	rep(i,N) cin >> C[i] >> S[i] >> F[i];
	rep(i,N) {
		ll ans = 0;
		ll ct = 0;
		for(int j=i; j<N-1; j++) {
			//cout << ct << " ";
			if(ct <= S[j]) {
				ct = S[j];
			}
			else {
				if((ct-S[j])%F[j] != 0) {
					ct += F[j] - ct % F[j];
				}
			}
			ct += C[j];
		}
		//cout << endl;
		cout << ct << endl;
	}
  return 0;
}


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

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
	int n, k, in;
	vl v;
	cin >> n >> k;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
	}
	ll ans = LINF;
	rep(i, n-k+1) {
		ll a = v[i];
		ll b = v[i + k - 1];
		ll c;
		if (a*b >= 0)c = max(abs(a), abs(b));
		else c = (abs(a) + abs(b)+min(abs(a), abs(b)));
		//cout << c << endl;
		ans = min(ans,c);
	}
	cout << ans << endl;
}


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

/**
 * Created by wild on 2016/07/23.
 */
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int len = scan.nextInt();
        String[] str = new String[num];
        for (int i = 0; i < str.length; i++){
            str[i] = scan.next();
        }

        Arrays.sort(str);
        for (String tmp: str) System.out.print(tmp);
    }
}

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

const int MAX_N = 185 + 5;

int n, m;
int dp[MAX_N][MAX_N][MAX_N][2], sum[MAX_N][MAX_N];
char s[MAX_N][MAX_N];

int query(int x1, int y1, int x2, int y2) {
	return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}

bool check(int x1, int y1, int x2, int y2) {
	int s = query(x1, y1, x2, y2);
	return s == 0 || s == (x2 - x1 + 1) * (y2 - y1 + 1);
}

int solve(int ans, int i, int j, int l) {
	int ql = i, qr = j - 1, ret = -1;
	while (ql <= qr) {
		int mid = (ql + qr) >> 1, u = dp[i][mid][l][ans & 1], v = dp[mid + 1][j][l][ans & 1];
		ret = std::max(ret, std::min(u, v));
		if (u < v)
			qr = mid - 1;
		else
			ql = mid + 1;
	}
	return ret;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
	}

	// for (int i = 1; i <= n; ++i) {
	// 	for (int j = 1; j <= m; ++j) putchar(s[i][j]);
	// 	puts("");
	// }

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (s[i][j] == '#');
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
			for (int l = 1, r; l <= m; l = r + 1) {
				r = l - 1;
				while (r < m && check(i, l, j, r + 1)) ++r;
				// std::cerr << l << " " << r << std::endl;
				for (int p = l; p <= r; ++p) {
					dp[i][j][p][0] = r;
				}
				if (r == l - 1)
					dp[i][j][l][0] = r, ++r;
			}
		}
	}

	int ans = 1;
	// std::cerr << dp[1][n][1][(ans & 1) ^ 1];
	while (dp[1][n][1][(ans & 1) ^ 1] < m) {
		// std::cerr << dp[1][n][1][(ans & 1) ^ 1];
		for (int i = 1; i <= n; ++i) {
			for (int j = i; j <= n; ++j) {
				for (int l = 1; l <= m; ++l) {
					int v = dp[i][j][l][(ans & 1) ^ 1];
					if (v == m) {
						dp[i][j][l][ans & 1] = m;
						continue;
					}
					dp[i][j][l][ans & 1] = std::max(dp[i][j][v + 1][(ans & 1) ^ 1], solve(ans - 1, i, j, l));
				}
			}
		}
		++ans;
	}
	printf("%d\n", ans - 1);
}

Measured memory_bytes: 30256