akhauriyash/Code-Regression huggingface dataset:
/* ITP1_7_D */;
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();

      String[] input = br.readLine().split(" ");
      int n = Integer.parseInt(input[0]);
      int m = Integer.parseInt(input[1]);
      int l = Integer.parseInt(input[2]);

      long[][] matrix_nm = new long[n][m];
      long[][] matrix_ml = new long[m][l];
      long[][] matrix_nl = new long[n][l];

      // input n*m
      for(int i = 0; i < n; i++){
        input = br.readLine().split(" ");
        for(int j = 0; j < m; j++){
          matrix_nm[i][j] = Integer.parseInt(input[j]);
        }
      }
      // input m*l
      for(int i = 0; i < m; i++){
        input = br.readLine().split(" ");
        for(int j = 0; j < l; j++){
          matrix_ml[i][j] = Integer.parseInt(input[j]);
        }
      }

      // calculation
      for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
          for(int k = 0; k < m; k++){
            matrix_nl[i][j] += matrix_nm[i][k] * matrix_ml[k][j];
          }
          if(j != 0) sb.append(" ");
          sb.append(matrix_nl[i][j]);
        }
        sb.append("\n");
      }
      System.out.print(sb);

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 33008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    string S;
    cin >> N >> S;
    ll ans = 0;
    for(int i=1;i<N;i++){
        string S1 = S.substr(0,i);
        string S2 = S.substr(i,N-i);
        map<char,int> memo,memo2;
        ll tmp = 0;
        for(int j=0;j<i;j++){
            if(memo[S1[j]]==0){
                memo[S1[j]]++;
                for(int k=0;k<S2.size();k++){
                    if(S2[k]==S1[j]){
                        if(memo2[S2[k]]==0){
                            memo2[S2[k]]++;
                            tmp++;
                        }
                    }
                }
            }
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      x.begin(),x.end()
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(string, s1);
  in(string, s2);
  if(
     s1[0] == s2[2] &&
     s1[1] == s2[1] &&
     s1[2] == s2[0] ){
    puts("YES");
  }else{
    puts("NO");
  }

  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;

int main() {
	
	cin.tie(0); cout.tie(0);
	ll a, b, n, i, k, cnt = 0; cin >> a >> b >> k;
	vector <ll> v;
	for(i = 1; i <= min(a, b); i++) {
		if(a % i == 0 && b % i == 0) v.pb(i);
	}
	reverse(v.begin(), v.end());
	cout << v[k - 1];
 	return 0;                        
}

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

using namespace std;

#define INF (1<<29)

int N, M;
vector<int> s, d;
int dp[110][1<<15];
int cost[1<<15];

int calc(int S, int D)
{
    return abs(cost[S] - D);
}

int solve(int m, int S)
{
    if (m == M) return 0;
  
    int &res = dp[m][S];
    if (res != -1) return res;
  
    res = INF;
    res = min(res, solve(m + 1, S) + calc(S, d[m]));    
    for (int i = 0; i < N; i++) {
        if (S >> i & 1) continue;
        res = min(res, solve(m, S|(1<<i)));    
    }
    return res;
}

void calc_cost()
{
    for (int i = 0; i < (1<<N); i++) {
        cost[i] = 0;
        for (int j = 0; j < N; j++) {
            if (i >> j & 1) {
                cost[i] += s[j];
            }
        }
    }
}

int main()
{
    while (cin >> N >> M, (N | M)) {
        s.clear(); s.resize(N);
        d.clear(); d.resize(M);

        for (int i = 0; i < N; i++) {
            cin >> s[i];
        }

        for (int i = 0; i < M; i++) {
            cin >> d[i];
        }

        sort(d.begin(), d.end());
    
        calc_cost();
        memset(dp, -1, sizeof(dp));
        cout << solve(0, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  int x, a, b;
  std::cin >> x >> a >> b;

  bool stomachache = ((b - a) > x);
  bool delicious = (b <= a);

  if (delicious) {
    cout("delicious");
  } else if (!stomachache) {
    cout("safe");
  } else {
    cout("dangerous");
  }
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	ll n, sum = 0;
	cin >> n;


	REP(i, n+1) {
		if(i % 3 != 0 && i %5 != 0) {
			sum += i;
		}
	}

	cout << sum << endl;

}



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

int main(){
  int m,d;
  cin>>m>>d;
  
  int ans=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=d;j++){
      int d1=j%10,d10=j/10;
      if(d1>=2&&d10>=2){
        if(d1*d10==i){
          ans++;
        }
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
  int p[n+2];
  for(int i=1;i<n+1;i++){
    scanf("%d", &p[i]); 
  }
  p[0]=0;
  p[n+1]=n+1;

  int bottom_count=0;
  int bottom_before=-1;
  int bottom=-1;
  int bottom_next=-1;
  int yes_flag=0;
  for(int i=0;i<n;i++){
    if(bottom_count==0 && p[i]>p[i+1]){
      bottom_before=p[i-1];
      bottom=p[i];
      bottom_next=p[i+1];
      bottom_count++;
    }else if(bottom_count!=0 && p[i]>p[i+1]){
      // cout<<bottom_before<<endl;
      // cout<<bottom<<endl;
      // cout<<bottom_next<<endl;
      if(p[i+1]>bottom_before && p[i+1]<bottom_next && p[i]<bottom && p[i+2]>bottom){
          yes_flag=1;
      }
      bottom_count++;
    }
  }
  if((yes_flag==1 and bottom_count==2) || bottom_count==0){
    printf("%s\n", "YES");
  }else{
    printf("%s\n", "NO");
  }
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>	
using namespace std;
#define ll long long 
long long n;
vector<long long> so_a;//素数を格納
int main(){
  ll n;
  cin >> n;
  vector<ll> l(n);
  
  for(int i = 0;i< n;i++){
    cin >> l[i];
  }
  sort(l.begin(), l.end(),greater<int>() );
  ll c = 0;
  for(int i = 0;i< n;i++){
    for(int j = i+1;j< n;j++){
      for(int k = j+1;k< n;k++){
        if(l[i]< l[j]+ l[k]){
          c += 1;
        }else{
          break;
        }
      }
    }
  }
  cout << c;

}


Measured memory_bytes: 3556
# N: 処理する区間の長さ 0_indexed
class SegmentTree:
  def __init__(self,N):
    self.N0 = 2**(N-1).bit_length()
    self.data = [None]*(2*self.N0)
    self.INF = (-1, 2**31-1)
  # 区間[l, r+1)の値をvに書き換える
  # vは(t, value)という値にする (新しい値ほどtは大きくなる)
  def update(self, l, r, v):
    L = l + self.N0; R = r + self.N0
    while L < R:
      if R & 1:
        R -= 1
        self.data[R-1] = v
      if L & 1:
        self.data[L-1] = v
        L += 1
      L >>= 1; R >>= 1
  # a_iの現在の値を取得
  def _query(self, k):
    k += self.N0-1
    s = self.INF
    while k >= 0:
      if self.data[k]:
        s = max(s, self.data[k])
      k = (k - 1) // 2
    return s
  # これを呼び出す
  def query(self,k):
    return self._query(k)[1]

N, Q = map(int, input().split())
row = SegmentTree(N-2)
col = SegmentTree(N-2)
ans = (N-2)*(N-2)
row.update(0,N-2,(0,N-2))
col.update(0,N-2,(0,N-2))
min_row = N
min_col = N
for i in range(1,Q+1):
  t,x = map(int, input().split())
  if t==1:
    num = col.query(x-2)
    ans -= num
    if x<min_col:
      row.update(0,num,(i,x-2))
      min_col = x
  else:
    num = row.query(x-2)
    ans -= num
    if x<min_row:
      col.update(0,num,(i,x-2))
      min_row = x
print(ans)


Measured memory_bytes: 89812
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int H1,M1,H2,M2,K;
cin>>H1>>M1>>H2>>M2>>K;
int tmp=(H2*60+M2)-(H1*60+M1)-K;
cout<<tmp<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


int main(){
    double r;   cin >> r;
    printf("%.10f\n", 2.0 * r * M_PI);

    return 0;
}


Measured memory_bytes: 3784
n, m = map(int, input().split())
x = [0 for _ in range(m)]
for i in range(n):
    k, *a = list(map(int, input().split()))
    for j in range(k):
        x[a[j] - 1] += 1
ans = 0
for i in range(m):
    if x[i] == n:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000000+7;
ll n,k;
vector<int> G[100010];
ll dfs(int now,ll a1,ll a2,int fa=-1){
    ll ans=max(0ll,k-a1-a2);
    int tot=0;
    for(int i=0;i<G[now].size();i++){
        if(G[now][i]==fa) continue;
        (ans*=dfs(G[now][i],1,tot+(fa!=-1),now))%=mod;
        tot++;
    }
    return ans;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int a,b;scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout<<dfs(1,0,0);
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, a;
    cin >> n;
    deque<int> q;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if ((i % 2) ^ (n % 2)) {
            q.push_front(a);
        } else {
            q.push_back(a);
        }
    }
    for (int i : q) {
        cout << i << ' ';
    }
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if (d <= t * s) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	string s;
	while(getline(cin,s)){
		string t="";
		set<string>out,no;
		rep(i,s.size())if(isalpha(s[i]))t+=toupper(s[i]);
		rep(i,t.size())loop(j,3,t.size()+1)if(i+j<=t.size()){
			string a=t.substr(i,j),b=a;
			reverse(all(b));
			if(a==b){
				out.insert(a);
				no.insert(t.substr(i+1,j-2));
			}
		}
		vector<string>ans;
		for(set<string>::iterator it=out.begin();it!=out.end();it++)
			if(no.find(*it)==no.end())
				ans.pb(*it);
		reverse(all(ans));
		rep(i,ans.size()){
			if(i)cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1260
s=input()
n=len(s)
x=(n-1)//2
y=(n+1)//2
for i in range(x):
    if s[i]!=s[n-i-1] or s[i+y]!=s[n-i-1] or s[i]!=s[x-i-1]:
        print("No")
        break
else: print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
signed main(){
	cin>>s;
	if(s[s.size()-1]=='s'){
		s+="es";cout<<s<<endl;return 0;
	}
	s+='s';
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3632
import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

X,Y,Z,K = LI()
A = LI()
B = LI()
C = LI()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = A[0] + B[0] + C[0]
l = 0
while h > l+1:
    m = (h+l) // 2

    num = 0
    for a in A:
        j = len(C) - 1
        for i in B:
            while i + C[j] < m - a:
                j -= 1
                if j < 0: break
            else:
                num += j + 1
                continue
            break
    if num > K:
        l = m
    else:
        h = m

ans = []
cnt = 0
for a in A:
    j = len(C) - 1
    last_cnt = cnt
    for i in B:

        while i + C[j] <= l - a:
            j -= 1
            if j < 0: break
        else:
            for k in range(j+1):
                ans.append(a+i+C[k])
                cnt += 1
            continue
        break
ans.sort(reverse=True)
for _ in range(K-len(ans)):
    ans.append(l)
print (*ans[:K],sep='\n')



Measured memory_bytes: 196208
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}
//sort(a, a + N, greater<int>())   // descend
//sort(a, a+N)                    //  ascend

using ll = long long;
using namespace std;

int main() {
	int p,q,r;
	int x = 0;
	cin >>p>>q>>r ;
	int a = p + q;

	int b = r + q;
	int c = p + r;
	int v = min(a, b);
	int w = min(v, c);
	cout << w;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  int mn_a = *min_element(a.begin(), a.end());
  int mx_a = *max_element(a.begin(), a.end());
  cout << mx_a - mn_a << endl;
}

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<vector<long long>> a(N, vector<long long>(N));
    for (int i=0; i<N; i++)
    for (int j=0; j<N; j++)
        cin>>a[i][j];

    vector<long long> C(1<<N);
    for (int b=0; b<1<<N; b++)
        for (int i=0; i<N; i++)
        if (b>>i&1)
        for (int j=0; j<i; j++)
        if (b>>j&1)
            C[b] += a[i][j];

    vector<long long> T(1<<N);
    for (int b=0; b<1<<N; b++)
    {
        T[b] = C[b];
        for (int c=(b-1)&b; c>0; c=(c-1)&b)
            T[b] = max(T[b], T[b^c] + C[c]);
    }
    cout<<T[(1<<N)-1]<<endl;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>
#define NIL -1
using namespace std;

struct Node {
	int parent = NIL;
	int left = NIL;
	int right = NIL;
};

Node node[25];


/*void initDepth(int k,int d) {
	depth[k] = d;
	if (node[k].left != NIL) {
		initDepth(node[k].left, d + 1);
	}
	if (node[k].right != NIL) {
		initDepth(node[k].right, d + 1);
	}
	return;
}

int initHeight(int k) {
	int h1 = 0, h2 = 0;
	if (node[k].left != NIL) {
		h1 = initHeight(node[k].left) + 1;
	}
	if (node[k].right != NIL) {
		h2 = initHeight(node[k].right) + 1;
	}

	return height[k] = max(h1, h2); 
	}*/


int getBro(int k) {
	if (node[k].parent == NIL) { return NIL; }
	if (node[node[k].parent].left == k) {
		return node[node[k].parent].right;
	}
	return node[node[k].parent].left;
}

void getType(int k) {
	if (node[k].parent == NIL) { cout << "root"; return; }
	if (node[k].left == NIL && node[k].right == NIL) { cout << "leaf"; return; }
	cout << "internal node";
}

int getDegree(int k) {
	int num = 0;
	if (node[k].left != NIL) { num++; }
	if (node[k].right != NIL) { num++; }
	return num;
}

int root(int k=0) {
	int root = 0;
	while (node[root].parent != NIL) {
		root = node[root].parent;
	}
	return root;
}

void p(int k) {
	if (k == NIL) { return; }
	cout << " "<<k;
	p(node[k].left);
	p(node[k].right);
}

void ml(int k) {
	if (k == NIL) { return; }
	ml(node[k].left);
	cout << " "<< k;
	ml(node[k].right);
}

void a(int k) {
	if (k == NIL) { return; }
	a(node[k].left);
	a(node[k].right);
	cout << " "<<k;
}


int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if (l >= r) { return; }
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}





int main() 
{
	int m;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> m;
		pre.push_back(m);
	}
	for (int i = 0; i < n; i++) {
		cin >> m;
		in.push_back(m);
	}
	solve();
}


Measured memory_bytes: 3168
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_ABC147
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            if(s[0]+s[1]+s[2]>21){
                WriteLine("bust");
            }else{
                WriteLine("win");
            }
        }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int i,len;
	long long num,sum=0;
	char str[11];
	scanf("%lld",&num);
	sprintf(str,"%lld",num);
	len=strlen(str);
	for(i=0;i<len;i++)
	{
		sum+=(str[i]-'0');
	}
	if(num%sum==0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

# aの要素すべてのXOR、sを求めます
s = a[0]
for num in a[1:]:
    s ^= num

# i番目のすぬけくんは、s xor a_iです
res = [0] * n
for i, num in enumerate(a):
    res[i] = s ^ num

print(*res)

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

using namespace std;
typedef long long int ll;

int main(){
    // read in integer 
    ll a;
    ll b;
    ll k;
    ll zero = 0;
    cin >> a >> b >> k;

    ll new_a = max(zero, a - k);
    ll remain_k = max(zero, k - a);
    ll new_b = max(zero, b - remain_k);

    cout << new_a << " " << new_b << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const ll INF = ll(1e18) + 1;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4765
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2000005);
 
mint f(int n, int k) {
  if (n < 0) return 0;
  // nPk = nCk * k!
  mint res = comb(n,k);
  res *= comb.fact[k];
  return res;
}

int k;
mint ans;
vector<int> to[100005];

void dfs(int v,int p=-1){
  for(int u:to[v]){
    if(u==p) continue;
    dfs(u,v);
  }
  int nk = (p==-1) ? k : k-2;
  int t = (p==-1) ? to[v].size() + 1 : to[v].size() - 1;
  ans *= f(nk,t);
}




int main(){
  int n;
  cin >> n >> k;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans = 1;
  dfs(0);
  cout << ans.x << endl;
}

Measured memory_bytes: 40448
//ALDS1_3C
#include <cstdio>
#include <list>
#include <algorithm>

using namespace std;

int main(){
 int q,x;
 char com[20];
 list<int> v;

 scanf("%d",&q);
 for(int i=0;i<q;i++){
  scanf("%s",com);
  if(com[0]=='i'){
   scanf("%d",&x);
   v.push_front(x);
  }else if(com[6]=='L'){
   v.pop_back();
  }else if(com[6]=='F'){
   v.pop_front();
  }else if(com[0]=='d'){
   scanf("%d",&x);
   for(list<int>::iterator it=v.begin();it!=v.end();it++){
    if(*it==x){
     v.erase(it);
     break;
    }
   }
  }
 }
 int i=0;
 for(list<int>::iterator it=v.begin();it!=v.end();it++){
  if(i++) printf(" ");
  printf("%d",*it);
 }
 printf("\n");

 return 0;
}

Measured memory_bytes: 32092
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;
#define _ << " " <<

int main() {
    string s;
    cin >> s;
    int l = s.size();

    int v[l + 5], w[l + 5];
    for (int i = 0; i <= l; i++) v[i] = w[i] = -1;

    for (int i = 0; i < l; i++) {
        if (char(s[i]) == '>' && char(s[i + 1]) == '<') v[i + 1] = w[i + 1] = 0;
    }
    if (char(s[0]) == '<') v[0] = w[0] = 0;
    if (char(s[l - 1]) == '>') v[l] = w[l] = 0;

    int idx = 0;
    while (idx < l) {
        int sub = 0;
        while (idx + sub < l && char(s[idx]) == '<' && char(s[idx + sub]) == '<') {
            v[idx + sub + 1] = v[idx + sub] + 1;
            sub++;
        }
        idx += max(1, sub);
    }
    for (int i = 0; i <= l; i++) {
        //sm += v[i];
        cerr << v[i] << " " ;
    }
    cerr << endl;
    idx = 0;
    while (idx < l) {
        int sub = 0;
        while (l - idx - sub - 1 >= 0 && char(s[l - idx - 1]) == '>' && char(s[l - idx - sub - 1]) == '>') {
            w[l - idx - sub - 1] = w[l - idx - sub] + 1;
            sub++;
        }
        idx += max(1, sub);
    }

    ll sm = 0;
    for (int i = 0; i <= l; i++) {
        sm += max(v[i], w[i]);
        cerr << max(v[i], w[i]) << " " ;
    }
    cerr << endl;
    cout << sm << endl;

}

Measured memory_bytes: 4740
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
bool cmp(const array<int,3> &a, const array<int,3> &b)
{
    return a[0]<b[0];
}
bool cmp2(const array<int,3> &a, const array<int,3> &b)
{
    return (double(a[2])/double(a[0]))>(double(b[2])/double(b[0]));
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
int main()
{
    vok();
    int n,m,x;
    IN n>>m>>x;
    int sum[m];
    memset(sum,0,sizeof(sum));
    int c[n];
    int arr[n][m];
    loop(i,0,n)
    {
        IN c[i];
        loop(j,0,m)
        {
            IN arr[i][j];
            sum[j]+=arr[i][j];
        }
    }
    loop(j,0,m)
    {
        if(sum[j]<x)
        {
            OUT -1;
            return 0;
        }
    }
    int ans=INT_MAX;
    loop(i,0,pow(2,n))
    {
        bitset<12> temp(i);
        vector<int> haha(m,0);
        int tans=0;
        loop(i,0,12)
        {
            if(temp[i])
            {
                tans+=c[i];
                loop(j,0,m)
                {
                    haha[j]+=arr[i][j];
                }
            }
        }
        bool flag=false;
        loop(i,0,m)
        {
            if(haha[i]<x)
            {
                flag=true;
                break;
            }
        }
        if(!flag)
        {
            ans=min(ans,tans);
        }
    }
    OUT ans<<endl
    return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))


template <typename T>
struct twodimBIT
{
// 1-indexed
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3095512#1
// https://www.slideshare.net/hcpc_hokudai/binary-indexed-tree
private:
	vector< vector<T> > array;
	const int n;
	const int m;

public:
	twodimBIT(int _n,int _m):
		array(_n+1,vector<T>(_m+1,0)), n(_n),m(_m){}

	// (1,1) ~ (x,y) ruisekiwa
	T sum(int x,int y) {
		T s = 0;
		for(int i=x;i>0;i-=i&(-i))
			for(int j=y;j>0;j-=j&(-j))
				s += array[i][j];
		return s;
	}

	// [(x1,y1),(x2,y2)] no souwa (x1<x2,y1<y2)
	T sum(int x1,int y1,int x2,int y2){
		return sum(x2,y2) - sum(x1-1,y2) - sum(x2,y1-1) + sum(x1-1,y1-1);
	}

	void add(int x,int y,T k) {
		for(int i=x;i<=n;i+=i&(-i))
			for(int j=y;j<=m;j+=j&(-j))
				array[i][j] += k;
	}
};

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> S(N),T(M);
	FOR(i,0,N)cin>>S[i];
	FOR(i,0,M)cin>>T[i];

	twodimBIT<ll> tb(N+1,M+1);
	ll ans = 1;
	FOR(i,0,N){
		FOR(j,0,M){
			if(S[i]==T[j]){
				ll x = tb.sum(i,j);
				(ans+=x+1) %= MOD;
				tb.add(i+1,j+1,(x+1)%MOD);
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 31744
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;
 
int main() {
    int n;
    cin >> n;
    vector<ll> l(n);
    rep(i,n) cin >> l[i];
    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                ll ma = max({l[i],l[j],l[k]});
                ll sum = l[i]+l[j]+l[k]-ma;
                if(sum > ma && l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) cnt++;
            }
        }
    }
    cout << cnt << endl;
	return 0;
}

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

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

typedef long long ll;

using namespace std;

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

int N;
string S;

void input()
{
    cin >> N;
    cin >> S;
}

void solve()
{
    string s1,s2;
    s1 = S.substr(0, N/2);
    s2 = S.substr(N/2, N/2);
    if(S.size() % 2 != 0) cout << "No" << endl;
    else if(s1 == s2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            int n = NextInt, k = NextInt;
            var array = Enumerable.Repeat(false, n).ToArray();
            for (int i = 0; i < k; i++)
            {
                int d = NextInt;
                var list = IntList;

                foreach (var item in list)
                {
                    array[item - 1] = true;
                }
            }

            System.Console.WriteLine(array.Count(b => !b));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 28488
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main(){
    fast;
    ll a; cin>>a;
    map<str, ll> mp;
    for(int q=0; q<a; q++){
        str t; cin>>t;
        sort(t.begin(), t.end());
        mp[t]++;
    }
    ll o = 0;
    for(auto i : mp) o+=i.S*(i.S-1)/2;
    cout<<o;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int INF=1001001001;


int main(){
   int n; cin>>n;
   if(n<=999) cout<<"ABC"<<endl;
   else cout<<"ABD"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");\
	else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};
//--------------------------------------//
int main(){
	cint2(a,b);
	int d=b-a;
	int s=(d*(d+1))/2;
	int ans=s-b;
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
struct ok
{
    string t;
    int ti;
};
int main()
{
    //freopen("test.inp","r",stdin);
    int n, i, j, sum;
    string x;
    ok a[1001];
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i].t >> a[i].ti;
    }
    cin >> x;
    for (i = 1; i <= n; i++) if (a[i].t == x)
    {
        j = i;
        break;
    }
    sum = 0;
    for (i = j+1; i <= n; i++)
    {
        sum += a[i].ti;
    }
    cout << sum;
    return 0;
}


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

#define ll           long long
#define inf        1e18
#define w(x)      int x; cin>>x; while(x--)
#define endl     "\n" 


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

int main(void)
{
    fio();
    int a,b;
    cin>>a>>b;
    int ans = a* b;
    cout<<ans<<endl;



    return 0;

}



Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define endl        '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  300005
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



// class MemoryGame{
// public:
// // vs construct(int n){
void solve(){
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k;
		return;
	}
	if(k<=a+b){
		cout<<a;
		return;
	}
	k-=(a+b);
	cout<<a-k;
}
// };
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll TESTS=1,an=1;
    // cin>>TESTS;
    while(TESTS--){
        // cout<<"Case #"<<an<<": ";
        an++;
        solve();

    }
    return 0;
}           

Measured memory_bytes: 3648
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*

a
aaa
//=> 3

contest
contest
//=> 7

*/

fn char_to_index(c: char) -> usize {
    (c as u8 - b'a') as usize
}

fn solve_fast(s: &[char], t: &[char]) -> Option<usize> {
    let sn = s.len();

    // s を2個つなげたもの
    let w = s.iter().chain(s).cloned().collect::<Vec<_>>();

    // next[ci][si]:
    // w の位置 si (< sn) から見て次に文字 ci が出現する位置
    let mut next = vec![vec![None; sn]; 26];

    for ci in 0..26 {
        // w において最後に文字 ci が出現した位置
        let mut last = None;

        for wi in (0..w.len()).rev() {
            if char_to_index(w[wi]) == ci {
                last = Some(wi);
            }

            next[ci][wi % sn] = last;
        }
    }

    let mut i = 0;
    for &c in t {
        let si = i % sn;
        let ni = match next[char_to_index(c)][si] {
            None => return None,
            Some(ni) => ni,
        };
        i += ni - si + 1;
    }
    Some(i)
}

fn main() {
    let s = rl().chars().collect::<Vec<_>>();
    let t = rl().chars().collect::<Vec<_>>();

    if let Some(i) = solve_fast(&s, &t) {
        println!("{}", i)
    } else {
        println!("-1")
    }
}


Measured memory_bytes: 59644
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
int n,x,ans;
char s[maxn];
int main(){
	scanf("%d",&n);scanf("%s",s);
	for(register int i=0;i<n;i++){
		if(s[i]=='I') x++;
		else x--;
		ans=x>ans?x:ans;
	}
	printf("%d",ans);
	return 0;
}

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

#define dump(a) cerr << #a << " " << a << endl
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;

int main(){
  int t, d,l;
  while(cin >> t >> d>>l, t){
    vector<int> x(t);
    vector<int> xx(t+100010,0);
    rep(i,t){
        cin>>x[i];
        if(x[i]>=l){
            xx[i+1]+=1;
            xx[i+d+1]-=1;
        }else{
            //xx[i]=0;
        }
        if(i!=0)xx[i]+=xx[i-1];
    }
    int ans=0,bf=0;
    rep(i,t){
        if(xx[i]){
            ans+=1;
        }
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 4320
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
constexpr int64_t SIZE = 1e6;

array<int64_t, SIZE+10> fac, ifac;

int64_t modpow(int64_t x, int64_t n, int64_t m = 1) {
    return n == 0 ? m : modpow(x * x % MOD, n >> 1, n & 1 ? m * x % MOD : m);
}

int64_t comb(int64_t n, int64_t k) {
    return n == 0 && k == 0 ? 1
        : n < k || n < 0 ? 0
        : fac[n] * ifac[k] % MOD * ifac[n-k] % MOD;
}

int main() {
    fac[0] = ifac[0] = 1;
    for (int64_t i = 0; i+1 < SIZE + 10; i++) {
        fac[i+1] = fac[i] * (i+1) % MOD;
        ifac[i+1] = ifac[i] * modpow(i+1, MOD-2) % MOD;
    }

    int x, y;
    cin >> x >> y;

    int64_t ans = 0;
    for (int64_t i = 0; i <= x; i++) {
        if (3 * i != -x + 2 * y) continue;
        int64_t t = i + (x-i) / 2;
        ans += comb(t, i);
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 15872
#include <iostream>
#include <string>
using namespace std;
int num[3];
int counter;
void bsort(int *a,int N){
    int i,j,temp;
    for(i=0;i<N-1;i++){
        for(j=i+1;j<N;j++){
            if(a[i]>a[j]){
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
}
int main(){
    cin >> num[0] >> num[1] >> num[2];
    counter = 0;
    while(1){
        bsort(num,3);
        if((num[1] - num[0] >= 2) || (num[2] - num[0] >= 2)){
            num[0] += 2;
            counter++;
            continue;
        }else if((num[0] == num[1]) && (num[1] != num[2])){
            num[0] += 1;
            num[1] += 1;
            counter++;
            continue;
        }else if((num[2] == num[1]) && (num[1]!= num[0])){
            num[0] += 2;
            counter++;
            continue;
        }
        if((num[0] == num[1]) && (num[0] == num[2])){
            break;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
xl, yl, xr, yr = 0, 0, W, H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xr = min(xr, x)
    elif a == 3:
        yl = max(yl, y)
    else:
        yr = min(yr, y)

if xl < xr and yl < yr:
    print(int((xr - xl) * (yr - yl)))
else:
    print(0)

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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

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

    int n, ans = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    ans = v[n / 2] - v[n / 2 - 1];
    cout << ans;

    return 0;
}

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

using namespace std;

const int N = 305;
int n, cnt[3];
long double dp[N][N][N];
bool solved[N][N][N];

long double calc(int a, int b, int c)
{
    if (max(a, max(b, c)) == 0)
    {
        return 0;
    }
    if (solved[a][b][c])
    {
    	return dp[a][b][c];
    }
    if (a)
    {
        dp[a][b][c] += a / (long double)(n) * (1 + calc(a - 1, b, c));
    }
    if (b)
    {
        dp[a][b][c] += b / (long double)(n) * (1 + calc(a + 1, b - 1, c));
    }
    if (c)
    {
        dp[a][b][c] += c / (long double)(n) * (1 + calc(a, b + 1, c - 1));
    }
    dp[a][b][c] += (n - a - b - c) / (long double)(n);
    dp[a][b][c] *= n / (long double)(a + b + c);
    
    solved[a][b][c] = 1;
    return dp[a][b][c];
}

int main() 
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        cnt[x - 1]++;
    }
    cout << fixed << setprecision(10) << calc(cnt[0], cnt[1], cnt[2]);
}


Measured memory_bytes: 258176
#include<stdio.h>
signed main(){
	int x,y;
	scanf("%d %d", &x,&y);
	if(x*2>y){
		printf("No");
	}else if(x*4<y){
		printf("No");
	}else if(y%2==0){
		printf("Yes");
	}else printf("No");
	printf("\n");
	return (0);
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        int result = 0;
        if (K != 1) {
            result = N - K;
        }

        System.out.println(result);
    }

}


Measured memory_bytes: 21844