akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD = 998244353;
ll x[301];
int N;

ll dp1[301][100001]; // 3-color
ll dp2[301][100001]; // 2-color


int main() {
    cin >> N;
    ll S = 0;
    ll ans = 1;
    for(int i = 0; i < N; i++) {
        cin >> x[i];
        S += x[i];
        ans *= 3;
        ans %= MOD;
    }

    dp1[0][0] = dp2[0][0] = 1;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 100001; j++) {
            dp1[i+1][j+x[i]] += dp1[i][j]; // 色を塗り替えても同じ．
            dp1[i+1][j+x[i]] %= MOD;
            dp1[i+1][j] += (2*dp1[i][j])%MOD;
            dp1[i+1][j] %= MOD;

            dp2[i+1][j+x[i]] += dp2[i][j];
            dp2[i+1][j+x[i]] %= MOD;

            dp2[i+1][j] += dp2[i][j];
            dp2[i+1][j] %= MOD;
        }
    }

    for(int i = (S+1)/2; i <= S; i++) {
        ans -= (dp1[N][i] * 3) % MOD; // 条件(S/2 > i)を満たさない数を引く
        ans %= MOD;
    }

    if(S%2 == 0) {
        ans += (dp2[N][S/2]*3 % MOD);
    }

    ans += MOD;
    ans %= MOD;
    cout << ans << endl;

}

Measured memory_bytes: 469760
/*
 ============================================================================
 Name        : alds1_3_a_stack.c
 Author      : lovesaemi
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) {
	S[++top] = x;
}
int pop() {
	top--;
	return S[top + 1];
}
int main(void) {
	int a, b;
	top = 0;
	char s[100];
//	printf("input:\n");
	while (scanf("%s", s) != EOF) {
//		printf("%s\n", s);
//		printf("%c\n", s[0]);
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		} else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		} else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		} else {
			push(atoi(s));
		}
	}
	printf("%d\n", pop());
	return EXIT_SUCCESS;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] s = line2.split(" ");

		int[] a = new int[s.length];
		for (int i = 0; i < s.length; i++) {
			a[i] = Integer.parseInt(s[i]);
		}

		StringBuilder str = new StringBuilder();

		while (n > 0) {
			str.append(a[n - 1]);
			if (n == 1) {
				break;
			}
			str.append(" ");
			n--;
		}

		System.out.println(str);
	}

}

Measured memory_bytes: 26016
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,t=map(int,readline().split())
    li=[list(map(int,readline().split())) for _ in range(n)]
    li.sort()
    a=[0]*n
    b=[0]*n
    for i in range(n):
        a[i],b[i]=li[i][0],li[i][1]

    #ナップサックDP
    inf=-float("inf")
    dp=[[inf]*(t+1) for _ in range(n+1)]
    dp[0][0]=0
    for i in range(n):
        for j in range(t+1):
            #i番目を食べる
            if j!=t:
                dp[i+1][min(t,j+a[i])]=max(dp[i+1][min(t,j+a[i])],dp[i][j]+b[i])
            
            #i番目を食べない
            dp[i+1][j]=max(dp[i+1][j],dp[i][j])

    print(max(dp[n]))

if __name__=="__main__":
    main()

Measured memory_bytes: 259848
def show (seqs):
    for i in range(len(seqs)):
        if i != len(seqs)-1:
            print(seqs[i], end = ' ')
        else :
            print(seqs[i])

num = int(input())
seqs = list(map(int,input().split()))

show(seqs)
for i in range(1,num):
    element = seqs[i]
    j = i-1
    while (j>=0 and seqs[j]>element):
        seqs[j+1] = seqs[j]
        j -=1
    seqs[j+1] = element
    show(seqs)


Measured memory_bytes: 5980
#!/usr/bin/python

import sys

def main(argv):
    for line in sys.stdin:
        sx, sy, tx, ty = line.rstrip("\n").split(" ")
        sx = int(sx)
        sy = int(sy)
        tx = int(tx)
        ty = int(ty)

        step = []
        x = sx
        y = sy
        while y < ty:
            step.append("U")
            y += 1
        while x < tx:
            step.append("R")
            x += 1
        while y > sy:
            step.append("D")
            y -= 1
        while x > sx:
            step.append("L")
            x -= 1
        step.append("L")
        x -= 1
        while y < ty + 1:
            step.append("U")
            y += 1
        while x < tx:
            step.append("R")
            x += 1
        step.append("D")
        y -= 1
        step.append("R")
        x += 1
        while y > sy - 1:
            step.append("D")
            y -= 1
        while x > sx:
            step.append("L")
            x -= 1
        step.append("U")
        y += 1

        print "".join(step)

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2948
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
  int a,b,c,sum;
  scanf("%d%d%d",&a,&b,&c);
  sum=a+b+c;
    if(sum<=21)
    {
      printf("win");
    }else{
      printf("bust");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> vec(h);
  rep(i,h) cin>>vec[i];

  vector<vector<int>> arr(h,vector<int>(w-1, 1));
  rep(i,1,h){
    rep(j,w-1){
      auto cnt = [&](int p, int q){
        int ret = 0;
        rep(xx,2)rep(yy,2) if(vec[p+xx][q+yy]=='#')ret++;
        return ret;
      };
      if( cnt(i-1,j)%2==0 ){
        arr[i][j] = arr[i-1][j] + 1;
      }
      else arr[i][j] = 1;
    }
  }
// rep(i,h)dbg(arr[i]);
  int ans = max(h,w);
  rep(i,h){
    vector<int> l(w),r(w);
    stack<int> st;
    rep(j,w-1){
      while(st.size() && arr[i][st.top()] >= arr[i][j]) st.pop();
      if(st.empty()) l[j]=0;
      else l[j]=st.top() + 1;
      st.push(j);
    }
    while(st.size()) st.pop();
    for(int j=w-2; j>=0; j--){
      while(st.size() && arr[i][st.top()] >= arr[i][j]) st.pop();
      if(st.empty()) r[j]=w-1;
      else r[j]=st.top();
      st.push(j);
    }
    rep(j,w-1) ans = max(ans, arr[i][j]*(r[j]-l[j] + 1));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 20096
import copy

def insert_to_sorted_list(vals:list, new_val):
    l = 0
    r = len(vals)
    while l < r:
        m = (l + r) // 2
        if vals[m] == new_val:
            vals.insert(m, new_val)
            return
        elif vals[m] < new_val:
            l = m + 1
        else:
            r = m
    vals.insert(l, new_val)
    return

n, k = map(int, input().split())
v = list(map(int, input().split()))

sum_l = [0] * (n + 1)
sum_r = [0] * (n + 1)
for i in range(1, n+1):
    sum_l[i] += sum_l[i - 1] + v[i - 1]
    sum_r[i] += sum_r[i - 1] + v[n - i]
max_score = -10000000
left_vals = []
left_minus_n = 0
for i in range(0, n + 1):
    if i > k:
        break
    if i > 0:
        if v[i-1] < 0:
           left_minus_n += 1
        insert_to_sorted_list(left_vals, v[i-1])
    vals = copy.copy(left_vals)
    minus_n = left_minus_n
    for j in range(0, n + 1 - i):
        if i + j > k:
            break
        if j > 0:
            if v[n-j] < 0:
                minus_n += 1
            insert_to_sorted_list(vals, v[n-j])
        score = sum_l[i] + sum_r[j]
        score -= sum(vals[0:min(k - i - j, minus_n)])
        if max_score < score:
            max_score = score
print(max_score)

    
        

Measured memory_bytes: 74764
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static List<ulong> Divisor(ulong input)
        {
            List<ulong> result = new List<ulong>();

            for (ulong i = 1; i * i <= input; i++)
            {
                if (0 == input % i)
                {
                    result.Add(i);
                    if (i * i != input)
                    {
                        result.Add(input / i);
                    }
                }
            }

            return result;
        }

        static int Digits(ulong M)
        {
            return (int)Math.Log10((double)M) + 1;
        }

        static void Main(string[] args)
        {
            ulong N = ulong.Parse(Console.ReadLine());

            List<ulong> div = Divisor(N);
            div.Sort();

            int ans = int.MaxValue;
            for (int i = 0; i < div.Count / 2 + 1; i++)
            {
                int tmp0 = Digits(div[i]);
                int tmp1 = Digits(N / div[i]);

                ans = Math.Min(ans, Math.Max(tmp0, tmp1));
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main()
{
    ll n,s,i,j,k=1,m=998244353;
    cin>>n>>s;
    ll dp[n+1][s+1];
    ll ar[n+1];
    for(i=1;i<=n;i++)
        cin>>ar[i];
    for(i=0;i<=n;i++){
        for(j=0;j<=s;j++){
            if(i==0)
                dp[i][j]=0;
            if(j==0){
                dp[i][j]=k%m;
                k=((k%m)*(2%m))%m;
            }
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=s;j++){
            if(ar[i]<=j)
                dp[i][j]=((dp[i-1][j-ar[i]]%m)+(2*(dp[i-1][j])%m)%m);
            else
                dp[i][j]=(2*(dp[i-1][j]%m)%m);
        }
    }
    cout<<dp[n][s]%m<<endl;
}


Measured memory_bytes: 73944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll X, Y;
    cin >> X >> Y;

    Y -= 2 * X;

    if(0<=Y and Y<=2*X and Y%2==0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main(){
	int a1,a2,a3,b1,b2,b3;
	int x[4][4];
	for(int i=1; i<=3; i++){
		for(int j=1; j<=3; j++){
			cin>>x[i][j];
		}
	}
	for(int i=0; i<=x[1][1]; i++){
		a1=i;
		b1=x[1][1]-a1;
		b2=x[1][2]-a1;
		b3=x[1][3]-a1;
		a2=x[2][1]-b1;
		a3=x[3][1]-b1;
		if(a2+b2==x[2][2] && a2+b3==x[2][3] && a3+b2==x[3][2] && a3+b3==x[3][3]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
typedef long long int ll;
int main()
{
   ll k,x;
   cin>>k>>x;
   ll r=x-k+1;
   ll i;
   for(i=1;i<=k-1;i++)
   {
       cout<<r<<" ";
       r++;
   }
   cout<<x<<" ";
   r=x+1;
   for(i=1;i<=k-1;i++)
   {
       cout<<r<<" ";
       r++;
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

struct edge{
  int to;
  i64 cost;
};

vector<edge> G[101010];
i64 dist[101010];

void dfs1(int v,int f = -1){
  for(edge &  e : G[v]){
    if(e.to == f) continue;
    dfs1(e.to , v);
    dist[v] = max(dist[v] , dist[e.to] + e.cost);
  }
}

int dfs2(int v,int d_f = 0,int f = -1){
  vector< pair<int,int> > d_child;
  d_child.push_back({0,-1});
  for(edge & e : G[v]){
    if(e.to == f) d_child.push_back({d_f + e.cost , e.to});
    else d_child.push_back({e.cost + dist[e.to] , e.to});
  }
  sort(d_child.rbegin(),d_child.rend());
  int ret = d_child[0].first + d_child[1].first;
  for(edge & e : G[v]){
    if(e.to == f) continue;
    ret = max(ret , dfs2(e.to,d_child[d_child[0].second == e.to].first , v));
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  for(int i = 0;i < N - 1;i++){
    int a,b,w;
    cin >> a >> b >> w;
    G[a].push_back({b,(i64)w});
    G[b].push_back({a,(i64)w});
  }
  dfs1(N / 2);
  cout << dfs2(N / 2) << endl;
}



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

using namespace std;

const int N_ = int(1.1e5);

int R, C, N;

using pii = pair<int, int>;
vector<pii> points;

int wh (int x, int y) {
  if(y == 0) return x;
  if(x == C) return C + y;
  if(y == R) return C + R + (C - x);
  return C + R + C + (R - y);
}

bool chk[N_];

int main() {
#ifdef IN_MY_COMPUTER
  freopen("e.in", "r", stdin);
#endif

  scanf("%d%d%d", &C, &R, &N);
  for(int i = 1; i <= N; i++) {
    int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    if((x1 == 0 || x1 == C || y1 == 0 || y1 == R) &&
       (x2 == 0 || x2 == C || y2 == 0 || y2 == R)) {
      points.emplace_back(wh(x1, y1), i);
      points.emplace_back(wh(x2, y2), i);
    }
  }

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

  stack<int> stk;
  for(auto it : points) {
    int i = it.second;

    if(!chk[i]) {
      chk[i] = true;
      stk.push(i);
    }else {
      if(stk.empty() || stk.top() != i) {
        puts("NO");
        return 0;
      }
      stk.pop();
    }
  }

  puts("YES");



  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

typedef struct 
	{
		int num;
		char city[11];
		int point;
	}restaurant;

int Compare(const void *a, const void *b) {
	if (strcmp(((restaurant*)a)->city, ((restaurant*)b)->city) != 0) 
		return strcmp(((restaurant*)a)->city, ((restaurant*)b)->city);
	else return ((restaurant*)b)->point - ((restaurant*)a)->point;

}

int main(void)
{
	
	int n;
	restaurant list[100];

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s %d", list[i].city, &list[i].point);
		list[i].num = i + 1;
	}
	qsort(list, n, sizeof(restaurant), Compare);

	for (int i = 0; i < n; i++) {
		printf("%d\n", list[i].num);
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
signed main(){
  int n,k;
  cin>>n>>k;
  P p[n];
  for(int i=0;i<n;i++) cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  for(int i=0;i<n;i++){
    if(k>p[i].second) k-=p[i].second;
    else{
      cout<<p[i].first<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
import sys

def resolve():
    inp = sys.stdin.readlines()
    inp = list(map(lambda x: x.strip(), inp))
    N = int(inp[0])
    A = list(map(int, inp[1].split(' ')))
    A.sort(reverse=True)
    num = 0
    for i in range(N-1):
        num += A[(i+1)//2]

    print(num)
    
resolve()

Measured memory_bytes: 92572
H, W = map(int, input().split())
S = [input() for i in range(H)]
P = [[0]*W for i in range(H)]
Q = [[0]*W for i in range(H)]
for i in range(H):
    p = -1
    for j in range(W):
        if S[i][j] == '#':
            c = j - p - 1
            for k in range(p+1, j):
                P[i][k] = c
            p = j
    c = W - p - 1
    for k in range(p+1, W):
        P[i][k] = c
for j in range(W):
    p = -1
    for i in range(H):
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                Q[k][j] = c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        Q[k][j] = c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j] + Q[i][j])
print(ans - 1)

Measured memory_bytes: 125272
N = int(input())

C = [[0]*(10) for _ in range(10)]
for i in range(N+1):
    S = str(i)
    s = int(S[0])
    e = int(S[-1])
    C[s][e] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += C[i][j]*C[j][i]
print(ans)

Measured memory_bytes: 40428
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int ans=0,n,m;
    vi x;
    priority_queue<int> d;
    cin>>n>>m;
    rep(i,m){
        int xi;
        cin>>xi;
        x.push_back(xi);
    }
    sort(x.begin(),x.end());
    if(n>=m){
        ans=0;
    }
    else{
        rep(i,m-1){
            d.push(x.at(i+1)-x.at(i));
        }
        rep(i,n-1){
            d.pop();
        }
        int z=d.size();
        rep(i,z){
            ans+=d.top();
            d.pop();
        }
    }
    cout<<ans;
}

Measured memory_bytes: 1400
#include<iostream>
#include<stdio.h>
using namespace std;
int cnt;
int keta(int n){
  if(n>0){
    cnt++;
    return keta(n/10);
  }else{
    return cnt;
  }
}
int main(){
  int a,b;
  int n;
  while(scanf("%d %d",&a,&b)!=EOF){
    cnt=0;
    a+=b;
    n=keta(a);
    cout<<n<<endl;
  }
  return 0;
}

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

#define xx first
#define yy second

const int N = 1e5 + 1;

int memo[N];
vector<int> adj[N];

int dp(int i) {
    if (memo[i] != -1)
        return memo[i];
    int mx = 0;
    for (auto& j : adj[i])
        mx = max(mx, 1 + dp(j));
    return memo[i] = mx;
}

void solve() {
    int n, m; cin >> n >> m;
    for (int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        --u, --v;
        adj[u].push_back(v);
    }
    int ans = -1;
    fill(memo, memo + n, -1);
    for (int i = 0; i < n; i++)
        ans = max(ans, dp(i));
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 11432
import Text.Regex
main = do
  s <- getLine
  putStrLn $ aux s

aux :: String -> String
aux s = if x0 < 0 || x1 > w || y0 < 0 || y1 > h then "No"
        else "Yes"
  where
    [w,h,x,y,r] = map (\x -> read x :: Int) $ splitRegex (mkRegex " +") s
    x0 = x- r
    x1 = x + r
    y0 = y - r
    y1 = y + r

Measured memory_bytes: 3928
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=200000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int dp[3][N + 5];
int main()
{
  finp;
  string s;
  cin>>s;
  int n = s.length();
  dp[1][1] = 1;

  afor(i,2,n)
  {
  	
	dp[1][i] = 1 + dp[2][i - 1];
	if(s[i - 1] != s[i - 2])dp[1][i] = max(dp[1][i], 1+ dp[1][i - 1]);

	if(i == 2)dp[2][i] = 1;
	else
	{
		dp[2][i] = dp[1][i - 2] + 1;
		if(i >= 4)
		{
			if(s[i - 3]!=s[i - 1] || s[i - 4]!=s[i - 2])
			{
				dp[2][i] = max(dp[2][i], dp[2][i - 2] + 1);
			}
		}
	}


  }

  cout<<max(dp[1][n], dp[2][n]);
  
return 0;
}

Measured memory_bytes: 2196
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL x[100],y[100],h[100];
 
LL X,Y,H = 0;

void solve(){
	//あらかじめh[i]が0でないようなx[i],y[i]を見つけておく
	//そのようなiをsample_indexとおく
	int sample_index = 0;
	for(int i=0;i<N;i++){
		if(h[i]!=0){
			sample_index = i;
			break;
		}
	}
	for(int Cx=0;Cx<=100;Cx++){
		for(int Cy=0;Cy<=100;Cy++){
			//Cx,Cyを仮定した時に
			//x[sample_index],y[sample_index],h[sample_index]から
			//ピラミッドの最大高さを推定、H_candとする
			LL H_cand = h[sample_index]
			 + abs(x[sample_index]-Cx)
			  + abs(y[sample_index]-Cy);

			auto ok = [&](){
				for(int i=0;i<N;i++){
					LL height = H_cand - abs(x[i]-Cx) - abs(y[i]-Cy);
					if(max(height,0LL)!=h[i]) return false;
				}
				return true;
			};
			if(!ok()) continue;
			X = Cx;
			Y = Cy;
			H = H_cand;
			return;
		}
	}
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> h[i];
 
    solve();
 
    cout << X <<" "<< Y <<" "<< H << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define mp make_pair
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

const int MOD=1e9+7;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    string s;
    cin>>n>>s;
    int d=0,ans=1;
    for(int i=1;i<=n;i++)
        ans=ans*i%MOD;
    for(int i=0;i<2*n;i++)
        if((s[i]=='W')^(i%2)) /// R
            ans=ans*d%MOD,
            d--;
        else /// L
            d++;
    if(d)
        ans=0;
    cout<<ans;
}


Measured memory_bytes: 720
N, K = map(int, input().split())
D = list(input().split())

flag = False
for a in range(N, 10*N):
	ans = list(str(a))
	for b in range(len(ans)):
		if ans[b] in D:
			break
		if b == len(ans) - 1 and ans[b] not in D:
			print(a)
			flag = True
	if flag:
		break

Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * Rectangle
 */
public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println(a * b + " " + (a + b) * 2);
        scan.close();
    }
}

Measured memory_bytes: 17160
a = int(input())
b = int(input())
c = int(input())
x = int(input())
x = x / 50
total = a+b+c
lists = []
for a in range(a+1):
    for b in range(b+1):
        for c in range(c+1):
            if 10*a + 2*b + c == x:
                lists.append(b)

length = len(lists)
print(length)



Measured memory_bytes: 3060
n, a, b = map(int, input().split())
ans = 0


def getsum(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n = n // 10
    return sum


for i in range(1, n + 1):
    su = getsum(i)
    if a <= su <= b:
        ans += i
print(ans)


Measured memory_bytes: 2940
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

namespace stdint_literal {
	constexpr uint64_t operator""_ui64(unsigned long long x)noexcept {
		return uint64_t(x);
	}
	constexpr int64_t operator""_i64(unsigned long long x)noexcept {
		return int64_t(x);
	}
	constexpr uint32_t operator""_ui32(unsigned long long x)noexcept {
		return uint32_t(x);
	}
	constexpr int32_t operator""_i32(unsigned long long x)noexcept {
		return int32_t(x);
	}
}
using namespace stdint_literal;

int32_t N;
uint32_t A[200000];
uint32_t B[200000];
uint32_t TMPA[200000];
uint32_t TMPB[200000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		in >> A[i];
	}
	for (int32_t i = 0; i < N; i++)
	{
		in >> B[i];
	}

	std::bitset<31> res = 0;
	for (int32_t dig = 0; dig < 29; dig++)
	{
		uint32_t mask_b = 1_ui32 << dig;
		uint32_t mask_e = mask_b << 1;

		for (int32_t i = 0; i < N; i++)
		{
			TMPA[i] = A[i]%mask_e;
		}
		for (int32_t i = 0; i < N; i++)
		{
			TMPB[i] = B[i] % mask_e;
		}
		std::sort(TMPB, TMPB + N);

		for (int32_t i = 0; i < N; i++)
		{
			if (TMPA[i] <= mask_b)
			{
				auto iter_b = std::lower_bound(TMPB, TMPB + N, mask_b - TMPA[i]);
				if (((std::lower_bound(TMPB, TMPB + N, mask_e - TMPA[i]) - iter_b) & 1) != 0) {
					res.flip(dig);
				}
			}
			else
			{
				auto num = (std::lower_bound(TMPB, TMPB + N, mask_e - TMPA[i]) - TMPB) + (TMPB + N - std::lower_bound(TMPB, TMPB + N, mask_b + mask_e - TMPA[i]));
				if ((num & 1) != 0) {
					res.flip(dig);
				}
			}
		}
	}
	out << res.to_ullong() << endl;

	return 0;
}
#endif


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

int main() {
    std::vector<int> a(4);
    for(int i = 1; i <= 3; i++) std::cin >> a[i];
    std::sort(a.begin(),a.end());
    std::cout << a[2]-a[1] + a[3]-a[2] << std::endl;
}

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

int max(int a,int b){
    int c;
    if(a>=b) c=a;
    else c=b;
    return c;
}
int min(int a,int b){
    int d;
    if(a>=b) d=b;
    else d=a;
    return d;
}
int gcd(int a,int b){
    int c,d,e;
    c=max(a,b);
    d=min(a,b);
    while(c%d!=0){
        e=c%d;
        c=d;
        d=e;
    }
    return d;
}

signed main(void){

    char str[1100000];
    char *tok;
    int m,n;
    int i1,i2,i3,i4,i44;
    int flag=0;
    int k[100001];
    

    fgets(str, sizeof(str), stdin);
    tok=strtok(str," ");
    n=strtol(tok,NULL,10);
    
    fgets(str, sizeof(str), stdin);
    tok=strtok(str," ");
    k[0]=strtol(tok,NULL,10);
    for(i2=1;i2<n;i2++){
        tok=strtok(NULL," ");
        k[i2]=strtol(tok,NULL,10);
    }
    
    for(i1=1;i1<n;i1++){
        k[i1]=gcd(k[i1-1],k[i1]);
    }
    
    
    printf("%d",k[n-1]);

    
    
}

Measured memory_bytes: 1536
n,c=map(int,input().split())
D=[]
for i in range(c):
    D.append(list(map(int,input().split())))
C=[]
for i in range(n):
    C.append(list(map(int,input().split())))

#print(D)

C1=[]
C2=[]
C3=[]
for i in range(n):
    for j in range(n):
        f=(i+j)%3
        if f==0:
            C1.append(C[i][j])
        if f==1:
            C2.append(C[i][j])
        if f==2:
            C3.append(C[i][j])
        

miniwa=1000*500*500

#print(C3)
iwa1=[]
iwa2=[]
iwa3=[]

for cc in range(0,c):
    iwa1.append(sum(D[i-1][cc] for i in C1))
    iwa2.append(sum(D[i-1][cc] for i in C2))
    iwa3.append(sum(D[i-1][cc] for i in C3))

for c1 in range(0,c):
    for c2 in range(0,c):
        for c3 in range(0,c):
            if c1!=c2 and c2!=c3 and c3!=c1 :
                iwa=iwa1[c1]+iwa2[c2]+iwa3[c3]
                miniwa=min(miniwa,iwa)

print(miniwa)


Measured memory_bytes: 7764
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

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

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

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) X(N);
    READVEC(X);
    int ret = 1 << 20;
    FOR(p, 0, 101) {
        int total = 0;
        for (int x : X)
            total += (x - p) * (x - p);
        ret = min(ret, total);
    }

    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 3656
#define L long long int
m[31][50];main(n,p,d,x){L a[50],b;for(;scanf("%d",&n),n;){memset(m,0,6200);for(p=0;p<n;a[p]=(L)1<<p,p++)for(scanf("%d",&x);x;x--)scanf("%d",&d),m[d][p]=1;for(d=1;d<31;d++){for(b=p=0;p<n;p++)if(m[d][p])b|=a[p];for(p=0;p<n;p++)if(m[d][p])if((a[p]=b)==((L)1<<n)-1){printf("%d\n",d);goto s;}}puts("-1");s:;}return 0;}

Measured memory_bytes: 416
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    int k;
    cin >> s >> k;

    set< string > st;
    int len = s.size();
    for( int i = 1; i <= min( len, k ) ; ++i ) {
        for( int j = 0; j < len - i + 1; ++j ) {
            string t;
            int pos = j;
            while( pos < j + i ) {
                t += s[pos];
                ++pos;

            }
            st.insert( t );

        }
    }

    auto it = st.begin();
    int pos = 1;
    while( pos < k ) {
        ++it; ++pos;

    }
    cout << *it << endl;
    return 0;
}



Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      String[] lines;
      double[] s;
      while( !(line = br.readLine()).equals("0") ){

        int n = Integer.parseInt(line);
        lines = br.readLine().split(" ");

        s =
          Stream.of(lines)
            .mapToDouble(Double::parseDouble)
            .toArray();
        
        double dm =
          Arrays.stream(s)
            .average()
          .getAsDouble();

        double result =
        Arrays.stream(s)
          .map(d -> Math.pow((d-dm),2))
          .sum();
        result = Math.sqrt((result)/n);

        System.out.printf("%.8f\n" ,result);
      }
    }
  }
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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

const ll SIZE = 1e5+10;

ll h, a;

int main(){
    cin >> h >> a;
    ll ans = h/a;
    if(h%a != 0)    ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,deque<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

// 温度, 量
deque<pdd> deq;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, L;
    cin >> n >> L;
    double nw = 0;
    ll t, v;
    cin >> t >> v;
    deq.pb(pdd(t, v));
    printf("%.12lf\n", (nw += t*v)/L);
    rep(i,n-1){
        ll t, v;
        cin >> t >> v;
        double sm = 0;
        while(true){
            pdd& p = deq.front();
            if(sm + p.se < v){
                sm += p.se;
                nw -= p.fi*p.se;
                deq.pop_front();
            }else{
                nw -= p.fi*(v-sm);
                p.se -= v-sm;
                break;
            }
        }
        double made = t*v, ryo = v;
        while(true){
            pdd& p = deq.back();
            if(p.fi*ryo < made){
                deq.pb(pdd(made/ryo,ryo));
                break;
            }else{
                made += p.fi*p.se;
                ryo += p.se;
                deq.pop_back();
                if(deq.empty()){
                    deq.pb(pdd(made/ryo,ryo));
                    break;
                }
            }
        }
        printf("%.12lf\n", (nw += t*v)/L);
    }
    return 0;
}


Measured memory_bytes: 19728
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

int inv(int h) {
  if (h == 0) return 0;
  return 24 - h;
}

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

  int N;
  cin >> N;

  int hour[24] = {};
  hour[12]++;

  REP(i, N) {
    int d;
    cin >> d;
    hour[(12 + d) % 24]++;
  }
  // d = 0
  REP(i, 24) {
    if (hour[i] > 2) {
      cout << 0 << endl;
      return 0;
    } else if (hour[i] == 2) {
      hour[i]--;
      hour[inv(i)]++;
    }
  }
  REP(i, 24) {
    if (hour[i] == 2) {
      cout << 0 << endl;
      return 0;
    }
  }

  for (int d = 1; d <= 12; d++) {
    for (int h = 0; h < 24; h++) {
      if (hour[h] == 0) continue;
      // cout << d << " " << h << endl;
      for (int k = h - d; k <= h + d; k++) {

        int hc = (k + 24) % 24;
        if (hc == h) continue;
        if (hour[hc] == 0) continue;

        if (hour[inv(hc)] > 0) {
          // cout << "a " << h << " " << hc << endl;
          cout << d << endl;
          return 0;

        } else {
          for (int l = inv(hc) - d; l <= inv(hc) + d; l++) {
            int hcc = (l + 24) % 24;
            // if (hcc == hc) continue;
            if (hour[hcc] > 0) {
              // cout << "b " << h << " " << hc << " " << hcc << " " << d << endl;
              cout << d << endl;
              return 0;
            }
          }
          hour[hc]--;
          hour[inv(hc)]++;
        }
      }
    }
  }

  return 0;
}


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

bool solve(int H, int W) {
    char s[H][W];
    set<char> se;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> s[i][j];
            if(s[i][j] != '.')se.insert(s[i][j]);
        }
    }
    vector<char> v;
    for (auto x : se) v.push_back(x);

    sort(v.begin(), v.end());
    map<char, int> lower, upper, left, right;
    for (auto x : v) {
        lower[x] = 0;
        upper[x] = 100;
        left[x] = 100;
        right[x] = 0;
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '.') continue;
            char tmp = s[i][j];
            lower[tmp] = max(lower[tmp], i);
            upper[tmp] = min(upper[tmp], i);
            left[tmp] = min(left[tmp], j);
            right[tmp] = max(right[tmp], j);
        }
    }
    map<char, set<int>> adj;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            vector<char> tmp;
            for (auto x : v) {
                if (upper[x] <= i && i <= lower[x]) {
                    if (left[x] <= j && j <= right[x]) {
                        tmp.push_back(x);
                        if(s[i][j] == '.')return false;
                    }
                }
            }
            if(s[i][j] == '.')continue;
            bool flag = true;
            for (auto x : tmp) {
                if (x == s[i][j]) {
                    flag = false;
                } else {
                    adj[x].insert(s[i][j]);
                }
            }
            if (flag) return false;
        }
    }
    do {
        map<char, int> idx;
        for (int i = 0; i < v.size(); i++) {
            idx[v[i]] = i;
        }
        bool ok = true;
        for (auto x : v) {
            for (auto to : adj[x]) {
                if (idx[x] < idx[to]) {
                    ok = false;
                }
            }
        }
        if (ok) return true;
    } while (next_permutation(v.begin(), v.end()));
    return false;
}

int main() {
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        int H, W;
        cin >> H >> W;
        cout << (solve(H, W) ? "SAFE" : "SUSPICIOUS") << endl;
    }
}


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

using namespace std;

int main(){
	int y;
	cin>>y;
	for(int i=0;i<y;i++){
		int c,a,n;
		cin>>c>>a>>n;
		
		int can=min(min(c,a),n);
		c-=can;
		a-=can;
		
		int cca=min(c/2,a);
		c-=cca*2;
		
		int ccc=c/3;
		
		cout<<can+cca+ccc<<endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void solve(int a, int b, int n, vector<bool>& ans)
{
    ans.assign(n+1, false);
    ans[0] = true;
    for(int i=0; i<n; ++i){
        if(ans[i]){
            if(i + a <= n)
                ans[i+a] = true;
            if(i + b <= n)
                ans[i+b] = true;
        }
    }
}

bool compare(int w1, int s1, int w2, int s2)
{
    return s1 * (w2 + s2) <= s2 * (w1 + s1);
}

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

    vector<bool> water, sugar;
    solve(a*100, b*100, f, water);
    solve(c, d, f, sugar);

    pair<int, int> ans(1, 0);
    for(int w=1; w<=f; ++w){
        if(!water[w])
            continue;
        for(int s=0; w+s<=f; ++s){
            if(!sugar[s])
                continue;
            if(compare(w, s, 100, e) && compare(ans.first, ans.second, w, s))
                ans = make_pair(w, s);
        }
    }
    cout << (ans.first + ans.second) << ' ' << ans.second << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
from collections import Counter
INF = float("inf")


def solve(N: int, K: int, A: "List[int]"):

    ans = 0

    # 累積和
    acc = [0]+list(accumulate(A))

    cnt = Counter()
    # 各jについて
    for j in range(1, N+1):
        # 区間に加える
        if j-1 >= 0:
            cnt[(acc[j-1]-(j-1)) % K] += 1

        # 区間から除く
        if j-K >= 0:
            cnt[(acc[j-K]-(j-K)) % K] -= 1

        # カウントする
        ans += cnt[(acc[j]-j) % K]
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64132
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]
b = []
for x in a:
    num = 0
    if x%2 == 0:
        x = x//2
        num += 1
        if x%2 == 0:
            num += 1
    b.append(num)
if b.count(0) <= b.count(2):
    print('Yes')
else:
    if b.count(0) == b.count(2)+1 and len(b) == b.count(0)+b.count(2):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14636
s = list(map(int,input()))

n = len(s)
 
ans_l = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    ans_l += 1
    if s[i] == 0:
      s[i+1] = 1
    else:
      s[i+1] = 0
print(ans_l)


Measured memory_bytes: 3956
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int n;
int a[111111];
int b[111111];
int c[111111];

int ch(int k){
  int x = c[k-1];
  int y = b[k]-1;
  int z = c[100000]-c[k];
  
  if(b[k]<=0) return 1<<28;

  //cout << x  << " " << y << " " << z << endl;

  if(x+z<y) return (y-x-z)%2;

  if(x>z) swap(x,z);
  x -= y/2;
  z -= y/2+y%2;

  return abs(x-z)%2;
}

int main(void){
  scanf("%d",&n);
  for(int i = 0; i < n; i++){
    scanf("%d",a+i);
    b[a[i]]++;
  }

  int ans = 0;
  for(int i = 0; i < 111111; i++){
    if(b[i]) ans++;
    c[i] = max(0,b[i]-1);
    if(i) c[i] += c[i-1];
  }

  
  int x = 1<<28;
  for(int i = 1; i <= 100000; i++){
    x = min(x,ch(i));
  }
  
  printf("%d\n",ans-x);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ll D;
    cin >> D;
    vl c(26);
    rep(i,26){
        cin >> c[i];
    }
    ll s[D][26];
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    vl latest_t(26,0);
    ll k=0;
    FOR(i,1,D+1){
        vl nt=latest_t;
        ll nk=k;
        ll MX=-INF;
        ll ans;
        rep(j,26){
            nk=k;
            nk+=s[-1+i][j];
            nt[j]=i;
            rep(l,26){
                nk-=c[l]*(i-latest_t[l]);
            }
            if(nk>MX){
                MX=nk;
                ans=j;
            }
            if(j==25){
                k=MX;
            }
        }
        cout << ans+1 << endl;
        latest_t[ans]=i;
    }
}

Measured memory_bytes: 3704
N = int(input())
A = list(map(int, input().split()))
c = 0
min_abs = float('inf')
for i in range(N):
  if A[i] < 0:
    c += 1
  if abs(A[i]) < min_abs:
    min_abs = abs(A[i])

s = 0
#print(min_abs)
if c % 2 == 0:
  for i in range(N):
    s += abs(A[i])
else:
  for i in range(N):
      s += abs(A[i])
  s -= abs(min_abs) * 2

print(s)


Measured memory_bytes: 14412