akhauriyash/Code-Regression huggingface dataset:
def insertion_sort(array, g):
    cnt = 0
    for i in range(g,len(array)):
        key = array[i]
        j = i - g
        while j >= 0 and array[j] > key:
            array[j+g] = array[j]
            j -= g
            cnt += 1
        array[j+g] = key
    return cnt

def shell_sort(array, ga):
    cnt = 0
    for g in ga:
        cnt += insertion_sort(array, g)
    return cnt

def print_array(array):
     print(str(array)[1:-1].replace(', ', ' '))


def main():
    N = int(input())
    array = [int(input()) for i in range(N)]
    # ga = [i for i in reversed(range(N)) if i % 3 == 1]
    ga = []
    v = 1
    while v <= N:
        ga.append(v)
        v = v * 3 + 1
    ga.reverse()
    cnt = shell_sort(array, ga)

    print(len(ga))
    print_array(ga)
    print(cnt)
    for v in array:
        print(v)

if __name__ == '__main__':
    main()

Measured memory_bytes: 47476
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAXN 200006
int n , m;

int head[MAXN] , to[MAXN << 1] , nex[MAXN << 1] , ecn = -1;
void ade( int u , int v ) {
	to[++ecn] = v , nex[ecn] = head[u] , head[u] = ecn;
}
int fa[MAXN];
int find( int x ) {
	return fa[x] == x ? x : fa[x] = find( fa[x] );
}
struct e{ int u , v; } E[MAXN];
int tt[MAXN] , deg[MAXN];
void dfs( int u , int fa , int ee ) {
	for( int i = head[u] ; ~ i ; i = nex[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		dfs( v , u , i );
	}
	if( u == 1 ) return;
	if( deg[u] ) {
		deg[u] ^= 1;
		if( ~ ee & 1 ) 
			swap( E[tt[ee >> 1]].u , E[tt[ee >> 1]].v );
	} else {
		deg[fa] ^= 1;
		if( ee & 1 ) 
			swap( E[tt[ee >> 1]].u , E[tt[ee >> 1]].v );
	}
}
int main() {
	memset( head , -1 , sizeof head );
	cin >> n >> m;
	if( m & 1 ) return puts("-1") , 0;
	for( int i = 1 ; i <= n ; ++ i ) fa[i] = i;
	for( int i = 1 , u , v ; i <= m ; ++ i ) {
		scanf("%d%d",&u,&v);
		E[i] = ( e ) { u , v };
		if( find( u ) != find( v ) ) {
			ade( u , v ) , ade( v , u );
			tt[ecn >> 1] = i;
			fa[find( u )] = find( v );
		} else {
			deg[u] ^= 1;
		}
	}
	dfs( 1 , 1 , 0 );
	for( int i = 1 ; i <= m ; ++ i ) printf("%d %d\n",E[i].u , E[i].v);
}

Measured memory_bytes: 11648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#define N 801000
#define int long long
typedef long long ll;
template<typename T> inline void read(T &x) {
  x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
}
using namespace std;
const int inf = 1e10;
inline void MIN(int &a, int b) {
  if (b < a)  a = b;
}
int n, q;
struct Edge{
  int u, v, w;
}E[N << 1];
int Etot;
bool cmp(const Edge &a, const Edge &b) {
  return a.w < b.w;
}
inline void Addedge(int x, int y, int w) {
  E[++Etot] = (Edge){x, y, w};
}
ll tag[N];
int fa[N];
int find(int cur) {
  return fa[cur] == cur ? cur : fa[cur] = find(fa[cur]);
}
signed main() {
  memset(tag, 0x3f, sizeof(tag));
  read(n), read(q);
  for (int i = 1; i <= q; ++i) {
    int a, b, c;
    read(a), read(b), read(c);
    Addedge(a, b, c);
    MIN(tag[a], c + 1);
    MIN(tag[b], c + 2);
  }
  int np = 0, nw = inf;
  for (int i = 1; i <= n + n; ++i) {
    MIN(nw, tag[np]);
    MIN(tag[np], nw);
    int nxt = (np + 1) % n;
    Addedge(np, nxt, nw);
    np = nxt; nw += 2;
  }
  for (int i = 1; i <= n; ++i)  fa[i] = i;
  ll ans = 0;
  sort(E + 1, E + 1 + Etot, cmp);
  for (int i = 1; i <= Etot; ++i) {
    int u = E[i].u, v = E[i].v;
    ++u; ++v;
    u = find(u), v = find(v);
    if (u == v) continue;
    ans += E[i].w; fa[u] = v;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 28176
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;

struct sco{
    int a;
    int w;
}sc[100007];

int main(){
    int n,m,p;
    int a = 0,w = 0;
    string s;

    cin >> n >> m;
    for(int i = 1;i<=n;i++){
        sc[i].a = 0;
        sc[i].w = 0;
    }
    while(m--){
        cin >> p >> s;
        if(s=="AC") sc[p].a++;
        else if(!sc[p].a) sc[p].w++;
    }
    for(int i = 1;i<=n;i++){
        if(sc[i].a){
            a++;
            w+=sc[i].w;
        }
    }
    cout << a << " " << w;
}


Measured memory_bytes: 1024
IDENTIFICATION DIVISION.
PROGRAM-ID. 171A.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A          PIC X.
*>
PROCEDURE DIVISION.
  ACCEPT A.
*>
  IF (A >= 'A' AND A <='Z')
    DISPLAY 'A'
  ELSE
    DISPLAY 'a'
  END-IF.
*>
  STOP RUN.


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

using namespace std;

const int maxn=1e2+5;
const int inf=(1<<21);

int n,m[maxn][maxn];
int d[maxn];

void bfs(int s)
{
    queue<int>q;
    q.push(s);
    for(int i=0;i<n;i++){
        d[i]=inf;
    }
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(int v=0;v<n;v++){
            if(m[u][v]==0){
                continue;
            }
            if(d[v]!=inf){
                continue;
            }
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<((d[i]==inf)?(-1):d[i])<<endl;
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=0;
        }
    }
    int u,k,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            m[u][v]=1;
        }
    }
    bfs(0);
    return 0;
}
/*
4
1 2 2 4
2 1 4
3 0
4 1 3
*/



Measured memory_bytes: 3252
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	int n;
	cin>>n;
	double p[n+1];
	for(ll i=1;i<=n;i++)
	{
		cin>>p[i];
		//cout<<p[i];
	}
	/*for(ll i=1;i<=n;i++)
	{
		//cin>>p[i];
		cout<<p[i];
	}*/
	double dp[n+1][n+1];
	memset(dp, 0.0, sizeof(dp)); 
	dp[0][0] = 1.0;
	//cout<<dp[0][0];

	for(int i=1;i<=n;i++)
	{
		//cout<<dp[i-1][0]<<endl;
		for(int j=0;j<=i;j++)
		{
		//	cout<<dp[i-1][j]<<endl;
			if(j==0)
			{
				//cout<<double(dp[i-1][j]) * double(1.0-p[i])<<endl;
				dp[i][j] = dp[i-1][j] * (1.0-p[i]); 
			}
			else
			{
				//cout<<(dp[i-1][j] * (1.0-p[i])) + (dp[i-1][j-1] * (p[i]))<<endl;
				dp[i][j] = (dp[i-1][j] * (1.0-p[i])) + (dp[i-1][j-1] * (p[i]));
			}
			//cout<<dp[i][j]<<endl;
		}
	}
	int st = (n/2) + 1;
	double ans=0.0;
	for(ll i=st;i<=n;i++)
	{
		ans += dp[n][i];
	}
	cout<<setprecision(10)<<ans;
}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()
 
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);
 
int main() {
	int N;
	scanf("%d", &N);
	while (N > 0) {
		if (N % 10 == 7) {
			printf("Yes\n");
			return 0;
		}
		N /= 10;
	}
	printf("No\n");
}

Measured memory_bytes: 3688
import itertools
n,a,b,c = map(int,input().split())

remain = []
res = []
for i in range(n):
    remain.append(int(input()))
x =tuple([ [0,1,2,3]]*n)
for t in list(itertools.product(*x)):
    l = [0,0,0,0]
    s = [0,0,0,0]
    for i in range(n):
        l[t[i]] += remain[i]
        s[t[i]] += 1
    if l[1]*l[2]*l[3] == 0:
        continue
    else:
        magic = (s[1]+s[2]+s[3]-3)*10
        magic += abs(l[1]-a)
        magic += abs(l[2]-b)
        magic += abs(l[3]-c)
        res.append(magic)
print(min(res)) 


Measured memory_bytes: 12916
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];

		for(int i=0; i<N; i++) {
			A[i] = sc.nextInt();
			B[i] = 0;

			while(A[i]%2 == 0) {
				A[i] = A[i]/2;
				B[i] += 1;
			}
		}

		int judge = 30;
		for(int j=0; j<N; j++) {
			if(B[j] < judge) {
				judge = B[j];
			}
		}

		System.out.println(judge);

	}

}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){
  long long int n,m;
  scanf("%lld %lld",&n,&m);
  if(n*2<=m){
    m-=2*n;
    n+=m/4;
  }else{
    n=m/2;
  }
  printf("%lld",n);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    int k;

    cin >> k;

    ll ans = 0;
    for(int a = 1;a < k+1;++a){
        for(int b = 1;b < k+1;++b){
            for(int c = 1;c < k+1;++c){
                ans += (ll)__gcd(a, __gcd(b, c));
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll x;cin>>x;
  ll ans=0;
  ll now=100;
  while(now<x){
    now=(ll)(now*1.01);
    ans++;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;

vector<long long> p_pow;
const int p = 61;

long long myhash(string s)
{
	long long res = 0;
	for (int i = 0; i < sz(s); i++)
	{
		res += (s[i] - 'a' + 1) * p_pow[i];

	}
	return res;
}

int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif

	int a, b, x;
	cin >> a >> b >> x;
	if (x < a || (a + b) < x)
		cout << "NO";
	else
		cout << "YES";
	return 0;

}

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

void f(string s,char b,int n){
    if(n==0){cout << s << endl; return;}
    for(char i='a';i<=b+1;i++){
        int m=max(i,b);
        f(s+i,m,n-1);
    }
}

int main(){
    int n; cin >> n;
    f("a",'a',n-1);
    return 0;
}

Measured memory_bytes: 1536
N , Y = map(int,input().split())

for i in range(N+1):
    x = i
    for y in range(9):
        z = N - x - y
        if z < 0 :
            break
        if 10000*x + 5000*y + 1000*z == Y:
            print(x,y,z)
            quit()
print(-1,-1,-1)


Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<string,int> mp;
  int maxi=0;
  for(int i=0;i<n;i++)
  {
    string s;
    cin>>s;
    mp[s]++;
    maxi=max(maxi,mp[s]);
  }
  for(auto i:mp)
  {
    if(i.second==maxi)
      cout<<i.first<<endl;
  }
  return 0;
}

Measured memory_bytes: 25216
#include <stdio.h>

long search(long bmax, long b[],long a){
  if(a < b[0]){
    return 0;
  }
  long low = 0;
  long high = bmax;
  long mid = (low + high)/2;
  while(high - 1 > low){
    if(a < b[mid]){
      high = mid;
      mid = (low + high)/2;
    }else{
      low = mid;
      mid = (low + high)/2;
    }
  }
  if(a < b[low]){
    return low;
  }else{
    return high;
  }
}

int main(){
  long n;
  long a[100000];
  scanf("%ld",&n);
  for(int i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  long b[100000];
  b[0] = a[n-1];
  long bmax = 0;
  long tmp;
  for(int i=n-2;i>=0;i--){
    if(b[bmax] <= a[i]){
      bmax += 1;
      b[bmax] = a[i];
    }else{
      tmp = search(bmax,b,a[i]);
      b[tmp] = a[i];
    }
  }
  printf("%ld\n",bmax+1);
  return 0;
}

Measured memory_bytes: 1664
// https://atcoder.jp/contests/abc173/tasks/abc173_a

#include <stdio.h>

int main(void) {
    
    int n;
    
    scanf("%d", &n);

    if(n%1000==0)
        printf("%d", 0);
    else if(n%1000<500||n%1000==500)
        printf("%d", 1000-(n%1000));
    else if(n%1000>500)
        printf("%d", 1000-(n%1000));

    return 0;
}


Measured memory_bytes: 1696
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<queue>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int N;
ll W,w[200],v[200];
ll base;
ll dp[110][310];

void init() { 
  base = w[0];
  rep(i,N) w[i] -= base;
}

void compute() {
  init();
  ll ans = 0;
  REP(use,1,N+1) {
    ll new_W = W - use * base;
    if( new_W < 0LL ) break;
    ll size = min(new_W+1LL,3LL*use+10LL);
    memset(dp,-1,sizeof dp);
    dp[0][0] = 0;
    rep(i,N) {
      for(int j=use-1;j>=0;--j) {
	rep(k,size+1) {
	  if( dp[j][k] == -1 ) continue;
	  if( k+w[i] <= size ) {
	    dp[j+1][k+w[i]] = max(dp[j+1][k+w[i]],
				  dp[j][k]+v[i]);
	  }
	}
      }
    }
    ll maxi = -1;
    rep(i,size) maxi = max(maxi,dp[use][i]);
    if( maxi != -1 ) ans = max(ans,maxi);
  }
  cout << ans << endl;
}

int main() {
  cin >> N >> W;
  rep(i,N) cin >> w[i] >> v[i];
  compute();
  return 0;
}

Measured memory_bytes: 512
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

class SegTree():
    def __init__(self, node:int):
        self.n = node
        self.bit = len(bin(self.n-1)) - 2
        self.bottom = 2**self.bit
        
        if self.n == 1:
            self.bottom = 1
            
        self.segtree = [0]*(2*self.bottom-1)
        
        
    def fill(self, n:int):
        self.segtree = [n]*(2*self.bottom-1)
        
    def update(self, idx:int, x:int):
        idx += (self.bottom-1)
        self.segtree[idx] = x
        while idx > 0:
            k = (idx-1) >> 1
            self.segtree[k] = min(self.segtree[2*k+1],
                                  self.segtree[2*k+2])
            idx = k
            
            
    def find(self, left:int, right:int, idx:int, l:int, r:int):
        if left <= l and r <= right:
            return self.segtree[idx]

        elif l >= right or r <= left:
            return 10**10
        
        else:
            return min(self.find(left, right, 2*idx+1, l, (l+r)//2),
                       self.find(left, right, 2*idx+2, (l+r)//2, r))
        
            
n,q = li()
com = []
xy = []
for _ in range(q):
    c,x,y = li()
    com.append(c)
    xy.append((x, y))
    
segtree = SegTree(n)
segtree.fill(2**31-1)
    
for c, (x,y) in zip(com, xy):
    if c == 0:
        segtree.update(x, y)
        
    else:
        print(segtree.find(x, y+1, 0, 0, segtree.bottom))




Measured memory_bytes: 24040
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll h = S.size() / 2;
    ll total = 0;
    rep(i, h)
    {
        total += S[i] != S[S.size()-i-1];
    }
    cout << total;
    return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  3e3 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x ,y, k , Q , ans ; string s,t;
ll a[401];
ll dp[401][401];



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//  freopen("test.in","r",stdin);

    cin>>n;

    for(int i = 0 ; i < n ; ++i)
        cin>>a[i];

    for(int i = 1 ; i < n ; ++i)
        a[i]+=a[i - 1];

    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < n ; ++j)
            dp[i][j] = 1e18;

    for(int i = 0 ; i < n ; ++i)
        dp[i][i] = 0;


    for(int len = 2 ; len <= n ; ++len)
        for(int i = 0 ; i + len - 1< n ; ++i){
            int j = i + len - 1;
            for(int k = 1 ; k < len ; ++k)
                 dp[i][j] = min(dp[i][j],dp[i][i + k - 1] + dp[i + k][j] + a[j] - (i ? a[i - 1]:0));
        }




    cout<<dp[0][n - 1]<<'\n';
    return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String s = sc.next();
    System.out.println(s.substring(0, 3));
  }
}

Measured memory_bytes: 32640
//============================================================================
// Name        : AOJCpp.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
static const int MAX = 200;

int main() {

	string str;
	stack<int> st;

	while(cin >> str) {
		int l, r;
		if (str == "*") {
			r = st.top();
			st.pop();
			l = st.top();
			st.pop();
			st.push(l*r);
		} else if (str == "/") {
			r = st.top();
			st.pop();
			l = st.top();
			st.pop();
			st.push(l/r);
		} else if (str == "-") {
			r = st.top();
			st.pop();
			l = st.top();
			st.pop();
			st.push(l-r);
		} else if (str == "+") {
			r = st.top();
			st.pop();
			l = st.top();
			st.pop();
			st.push(l+r);
		} else {
			st.push(stoi(str));
		}
	}
	cout << st.top() << endl;
}




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

int main(){
    int H, W; cin >> H >> W;
    vector<vector<char>> board(55, vector<char>(55));
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> board.at(i).at(j);
        }
    }
    int cnt = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (board.at(i).at(j) == '#' &&
            board.at(i).at(j-1) != '#' &&
            board.at(i-1).at(j) != '#' &&
            board.at(i).at(j+1) != '#' &&
            board.at(i+1).at(j) != '#') {
                cnt++;
            }
        }
    }
    cout << (cnt == 0 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c && c < b)
		cout << "Yes\n";
	else if (a > c && c > b)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int n = a * x + b * y;
  int m = 2 * c * max(x, y);
  int p = x > y ? a : b;
  int l = 2 * c * min(x, y) + p * abs(x - y);

  cout << min(n, min(m, l)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//debug
#define dump(x)  cout << #x << = << (x) << endl;

int main(){
 int a,b,c;
 cin >> a >> b;
 c = a*b;
 if(a > 9 || a < 1){
     cout << -1 << endl;
 }else if(b > 9 || b < 1){
     cout << -1 << endl;
 }else{
     cout << c << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;



int main() {
  double W, H, x, y; cin >> W >> H >> x >> y;
  cout << fixed << setprecision(10) << W*H/2.0 << endl;
  if(x == W/2 && y == H/2) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}


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

int main()
{
    ll n, k;

    cin >> n >> k;

    ll a[n + 5], sum = 0;

    for(ll i = 0; i < n; i++) cin >> a[i];

    sort(a, a + n);

    for(ll i = 0; i < (n - k); i++) sum += a[i];

    if(k >= n) cout << 0 << endl;
    else cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val al = Seq.fill(n)(sc.nextInt)

  val sum = al.sum
  val alRes = al.filter(_ % 10 != 0)

  val res =
    if(sum % 10 != 0) sum
    else if(alRes.nonEmpty) sum -  alRes.min else 0

  println(res)
}


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

int main() {
  int64_t n,x; cin>>n>>x;
  int64_t a=0;
  vector<int64_t> vec(n);
  for (int i = 0; i<n; i++) cin>>vec.at(i);
  
  if (vec.at(0)>x) {
    a += abs(x-vec.at(0)); 
    vec.at(0)=x;
  }
  
  for (int i = 1; i < n; i++) {
    if (vec.at(i-1)+vec.at(i) > x/* && vec.at(i)!=0*/) {
      a += abs(vec.at(i)+vec.at(i-1) - x);
      vec.at(i) -= abs(vec.at(i)+vec.at(i-1) - x);
    }
  }
  cout<<a<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
        }

        Dictionary<char, int> dict = new Dictionary<char, int>();
        string march = "MARCH";

        void Solve()
        {
            int n = int.Parse(Console.ReadLine());
            var names = new string[n];

            for (int i = 0; i < march.Length; i++)
            {
                dict.Add(march[i], 0);
            }

            for (int i = 0; i < n; i++)
            {
                names[i] = Console.ReadLine();
                if (dict.ContainsKey(names[i][0]))
                {
                    dict[names[i][0]] += 1;
                }
            }

            long ans = Recursive(0);
            Console.WriteLine(ans);
        }

        bool[] used = new bool[5];

        long Recursive(int index)
        {
            if (index == 5)
            {
                long ret = 1;
                int count = 0;
                for (int i = 0; i < used.Length; i++)
                {
                    if (used[i])
                    {
                        ret *= dict[march[i]];
                        count++;
                    }
                }
                if (count != 3)
                    return 0;

                return ret;
            }
            long t = 0;
            if (dict[march[index]] != 0)
            {
                used[index] = true;
                t = Recursive(index + 1);
            }

            used[index] = false;
            long f = Recursive(index + 1);

            return t + f;

        }

    }
}


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

int main() {
	ll n;
	cin>>n;
	ll ma=0;
	map<string,ll>a;
	for(ll i=0;i<n;i++){
		string now;
		cin>>now;
		a[now]++;
		ma=max(a[now],ma);
	}
	vector<string>b;
    for(auto itr = a.begin(); itr != a.end(); ++itr) {
        string now= itr->first;
        ll next= itr->second ;    // 値を表示
        if(next==ma){
        	b.push_back(now);
        }
    }	
    sort(b.begin(),b.end());
    for(ll i=0;i<b.size();i++){
    	cout << b[i]<<endl;
    }

	// your code goes here
	return 0;
}

Measured memory_bytes: 26868
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

typedef long long ll;

const double EPS = 1e-9;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

typedef vector<int> vi;
typedef pair<int, int> pi;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()

int main(){
  int n;
  scanf("%d",&n);
  string s = to_string(n);
  string buf = "ABC" + s;
  printf("%s\n", buf.c_str());

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
  int a, b, c;
  scanf("%d %d %c", &a, &b, &c);
  if (a < b && b < c) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}



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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
/* -------------------------------------------------------------------------- */

struct data
{
    int C;
    int S;
    int F;
};

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    vector<data> d(N+1);

    for (int i=1; i < N; i++) {
        cin >> d[i].C >> d[i].S >> d[i].F;
    }

    for (int i=1; i<=N; i++) {
        int t = d[i].S + d[i].C;

        if (i == N) {
            cout << 0 << endl;
            break;
        }

        for (int j=i+1; j < N; j++) {
            while (!(d[j].S <= t && ((t % d[j].F) == 0))) {
                t++;
            }
            t +=  d[j].C;
        }

        cout << t << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

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

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());

#define TRACE
#ifdef AYUSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

int const mod = 1e9 + 7;
int const inf = 1e18;

int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) {if (y & 1)ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1;} return ans;}
int modinv(int a, int m) {return power(a, m - 2, m);}
int n, m, x; 
vector<vii> a;
const int N = 1LL<<14;
vii dp(N, -1);
int ans(int mask){
	trace(mask, __builtin_popcount(mask));
	vii c(m + 1);
	bool done = true;
	for(int i=0;i<n;++i){
		if((mask>>i)&1){
			for(int j=1;j<=m;++j){
				c[j] += a[i][j];
			}
		}
	}
	for(int i=1;i<=m;++i){
		if(c[i] < x){
			done = false;
		}
	}
	if(done){
		return 0;
	}
	if(__builtin_popcount(mask) == n && !done){
		return LLONG_MIN;
	}
	if(dp[mask] != -1){
		return dp[mask];
	}
	int r = LLONG_MAX;
	for(int i=0;i<n;++i){
		if(((mask>>i)&1) == 0){
			int new_mask=(1<<i)^mask;
			trace(new_mask);
			r = min(r, a[i][0] + ans(new_mask));
		}
	}
	trace(mask, r);
	return dp[mask] = r;
}



void solve() {
	cin >> n >> m >> x;
	a.resize(n);
	for (int i = 0; i < n; ++i) {
		int r;cin>>r;
		a[i].pb(r);
		for(int j=0;j<m;++j){
			cin>>r;
			a[i].pb(r);
		}
	}
	int aa = ans(0);
	if(aa < 0){
		cout<<-1<<endl;
	}
	else{
		cout<<aa<<endl;
	}


}
signed main() {
	IOS
	int t = 1, T = 1;
	// cin>>t;
	while (t--) {
		// cout<<"Case #"<<T<<": ";
		solve();
		// ++T;
	}
	return 0;
}

Measured memory_bytes: 3664
while True:
    height, width = map(int, input().split())
    if height == 0 and width == 0:
        break
    for i in range(height):
        if i == 0 or i == height -1:
            print("#" * width)
        else:
            print("#" + "." * (width -2) + "#")
    print()


Measured memory_bytes: 5616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    long N = 0, i = 0, stack_A = 0, stack_B = 0, no_stack = 0;
    int len = 0, j = 0, flag = 0;
    char **S = NULL;
    long A = 0;

    scanf("%ld", &N);

    S = (char **) malloc(N);
    for (i = 0; i < N; i++) {
        S[i] = (char *) malloc(11);
        scanf("%s", S[i]);

        if (S[i][0] == 'B') {
            stack_B++;
            flag++;
        }

        len = strlen(S[i]);
        if (S[i][len - 1] == 'A') {
            stack_A++;
            flag++;
        }

        if (flag >= 2) {
            no_stack++;
        }
        flag = 0;

        for (j = 0; S[i][j] != '\0'; j++) {
            if (S[i][j] == 'A' && S[i][j + 1] == 'B') {
                A++;
            }
        }
    }

    if (stack_A >= stack_B) {
        A += stack_B;
    } else {
        A += stack_A;
    }

    if (no_stack >= 1 && stack_A <= no_stack && stack_B <= no_stack) {
        A -= 1;
    }

    printf("%ld", A);

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int H, W;
string S[333];
int ans;

void solve() {
    FOR(W - 1) {
        int dp[333][333] = {};
        int cost[333][333] = {};
        FOR(l, 1, H + 1) {
            FOR(r, 1, H + 1) {
                cost[l][r] = cost[l - 1][r - 1] + (S[l - 1][i] == S[r - 1][i + 1]);
            }
        }
        Fill(dp, INF);
        FOR(H + 1)
        dp[i][0] = 0;
        FOR(H + 1)
        dp[0][i] = 0;
        FOR(l, 1, H + 1) {
            FOR(r, 1, H + 1) {
                dp[l][r] = min(dp[l][r - 1] + cost[l][r], dp[l - 1][r] + cost[l][r]);
            }
        }
        ans += dp[H][H];
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);


    cin >> H >> W;
    FOR(H)
    cin >> S[i];
    FOR(H)
    for (auto& c : S[i])
        c -= 'a';
    solve();
    return 0;
}


Measured memory_bytes: 2048
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    for (i in 1..9) {
        if (n % i == 0 && n / i in 1..9) {
            println("Yes")
            return
        }
    }
    println("No")
}

Measured memory_bytes: 31384
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    now = 0
    ans = 0
    for i in range(n):
        if now <= A[i]:
            now = A[i]
        else:
            ans += abs(now-A[i])
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 32852
# -*- coding: utf-8 -*-
#import time

def check(ary, m, x):
  for i in range(1, m+1):
    if ary[i] < x:
      return False
  return True


#
#

n, m, x = map(int, input().split())

#start = time.time()

ans = -1
records = []
for i in range(0, n):
  ary = list(map(int, input().split()))

  if 0 < ans and ans <= ary[0]:
    continue

  next_records = []

  if check(ary, m, x):
    ans = ary[0]
  else:
    next_records.append(ary)

  for rec in records:
    if 0 < ans and ans <= ary[0] + rec[0]:
      continue
    dst = [ ary[i] + rec[i] for i in range(0, m+1)]
    if check(dst, m, x):
      ans = dst[0]
    else:
      next_records.append(dst)

  if i == n - 1:
    break

  if ans < 0:
    records = records + next_records
  else:
    new_records = []
    for rec in records:
      if rec[0] < ans:
        new_records.append(rec)
    for rec in next_records:
      if rec[0] < ans:
        new_records.append(rec)
    records = new_records

  #print(records)

print(ans)

#elapsed_time = time.time() - start
#print("elapsed_time:{0}".format(elapsed_time) + "[sec]")

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

int main() {
	string s;
	cin >> s;

	int d[4] = { 0 };
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'N') { ++d[0]; }
		if (s[i] == 'W') { ++d[1]; }
		if (s[i] == 'S') { ++d[2]; }
		if (s[i] == 'E') { ++d[3]; }
	}

	bool can = true;
	if (d[0] > 0) {
		if (d[2] == 0) { can = false; }
	}
	if (d[2] > 0) {
		if (d[0] == 0) { can = false; }
	}
	if (d[1] > 0) {
		if (d[3] == 0) { can = false; }
	}
	if (d[3] > 0) {
		if (d[1] == 0) { can = false; }
	}

	if (can) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    static int[] balls = new int[10];
    
    static boolean order(int i,int B,int C) {
        if(i<10) {
            if(balls[i]>B) {
                return order(i+1,balls[i],C);
            }
            if(balls[i]>C) {
                return order(i+1,B,balls[i]);
            }
            if(balls[i]<=B && balls[i]<=C){
               return false;
            }
        }
       return true;
    }
    
   public static void main(String[] args) {
       try(Scanner sc = new Scanner(System.in)){
           int n = sc.nextInt();
           for(int i=0;i<n;i++) {
               for(int j=0;j<10;j++) {
                   balls[j] = sc.nextInt();
               }
               if(order(0,0,0)) {
                   System.out.println("YES");
               }else {
                   System.out.println("NO");
               }
           }
       }
   }
}


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

long long n;
vector<long long>a;

long long solve();

int main() {
    cin >> n;
    a.resize(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    cout << solve() << endl;
    return 0;
}

long long solve(){
    long long ans = 0,cnt = 0,x = abs(a[0]);
    for(int i = 0;i < n;++i){
        if(a[i] < 0){
            ++cnt;
            a[i] *= -1;
        }
        ans += a[i];
        x = min(a[i],x);
    }
    if(cnt % 2 == 0)return ans;
    return ans - 2 * x;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size() <= k){
        cout << s << endl;
    }else{
        for(ll i = 0; i < k; i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	int ans = (10000 - N) % 1000;
	cout << ans << endl;
}







Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x%MOD + MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n; cin >> n;
    if (n < 2) OUT(0)
    else {
        int ans = mod(0LL + modpow(10,n) - modpow(9,n) - modpow(9,n) + modpow(8,n));
        cout << ans << '\n';
    }

    return 0;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  string S[60];
  for(int i=0;i<H;i++) cin >>S[i];
  int count[60][60];
  for(int i=0;i<60;i++)
    for(int j=0;j<60;j++)
      count[i][j]=0;
  //隣接する黒マスカウント
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i].at(j)=='#'){
      	count[i][j+1]++;
        count[i+2][j+1]++;
        count[i+1][j]++;
        count[i+1][j+2]++;
      }
        
    }
  }
  //黒マスが独立しているときかけない
  bool flag=true;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i].at(j)=='#')
        if(count[i+1][j+1]==0){
          flag=false;
          break;
        }
    }
  }
  //出力
  if(flag){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256