akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
const ll maxn =100001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}
using cd = complex<ld>;
const ld PI = acos(-1);
 
void fft(vector<cd> & a, bool invert) {
    ll n = a.size();
    if (n == 1)
        return;
 
    vector<cd> a0(n / 2LL), a1(n / 2LL);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2LL*i];
        a1[i] = a[2LL*i+1LL];
    }
    fft(a0, invert);
    fft(a1, invert);
 
    ld ang = 2LL * PI / n * (invert ? -1LL : 1LL);
    cd w(1LL), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}
 
vector<ll> multiply(vector<ll> const& a, vector<ll> const& b) {
vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
ll n = 1;
while (n < a.size() + b.size()) 
    n <<= 1;
fa.resize(n);
fb.resize(n);

fft(fa, false);
fft(fb, false);
for (int i = 0; i < n; i++)
    fa[i] *= fb[i];
fft(fa, true);

vector<ll> result(n);
for (int i = 0; i < n; i++)
    result[i] = round(fa[i].real());
return result;
}

int main()
{
  
  IOS

  ll n,m;
  cin>>n>>m;
  vl a(maxn);

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

  }
  vl b=a;
  vl c=multiply(a,b);
  ll tot=0,cur=0;
  for(ll i=c.size()-1;i>=0;i--)
  {
    tot+=(min(c[i],m-cur))*i;
    cur+=(min(c[i],m-cur));
    if(cur==m)
      break;

  }
  cout<<tot<<" ";




}

Measured memory_bytes: 36772
#include<bits/stdc++.h>
using namespace std;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int K;
char S[17];
int main(){
  int i, res=0;
  K = rd(S);
  for(i=0;i<K;i++){
    if(S[i]=='x'){
      res++;
    }
  }
  if(res<=7){
    wt_L("YES");
    wt_L('\n');
  }
  else{
    wt_L("NO");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190609-1

// --- original code ---
// int K; char S[17];
// {
//   int i, res = 0;
//   rd(S@K);
//   rep(i,K) if(S[i]=='x') res++;
//   wt( if[res<=7, "YES", "NO"] );
// }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int[] arr = new int[n];

        for (int i = 0; i < m; i++) {
            int num = sc.nextInt();
            arr[num - 1]++;
            num = sc.nextInt();
            arr[num - 1]++;
        }

        sc.close();

        for (int i = 0; i < n; i++) {
            System.out.println(arr[i]);
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 200010
#define inf 1000000007
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char s[maxn];
int col[maxn],fa[maxn],size[maxn];
int d[7][maxn];
int n;
int head[maxn],nxt[maxn*2],to[maxn*2],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
ll ans=0;
void dfs1(int x,int las)
{
    fa[x]=las;size[x]=col[x];
    if(!nxt[head[x]]&&x!=1)
    {
        d[1][x]=0;
        if(col[x])  d[3][x]=0;
        else        d[3][x]=inf;
        return;
    }
    int mx=0,mx2=inf;
    for(int i=head[x];i;i=nxt[i])
    {
        if(to[i]==las)  continue;
        int v=to[i];
        dfs1(v,x);
        size[x]+=size[v];
        mx=max(mx,d[1][v]);
        if(d[3][v]<inf)  mx2=min(mx2,d[1][v]);
    }
    d[1][x]=mx+1;d[3][x]=mx2+1;
    if(col[x])  d[3][x]=min(d[3][x],d[1][x]);
}
int p[maxn],top;
int pre[maxn],suf[maxn];
void dfs2(int x,int las)
{
    d[2][x]=max(d[2][x],(las!=0)+d[2][las]);
    if(las)  d[5][x]=max(d[5][x],d[2][x]-1);
    top=0;
    for(int i=head[x];i;i=nxt[i])
    {
        if(to[i]==las)  continue;
        p[++top]=to[i];
    }
    pre[0]=suf[top+1]=-1;
    for(int i=1;i<=top;i++)  pre[i]=max(pre[i-1],d[1][p[i]]);
    for(int i=top;i>=1;i--)  suf[i]=max(suf[i+1],d[1][p[i]]);
    for(int i=1;i<=top;i++)  d[2][p[i]]=max(d[2][p[i]],max(pre[i-1],suf[i+1])+2);
    for(int i=head[x];i;i=nxt[i])
    {
        if(to[i]==las)  continue;
        dfs2(to[i],x);
    }
}
int main()
{
    n=read();
    memset(d[3],125,sizeof(d[3]));
    memset(d[4],125,sizeof(d[4]));
    for(int i=1;i<n;i++)
    {
        int q=read(),w=read();
        add(q,w);
        add(w,q);
    }
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)  col[i]=s[i]-'0';
    int flag=0;
    for(int i=1;i<=n;i++)  flag|=col[i];
    if(!flag)
    {
        puts("0");
        return 0;
    }
    if(n==1)
    {
        puts("1");
        return 0;
    }
    dfs1(1,0);
    dfs2(1,0);
    for(int i=1;i<=n;i++)
    {
        if(col[i])  d[6][i]=0;
        else        d[6][i]=min(d[3][i],(size[i]==size[1])?inf:d[2][i]);
        int tmp=max(d[1][i],d[2][i])-1;
        for(int j=head[i];j;j=nxt[j])
        {
            int v=to[j];
            if(v==fa[i])  tmp=min(tmp,d[1][i]+1);
            else          tmp=min(tmp,d[5][v]+1);
        }
        ans+=max(tmp-d[6][i]+1,0);
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 24320
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void dump(vector<long long> hoge) {
    int n = hoge.size(); for(int i = 0; i < n; ++i){ cout << hoge[i] << " "; } cout << endl;
}

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

    int n;
    cin >> n;

    vector<long long> a(n);
    vector<pair<long long, int>> p;
    p.reserve(n+1);

    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        p.push_back(make_pair(a[i], i));
    }

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

    vector<long long> nums(n);
    for(int i = 0; i < n; ++i){
      int original_ind = p[i].second;
      int rank = i;
      nums[original_ind] = i;
    }

    int l = n-1;
    int amed = p[(l+1)/2].first;
    int bmed = p[(l+1)/2 - 1].first;

    for(int i = 0; i < n; ++i){
      // cout << nums[i] << " ";

      if(nums[i] < (l+1)/2) {
        cout << amed;
      } else {
        cout << bmed;
      }

      cout << endl;
    }

}


Measured memory_bytes: 8448
use std::cmp::{max, min};

fn solve(src: &str) -> String {
    use std::fmt::Write;
    let mut buf = String::new();
    let mut sc = Scanner::from_str(&src);

    let n : usize = sc.read();
    let m : usize = sc.read();
    let edges: Vec<(usize, usize)> =
        (0..m).map(|_| (sc.read::<usize>()-1, sc.read::<usize>()-1)).collect();
    let child = child(true, n, &edges);
    let cycle = any_cycle(n, &child);
    if cycle == None {
        return "-1".to_string()
    }
    let cycle = cycle.unwrap();

    let mut start = 0;
    let mut end = cycle.len();
    let mut index = vec![None; n];
    for i in 1..cycle.len() {
        let v = cycle[i];
        index[v] = Some(i);
        for &w in child[v].iter() {
            if let Some(j) = index[w] {
                start = max(start, j);
                end = i + 1;
            }
        }
        if start != 0 || end != cycle.len() {
            break
        }
    }

    writeln!(&mut buf, "{}", end-start);
    for i in start..end {
        writeln!(&mut buf, "{}", cycle[i] + 1);
    }

    buf
}

fn child(directed: bool, size: usize, edges: &Vec<(usize,usize)>) -> Vec<Vec<usize>> {
    let mut child = vec![Vec::new(); size];
    for &(v, w) in edges.iter() {
        child[v].push(w);
        if !directed {
            child[w].push(v);
        }
    }
    child
}

fn any_cycle(size: usize, child: &Vec<Vec<usize>>) -> Option<Vec<usize>> {
    let mut path = vec![0; size];
    'search: for s in 0..size {
        let mut visited = vec![false; size];
        let mut stack = vec![s];
        let mut depth = vec![0; size];
        let mut s_visited = false;
        while let Some(v) = stack.pop() {
            if v == s {
                if s_visited {
                    path.resize(depth[s], 0);
                    break 'search;
                } else { s_visited = true; }
            }
            path[depth[v]] = v;
            for &w in child[v].iter() {
                if visited[w] { continue; }
                visited[w] = true;
                depth[w] = depth[v] + 1;
                stack.push(w);
            }
        }
        if s == size - 1 {
            return None;
        }
    }
    Some(path)
}

fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf);
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes());
}

struct Scanner<I>{
    src: I
}

impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner { src: src.split_whitespace() }
    }
}

impl<'a, I> Scanner<I> where I: std::iter::Iterator<Item = &'a str>{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int n;
  cin >> n;
  cout << n*n*n << endl;
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    if(a.length()>b.length())
        cout<<"GREATER\n";
    else if(a.length()<b.length())
        cout<<"LESS\n";
    else
    {int eq=0;
        for(int i=0;i<a.length();i++)
        {
            if(a[i]>b[i])
            {
                eq=1;
                break;
            }
            else if(a[i]<b[i])
            {
                eq=-1;
                break;
            }
        }
        if(eq==1)
            cout<<"GREATER\n";
        else if(eq==-1)
            cout<<"LESS\n";
        else
            cout<<"EQUAL\n";

    }
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
s =input()
n =len(s)
count=0
count2=0
for i in range(n):
	if i %2==0:
		x="0"
	else:
		x="1"
	if s[i]==x:
		count2+=1
		#print(i,s[i],x,"OK")
	else:
		count +=1
		#print(i,s[i],x)
print(min(count,count2))

Measured memory_bytes: 3188
#include<iostream>
#include<complex>
#include<queue>

using namespace std;

int main() {
	int n;
	queue<complex<float> > q;
	const complex<float> end(100, 0);
	const complex<float> c3(3, 0),c2(2,0);
	const complex<float> a60(0.5, sqrt(3) / 2.0);
	q.emplace(0, 0);
	q.emplace(100, 0);
	cin >> n;
	complex<float> a, b;
	for (int i = 0;i < n;i++) {
		a = q.front();
		q.pop();
		q.push(a);
		while (a != end) {
			b = q.front();
			q.pop();
			q.push(a + (b - a) /c3);
			q.push(a + (b - a) / c3 + (b - a) * a60 / c3);
			q.push(a + (b - a) * c2 / c3);
			q.push(b);
			a = b;
		}
	}
	while (!q.empty()) {
		cout << q.front().real() << " " << q.front().imag() << endl;
		q.pop();
	}
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<int, int>;

struct Edge {
    int u;
    int v;
    int cost;
};

const int INF = 1<<29;

int main() {
    int n, m, p; cin >> n >> m >> p;
    V<Edge> E(m);
    loop (m, i) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        E[i] = { a, b, p - c };
    }

    V<int> dist(n, INF);
    dist[0] = 0;
    loop (n - 1, i) {
        loop (E.size(), j) {
            auto e = E[j];
            if (dist[e.u] != INF && dist[e.v] > dist[e.u] + e.cost) {
                dist[e.v] = dist[e.u] + e.cost;
            }
        }
    }

    V<int> vis(n);
    vis[n - 1] = 1;
    loop (n - 1, i) {
        loop (E.size(), j) {
            auto e = E[j];
            if (vis[e.v]) vis[e.u] = 1;
        }
    }

    unordered_set<int> pnts;
    loop (n, i) {
        if (dist[i] < INF && vis[i]) pnts.insert(i);
    }
    loop (E.size(), j) {
        auto e = E[j];
        if (dist[e.v] > dist[e.u] + e.cost) {
            if (pnts.count(e.v)) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << max(0, -dist[n - 1]) << endl;
    return 0;
}



Measured memory_bytes: 384
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                Max=max(L[i],L[j],L[k])
                two=L[i]+L[j]+L[k]-Max
                if Max<two:
                    ans+=1

print(ans)

Measured memory_bytes: 9144
<?php
/*
    Problem URL : http://abc050.contest.atcoder.jp/tasks/abc050_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %s %d", $a, $op, $b);

switch ($op) {
    case "+":
        echo $a + $b . PHP_EOL;
        break;

    case "-":
        echo $a - $b . PHP_EOL;
        break;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll memo[2][1005][1005] = {0};
char c;
ll x,y,bw,n,k;

ll solve(){
  ll ans = 1, now[2];
  rep(i,k)rep(j,k)rep(l,2){
    now[l] = memo[l][i][j];
    if(i != k-1 && j != k-1){
      now[l] += memo[l][k-1][k-1];
      now[l] -= memo[l][i][k-1];
      now[l] -= memo[l][k-1][j];
      now[l] += memo[l][i][j];
    }
    now[l] += memo[1-l][k-1][j] - memo[1-l][i][j];
    now[l] += memo[1-l][i][k-1] - memo[1-l][i][j];
    ans = max(ans, now[l]);
  }
  return ans;
}

int main(){
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> x >> y >> c;
    bw = (c == 'B');
    memo[(x/k + y/k + bw)%2][x%k][y%k]++;
  }
  
  rep(l,2)rep(i,k)rep(j,k){
    if(j != 0) memo[l][i][j] += memo[l][i][j-1];
    if(i != 0) memo[l][i][j] += memo[l][i-1][j];
    if(i != 0 && j != 0){
      memo[l][i][j] -= memo[l][i-1][j-1];
    }
  }
  
  cout << solve() << endl;

  return 0;
}

Measured memory_bytes: 16000
N, L = map(int, input().split())
aji = []
for i in range(N):
    aji.append(L + i)
if L >= 0:
    print(sum(aji) - min(aji))
else:
    if max(aji) >= 0:
        print(sum(aji))
    else:
        print(sum(aji) - max(aji))

Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
  int c1, c5, c10, c50, c100, c500;
  scanf("%d %d %d %d %d %d", &c1,&c5,&c10,&c50,&c100,&c500);
  if( c1+c5*5+c10*10+c50*50+c100*100+c500*500 >= 1000)
  {
    printf("1\n");
  }
  else{
    printf("0\n");
  }
  return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    ll h,w,n;
    cin >> h >> w >> n;
    map<pii,int> mp;
    rep(i,0,n){
        int a,b;
        cin >> a >> b;
        mp[make_pair(b,a)]=i;
    }

    auto ok_x=[&](int x){
        return 0<x and x<=w;
    };
    auto ok_y=[&](int y){
        return 0<y and y<=h;
    };
    auto ok=[&](int x,int y){
        return ok_x(x) and ok_y(y);
    };
    const int dx[9]={-1,0,1,-1,0,1,-1,0,1},
              dy[9]={1,1,1,0,0,0,-1,-1,-1};
    int ans[10]={};
    for(const auto &p:mp){
        int x0=p.first.first,y0=p.first.second;
        int idx=p.second;
        rep(x,x0-1,x0+2){
            if(!ok_x(x)) continue;
            rep(y,y0-1,y0+2){
                if(!ok_y(y)) continue;
                bool f=true;
                int count=0;
                rep(i,0,9){
                    int x1=x+dx[i],y1=y+dy[i];
                    if(!ok(x1,y1)){
                        f=false;
                        break;
                    }
                    auto tmp=make_pair(x1,y1);
                    if(mp.find(tmp)==mp.end()) continue;
                    else{
                        if(mp[tmp]<idx){
                            f=false;
                            break;
                        }
                        ++count;
                    }
                }
                if(f) ++ans[count];
            }
        }
    }
    ll ans0=(h-2)*(w-2);
    rep(i,1,10) ans0-=ans[i];
    cout << ans0 << endl;
    rep(i,1,10) cout << ans[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
  
int main() {
  int H, N;
  std::cin >> H >> N;
  bool win = false;
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    if((H -= A) <= 0) win = true;
  }
  std::cout << (win? "Yes": "No") << std::endl;
  return 0;
}


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

#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n_lines, input, n_prime;
	bool isPrime;
	cin >> n_lines;

	n_prime = 0;

	for(int i=0; i<n_lines; i++){
		isPrime = true;
		cin >> input;
		for(int j=2; j<=sqrt(input); j++){
			if(input%j==0){
				isPrime = false;
				break;
			}
		}
		if(isPrime==true){
			n_prime = n_prime + 1;
		}
	}
	cout << n_prime << "\n";

	return 0;
}



Measured memory_bytes: 3068
#include <stdio.h>
#include <string.h>
#include <algorithm>

#define MAX_L 3006

using namespace std;

int f(int a, int b);
void printPath(int x, int y);

char firstInput[MAX_L], secondInput[MAX_L];

int fInputL, sInputL;

int dp[MAX_L][MAX_L];

int main() {

	scanf("%s %s", firstInput, secondInput);

	fInputL = strlen(firstInput);
	sInputL = strlen(secondInput);

	int i, j;
	for(i = 0; i < fInputL+3; i++) {
		for(j = 0; j < sInputL+3; j++) {
			dp[i][j] = -1;
		}
	}

  f(0, 0);

	printPath(0, 0);
	printf("\n");
}

int f(int a, int b) {
	
	if(a == fInputL || b == sInputL)
		return dp[a][b] = 0;

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

	if(firstInput[a] == secondInput[b])
		return dp[a][b] = 1 + f(a+1, b+1);
	
	return dp[a][b] = max(f(a+1, b), f(a, b+1));
}

void printPath(int x, int y) {

	if(x == fInputL || y == sInputL)
		return;

	if(firstInput[x] == secondInput[y] && dp[x][y] -1 == dp[x+1][y+1] ) {
		printf("%c", firstInput[x]);
		printPath(x+1, y+1);
		return;
	}

	if(dp[x+1][y] == dp[x][y]) {
		printPath(x+1, y);
	} else {
		printPath(x, y+1);
	}
}

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAXN = 2e5+1;
string str[2];
int bnd[2], pos[2], n;
map<pair<int,int>, char> chars; // chars[type][dir]


void solve_it(int type) { 
    int x1 = pos[type], x2 = pos[type];
    for (int pref = 0; pref < n; ++pref) {
        if (str[0][pref] == chars[make_pair(type,0)])
            --x1;
        if (x1 < 1) {
            cout << "NO\n";
            exit(0);
        }
        if (str[1][pref] == chars[make_pair(type,1)])
            x1 = min(bnd[type], x1+1);


        if (str[0][pref] == chars[make_pair(type,1)])
            ++x2;
        if (x2 > bnd[type]) {
            cout << "NO\n";
            exit(0);
        }
        if (str[1][pref] == chars[make_pair(type,0)])
            x2 = max(1, x2 - 1);
    }
}


void solve() {
    cin >> bnd[0] >> bnd[1] >> n;
    cin >> pos[0] >> pos[1];
    cin >> str[0] >> str[1];

    chars.insert({make_pair(0,0), 'U'});
    chars.insert({make_pair(0,1), 'D'});
    chars.insert({make_pair(1,0), 'L'});
    chars.insert({make_pair(1,1), 'R'});

    solve_it(0);
    solve_it(1);

    cout << "YES\n";
}


/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
	#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

	#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int &ai : a) cin >> ai;

    // ... ai-1 , ai, ai+1, ...
    // 1回目はai+1~だけ
    // 2回目以降は全て
    vector<ll> cnt_before(N), cnt_after(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            if (a[j] < a[i]) cnt_before[i]++;
        }
        for (int j = i + 1; j < N; j++) {
            if (a[j] < a[i]) cnt_after[i]++;
        }
    }
    ll ans = 0;
    ll before = ((K - 1) * K / 2) % MOD;
    ll after = (K * (K + 1) / 2) % MOD;
    for (int i = 0; i < N; i++) {
        ans += before * cnt_before[i];
        ans %= MOD;
        ans += after * cnt_after[i];
        ans %= MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>

int main(void){
    int N, pr, k, K, ans, tmp;
    scanf("%d", &N);

    ans = 0;

    for(int i=1; i<N; i++){
        tmp = 0;
        pr = N - i; // N-Cのこと
        // prをA*Bに分解
        K = sqrt(pr);
        for(k=1; k<=K; k++) if(pr%k == 0) tmp++;

        ans += (2*tmp);

        if(K*K == pr) ans--;
    }

    printf("%d\n", ans);

    return 0;
}


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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void readVector(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void readMatrix(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}


//TODO: SOLUTION

struct node {
            vector<node*> children;
            bool beginpoint;
            node * parent;
            char letter;
            node(node * p, char c) {
                children.resize(26, nullptr);
                beginpoint = false;
                parent = p;
                letter = c;
            }

        };

ll n;
vs w;
vector<node*> beginpoints;
node * root;

ll computePairs(node * r) {
    set<char> met;
    met.insert(r->letter);
    ll ans = 0;
    r = r->parent;

    met.insert(r->letter);

    while (r != root) {
        r = r->parent;
        for (node * c : r->children) {
            if (c != nullptr && c->beginpoint && met.count(c->letter))
                ans++;
        }
        met.insert(r->letter);
    }

    return ans;
}

void mktrie() {
    root = new node(nullptr, '0');
    beginpoints.resize(n, nullptr);

    for (int i = 0; i < n; i++) {
        reverse(w[i].begin(), w[i].end());
        node *r = root;
        for (auto c : w[i]) {
            int j = c - 'a';
            if (r->children[j] == nullptr)
                r->children[j] = new node(r, c);
            r = r->children[j];
        }
        r->beginpoint = 1;
        beginpoints[i] = r;
    }
}

void solve() {
    cin >> n;
    readVector(w, n, 0);

    mktrie();

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += computePairs(beginpoints[i]);
    }

    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 285480
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    import copy

    n = int(input())

    aa = list(map(int, input().split()))

    q = int(input())

    ans = set()

    for a in aa:
        for element in copy.deepcopy(ans):
            ans.add(element+a)
        ans.add(a)

    for m in map(int, input().split()):
        if m in ans:
            print('yes')
        else:
            print('no')



Measured memory_bytes: 6384
#include <iostream>
using namespace std;
int main(){
  int n;cin >> n;
  int a[n];
  int count = 0;
  for(int i = 0; i < n; i++)cin >> a[i];
  for(int i = 0; i < n; i++){
    while(a[i]%2==0){
      a[i]/=2;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int x,t;
	cin >> x >> t;
	if (t>= x){
		cout << 0 << endl;
	}
	else{
		cout << x - t << endl;
	}
	return 0;
}

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

/**
 * Union-Find木です。
 * クラスカル法でも扱う時にどうぞ
 */
typedef class unionFind {
	private:
		vector<int> parent; // 負数ならばデータ数、正数ならば親の場所
	public:
		unionFind(int n) : parent(n, -1){}
		int find(int n);
		void unite(int n, int m);
		bool isEqual(int n, int m);
		int getSize(int n);
} UnionFind;

/**
 * nの属している木の頂点を返します
 * @param n 調べるデータ
 * @return nが属している木の頂点
 */
int unionFind::find(int n) {
	if (parent[n] < 0) return n;
	return parent[n] = find(parent[n]);
}

/**
 * nの属する木とmの属する木を結合します
 * @param n 結合したいデータ
 * @param m 結合したいデータ
 */
void unionFind::unite(int n, int m) {
	n = find(n);
	m = find(m);
	if (n == m) return;
	if (parent[n] > parent[m]) {
		parent[m] += parent[n];
		parent[n] = m;
	} else {
		parent[n] += parent[m];
		parent[m] = n;
	}
}

/**
 * nとmが同じ木に属しているか調べます
 * @param n 調べるデータ
 * @param m 調べるデータ
 * @return 同じ木に属していたならtrue
 */
bool unionFind::isEqual(int n, int m) {
	return find(n) == find(m);
}

/**
 * nの属している木のデータ数を返します。
 * @param n 調べるデータ
 * @return nの属している木のデータ数
 */
int unionFind::getSize(int n) {
	return parent[find(n)];
}

const int MAX = 100000;
int main() {
	int N, M, p[MAX], x, y;
	cin >> N >> M;
	UnionFind union_Find(N);
	for (int i = 0;i < N;i ++) cin >> p[i];
	for (int i = 0;i < M;i ++) {
		cin >> x >> y;
		union_Find.unite(x - 1, y - 1);
	}
	int ans = 0; // 答えとなる個数
	for (int i = 0;i < N;i ++) {
		if (union_Find.isEqual(i, p[i] - 1)) ans ++;
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

ここである(x_i,y_i)と(x_j,y_j)に対し、どれか一つが等しいとする
するとこの3つの要素は任意に入れ替えられる
これは個数が増えても等しいので、任意の共有する範囲で入れ替えることができる
その中で数字が一致する個数を数えれば良い
後はこれを全ての数字でやればいい
Union-Findライブラリで殴ることにしますね
*/

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# 方針
# 実験すると'aa'や'aba'を含むのパターンのみが
# 条件を満たす文字列であると予想できる
# 存在するかを前から探すだけ

def main():
  s=S()

  ln=len(s)
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      return str(i+1)+' '+str(i+2)
    if i<ln-2:
      if s[i]==s[i+2]:
        return str(i+1)+' '+str(i+3)

  return '-1 -1'

print(main())


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

int main() {
	long long l, r;
	cin >> l >> r;
	if(r-l>=10000) cout << 0;
	else{
	    long long res=2019;
	    for(long long i=l; i<r; i++){
	        for(long long j=l+1; j<=r; j++){
	            res=min(res, (i*j)%2019);
	           // cout << i << " "<< j << res << endl;
	        }
	    }
	    cout << res;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A,B;
inline long long read(){
	int x=0,f=1;
	char c;
	do{c=getchar();if(c=='-'){f*=-1;}}while(!isdigit(c));
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
int main(){
	A=read();B=read();
	if(A<=9&&B<=9){printf("%d\n",A*B);}
	else{printf("-1\n");}
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  int ans = 0;
  for ( int n = a; n <= b; n++ ) {
    string num = to_string(n);
    if ( num[0] == num[4] && num[1] == num[3] ) { ans++; }
  }

  cout << ans << endl;
  return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

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

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;
signed main() {
  int64_t d;
  cin >> d;
  int64_t c[26];
  vector<vector<int64_t>> s(d);
  for(int i=0;i<26;i++){
    cin >> c[i];
  }
  
  for(int i=0;i<d;i++){
    for(int j=0;j<26;j++){
      int x;
      cin >> x;
      s[i].push_back(x);
    }
  }
  
  int64_t satis[26] = {0};
  int lastD[26] = {0};

  int t[d];

  int64_t totalSatis = 0;
  for(int i=0;i<d;i++){
    int64_t tmpTotal = totalSatis;
    int maxId = 0;
    int64_t maxTotal = tmpTotal;
    for(int j=0;j<26;j++){
      int tmpTotal = totalSatis;
      tmpTotal += s[i][j];
      for(int k=0;k<26;k++){
        if(k==j)continue;
        tmpTotal -= c[k]*(i+1-lastD[k]);
      }
      if(tmpTotal>maxTotal){
        maxTotal = tmpTotal;
        maxId = j;
      }
    }
    lastD[maxId]=i+1;
    totalSatis = maxTotal;
    cout << maxId+1 << endl;
  }
  
  return 0;
}




Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		//input
		// ① N（枚）
		// ② Y（円）
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int Y = scan.nextInt();

		//input check

		if(N<1 || N>2000) {
			System.out.println("N is illegal");
			System.exit(1);
		}

		if(Y<1000 || Y>2*Math.pow(10, 7)) {
			System.out.println("Y is illegal");
			System.exit(1);
		}

		//logic
		//	1.
		int num_10000 = 0;
		int num_5000 = 0;
		int num_1000 = 0;
		boolean is_match = false;


		for(int i = 0; i <= Y/10000;i++) {

			for(int j = 0; j <= Y/5000;j++) {

				int k = N - i - j;//3重loopを2重loopへ
				if(k < 0) continue;

				if((10000*i) + (5000*j) + (1000*k) == Y) {
						num_10000 = i;
						num_5000 = j;
						num_1000 = k;
						is_match = true;
						break;
				}

			}
		}



		//output
		//N枚のお札の合計金額が Y円となることがありえない場合は、-1 -1 -1 と出力
		if(is_match == false) {
			System.out.println("-1 -1 -1");

		}else {
			System.out.print(num_10000);
			System.out.print(" ");
			System.out.print(num_5000);
			System.out.print(" ");
			System.out.print(num_1000);
			System.out.print(" ");
		}

	}



}


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

#define N 200010
#define MAX 1000000000000000000

int main (void)
{
    char s[N], t[N];
    long i, j = 0;

    scanf("%s %s", s, t);

    for (i = 0; s[i] != '\0'; i++) {
        if (s[i] != t[i]) j++;
    }

    printf("%ld", j);

    return 0;
}


Measured memory_bytes: 2124
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()

ans = 0
for i in range(N):
    a = set(Counter(S[:i]).keys())
    b = set(Counter(S[i:]).keys())
    ans = max(ans, len(a&b))
print(ans)


Measured memory_bytes: 13668
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct actv{
ll f,s,t;
};
int main(){
    ll n;
    cin>>n;
    vector < actv > v,dp;
    v.resize(n);
    dp.resize(n);
    for(ll i=0;i<n;i++){
        cin>>v[i].f>>v[i].s>>v[i].t;
        dp[i].f=dp[i].s=dp[i].t=0;
    }
    dp[0].f=v[0].f;
    dp[0].t=v[0].t;
    dp[0].s=v[0].s;
    for(ll i=1;i<n;i++){
        dp[i].f=v[i].f+max(dp[i-1].s,dp[i-1].t);
        dp[i].s=v[i].s+max(dp[i-1].f,dp[i-1].t);
        dp[i].t=v[i].t+max(dp[i-1].s,dp[i-1].f);
    }
    cout<<max(max(dp[n-1].f,dp[n-1].s),dp[n-1].t);
return 0;
}


Measured memory_bytes: 4992
s = str(input())
s_length = len(s)
answer = 0
cnt = 0
t = 0
_t = 0
for i in range(s_length):
  if s[i] == '<':
    t += 1
    cnt = 0
    answer += t
  else:
    if t == 0:
      if _t <= cnt:
        t = 0
        cnt += 1
        answer += cnt 
      else:
        t = 0
        cnt += 1
        answer += cnt - 1
    else:
      _t = t
      t = 0
      answer += cnt * 1
      cnt += 1
print(answer)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vvi board(h, vi(w, 1));
  rep(y, h){
    rep(x, w){
      char s;
      cin >> s;
      if(s == '#') board[y][x] = 0;
    }
  }
  int far = 0;
  vi movex{0, 0, 1, -1};
  vi movey{1, -1, 0, 0};
  rep(a, h){
    rep(b, w){
      if(!board[a][b]) continue;
      vvi checked(h, vi(w, -1));
      checked[a][b] = 0;
      queue<vi> que;
      que.push({a,b});
      while(!que.empty()){
        vi pos = que.front();
        que.pop();
        int posx = pos[1], posy = pos[0];
        far = far < checked[posy][posx] ? checked[posy][posx] : far;
        rep(j, 4){
          int x = posx + movex[j];
          int y = posy + movey[j];
          if(x >= 0  && x < w && y >= 0 && y < h && board[y][x] && checked[y][x] == -1){
            que.push({y, x});
            checked[y][x] = checked[posy][posx] + 1;
          }
        }
      }   
    }
  }
  cout << far << endl;
}

Measured memory_bytes: 256
s = list(map(int,input().split()))
ORDER = input()
order = list(ORDER)

for i in order:
  if i == 'E':
    s[0], s[3] = s[3], s[0]
    s[3], s[5] = s[5], s[3]
    s[5], s[2] = s[2], s[5]
    
  if i == 'N':
    s[0], s[1] = s[1], s[0]
    s[1], s[5] = s[5], s[1]
    s[5], s[4] = s[4], s[5]
    
    
  if i == 'S':
    s[0], s[4] = s[4], s[0]
    s[4], s[5] = s[5], s[4]
    s[5], s[1] = s[1], s[5] 
    
  if i == 'W':
    s[0], s[2] = s[2], s[0]
    s[2], s[5] = s[5], s[2]
    s[5], s[3] = s[3], s[5]

print(s[0])



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

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

  // 全文字が同じの場合は例外処理の必要があるためチェック
  bool isSame = true;
  for (int i = 1; i < s.size(); i++) {
    if (s.at(i) != s.at(i -1)) {
      isSame = false;
      break;
    }
  }

  int sameA = 1, sameB = 1;
  int sameCnt = 1;
  int64_t cnt = 0;
  if (isSame) {
    cnt = s.size() * k / 2;
  } else {
    for (int i = 1; i < s.size(); i++) {
      if (s.at(i) == s.at(i - 1)) {
        sameCnt++;
      } else {
        cnt += sameCnt / 2;
        sameCnt = 1;
      }
    }
    cnt += sameCnt / 2;
    cnt *= k;

    if (k >= 2 && s.at(0) == s.at(s.size() - 1)) {

      // 先頭から同じ文字が何回続くか確認
      for (int i = 1; i < s.size(); i++) {
        if (s.at(i) == s.at(i - 1)) {
          sameA++;
        } else {
          break;
        }
      }

      // 末尾から同じ文字が何回続くか確認
      for (int i = s.size() - 1; i >= 0; i--) {
        if (s.at(i) == s.at(i - 1)) {
          sameB++;
        } else {
          break;
        }
      }

      cnt -= (sameA / 2 + sameB / 2 - (sameA + sameB) / 2) * (k - 1);

    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <map>

using namespace std;

#define INF 210000000
#define int long long

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
    int n,m;
    cin >> n >> m;
    vector<int> a;
    vector<int> b;
    map<int,int> tyoku;
    for(int i=0;i<m;i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
        cin >> tmp;
        b.push_back(tmp);
        if(a[i] == 1){
            tyoku[b[i]]++;
        }
    }
    string ans;
    for(int i=0;i<m;i++){
        if(0 < tyoku[a[i]] && b[i] == n){
            ans = "POSSIBLE";
            break;
        }else{
            ans = "IMPOSSIBLE";
        }
    }
    cout << ans;

}



Measured memory_bytes: 15840
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int max=0;
    int count=0;
    for(int length=1; length<s.size(); length++){
        string a=s.substr(0,length);
        string b=s.substr(length,s.size()-length);
        set<char> V;
        for(int i=0; i<a.size(); i++){
            for(int j=0; j<b.size(); j++){
                if(a.at(i)==b.at(j)){
                    V.insert(a.at(i));
                }
            }
        }
        if(max<V.size())
        max=V.size();
    }
    cout << max << endl;
}

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

using namespace std;
using ll = long long;

ll calc_final_sat(vector<ll>& t, vector<vector<ll>>& s, vector<ll>& c, ll d);

int main()
{
    ll d;
    cin >> d;
    vector<ll> c;
    vector<vector<ll>> s;
    vector<ll> t;
    vector<ll> last(26, 0);

    vector<ll> sat_vec;
    vector<vector<ll>> t_vec;

    ll m;
    vector<ll> q1, q2;

    for (ll i = 0; i < 26; i++) {
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    for (ll i = 0; i < d; i++) {
        vector<ll> tmp_v;
        for (ll j = 0; j < 26; j++) {
            ll tmp;
            cin >> tmp;
            tmp_v.push_back(tmp);

        }
        s.push_back(tmp_v);
    }

    for (int i = 0; i < d; i++) {
        ll tmp;
        cin >> tmp;
        t.push_back(tmp);
    }
    cin >> m;
    for (ll i = 0; i < m; i++) {
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        q1.push_back(tmp1);
        q2.push_back(tmp2);
    }

    ll sat = calc_final_sat(t, s, c, d);
    sat_vec.push_back(sat);
    t_vec.push_back(t);
    for (int i = 0; i < m; i++) {
        t[q1[i] - 1] = q2[i];
        sat = calc_final_sat(t, s, c, d);
        sat_vec.push_back(sat);
        t_vec.push_back(t);
    }
    for (int i = 1; i < sat_vec.size(); i++) {
        cout << sat_vec[i] << endl;
    }

    return 0;

}

ll calc_final_sat(vector<ll> &t, vector<vector<ll>> &s, vector<ll> &c, ll d) {
    ll sat = 0;
    vector<ll> last(26, 0);
    for (ll i = 0; i < d; i++) {
        ll contest = t[i] - 1;
        sat += s[i][contest];
        last[contest] = i + 1;
        for (ll j = 0; j < 26; j++) {
            sat -= (i + 1 - last[j]) * c[j];
        }
    }
    return sat;
}


Measured memory_bytes: 293844