akhauriyash/Code-Regression huggingface dataset:
n=int(input())
lst=[]
for i in range(n):
    a=int(input())
    lst.append([list(map(int,input().split())) for _ in range(a)])

ans=0
for i in range(2**n):
    s=bin(i)[2:].zfill(n)  #[2:]はbinにしたときに最初につく0bをのぞく．zfillはn桁の0埋め．
    f=True
    for j,k in enumerate(lst):  #kは証言，jはそれを言った人の番号
        for x,y in k:   #xは人番号なので，インデックスのときは-1する
            if s[x-1]!=str(y) and s[j]=='1':    #仮定したsとjの人の証言を照らし合わせる．jの人が不親切という仮定の時，証言に意味はないので無視．
                f=False                                #仮定と証言で一致しないものがあったとき，flagを消す．
    if f:                                   #全ての証言と照らし合わせてもokのとき，仮定したsは正しい．
        ans=max(ans,s.count('1'))   #ansを更新
print(ans) 


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

int main(){
    string S; cin >> S;
    vector<int> values(26);
    for (int i = 0; i < S.size(); i++)
    {
        values.at(S.at(i) - 'a') = 1;
    }

    char ans;
    for (int i = 0; i < values.size(); i++)
    {
        if(values.at(i) != 1){
            ans = 'a' + i;
            cout << ans << endl;
            return 0;
        } 
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type edge struct {
	to    int
	value int
}

var edges [][]edge
var vertex []int
var visited []bool

func fillNumber(x int) {
	visited[x] = true
	for _, e := range edges[x] {
		if !visited[e.to] {
			vertex[e.to] = vertex[x] + e.value
			fillNumber(e.to)
		} else if vertex[e.to] != vertex[x]+e.value {
			fmt.Println("No")
			os.Exit(0)
		}
	}
}

func main() {
	in := IOInitialize()
	n, m := Int(in), Int(in)

	if m == 0 || m == 1 {
		fmt.Println("Yes")
		return
	}

	edges = make([][]edge, n)
	for i := range edges {
		edges[i] = make([]edge, 0, 8)
	}

	for i := 0; i < m; i++ {
		l, r, d := Int(in)-1, Int(in)-1, Int(in)
		edges[l] = append(edges[l], edge{to: r, value: d})
		edges[r] = append(edges[r], edge{to: l, value: -d})
	}

	vertex = make([]int, n)
	visited = make([]bool, n)

	for i := range visited {
		if !visited[i] {
			visited[i] = true
			fillNumber(i)
		}
	}
	fmt.Println("Yes")
}

//////////
//
//

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


Measured memory_bytes: 72704
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int h[123456], N, A, B;

bool possible(LL total) {
	LL use = total;
	LL dif = A - B;
	FOR (i, N) {
		LL tmp = h[i];
		tmp -= 1LL * total * B;
		if (tmp > 0LL) {
			int cnt = (tmp + dif - 1LL) / dif;
			use -= cnt;
			if (use < 0LL)
				return false;
		}
	}
	return true;
}

int main() {
	scanf("%d %d %d", &N, &A, &B);
	FOR (i, N)
		scanf("%d", &h[i]);
	LL s = 1, e = 1000000000, mid;
	LL ret = -1;
	while (s <= e) {
		mid = (s + e) >> 1;
		if (possible(mid)) {
			ret = mid;
			e = mid - 1;
		}
		else
			s = mid + 1;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main (void) {
    int faces1[6], faces2[6];
    int top, label;
    int sheet[6][7] = {{2, 3, 5, 4, 2, 3, 5},
                       {1, 4, 6, 3, 1, 4, 6},
                       {1, 2, 6, 5, 1, 2, 6},
                       {1, 5, 6, 2, 1, 5, 6},
                       {1, 3, 6, 4, 1, 3, 6},
                       {2, 4, 5, 3, 2, 4, 5}};

    for (int i=0; i<6; i++) scanf ("%d", faces1+i);
    for (int i=0; i<6; i++) scanf ("%d", faces2+i);
    
    for (int i=0; i<6; i++) {
        if (faces1[0]==faces2[i] && faces1[5]==faces2[5-i]) {
            top = i+1;
            for (int j=0; j<4; j++) {
                if (faces1[1]==faces2[sheet[top-1][j]-1]) {
                    for (int k=0; k<4; k++) {
                        if (faces1[sheet[0][k]-1]!=faces2[sheet[top-1][j+k]-1]) break;
                        if (k==3) {
                            printf ("Yes\n");
                            return 0;
                        }
                    }
                }
            }
        }
    }
    
    printf ("No\n");
    return 0;
}




Measured memory_bytes: 2084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iK = int.Parse(sS[1]);
            List<string> lstHet = new List<string>();
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < sS.Length; i++) { lstHet.Add(sS[i]); }           // 嫌いな数字

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = iN;
            while (true)
            {
                string sOut = iOut.ToString();
                Boolean bHet = false;
                for (int i = 0; i < sOut.Length; i++) { if (lstHet.Contains(sOut.Substring(i, 1))) { bHet = true; break; } }    // 嫌いな数字ある
                if (!bHet && iOut >= iN) { break; }                                                                             // OK
                iOut += 1;                                                                                                      // ＋１
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 15200
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a,b;
    char op;
    cin >> a >> op >> b;
    if(op == '+'){
        cout << a + b << endl;
    }else{
        cout << a - b << endl;
    }
}

Measured memory_bytes: 256
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
 
using namespace std;
 
#define ll long long
const int N = (ll)(2e5) + 100;

int a[N + 1];

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

int lcm (int a, int b) {
    return a / gcd (a, b) * b;
}
 

void solve() {
    int n;cin >> n;
    int a[n + 1];
    for (int i = 1;i <= n;i ++) cin >> a[i];
    sort (a + 1, a + 1 + n);
    cout << abs(a[n] - a[1]);
}
 
int main() {
    solve();
    return 0;
}

// 41 59 31
// 59 41 31
// 31 41 59


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

#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
const ll N=2e3+5,inf=1e18;

ll vis[N],dis[N];
	vll G[N];
	ll ans[N];
ll dfs(ll a,ll d)
{
	vis[a]=1;
	dis[a]=d;
	queue<ll> q;
	q.push(a);
	dis[a]=0;
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		lp(i,0,G[x].size())
		{
			if(!vis[G[x][i]])
			{
				q.push(G[x][i]);
				vis[G[x][i]]=1;
				dis[G[x][i]]=dis[x]+1;
			}
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n,x,y;
	cin >> n >> x >> y;
	lp(i,0,n-1)
	{
		G[i].pb(i+1);
		G[i+1].pb(i);
	}
	x--;
	y--;
	G[x].pb(y);	
	G[y].pb(x);	
	lp(i,0,n)
	{
		memset(vis,0,sizeof(vis));
		dfs(i,0);
		lp(i,0,n)
		{
			ans[dis[i]]++;
		}
	}   
	lp(i,1,n)
	{
		cout<<ans[i]/2<<endl;
	} 	
	return 0;
}

Measured memory_bytes: 384
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import Data.Ord

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine
getIntListN n = map readInt <$> replicateM (fromIntegral n) BS.getLine

printing (x : xs) ma ma2 = do
  if x /= ma
    then print ma
    else print ma2
  when (xs /= []) $ printing xs ma ma2

main = do
  n <- getInt
  as <- getIntListN n
  let as' = sortOn Data.Ord.Down as
  let ma = head as'
  let ma2 = head (tail as')
  printing as ma ma2


Measured memory_bytes: 69244
/** Bismillahir Rahmanir Rahim **/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define Fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define print(x) cout << "x " << x;

char ch[20][20];
vector<pair<int, int> > v;
int tx[] = {1, -1, 0, 0};
int ty[] = {0, 0, 1, -1};

int bfs(int r, int c, int x, int y) {
    // cout << x << " " << y << endl;
    int vis[r][c];
    for (int i = 0; i < r; i++) 
        for (int j = 0; j < c; j++)
            vis[i][j] = INT_MAX;

    queue<pair<int, int> > q;
    q.push({x, y});
    vis[x][y] = 0;
    
    while (q.size() != 0) {
        int px = q.front().first;
        int py = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
            x = px + tx[i];
            y = py + ty[i];

            if (x >= 0 and x < r and y >= 0 and y < c) {
                if (ch[x][y] == '.' and vis[x][y] == INT_MAX) {
                    q.push({x, y});
                    vis[x][y] = vis[px][py] + 1;
                }
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if (vis[i][j] != INT_MAX and vis[i][j] > mx) {
                mx = vis[i][j];
            }
        }
    }
    return mx;
}

int main()
{
    int r, c;
    cin >> r >> c;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> ch[i][j];
            if (ch[i][j] == '.') v.pb({i, j});
        }
    }
    int mx = 0;
    for (int i = 0; i < v.size(); i++) {
        mx = max(mx, bfs(r, c, v[i].first, v[i].second));
    }

    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 256
ll = [list(map(int,input().split())) for _ in range(int(input()))]
x,y,h = list(filter(lambda k:k[2],ll))[0]
for cx in range(101):
  for cy in range(101):
    ch = h+abs(x-cx)+abs(y-cy)
    if all(max(ch-abs(x-cx)-abs(y-cy),0)==h for x,y,h in ll): print(cx,cy,ch); exit()

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

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


Measured memory_bytes: 3628
from math import *


def read(): return list(map(int, input().split()))

def f(a, b):
    return max(len(str(a)), len(str(b)))


n = int(input())
ans = 114514
for a in range(1, int(sqrt(n)) + 1):
    if n % a != 0: continue
    b = n // a
    ans = min(ans, f(a, b))

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std; 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define forin(i, n) for ( int i = 0; i < (int)n; ++i )
typedef long long ll;
const char nl = '\n';

vector<ll> nums;
int main()
{
    //IOS
    
    int n; cin >> n;
    ll resp = 1;
    nums.resize(n); bool cero = false;
    forin(i, n)
    {
        cin >> nums[i];
        if ( nums[i] == 0 ) cero = true;
    }

    if (cero) cout << '0' << nl;
    else
    {
        forin(i, n)
        {
            if ( nums[i] <= ( 1000000000000000000 / resp ) )
            {
                resp = resp * nums[i];
            }
            else
            {
                printf("-1");
                return 0;
            }
        }
        cout << resp << nl;
    }
    
    return 0;
}


Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

ll dp[100], bstX[35000][20], bstY[35000][20];

int main()
{
    fastInp;

    ll n;
    cin >> n;
    
    vector<tuple<ll, ll, ll>> hs;
    for (int i = 0; i < n; i++) {
        ll x, y, p;
        cin >> x >> y >> p;
        hs.push_back({x, y, p});
    }

    ll pw = (1ll << n);
    for (int m = 0; m < pw; m++) {
        for (int i = 0; i < n; i++) {
            ll bst = abs(get<0>(hs[i]));
            for (int j = 0; j < n; j++) {
                if ((m >> j) & 1) {
                    bst = min(bst, abs(get<0>(hs[i]) - get<0>(hs[j])));
                }
            }
            bstX[m][i] = bst;
        }
    }

    for (int m = 0; m < pw; m++) {
        for (int i = 0; i < n; i++) {
            ll bst = abs(get<1>(hs[i]));
            for (int j = 0; j < n; j++) {
                if ((m >> j) & 1) {
                    bst = min(bst, abs(get<1>(hs[i]) - get<1>(hs[j])));
                }
            }
            bstY[m][i] = bst;
        }
    }

    vector<ll> bst(n + 1);
    for (int i = 0; i <= n; i++) bst[i]  = INF;
    for (int m = 0; m < pw; m++) {
        ll vl = INF, cnt = 0;
        for (int s=m; ; s=(s-1)&m) {
            ll cur = 0;
            for (int i = 0; i < n; i++) {
                if ((m >> i) & 1) continue;
                
                ll d = min(abs(get<0>(hs[i])), abs(get<1>(hs[i])));

                ll xr = (m ^ s);
                d = min(bstX[xr][i], bstY[s][i]);

                cur += d * get<2>(hs[i]);
            }
            vl = min(vl, cur);
	        if (s==0)  break;
        }

        for (int i = 0; i < n; i++) {
            if ((m >> i) & 1ll) cnt++;
        }

        bst[cnt] = min(bst[cnt], vl);
    }

    bst[n] = 0;
    for (auto cur : bst) {
        cout << cur << "\n";
    }
    return 0;
}

Measured memory_bytes: 13856
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
D = [LIST() for _ in range(N)]

cnt = 0
for x, y in D:
	if x == y:
		cnt += 1
		if cnt == 3:
			print("Yes")
			break
	else:
		cnt = 0
else:
	print("No")

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

int s, n, t, m, p;

bool minutes[7 * 24 * 60];

int wbits, tbits;

double ck(int start){
  int cnt = 0;
  for(int i = 0; i < m; i++, start += t){
    bool flag = true;
    for(int j = 0; j <= s; j++){
      if(!minutes[(start + j) % (7 * 24 * 60)]){
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return( 1.0 - pow( 1.0 - 1.0/p, (double)cnt * n));
}


inline int todays(int i){
  return(i / (24 * 60));
}
inline bool totime(int i){
  int tm = i % (24 * 60) / 24;
  return(tm >= 18 || tm < 6);
}

int main(){
  string weekday, time ;
  while( cin >> s >> n >> t >> weekday >> time >> p >> m, m){
    if(weekday == "All") wbits = (1 << 7) - 1;
    else wbits = 1 ;
    if(time == "Night") tbits = 1;
    else if(time == "Day") tbits = 2;
    else tbits = 3; 

    double ans = 0.0;
    for(int i = 7 * 24 * 60 - 1; i >= 0; i--){
      minutes[i] = false;
      if((wbits & (1 << i/1440)) == 0) continue;
      if((tbits & (1 << ((i/360+1)%4/2))) == 0) continue;
      minutes[i] = true;
    }

    for(int i = 24 * 60 - 1; i >= 0; i--){
      ans = max( ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}

Measured memory_bytes: 1344
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define mp make_pair
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;
int lb(ll a[], int low, int high, ll x){
    int ans = -1;
    while(low <= high){
        int mid = (low + high) / 2;
        if(a[mid] <= x){
            ans = mid;
            low = mid + 1;
        }
        else
            high = mid - 1;
    }
    return ans;
}
int ub(ll a[], int low, int high, ll x){
    int ans = -1;
    while(low <= high){
        int mid = (low + high) / 2;
        if(a[mid] >= x){
            ans = mid;
            high = mid - 1;
        }
        else
            low = mid + 1;
    }
    return ans;
}
int main(){
    FASTIO
    int a, b, q;
    cin >> a >> b >> q;
    ll s[a], t[b];
    rep(i, 0, a)
    cin >> s[i];
    rep(i, 0, b)
    cin >> t[i];
    while(q--){
        ll x;
        cin >> x;
        int ls = lb(s, 0, a - 1, x), lt = lb(t, 0, b - 1, x);
        int rs = ub(s, 0, a - 1, x), rt = ub(t, 0, b - 1, x);
        ll ans = LLONG_MAX;
        if(ls != -1 && lt != -1)
        ans = min(ans, x - min(s[ls], t[lt]));
        if(rs != -1 && rt != -1)
        ans = min(ans, max(s[rs], t[rt]) - x);
        if(ls != -1 && rt != -1)
        ans = min(ans, min(2LL * (x - s[ls]) + t[rt] - x, 2LL * (t[rt] - x) + x - s[ls]));
        if(lt != -1 && rs != -1)
        ans = min(ans, min(2LL * (x - t[lt]) + s[rs] - x, 2LL * (s[rs] - x) + x - t[lt]));
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std ;

typedef long long LL ;
const int N=2e5+10 ;

char s[N] , t[N] ;
int nxt[N][26] ;
int n , m ;
int main ()
{
	int i , j ;
	scanf(" %s %s ",s+1,t+1);
	n=strlen(s+1),m=strlen(t+1);
	for ( i=1 ; i<=n ; i++ ) s[i+n]=s[i];
	for ( i=2*n ; i>=0 ; i-- )
		for ( j=0 ; j<=25 ; j++ )
			if ( s[i+1]==j+'a' ) nxt[i][j]=i+1;
			else nxt[i][j]=nxt[i+1][j];
	// for ( i=0 ; i<=n ; i++,puts("") )
	// 	for ( j=0 ; j<=25 ; j++ ) printf("%d ",nxt[i][j]);
	LL res=0 ;
	for ( j=0,i=1 ; i<=m ; i++ )
		if ( !nxt[j][t[i]-'a'] ) return puts("-1")*0;
		else
		{
			// printf("%d -> %d\n",j,nxt[j][t[i]-'a']);
			res+=nxt[j][t[i]-'a']-j;
			j=(nxt[j][t[i]-'a']-1)%n+1;
		}
	printf("%lld\n",res);
	return 0 ;
}


Measured memory_bytes: 20864
#include <stdio.h>
#include <bits/stdc++.h>
#define endl "\n"
#define si(a) scanf("%d ",&a);
#define si2(a,b) scanf("%d %d ",&a,&b);
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sll(a) scanf("%lld ",&a);
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sf(a) scanf("%f ",&a);
#define sd(a) scanf("%lf ",&a);
#define sc(a) scanf("%c ",&a);
#define ss(a) scanf("%s ",a);
#define sf2(a,b) scanf("%f %f ",&a,&b);
#define sd2(a,b) scanf("%lf %lf ",&a,&b);
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define forq(i,q,n) for(int i=q;i<n;i++)
#define form(i,n) for(int i=n;i>=0;i--)
#define forp(i,q,n) for(int i=q;i>=n;i--)
#define fi first
#define se second
#define INF 1000000010
#define MOD 1000000007
#define MAXN
#define LL long long int
     
     
using namespace std;
     
int x, y;
     
void init()
{
    si2(x, y);
    if(x == 2 and y == 2) { printf("Yes\n");} 
    else if((x == 4 or x == 6 or x == 9 or x == 11) and (y == 4 or y == 6 or y == 9 or y == 11)) { printf("Yes\n");}
    else if((x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12) and (y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12)){
    	printf("Yes\n");

    }
    else {
    	printf("No\n");
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
      //  freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
    #endif
    init();
    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    long long A[N];
    for (int i=0; i<N; i++) cin >> A[i];
    long long sum1=0;
    long long count1=0;
    for (int i=0; i<N; i++){
       sum1+=A[i];
       if (i%2==0 && sum1<=0){
           count1+=(1-sum1);
           sum1=1;
       }
       if (i%2==1 && sum1>=0){
           count1+=(sum1+1);
           sum1=-1;
       }
    }
    long long sum2=0;
    long long count2=0;
    for (int i=0; i<N; i++){
        sum2+=A[i];
        if (i%2==0 && sum2>=0){
            count2+=(sum2+1);
            sum2=-1;
        }
        if (i%2==1 && sum2<=0){
            count2+=(1-sum2);
            sum2=1;
        }
    }
    cout << min(count1, count2) << endl;
    
}

Measured memory_bytes: 1024
import Data.Bits (xor)
import Data.Bool (bool)

main :: IO ()
main = do
    s <- getLine
    answer $ solve s

type Answer = Bool
answer :: Answer -> IO ()
answer = putStrLn . bool "First" "Second"

solve :: String -> Answer
solve s = inner True s
  where
    h = head s
    inner x ccs
      | null cs   = (h == c) `xor` y
      | otherwise = inner y cs
      where
        (c : cs) = ccs
        y = not x


Measured memory_bytes: 7164
require "set"

class Priority_queue
  attr_accessor :a
  def initialize(max)
    @h = 0
    @a = Array.new(max+1)
    @INF = 1<<30
  end
  
  def max_heapify(i)
    l = 2*i
    r = 2*i+1
    
    if l<=@h && @a[l][0]>@a[i][0]
      largest = l
    else
      largest = i
    end
    
    if r<=@h && @a[r][0] > @a[largest][0]
      largest = r
    end
    
    if largest != i
      @a[i], @a[largest] = @a[largest], @a[i]
      max_heapify(largest)
    end
  end
  
  def extract
    if @h < 1
      return [-@INF]
    end
    
    maxv = @a[1]
    @a[1] = @a[@h]
    @h-=1
    max_heapify(1)
    return maxv
  end
  
  def increase_key(i, key)
    if key[0] < @a[i][0]
      return
    end
    
    @a[i] = key
    
    while i>1 && @a[i/2][0] < @a[i][0]
      @a[i], @a[i/2] = @a[i/2], @a[i]
      i = i/2
    end
  end
  
  def insert(key)
    @h+=1
    @a[@h] = [-@INF]
    increase_key(@h, key)
    
    return key.to_s
  end
end

def is_used?(memo, ary)
  return flag
end

q = Priority_queue.new(3000*3)
memo = Set.new

xmax,ymax,zmax,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
b = gets.split.map(&:to_i).sort.reverse
c = gets.split.map(&:to_i).sort.reverse

q.insert([a[0]+b[0]+c[0], 0, 0, 0])
memo.add([a[0]+b[0]+c[0], 0, 0, 0])

[k,xmax*ymax*zmax].min.times do
  #p q.a
  sum,s,t,u = q.extract
  p sum
  #p [sum,s,t,u]

  if s+1<xmax
    if !memo.include?(key = [a[s+1]+b[t]+c[u],s+1,t,u])
      q.insert(key)
      memo.add(key)
    end
  end
  
  if t+1<ymax
    if !memo.include?(key = [a[s]+b[t+1]+c[u],s,t+1,u])
      q.insert(key)
      memo.add(key)
    end
  end
  
  if u+1<zmax
    if !memo.include?(key = [a[s]+b[t]+c[u+1],s,t,u+1])
      q.insert(key)
      memo.add(key)
    end
  end
end


Measured memory_bytes: 3448
#include <iostream>
#include <iomanip>
#include <string>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    repi(i,n,0){
        if(!(i&1))cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;




set<int> divisors(int x)
{
    set<int> s;
    for(int i = 1; i*i <= x; ++i)
        if(x % i == 0)
            s.insert(i), s.insert(x/i);

    s.erase(1);
    return s;
}

int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int n;
    cin >> n;

    vector<int> v(n);

    bool ok = true;

   	set<int> s;



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

    }




    for(int i = 0; i < n; i++)
    {
    	set<int> s2 = divisors(v[i]);
    	for(auto &j : s2)
    	{
    		if(s.count(j))
    		{
    			ok = false;
    			break;
    		}
    		s.insert(j);
    	}
    	if(!ok)
    	{
    		break;
    	}
    }


 

    if(ok)
    {
    	cout << "pairwise coprime";
    }
    else
    {
    	ok = true;

    	int gc = v[0];

    	for(int i = 1; i < n; i++)
    	{
    		gc = __gcd(gc,v[i]);
    	}

    	if(gc != 1)
    	{
    		ok = false;
    	}

    	if(ok)
    	{
    		cout << "setwise coprime";
    	}
    	else
    	{
    		cout << "not coprime";
    	}

    }




    return 0;
}


Measured memory_bytes: 11004
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1e18;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n, W, V = 0;
    cin >> n >> W;
    
    int w[n], v[n];
    forn(i, 0, n) {
        cin >> w[i] >> v[i];
        V += v[i];
    }
    
    vector<ll> dp(V+1, INF);
    dp[0] = 0;
    forn(i, 0, n) {
        for (int j = V; j >= v[i]; --j) {
            ll a = dp[j];
            ll b = dp[ j-v[i] ] + w[i];
            dp[j] = min(a, b);
        }
    }
    
    for (int j = V; j >= 0; --j) {
        if (dp[j] <= W) {
            cout << j << endl;
            break;
        }
    }
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
const int N = 100010;
int mod = 1000000007;
typedef pair<int, bool> pib;
vector<pib> rec;
int main()
{
//	freopen("in.txt", "r", stdin);
	int n, h;
	while (~scanf("%d%d", &n, &h))
	{
		rec.clear();
		for (int i = 0; i < n; i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			rec.push_back(make_pair(-b, 1));
			rec.push_back(make_pair(-a, 0));
		}
		sort(rec.begin(), rec.end());
		int ans = 0;
		for (int i = 0; i < rec.size(); i++)
		{
			if (rec[i].second)
			{
				h -= -rec[i].first;
				ans++;
				if (h <= 0)
					break;
			}else
			{
				rec[i].first = -rec[i].first;
				ans += h/rec[i].first;
				h %= rec[i].first;
				if (h)
					ans++;
				break;
			}
		}
		printf("%d\n", ans);
	}
   	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

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

    int n, t;
    cin >> n >> t;
    vector< P > ab(n);
    rep (i, n)
    {
        cin >> ab[i].first >> ab[i].second;
    }
    // sort(ab.begin(), ab.end());

    int dp1[n + 1][t];
    int dp2[n + 1][t];
    rep (i, n + 1) rep (j, t) { dp1[i][j] = 0; dp2[i][j] = 0; }

    rep (i, n)
    {
        rep (j, t)
        {
            if (j < ab[i].first)
            {
                dp1[i + 1][j] = dp1[i][j];
            }
            else
            {
                dp1[i + 1][j] = MAX(dp1[i][j], dp1[i][j - ab[i].first] + ab[i].second);
            }
        }
    }

    for (int i = n; i >= 1; --i)
    {
        rep (j, t)
        {
            if (j < ab[i - 1].first)
            {
                dp2[i - 1][j] = dp2[i][j];
            }
            else
            {
                dp2[i - 1][j] = MAX(dp2[i][j], dp2[i][j - ab[i - 1].first] + ab[i - 1].second);
            }
        }
    }

    int ans = 0;
    rep (i, n)
    {
        rep (j, t)
        {
            ans = MAX(ans, dp1[i][j] + dp2[i + 1][t - 1 - j] + ab[i].second);
        }
    }


    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 70656
#!/usr/bin/env python3

n_list = []
m_list = []
a_list = []

while True:
    n, m = list(map(int, input().split(' ')))

    if n == 0 and m == 0:
        break

    a = list(map(int, input().split(' ')))

    n_list.append(n)
    m_list.append(m)
    a_list.append(a)


for n, m, a in zip(n_list, m_list, a_list):
    m_sum = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            tmp = a[i] + a[j]
            if m_sum < tmp and tmp <= m:
                m_sum = tmp

    if m_sum > 0:
        print(m_sum)
    else:
        print('NONE')



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

ll a,b,x;
ll CountOfMultiples(ll n) {
	if (n == -1) return 0;
	else return n/x + 1;
}

int main() {
	cin >> a >> b >> x;
	ll ans = CountOfMultiples(b) - CountOfMultiples(a-1);
	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 3620
// AtCoder Regular Contest 062
// E - AtCoDeerくんと立方体づくり / Building Cubes with AtCoDeer

#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#define MAX_N 400
using namespace std;

typedef long long int ll;
typedef vector<int> Tile;


int N;
vector<Tile> tiles;
multiset<Tile> used;
ll ans;

Tile rotate(Tile t) {
  return { t[1], t[2], t[3], t[0] };
}

int main() {

  Tile t1, t2;
  int c;
  ll cnt, tmp;
  vector<Tile>::iterator itr1, itr2;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    Tile t;
    for (int j = 0; j < 4; j++) {
      scanf("%d", &c);
      t.push_back(c);
    }
    tiles.push_back(t);
  }

  sort(tiles.begin(), tiles.end());

  ans = 0;
  for (itr1 = tiles.begin(); itr1 != tiles.end(); itr1++) {
    for (itr2 = itr1, itr2++; itr2 != tiles.end(); itr2++) {
      t1 = *itr1; t2 = *itr2;
      for (int d = 0; d < 4; d++) {
        used.clear();
        used.insert(t1);
        used.insert(t2);
        cnt = 1;
        for (int i = 0; i < 4; i++) {
          tmp = 0;
          Tile t = { t1[(1 + i) % 4], t1[(0 + i) % 4], t2[(4 - i) % 4], t2[(7 - i) % 4] };
          for (int j = 0; j < 4; j++) {
            tmp += upper_bound(tiles.begin(), tiles.end(), t) - lower_bound(tiles.begin(), tiles.end(), t);
            tmp -= used.count(t);
            t = rotate(t);
          }
          tmp = max(tmp, 0LL);
          cnt *= tmp;
          used.insert(t);
        }
        ans += cnt;
        t2 = rotate(t2);
      }
    }
  }

  ans /= 3;
  printf("%lld\n", ans);

  return 0;

}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define MAX_V 10100
struct edge{int to,cap,rev;};
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,int cap){
	G[from].pb((edge){to,cap,G[to].size()});
	G[to].pb((edge){from,0,G[from].size()-1});	
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0&&level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0)flow+=f;
	}
}
int H,W;
string str[104];
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++)cin >> str[i];
	int S = 0,T = H+W+1;
	// 0,1...H,H+1...H+W,H+W+1
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(str[i][j]=='o'){
				add_edge(i+1,H+j+1,1);
				add_edge(H+j+1,i+1,1);
			}
			if(str[i][j]=='S'){
				add_edge(S,i+1,INF);
				add_edge(S,H+j+1,INF);
			}
			if(str[i][j]=='T'){
				add_edge(i+1,T,INF);
				add_edge(H+j+1,T,INF);
			}
		}
	}
	int ans = max_flow(S,T);
	if(ans>=INF)cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main(void)
{
	int N,count=0;
	long long int a[100010];
	long long int min,sum=0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
		if (a[i] < 0) {
			count++;
		}
		if (i == 0) {
			min = abs(a[i]);
		}
		if (abs(a[i]) < min) {
			min = abs(a[i]);
		}
		sum += abs(a[i]);
	}
	if (count % 2 == 0) {
		printf("%lld", sum);
		return 0;
	}
	else {
		printf("%lld", sum - 2*min);
		return 0;
	}
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define fo(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    ll n,i,j,k,t,a[10]={0};

    cin>>n;

    fo(i,n)
    {
        cin>>j;
        if(j>=1 && j<=399)
            a[0]=1;
        if(j>=400 && j<=799)
            a[1]=1;
        if(j>=800 && j<=1199)
            a[2]=1;
        if(j>=1200 && j<=1599)
            a[3]=1;
        if(j>=1600 && j<=1999)
            a[4]=1;
        if(j>=2000 && j<=2399)
            a[5]=1;
        if(j>=2400 && j<=2799)
            a[6]=1;
        if(j>=2800 && j<=3199)
            a[7]=1;
        if(j>=3200)
            a[8]++;
    }

    ll sum=0;
    fo(i,8)
        sum+=a[i];

    if(sum==0)
    {
        sum++;
        a[8]--;
    }
    cout<<sum<<" "<<sum+a[8];

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int V;
vector<int>G[10000],rG[10000],vs;
bool used[10000];
int cmp[10000];

void add_edge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    if(!used[G[v][i]])dfs(G[v][i]);
  }
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]])rdfs(rG[v][i],k);
  }
}

int scc(void){
  fill(used,used+V,0);
  vs.clear();
  for(int v=0;v<V;v++)if(!used[v])dfs(v);

  fill(used,used+V,0);
  int k=0;
  for(int i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]])rdfs(vs[i],k++);
  }
  return k;
}

int main(void){
  int m,q,a,b;

  cin >> V >> m;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    add_edge(a,b);
  }

  scc();

  cin >> q;
  for(int i=0;i<q;i++){
    cin >> a >> b;
    cout << (cmp[a]==cmp[b]) << endl;
  }

  return 0;
}

Measured memory_bytes: 2780
#include <bits/stdc++.h>
using namespace std;
const int oo=-10;
int n,m,a[52][52];
char c;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>c;
            if(c=='#')
            {
                a[i][j]=oo;
                a[i-1][j-1]++;
                a[i-1][j]++;
                a[i-1][j+1]++;
                a[i][j-1]++;
                a[i][j+1]++;
                a[i+1][j-1]++;
                a[i+1][j]++;
                a[i+1][j+1]++;
            }
        }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            if(a[i][j]<0)cout<<"#";
            else cout<<a[i][j];
        cout<<endl; 
    }   
}

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

string s, t;
string str = "abcd";

int operate(int a, int b, char op){
    if(op == '+') return a | b;
    if(op == '*') return a & b;
    return a ^ b;
}

int calchash(string r){
    string s2 = s;
    stack<string> st;
    rep(i, 0, s.size()){
        size_t pos = str.find(s[i]);
        if(pos == string::npos) continue;
        s2[i] = r[pos];
    }
    // cout << s2 << endl;
    rep(i, 0, s.size()){
        if(isdigit(s2[i]) || s2[i] == '*' || s2[i] == '^' || s2[i] == '+'){
            string ts = "";
            ts += s2[i];
            st.push(ts);
        }else if(s2[i] == ']'){
            string a = st.top(); st.pop();
            string b = st.top(); st.pop();
            string op = st.top(); st.pop();
            int numa = stoi(a);
            int numb = stoi(b);
            char cop = op[0];
            int tmp = operate(numa, numb, cop);
            string ts = "";
            ts += to_string(tmp);
            st.push(ts);
        }
    }
    int res = stoi(st.top());
    return res;
}

int main(){
    while(1){
        cin >> s;
        if(s == ".") break;
        cin >> t;
        int ans = calchash(t);
        int cnt = 0;
        rep(i, 0, 10000){
            string tmp = to_string(i);
            while(tmp.size() < 4) tmp = "0" + tmp;
            if(calchash(tmp) == ans) cnt++;
        }
        cout << ans << " " << cnt << endl;
    }
}


Measured memory_bytes: 3240
from collections import deque

N=int(input())
S=input()

left=deque([0])
right=[0]
for i in range(N):
  if S[i]=='W':plus=1
  else:plus=0
  left.append(left[-1]+plus)
  if S[-i-1]=='E':plus=1
  else:plus=0
  right.append(right[-1]+plus)
  
left.popleft()
right = right[::-1]
right.pop()

print(min([left[i]+right[i] for i in range(N)])-1)

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;

signed main(){
    string s;
    cin >> s;
    vector<vector<vector<vector<vector<vector<i64>>>>>> dp;
    dp.resize(s.size()+1);
    for(i64 i = 0;i < s.size() + 1;i++){
        dp.at(i).resize(10);
        for(i64 j = 0;j < 10;j++){
            dp.at(i).at(j).resize(10);
            for(i64 k = 0;k < 10;k++){
                dp.at(i).at(j).at(k).resize(10);
                for(i64 l = 0;l < 10;l++){
                    dp.at(i).at(j).at(k).at(l).resize(2);
                    for(i64 m = 0;m < 2;m++){
                        dp.at(i).at(j).at(k).at(l).at(m).resize(2, 0);
                    }
                }
            }
        }
    }

    dp[0][0][0][0][0][1] = 1;

    for(i64 i = 0; i < s.size(); ++i){
        for(i64 j = 0; j < 10; ++j){
            for(i64 k = 0; k < 10; ++k){
                for(i64 l = 0; l < 10; ++l){
                    for(i64 mit = 0; mit < 2; ++mit){
                        if(!dp[i][j][k][l][mit][0] && !dp[i][j][k][l][mit][1])
                            continue;
                        for(i64 nex = 0; nex < 10; ++nex){
                            bool fl = mit | (j == 5 && k == 1 && nex == 3);
                            if(s[i] - '0' > nex){
                                dp[i + 1][k][l][nex][fl][0] += dp[i][j][k][l][mit][1];
                            }else if(s[i] - '0' == nex){
                                dp[i + 1][k][l][nex][fl][1] += dp[i][j][k][l][mit][1];
                            }else{
                            }
                            dp[i + 1][k][l][nex][fl][0] += dp[i][j][k][l][mit][0];
                        }
                    }
                }
            }
        }
    }

    i64 ans = 0;
    for(i64 j = 0; j < 10; ++j)
        for(i64 k = 0; k < 10; ++k)
            for(i64 l = 0; l < 10; ++l)
                for(i64 fl = 0; fl < 2; ++fl){
                    ans += dp[s.size()][j][k][l][1][fl];
                    // ans += dp[s.size()][j][k][l][0][fl];
                }

    cout << ans << endl;
}



Measured memory_bytes: 6068
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

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

    ll a, b, k;
    cin >> a >> b >> k;

    cout << max(0ll, a - k) << endl;
    cout << max(0ll, min(b, a + b - k)) << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    a, b = mi()
    print(max(a+b, a-b, a*b))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <cstdlib>
using namespace std;
typedef long long ll;

int digit_sum(ll N){
  int cnt = 0;
  while(N>0){
    cnt += N%10;
    N /= 10;
  }
  return cnt;
}
int main(){
  int N;
  cin >> N;
  if(N%digit_sum(N)==0) cout << "Yes" <<endl;
  else cout << "No" <<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cassert>
using namespace std;
string data;
const char *str;
int parse(int i){
	if('0'<=data[i]&&data[i]<='9')return strtol(str+i,NULL,10)/2+1;
	assert(data[i]=='[');
	vector<int>v;
	int j=i,c=0;
	for(;;j++){
		if(data[j]=='[')if(++c==1)v.push_back(parse(j+1));
		if(data[j]==']')if(--c==-1)break;
	}
	sort(v.begin(),v.end());
	for(c=j=0;j<=v.size()/2;j++)c+=v[j];
	return c;
}
main(){
	int T;
	for(cin>>T,getline(cin,data);T--;cout<<parse(1)<<endl)getline(cin,data),str=data.c_str();
}

Measured memory_bytes: 1284