akhauriyash/Code-Regression huggingface dataset:
grid = [[], [], []]
for i in range(3):
    grid[i] = [int(i) for i in input().split()]
x = [0] * 3
y = []
ret = True
for i in range(3):
    y.append(grid[0][i] - x[0])
for i in range(3):
    x[i] = grid[i][0] - y[0]
for i in range(3):
    for j in range(3):
        if not x[i] + y[j] == grid[i][j]:
            ret = False
    else:
        continue
    break
print("Yes" if ret else "No")


Measured memory_bytes: 3064
def solve():
    X = int(input())
    memo = {}
    for A in range(500):
        for B in range(500):
            memo[A**5-B**5] = (A,B)
            memo[A**5+B**5] = (A,-B)
    A,B = memo[X]
    print(A, B)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 82356
#include <stdio.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a < b){
    if(b < c){printf("%d %d %d\n",a,b,c);
    }else if(a < c){printf("%d %d %d\n",a,c,b);          
    }else{printf("%d %d %d\n",c,a,b);
    }
    }    
    else if(b < c){
    if(a < c){printf("%d %d %d\n",b,a,c);
    }else {printf("%d %d %d\n",b,c,a);
    }}
    else{printf("%d %d %d\n",c,b,a);        
        } 
    return 0;
}    

Measured memory_bytes: 596
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w = inpl()
dx = [1,0,-1,0]
dy = [0,1,0,-1]
field = []
for i in range(h):
    field.append(list(input()))

dist = [[-1 for i in range(w)] for j in range(h)]
dist[0][0] = 0
q = deque([[0,0]])
while q:
    v = q.popleft()
    for i in range(4):
        nh = v[0] + dx[i]
        nw = v[1] + dy[i]
        if nh < 0 or nh >= h or nw < 0 or nw >= w:
            continue
        if field[nh][nw] == '#':
            continue
        if dist[nh][nw] != -1:
            continue
        dist[nh][nw] = dist[v[0]][v[1]] + 1
        q.append([nh,nw])

if dist[h-1][w-1] == -1:
    print(-1)
else:
    black_cnt = 0
    for i in range(h):
        for j in range(w):
            if field[i][j] == '#':
                black_cnt += 1
    print(h*w - black_cnt - dist[h-1][w-1] - 1)


Measured memory_bytes: 4080
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
//#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

//namespace mp = boost::multiprecision;
//using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int a,b;
	cin>>a>>b;
	int ans=a*b;
	ans=max(ans,a-b);
	ans=max(ans,a+b);
	cout<<ans<<endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n, k; scanf("%d%d", &n, &k);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int x; scanf("%d", &x);
		ans += 2*min(x, abs(k-x));
	}
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),m=in();
	print((m*1900+(n-m)*100)*(int)pow(2,m));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int tr[4][14];
    int n,i,j,c;
    char m,d;
    for(i = 0 ; i < 4 ; i++){
        for(j = 0 ; j < 14 ; j++){
            tr[i][j] = 0;
        }
    }
    scanf("%d",&c);
    for(i = 0 ; i < c ; i++){
        scanf("%c",&d);
        scanf("%c %d",&m,&n);
        if(m == 'S'){
            tr[0][n] = 1;
        }else if(m == 'H'){
            tr[1][n] = 1;
        }else if(m == 'C'){
            tr[2][n] = 1;
        }else if(m == 'D'){
            tr[3][n] = 1;
        }
    }
    for(j = 1 ; j < 14 ; j++){
        if(tr[0][j] != 1){
            printf("S %d\n",j);
        }
    }
    for(j = 1 ; j < 14 ; j++){
        if(tr[1][j] != 1){
            printf("H %d\n",j);
        }
    }
    for(j = 1 ; j < 14 ; j++){
        if(tr[2][j] != 1){
            printf("C %d\n",j);
        }
    }
    for(j = 1 ; j < 14 ; j++){
        if(tr[3][j] != 1){
            printf("D %d\n",j);
        }
    }
    return 0;
}



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

int main() {
    int N, Y;
    cin >> N >> Y;
    Y -= 1000 * N;

    for (int a = 0; a <= N; a++)
    {
        if (a * 9000 > Y) {
            break;
        }
        int y = Y - 9000 * a;
        if (y % 4000 != 0)
        {
            continue;
        }
        int b = y / 4000;
        if (a + b > N) {
            continue;
        }
        int c = N - (a + b);
        cout << a << ' ' << b << ' ' << c << endl;
        return 0;
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    vector<map<ll,ll>> T;
    READV(N);
    T.resize(N+1);
    FORI(i,0,N)
    {
        READV(A);
        FORI(j,0,A)
        {
            READV(x);
            READV(y);
            T[i][x-1]=y;
        }
    }
    ll ans=0;
    FORI(i,0,pow(2,N))
    {
        vector<ll> X;
        ll z=i;
        FORI(j,0,N)
        {
            X.pb(z%2);
            z=z/2;
        }
        bool ok=true;
        ll cnt=0;
        FORI(j,0,N)
        {
            if(X[j]==1)
            {
                for(auto p:T[j])
                {
                    if (X[p.fi]!=p.se)
                    {
                        ok=false;
                    }
                }
                cnt++;
            }
        }
        if (ok)
        {
            ans=max(cnt,ans);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }

  rep(iter,k) {
    // Check a
    bool isFinished = true;
    rep(i,n) {
      if (a[i] != n) {
        isFinished = false;
        break;
      }
    }
    if (isFinished) { break; } // reached to last state

    vector<ll> na(n);
    rep(i,n) {
      ll d = a[i];
      ll l = max(i-d, 0ll);
      ll r = min(i+d+1, n);
      ++na[l];
      if (r < n) {
        --na[r];
      }
    }
    rep(i,n-1) {
      na[i+1] += na[i];
    }

    // For Debug
    // printvec(na);

    swap(na,a);
  }

  rep(i,n) {
    cout << a[i];
    if (i<n-1) {
      cout << " ";
    }
  }
  cout << endl;
}


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

int main() {
  string s;
  cin >> s;
  if(s.size()<4) cout << "No" << endl;
  else {
    if(s.substr(0,4)=="YAKI") cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

int main(int argc, char* argv[]) {
  int points_i = 0;
  int points[5] = {};
  int pointsLength = 5;
  int k = 0;
  
  for(points_i = 0; points_i < pointsLength;  points_i++)
  {
    std::cin >> points[points_i];
  }
  std::cin >> k;

  if( k < (points[pointsLength-1]-points[0]) )
  {
    std::cout << ":(" << std::endl;
  }
  else
  {
    std::cout << "Yay!" << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int N,T,mi;
    mi=1001;
    cin>>N>>T;
    vector<int> c(N);
    vector<int> t(N);
    for(int i=0;i<N;i++){
        cin>>c[i]>>t[i];
        if(t[i]<=T){
            mi=min(c[i],mi);
        }
    }
    if(mi==1001) cout<<"TLE"<<endl;
    else cout<<mi<<endl;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

double l[30], a[30], b[30];

int n, m;
double dfs(int q,vector<vector<double>> t){
	if (q == n){
		double ret = 0;
		rep(i, t.size())For(j,i+1,t.size()){
			rep(k, 3){
				ret += sqr(t[i][k] - t[j][k]);
			}
		}
		return ret;
	}
	vector<double> tmp;
	tmp.push_back(l[q]);
	tmp.push_back(a[q]);
	tmp.push_back(b[q]);

	double ret = dfs(q + 1, t);
	if (t.size() < m){
		t.push_back(tmp);
		return max(ret, dfs(q + 1, t));
	}
	return ret;
}

int main(){

	cin >> n >> m;
	rep(i, n){
		cin >> l[i] >> a[i] >> b[i];
	}
	cout << fixed << setprecision(30) << dfs(0, vector<vector<double>>()) << endl;

	return 0;
}

Measured memory_bytes: 1332
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
   ll a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
    int n,m;
    cin>>n>>m;
    vector<int> broken(n+1);
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        broken[a]=1;
    }
    vector<int> dp(n+2);
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        if(broken[i]){
            dp[i]=0;
            continue;
        }
        dp[i]=(dp[i+1]+dp[i+2])%MOD;
    }
    cout<<dp[0]<<endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }
#define each(it,o) for(auto it = (o).begin(); it != (o).end(); ++ it)

struct MaximumFlow {
	typedef int Index;
	typedef ll Flow;
	static constexpr Flow InfCapacity = INFL;
	struct Edge {
		Index to;
		Flow capacity;
		Index rev;
	};
	vector<vector<Edge> > g;
	void init(Index n) { g.assign(n, vector<Edge>()); }
	void add(Index i, Index j, Flow capacity) {
		Edge e, f; e.to = j, f.to = i; e.capacity = capacity, f.capacity = 0;
		g[i].push_back(e); g[j].push_back(f);
		g[i].back().rev = (Index)g[j].size() - 1; g[j].back().rev = (Index)g[i].size() - 1;
	}
	void addB(Index i, Index j, Flow capacity) {
		Edge e, f; e.to = j, f.to = i; e.capacity = capacity, f.capacity = capacity;
		g[i].push_back(e); g[j].push_back(f);
		g[i].back().rev = (Index)g[j].size() - 1; g[j].back().rev = (Index)g[i].size() - 1;
	}
	//gを破壊する
	Flow maximumFlow(int s, int t) {
		int n = g.size();
		vector<Index> level(n);
		Flow total = 0; bool update;
		do {
			update = false;
			fill(level.begin(), level.end(), -1); level[s] = 0;
			queue<Index> q; q.push(s);
			for (Index d = n; !q.empty() && level[q.front()] < d; ) {
				int u = q.front(); q.pop();
				if (u == t) d = level[u];
				each(e, g[u]) if (e->capacity > 0 && level[e->to] == -1)
					q.push(e->to), level[e->to] = level[u] + 1;
			}
			vector<Index> iter(n);
			for (Index i = 0; i < n; i ++) iter[i] = (int)g[i].size() - 1;
			while (1) {
				Flow f = augment(level, iter, s, t, InfCapacity);
				if (f == 0) break;
				total += f; update = true;
			}
		} while (update);
		return total;
	}
	Flow augment(vector<Index> &level, vector<Index> &iter, Index u, Index t, Flow f) {
		if (u == t || f == 0) return f;
		Index lv = level[u];
		if (lv == -1) return 0;
		level[u] = -1;
		for (; iter[u] >= 0; -- iter[u]) {
			Edge &e = g[u][iter[u]];
			if (level[e.to] <= lv) continue;
			Flow l = augment(level, iter, e.to, t, min(f, e.capacity));
			if (l == 0) continue;
			e.capacity -= l; g[e.to][e.rev].capacity += l;
			level[u] = lv;
			return l;
		}
		return 0;
	}
};

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> a(N);
		for (int i = 0; i < N; ++ i)
			scanf("%d", &a[i]);
		int src = N, dst = src + 1;
		MaximumFlow mf;
		mf.init(dst + 1);
		ll base = 0;
		rep(i, N) {
			int x = i + 1;
			for(int y = x * 2; y <= N; y += x)
				mf.add(i, y - 1, INFL);
			base += max(a[i], 0);
			if (a[i] > 0)
				mf.add(i, dst, a[i]);
			else
				mf.add(src, i, -a[i]);
		}
		ll flow = mf.maximumFlow(src, dst);
		ll ans = base - flow;
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
def main():
  # import bisect
  # from collections import Counter
  # from collections import defaultdict
  # from collections import deque
  # from copy import deepcopy
  # from fractions import gcd
  # from heapq import heappop,heappush
  # from itertools import accumulate
  # from itertools import combinations
  # from itertools import permutations
  # from itertools import product
  # from math import ceil,floor, pi
  import sys
  sys.setrecursionlimit(10**6)
  readline = sys.stdin.readline
  ints = lambda: map(int, readline().split())
  floats = lambda: map(float, readline().split())
  pyes = lambda: print("Yes")
  pno = lambda: print("No")
  lli = lambda I, J: [[0] * J for _ in range(I)]
  mod = 10**9+7

  n, k = ints()
  a = n % k
  print(min(a, abs(a - k)))

if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
string s, t;
set<string> S;
void Work(string s,string t)
{
    int lens = s.size(),lent = t.size();
    for(int i=0;i<lens;i++)
    {
        if(s[i] == '?' || s[i] == t[0])
        {
            string tmp = s;
            for(int j=0;j<i;j++)
                if(tmp[j] == '?') tmp[j] ='a';    
            bool can = false;
            for(int j=0;j<lent;j++)
            {
                if(tmp[i+j]!='?' && tmp[i+j]!=t[j])
                    break;
                tmp[i+j] = t[j];
                if(j == lent-1) can = true;
            }
            if(can)
			{
                for(int j=i+lent;j<lens;j++)
					if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);
            }
        }
    }
    if(S.size()!=0) cout<<*S.begin();
    else cout<<"UNRESTORABLE";
}
int main()
{
    cin>>s>>t;
    Work(s,t);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll n;
    cin >> n;
    vll plus;
    ll mi=0;
    ll count=0;
    vll a(n);
    rep(i, n) cin >> a[i];
    vll b(n);
    rep(i, n) cin >> b[i];
    rep(i,n){
        if(a[i]>b[i]) plus.push_back(a[i]-b[i]);
        else if(b[i]>a[i]){
            mi+=b[i]-a[i];
            count++;
        }
    }
    sort(all(plus));
    reverse(all(plus));
    if(mi==0){
        cout<<0<<endl;
        return 0;
    }
    rep(i,plus.size()){
        mi-=plus[i];
        count++;
        if(mi<=0){
            cout<<count<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 2428
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int n;
int t[202][202];
bool used[202];

int solve(int start) {
  fill(used, used + n, false);

  int res = 1;
  set<int> pre;
  pre.insert(start);
  used[start] = true;

  while (true) {
    set<int> next;
    for (auto &from: pre) {
      for (int to = 0; to < n; to++) {
        if (t[from][to] == 0) {
          continue;
        }
        if (pre.find(to) != pre.end()) {
          return -1;
        }
        if (used[to]) {
          continue;
        }
        used[to] = true;
        next.insert(to);
      }
    }
    if (next.empty()) {
      break;
    }
    pre = next;
    res++;
  }

  return res;
}

int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        char ch;
        cin >> ch;
        t[i][j] = (int)(ch - '0');
      }
    }

    int ans = -1;
    for (int i = 0; i < n; i++) {
      ans = max(ans, solve(i));
    }
    cout << ans << endl;
  }
}


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

using namespace std;

typedef long long ll;
const int MOD = 998244353;
ll n, a, b, k, inv[300005], n1 = 1;

ll pw(ll b) {
	if(b == 1) return 1;
	return (MOD-MOD/b)*pw(MOD%b)%MOD;
}

ll C(ll k) {
	if(k == 0) return 1ll;
	if(k < 0) return 0;
	return (n1 * inv[n - k] % MOD) * inv[k] % MOD;
}

int main() {
	inv[0] = 1;
	for(int i = 1; i <= 3e5+5; i++) {
		inv[i] = inv[i - 1] * pw(i) % MOD;
	}
	cin >> n >> a >> b >> k;
	for(int i = 2; i <= n; i++) {
		n1 = n1 * i % MOD;
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++) {
		if((k - a * i) % b == 0 && (k-a*i)/b <= n) {
			ans += C(i) * C((k - a * i) / b) % MOD;
			ans %= MOD;
		}
	}
	cout << ans;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm> 
#include<string.h>
using namespace std;
int main()
{
	int b;
	string s;
	while(cin>>s)
	{
	int a=s.length();
	if(s[0]==s[a-1])
	b=a-3;
	else
	b=a-2;
	if(b%2)
	cout<<"First"<<endl;
	else
	cout<<"Second"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
<?php
$N=fgets(STDIN);
$d=[];
$d[0]=1;
for ($i=1; $i <=7 ; $i++) {
  // code...
  $K=pow(2,$i);
  $d[$i]=$K;
}
for ($i=0; $i <=7 ; $i++) {
  // code...
  if($d[$i]>$N){
    echo $d[$i-1];
    break;
  }
}
 ?>


Measured memory_bytes: 3828
N, K = map(int,input().split())
p = [int(i) for i in input().split()]
P = []
P_S = [0]
ans_list = []
temp = 0

for i in range(N):
    P.append((p[i] + 1)/2)
    temp = temp + P[i]
    P_S.append(temp)
for i in range(K,N+1):
    ans_list.append(P_S[i] - P_S[i - K])

print(max(ans_list))

Measured memory_bytes: 29896
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	while(-1){
		int h,w,j,i;cin>>h>>w;
		if(h+w==0){RE;}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if((i+j)%2){cout<<'.';}
				else{cout<<'#';}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	RE;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll ans=0;
  rep(i,n) ans+=a[i]-1;
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int n;
void partition(int A[],int p,int r){
  int x,i,j,temp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i += 1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
     }
  }
  for(j=0;j<i+1;j++)printf("%d ",A[j]);
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  printf("[%d] ",A[i+1]);
  for(j=i+2;j<n-1;j++)printf("%d ",A[j]);
  
  printf("%d\n",A[n-1]);
}

int main(){
  int i,A[N];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  partition(A,0,n-1);
  return 0;
}

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

#define mset(x, v) memset(x, v, sizeof(x));
#define fi first
#define se second
#define pb push_back
#define be begin()
#define en end()
#define mp make_pair

#define sd(x) scanf("%lld",&x);
#define sd2(x,y) scanf("%lld %lld",&x,&y);
#define sd3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z);

#define pf(x) printf("%lld", x);
#define pf2(x,y) printf("%lld %lld", x,y);
#define pf3(x,y,z) printf("%lld %lld %lld", x,y,z);

using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef set<ll> sll;
typedef queue<ll> qll;

template<class U, class V>
ostream& operator<<(ostream& os, const pair<U, V>& p) {os << "(" << p.first << ", " << p.second << ")";return os;}

template<class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {in >> p.first >> p.second;return in;}

vvll al;
vector <bool> mark;
vll top;

void dfs (ll u)
{
    mark.at (u) = true;
    for (auto v : al[u])
    {
        if (!mark.at (v)) {
            dfs (v);
        }
    }
    top.push_back (u);
}

int main ()
{
    ll n, m; sd2 (n, m);
    al = vvll (n);
    mark = vector <bool> (n, false);

    for (ll i = 0; i < m; i++)
    {
        ll x, y; sd2 (x, y);
        al[x-1].pb (y-1);
    }
    ll res = 0;
    for (ll i = 0; i < n; i++)
    {
        if (!mark.at (i))
            dfs (i);
    }
    reverse (top.be, top.en);
    
    ll dp[n]; mset (dp, 0);
    for (auto u : top)
    {
        for (auto v : al[u]) {
            dp[v] = max (dp[v], dp[u]+1);
        }
    }
    res = max(res, *max_element (dp, dp+n));
    
    cout << res << endl;
    return 0;
}

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

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

int h, w, th;
string s[10];
int t[1001];

int sub(int q) {
  int d = __builtin_popcount(q) + 1;
  vector<int> masks(d);
  int cnt = 0;
  for (int i = 0; i < h; ++i) {
    masks[cnt] |= 1 << i;
    if ((q >> i) & 1) ++cnt;
  }
  
  int ans = d - 1;
  vector<int> cur(d);
  for (int j = 0; j < w; ++j) {
    vector<int> del(d);
    for (int k = 0; k < d; ++k) {
      del[k] = __builtin_popcount(t[j] & masks[k]);
      cur[k] += del[k];
    }
    if (*max_element(del.begin(), del.end()) > th) return 1e9;
    if (*max_element(cur.begin(), cur.end()) > th) {
      cur = del;
      ++ans;
    }
  }
  return ans;
}

int main() {
  cin >> h >> w >> th;
  for (int i = 0; i < h; ++i) cin >> s[i];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      t[j] |= (s[i][j] - '0') << i;
    }
  }
  ++w;
  
  int mn = 1e9;
  for (int q = 0; q < (1 << (h - 1)); ++q) {
    mn = min(mn, sub(q));
  }
  cout << mn << endl;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
max_ = 0
cur = 0
for i in rr():
    if i == 'D':
        cur -= 1
    if i == 'I':
        cur += 1
    max_ = max(cur, max_)
print(max_)









Measured memory_bytes: 26832
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <climits>
#include <stack>
#include <string>
#include <random>
#include<set>
#include <iomanip>
#include <climits>
struct Flag {
	Flag() :index{ 0 } {};
	Flag(int i) : index{ i } {};
	int index;
	Flag use(const int position) const { return Flag{ index | (1 << position) }; }
	bool operator()(const int position) const { return (index & (1 << position)) != 0; }
};
constexpr long long int mod = 1000000007;
long long int s(const std::vector<std::vector<bool>> &prefer, std::vector<long long int> &memo, const int current = 0, const Flag flag = Flag()) {
	if (current >= prefer.size()) return 1l;
	else if (memo[flag.index] >= 0) {
		return memo[flag.index];
	}else {
		memo[flag.index] = 0;
		for (auto i = 0; i < prefer.size(); ++i) {
			if (!flag(i) && prefer[current][i]) {
				memo[flag.index] += s(prefer, memo, current + 1, flag.use(i));
			}
		}
		memo[flag.index] %= mod;

		return memo[flag.index];
	}
}
long long int solve(const std::vector<std::vector<bool>> &prefer) {
	std::vector<long long int> memo(1 << prefer.size(), - 1l);
	return s(prefer, memo);
}
int main() {
	int n; std::cin >> n;
	std::vector<std::vector<bool>> prefer(n);
	for (auto &s : prefer) {
		std::vector<bool> vec(n);
		std::string str;
		for (auto i = 0; i < vec.size(); ++i) {
			std::cin >> str;
			vec[i] = str == "1";
		}
		s = std::move(vec);
	}
	std::cout << solve(prefer) << std::endl;
}

Measured memory_bytes: 16640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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

























int main(){
    ll n, k;
    cin >> n >> k;
    
    if(k == 0){
        REP(i, (2 << n)){
            cout << i / 2 << " \n"[i == (2 << n) - 1];
        }
        return 0;
    }
    
    vector<ll> ans(2 << n);
    ans[(1 << n) - 1] = k;
    ll t = 0;
    ll xs = 0;
    for(ll i = (1 << n); i < (2 << n) - 1; i++){
        ans[i] = t;
        xs ^= t;
        t++;
        if(t == k) t++;
    }
    // cerr << xs << " " << k << endl;
    if(xs != k){
        cout << -1 << endl;
        return 0;
    }
    ans[(2 << n) - 1] = k;
    for(ll i = 0; i < (1 << n) - 1; i++){
        ans[i] = ans[(2 << n) - 2 - i];
    }
    
    REP(i, (2 << n)){
        cout << ans[i] << " \n"[i == (2 << n) - 1];
    }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef long double ldbl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
// constant
const double PI  = acos(-1.0);
const int    MOD = (int)(1e9 + 7);
// DO NOT set INFTY_XXXs constants. They may bring some BUG! Use MAX_XXXs in climit instead.
 
// clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
// debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl


template<typename T>
inline vector<T> cin_vector(const size_t n) {
     vector<T> vec;
    vec.reserve(n);
    REP(i, n) {
        T element; cin >> element;
        vec.push_back(element);
    }
    return vec;
}

template<typename T>
inline vector< vector<T> > cin_matrix(const size_t m, const size_t n) {
    vector< vector<T> > matrix;
    matrix.reserve(m);
    REP(i, m) {
        vector<T> vec = cin_vector<T>(n);
        matrix.push_back(vec);
    }
    return matrix;
}

template<typename T>
inline void cout_vector(const vector<T>& vec) {
    REP(i, SZ(vec)-1) {
       cout << vec[i] << ' ';
    }
    cout << vec[SZ(vec)-1] << endl;
}

template<typename T>
inline void cout_matrix(vector< vector<T> > matrix) {
    for(const vector<T>& vec : matrix) {
         cout_vector<T>(vec);
    }
}


int main() {
    ll n, k; cin >> n >> k;
    ll ans = 1, m = 1;
    while (true) {
        m *= k;
        if (n < m) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
  int n, ba, m[16];
  string s;

  while(cin >> n, n){
    cin >> s;
    for(int i = 0;i < 16; i++) m[i] = 0;
    ba = 0;
    for(int i = 0;i < s.size(); i++){
      if(s[i] == 'M') m[i % n]++;
      if(s[i] == 'S'){
        ba += m[i % n] + 1; m[i % n] = 0;
      }
      if(s[i] == 'L'){
        m[i % n] += ba + 1; ba = 0;
      }
    }
    sort(m, m + n);
    cout << m[0];
    for(int i = 1;i < n; i++)
      cout << " " << m[i];
    cout << " " << ba << endl;
  }
}


Measured memory_bytes: 1224
from itertools import groupby
from math import ceil

n, k = map(int, input().split())
s = input()

block = [sum(1 for _ in it) for k, it in groupby(s)]
if s[0] != '1':
    block.insert(0, 0)

m = len(block)
left, right = 0, 2*k
res = val = sum(block[left:right-1])
while right <= m:
    val += block[right-1] if right == m else block[right-1] + block[right]
    res = max(res, val)
    val -= block[left] + block[left+1]
    left += 2
    right += 2
print(res)


Measured memory_bytes: 10412
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    ls = list(map(int, input().split(' ')))
    diff = -1
    for i in range(101, -1, -1):
        if i not in ls:
            if diff == -1:
                diff = abs(i - X)
                result = i
            else:
                diff = min(diff, abs(i - X))
                if diff == abs(i - X):
                    result = i
    print(result)

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

using namespace std;

int N;
string s;

bool CHECK(string str) {

	for (int i = 0; i <= N - 1; i++) {
		//cout << s[i] << " " << str[i] << endl;
		if (s[i] == 'o' && str[i] == 'S') { if (str.substr((i - 1 + N) % N,1 ) == str.substr((i + 1) % N,1)) {} else { return false; } }
		else if (s[i] == 'o' && str[i] == 'W') { if (str.substr((i - 1 + N) % N,1) != str.substr((i + 1) % N,1)) {} else { return false; } }
		else if (s[i] == 'x' && str[i] == 'S') { if (str.substr((i - 1 + N) % N,1) != str.substr((i + 1) % N,1)) {} else { return false; } }
		else if (s[i] == 'x' && str[i] == 'W') { if (str.substr((i - 1 + N) % N,1) == str.substr((i + 1) % N,1)) {} else { return false; } }
	}
	return true;
}

string s1, s2, s3, s4;

string ANTI(string str) {
	if (str == "S") { return "W"; }
	return "S";
}

string EXPAND(string str) {

	string ret = str;

	for (int i = 2; i <= N - 1; i++) {
		if (s[i - 1] == 'o' && ret[i-1]=='S') { ret += ret.substr(i - 2, 1); }
		else if (s[i - 1] == 'o' && ret[i - 1] == 'W') { ret += ANTI(ret.substr(i - 2, 1)); }
		else if (s[i - 1] == 'x' && ret[i - 1] == 'S') { ret += ANTI(ret.substr(i - 2, 1)); }
		else if (s[i - 1] == 'x' && ret[i - 1] == 'W') { ret += ret.substr(i - 2, 1); }
	}

	return ret;
};

int main(void) {

	cin >> N;
	cin >> s;

	string ans;

	s1 = "SS";
	s1 = EXPAND(s1); //cout << "s1= "<< s1 << endl;	
	if (CHECK(s1)) { ans = s1; }

	s2 = "SW";
	s2 = EXPAND(s2); //cout << "s2= " << s2 << endl;
	if (CHECK(s2)) { ans = s2; }

	s3 = "WS";
	s3 = EXPAND(s3);// cout << "s3= " << s3 << endl;
	if (CHECK(s3)) { ans = s3; }

	s4 = "WW";
	s4 = EXPAND(s4); //cout << "s4= " << s4 << endl;
	if (CHECK(s4)) { ans = s4; }


	if (ans == "") { cout << -1 << endl; }
	else { cout << ans << endl; }



	//system("pause");
	return 0;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};
ll int n,m;

int main()
{
    ll var;
    sfl(n);
    c=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                c+=(__gcd(i,__gcd(j,k)));
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3684
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

int main(){
  int f[5];
  rep(i,5) cin>>f[i];
  sort(f,f+5);
  reverse(f,f+5);
  
  rep(i,5){
    if(i) cout<<" ";
    cout<<f[i];
  }
  cout<<endl;
    
  return 0;
}


Measured memory_bytes: 3148
N,M = gets.split.map(&:to_i)
S = (0...N).map{ gets.split.map(&:to_i) }
P = (0...M).map{ |i|
  x,y = gets.split.map(&:to_i) 
  [x,y,i+1]
}
puts S.map{ |x,y|
  P.sort_by{ |xx,yy,i|
    [(x-xx).abs+(y-yy).abs, i]
  }[0][2]
}
  


Measured memory_bytes: 1788
#include <bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000007)
#define PI 3.14159265358979323846

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

i64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

class UnionFind {
 public:
  vector<u64> Par;
  vector<u64> sz;

  UnionFind(u64 n);
  u64 root(u64 x);
  bool same(u64 x, u64 y);
  void unite(u64 x, u64 y);
  u64 size(u64 x);
};

UnionFind::UnionFind(u64 n) {
  Par.resize(n);
  sz.assign(n, 1);
  for (u64 i = 0; i < n; ++i) Par[i] = i;
}

u64 UnionFind::root(u64 x) {
  if (Par[x] == x) {
    return x;
  } else {
    return Par[x] = root(Par[x]);
  }
}

bool UnionFind::same(u64 x, u64 y) { return root(x) == root(y); }

u64 UnionFind::size(u64 x) { return sz[root(x)]; }

void UnionFind::unite(u64 x, u64 y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  Par[y] = x;
}

int main() {
  cout << setprecision(18);
  string S;
  cin >> S;
  u32 year = stoi(S.substr(0, 4));
  u32 M = stoi(S.substr(5, 2));
  u32 D = stoi(S.substr(8, 2));
  if (year < 2019) {
    cout << "Heisei" << endl;
  } else if (year == 2019) {
    if (M < 4) {
      cout << "Heisei" << endl;
    } else if (M == 4) {
      if (D <= 30) {
        cout << "Heisei" << endl;

      } else {
        cout << "TBD" << endl;
      }
    } else {
      cout << "TBD" << endl;
    }
  } else {
    cout << "TBD" << endl;
  }

  return 0;
}


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

const long long INF = 100000000000000007LL;
int N;
long long dp[405][410];
long long acc[410];

int main()
{
    cin >> N;

    acc[0] = 0LL;
    for (int i = 1; i <= N; ++i) {
        cin >> acc[i];
        acc[i] += acc[i - 1];
    }

    for (int i = 0; i < N; ++i)
        dp[i][i + 1] = 0LL;

    for (int w = 2; w <= N; ++w) {
        for (int i = 0; i <= N - w; ++i) {
            int j = i + w;
            long long subcost = INF;
            for (int k = i + 1; k < j; ++k) {
                subcost = min(subcost, dp[i][k] + dp[k][j]);
            }
            dp[i][j] = subcost + acc[j] - acc[i];
        }
    }

    cout << dp[0][N] << endl;
}

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

int main(){
  int n;
  cin>>n;
  int64_t ans,a=2,b=1;
  if(n==0){
    cout<<a<<endl;
    return 0; 
  }
  if(n==1){
    cout<<b<<endl;
    return 0;
  }
  for(int i=1;i<n;i++){
    ans=a+b;
    a=b;
    b=ans;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n;
      cin >> n;
      //sort(s.begin(),s.end());
      //if(s=="1479") cout << "YES" << endl;
      //else cout << "NO" << endl;
      cout << 180*(n-2) << endl;
      return 0;
    }

Measured memory_bytes: 256