akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const std::string RGB = "RGB";

ll N;
std::string S;
std::map<ll, ll> cnt;

int main() {
  std::cin >> N >> S;

  rep( i, N ) {
    ++cnt[RGB.find(S[i])];
  }

  ll ans = cnt[0]*cnt[1]*cnt[2];

  rep( i, N ) {
    repi( j, 1, N ) {
      if( i-j < 0 || i+j >= N )
        break;

      std::set<char> st = { S[i], S[i-j], S[i+j] };

      if( st.size() == 3 )
        --ans;
    }
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ll = int64_t;
using ul = uint64_t;
using namespace std;

// auto trace = [&](auto V) {
//   for (const auto v : V) {
//     cout << v.first << " " << v.second << endl;
//   }
// };

void solve() {
  int n;
  cin >> n;

  map<int, int> D;
  rep(i, n) {
    int diff;
    cin >> diff;
    if (D.find(diff) != D.end()) {
      D[diff]++;
    } else {
      D[diff] = 1;
    }
  }

  int m;
  cin >> m;

  map<int, int> T;
  rep(i, m) {
    int diff;
    cin >> diff;
    if (T.find(diff) != T.end()) {
      T[diff]++;
    } else {
      T[diff] = 1;
    }
  }

  if (n < m) {
    cout << "NO";
    return;
  }

  for (const auto t : T) {
    if (D.find(t.first) != D.end()) {
      if (D[t.first] < t.second) {
        cout << "NO";
        return;
      }
    } else {
      cout << "NO";
      return;
    }
  }

  cout << "YES";
  return;
}

void wrapper() {
  rep(i, 4) {
    cout << "[TEST " << (i + 1) << "]\n";
    solve();
    cout << "\n";
  }
}

int main() {
  fastIO;
  // wrapper();
  solve();
}


Measured memory_bytes: 22356
#include <stdio.h>
#include <stdlib.h>
#define INFINITY 1000000001

int pertition(int*, char*, int, int);
void quickSort(int*, char*,int, int);
int check(int,int*, char*, int*, char*);
void merge(int *, char *, int, int, int);
void mergeSort(int *, char *, int, int);

main(){
  int n, i, r, *Ad, *cpyAd;
  char *Ac, *cpyAc;

  scanf("%d", &n);
  Ad = malloc(sizeof(int)*n);
  Ac = malloc(sizeof(char)*n);
  cpyAd = malloc(sizeof(int)*n);
  cpyAc = malloc(sizeof(char)*n);

  for(i=0; i<n; i++){
    scanf(" %c", Ac+i);
    scanf("%d", Ad+i);
    cpyAc[i] = Ac[i];
    cpyAd[i] = Ad[i];
    //printf("i=%d\n", i);
  }

  quickSort(Ad, Ac, 0, n-1);
  
  if(check(n, Ad, Ac, cpyAd, cpyAc)) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0; i<n; i++){
    printf("%c %d\n", Ac[i], Ad[i]);
  }

  free(Ad);
  free(Ac);
  free(cpyAd);
  free(cpyAc);
  return 0;
}

void quickSort(int *A, char *A2, int p, int r){
  int q;

  if(p < r){
    q = partition(A, A2, p, r);
    quickSort(A, A2, p, q-1);
    quickSort(A, A2, q+1, r);
  }
}

int partition(int *A, char *A2, int p, int r){
  int x = A[r];
  int i = p-1;
  int j, tmp;
  char tmp2;

  for(j=p; j<r; j++){
    if(A[j] <= x){
      i = i+1;
      tmp = A[i];
      tmp2 = A2[i];
      A[i] = A[j];
      A[j] = tmp;
      A2[i] = A2[j];
      A2[j] = tmp2;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  tmp2 = A2[i+1];
  A2[i+1] = A2[r];
  A2[r] = tmp2;

  return i+1;
}

int check(int n, int *Ad, char *Ac, int *oriAd, char *oriAc){
// 安定なソートであるMergeSortの結果と比較する
// 安定 : 1
// 安定でない : 0
  int i;

mergeSort(oriAd, oriAc, 0, n);

#ifdef DEBUG
  printf("\n****** MergeSort ******\n");
  for(i=0; i<n; i++) printf("%c %d\n", oriAc[i], oriAd[i]);
  printf("\n***********************\n");
#endif

  //アルファベットについて一致するか判定
  for(i=0; i<n; i++){
    if(/*QuickSort*/Ac[i] != /*MergeSort*/oriAc[i]) return 0;
  }
  return 1;
}

void merge(int *arryA, char *arryB, int left, int mid, int right){
  int n1, n2, i, j, k, *arryL, *arryR;
  char *arryLc, *arryRc;

  n1 = mid - left;
  n2 = right - mid;

  arryL = (int *)malloc(sizeof(int)*(n1 + 1));
  arryR = (int *)malloc(sizeof(int)*(n2 + 1));
  arryLc = (char *)malloc(sizeof(char)*(n1 + 1));
  arryRc = (char *)malloc(sizeof(char)*(n2 + 1));
  for(i=0; i<n1; i++){
    arryL[i] = arryA[left+i];
    arryLc[i] = arryB[left+i];
    //printf("++ arrLc[%d] = %c\n", i, arryB[left+i]);
  }
  for(i=0; i<n2; i++){
    arryR[i] = arryA[mid+i];
    arryRc[i] = arryB[mid+i];
    //printf("++ arrRc[%d] = %c\n", i, arryB[mid+i]);
  }
  arryL[n1] = INFINITY;
  arryR[n2] = INFINITY;

  i=0;//L
  j=0;//R

  for(k=left; k<right; k++){
    if(arryL[i] <= arryR[j]){
      arryA[k] = arryL[i];
      arryB[k] = arryLc[i];
      i++;
    }
    else{
      arryA[k] = arryR[j];
      arryB[k] = arryRc[j];
      j++;
    }
  }

  free(arryL);
  free(arryR);
  free(arryLc);
  free(arryRc);
}

void mergeSort(int *arryA, char *arryB,int left, int right){
  int mid;

  if(left+1 < right){
    mid = (right + left) / 2;
    mergeSort(arryA, arryB, left, mid);
    mergeSort(arryA, arryB, mid, right);
    merge(arryA, arryB, left, mid, right);
  }
}

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

ll S[100010];

bool binarysearch(ll n, ll key){
    ll left=0;
    ll right=n;
    while(left<right){
        ll mid=(left+right)/2;
        if(S[mid]==key) return true;
        else if(key<S[mid]) right=mid;
        else    left=mid+1;
    }
    return false;
}

int main(void){
    ll n, q, T[50010];
    cin>>n;
    for(int i=0; i<n; i++){
        cin >> S[i];
    }
    cin>>q;
    for(int i=0; i<q; i++){
        cin >> T[i];
    }
    ll count=0;
    for(int i=0; i<q; i++){
        count+=binarysearch(n, T[i])? 1:0;
    }
    cout << count << "\n";
}



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void Main(){
    ll n;
    cin >> n;
    auto v = prime_factor(n);
    int ans = 0;
    for(auto itr = v.begin(); itr != v.end(); ++itr) {
        int p = 1;
        int i = itr->second;
        while(i >= p) {
            i -= p;
            p++;
            ans++;
        }
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3664
def main():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    cnt = 0
    calc = 0

    for i in range(N):
        calc = 0
        A = list(map(int, input().split()))
        for j in range(len(A)):
            calc += A[j] * B[j]
        if calc + C > 0:
            cnt += 1
    print(cnt)
main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
inline int read()
{
    char c = getchar();
    int x = 0, s = 1;
    while (c < '0' || c > '9')
    {
        if (c == '-')
            s = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * s;
}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a, b) memset(a, b, sizeof(a))
#define lowbit(x) (x) & (-x)
const int N = 1e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const double II = acos(-1);
const double PP = (II * 1.0) / (180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    ull n, sum = 0;
    cin >> n;
    ull arr[n + 5] = {0}, ans[n + 5] = {00};
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    for (int i = 1; i <= n; i++)
        ans[i] = (arr[i] + ans[i - 1]);
    for (int i = 1; i <= n; i++)
        sum = ((sum + arr[i] * ((ans[n] - ans[i]) % mod)) % mod) % mod;
    cout << sum << endl;
}


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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (n % 3 == 0) {
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < n / 3; ++j) {
        if (a[i * n / 3] != a[i * n / 3 + j]) {
          cout << "No" << "\n";
          return 0;
        }
      }
    }
    cout << (a[0] ^ a[n / 3] ^ a[2 * n / 3] ? "No" : "Yes") << "\n";
  } else {
    cout << (a.back() ? "No" : "Yes") << "\n";
  }
  return 0;
}


Measured memory_bytes: 640
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,v,u) for(int i=last[v],u=to[last[v]];i;i=nxt[i],u=to[i])
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
void read(int &n)
{
	int t=0,p=1;char ch;
	for(ch=getchar();!('0'<=ch && ch<='9');ch=getchar())
		if(ch=='-') p=-1;
	for(;'0'<=ch && ch<='9';ch=getchar()) t=t*10+ch-'0';
	n=t*p;
}
const int N=4e5+5,M=60000005;
int n,nn,vtot,tot,root,b[N][2];
struct node
{
	int x,id;
}a[N];
bool cmp(node a,node b){return a.x<b.x;}
int m,co[N],to[M],nxt[M],last[N],ls[N],rs[N],list[N];
void link(int u,int v)
{
	to[++m]=v,nxt[m]=last[u],last[u]=m;
}
void build(int &v,int l,int r)
{
	if(l==r)
	{
		v=b[a[l].id][0];
		return;
	}
	v=++tot;
	int mid=l+r>>1;
	build(ls[v],l,mid);build(rs[v],mid+1,r);
	link(v,ls[v]);link(v,rs[v]);
}
void add(int v,int l,int r,int x,int y,int p)
{
	if(x>y || l>r) return;
	if(l==x && r==y)
	{
		link(p,v);
		return;
	}
	int mid=l+r>>1;
	if(y<=mid) add(ls[v],l,mid,x,y,p);
	else
	if(x>mid) add(rs[v],mid+1,r,x,y,p);
	else add(ls[v],l,mid,x,mid,p),add(rs[v],mid+1,r,mid+1,y,p);
}
bool dfs(int v)
{
	if(v<=vtot && co[v^1]) return 0;
	if(v<=vtot && co[v]) return 1;
	co[v]=1;
	list[++list[0]]=v;
	efo(i,v,u) if(!co[u])
		if(!dfs(u)) return 0;
	return 1;
}
bool check(int lim)
{
	m=0;mset(last,0);
	fo(i,1,n)
	{
		link(b[i+i-1][0],b[i+i][1]),link(b[i+i][1],b[i+i-1][0]);
		link(b[i+i-1][1],b[i+i][0]),link(b[i+i][0],b[i+i-1][1]);
	}
	tot=vtot;
	build(root,1,nn);
	int l=1,r=1;
	fo(i,1,nn)
	{
		while(l<nn && a[i].x-a[l].x>=lim) ++l;
		while(r<nn && a[r+1].x-a[i].x<lim) ++r;
		add(root,1,nn,l,i-1,b[a[i].id][1]);
		add(root,1,nn,i+1,r,b[a[i].id][1]);
	}
	mset(co,0);
	fo(i,1,tot)
	{
		int x=i+i-1;
		if(!co[b[x][0]] && !co[b[x][1]])
		{
			list[0]=0;
			if(!dfs(b[x][0]))
			{
				fo(j,1,list[0]) co[list[j]]=0;
				list[0]=0;
				if(!dfs(b[x][1])) return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int x,y;
	read(n);nn=n+n;
	fo(i,1,n) read(a[i+i-1].x),read(a[i+i].x);
	vtot=1;
	fo(i,1,nn) a[i].id=i,b[i][0]=++vtot,b[i][1]=++vtot;
	sort(a+1,a+nn+1,cmp);
	int l=0,r=a[nn].x+1;
	while(l<r-1)
	{
		int mid=l+r>>1;
		if(check(mid)) l=mid;
		else r=mid;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 20736
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define rg register
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define mod 998244353
#define Gi 3
using namespace std;

const int maxn=2e4+5;
int n,m,rev[maxn];
ll GI,A[maxn],B[maxn],C[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc == '-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline int qpow(int x,int k){
	ll ss=1,tmp=x;
	while(k > 0){
		if(k & 1) ss=ss*tmp%mod;
		tmp=tmp*tmp%mod;
		k>>=1;
	}
	return ss;
}

inline int get(int x){
	int j=0; while((x >> 1) > 0) x>>=1,j++;
	return j;
}

inline void ntt(ll *f,int limit,int op){
	int L=get(limit);
	go(i,limit,0){
		rev[i]=(rev[i>>1]>>1) | ((i&1)<<(L-1));
		if(rev[i] > i) swap(f[rev[i]],f[i]);
	}
	for(rg int mid=1;mid<limit;mid<<=1){
		ll wn=qpow(op == 1 ? Gi : GI,(mod-1)/(mid<<1));
		for(rg int j=0;j<limit;j+=mid<<1){
			ll w=1;
			for(rg int k=0;k<mid;k++,w=w*wn%mod){
				ll x=f[j+k],y=f[j+k+mid]*w%mod;
				f[j+k]=(x+y)%mod;
				f[j+k+mid]=(x-y+mod)%mod;
			}
		}
	}
	ll invlen=qpow(limit,mod-2);
	if(op == -1) go(i,limit,0) f[i]=f[i]*invlen%mod;
}

int main(){
	int a,b,c; GI=qpow(3,mod-2);
	a=rd(); b=rd(); c=rd(); n=rd();
	int limit=1; while(limit <= n*3) limit<<=1;
	for(rg int i=0;i<=n;i+=a) A[i]=1;
	for(rg int i=0;i<=n;i+=b) B[i]=1;
	for(rg int i=0;i<=n;i+=c) C[i]=1;
	ntt(A,limit,1); ntt(B,limit,1); ntt(C,limit,1);
	go(i,limit,0) A[i]=A[i]*B[i]%mod*C[i]%mod;
	ntt(A,limit,-1);
	printf("%lld",A[n]);
	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int T = scan.nextInt();
		int[] t = new int[N];

		for(int i=0;i<N;i++){
			t[i]=scan.nextInt();
		}

		long sumT = 0;

		for(int i=0;i<N;i++){
			if(i==N-1){
				sumT+=T;
			}else{

				if(t[i+1]-t[i]>=T){
					sumT+=T;
				}else{
					sumT+=t[i+1]-t[i];
				}


			}
		}

		System.out.println(sumT);

	}

}


Measured memory_bytes: 88848
#include <iostream>
using namespace std;
int G[101][101];
int n,v,k,p;
int main(){
	cin >>n;
	for(int i=0;i<n;i++){
		cin >> v>>k;
		for(int j=0;j<k;j++){
			cin >> p;
			G[v][p]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			cout << G[i][j]<<" ";
		}
		cout << G[i][n]<<endl;
	}
}

Measured memory_bytes: 3120
s = input()


li = "abdefghijklmnopqrstuvwxyz"
li = li.upper()
li = list(li)

if s[0] == "A" and "C" in s[2:-1] and s.count("C") == 1:
    for i in li:
        if i not in s[1:]:
            pass
        else:
            print("WA")
            break
    else:
        print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
PY = [LIST() for _ in range(M)]
PY_ = deepcopy(PY)
PY_.sort(key=lambda x: (x[0], x[1]))
# print(PY)
tmp = 0
i = 0
lis = []
dic = {}
for p, y in PY_:
	if p == tmp:
		i += 1
	else: # 県が変わったら
		lis.append([])
		tmp = p
		i = 1
	dic[str(p)+"_"+str(y)]=str(p).zfill(6)+str(i).zfill(6)

for p, y in PY:
	print(dic[str(p)+"_"+str(y)])


Measured memory_bytes: 69368
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; cin >> a;
    cout << 3 * a * a << endl;

    return 0;
}


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

int main(){
  int H,N;
  cin>>H>>N;
  int sum=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    sum+=a;
  }

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int a[35];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int k,x;
		scanf("%d",&k);
		for(int j=0;j<k;j++)
		{
			scanf("%d",&x);
			a[x]++;
		}
	}
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i]==n) sum++;
	}
	printf("%d",sum);
} 

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

int main(){
    int n,m;
    cin >> n >> m;
    int a[n],b[n],c[m],d[m];
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<m;i++){
        cin >> c[i] >> d[i];
    }
    for(int i=0;i<n;i++){
        int tmp = 2000000000;
        int k;
        for(int j=0;j<m;j++){
            if(tmp > abs(a[i]-c[j])+abs(b[i]-d[j])){
                tmp = abs(a[i]-c[j])+abs(b[i]-d[j]);
                k  =j+1;
            }

        }
        cout << k << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int[] costMasuList;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		try {
			String[] inputTmp = scanner.nextLine().split(" ");
			int masuLength = Integer.parseInt(inputTmp[0]);
			int costMasuLength = Integer.parseInt(inputTmp[1]);
			int startMasu = Integer.parseInt(inputTmp[2]);
			costMasuList = new int[costMasuLength];
			for (int i=0;i < costMasuLength;i++) {
				costMasuList[i] = scanner.nextInt();
			}

			int startLeftCost = 0;
			int startRightCost = 0;
			for (int i = 1; i < masuLength; i++) {
				if (!isCostMasu(i)) {
					continue;
				}
				if (i < startMasu) {
					startLeftCost++;
				} else if (i > startMasu) {
					startRightCost++;
				}
			}

			System.out.print(startLeftCost < startRightCost ? startLeftCost : startRightCost);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}
	}

	private static boolean isCostMasu(int input) {
		for (int i = 0; i < costMasuList.length; i++) {
			if (costMasuList[i] == input) {
				return true;
			}
		}
		return false;
	}
}


Measured memory_bytes: 21588
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


bool isM(string s){
  if(s.length() != 2) return false;
  if(s[0] == '0' && s[1] != '0') return true;
  if(s[0] == '1' && (s[1] == '0' || s[1] == '1' || s[1] == '2')) return true;
  return false;
}

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

    ll n,k;
    string s;
    cin >> s;
    if(isM(s.substr(0,2)) && isM(s.substr(2,2))) cout << "AMBIGUOUS"<<endl;
    else if(isM(s.substr(0,2))){
      cout << "MMYY" << endl;
    }
    else if(isM(s.substr(2,2))){
      cout << "YYMM" << endl;
    }
    else cout << "NA" << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=[int(i) for i in input().split()]
a=[]
ans=0
for i in range(n):
    a=[int(j) for j in input().split()]
    p=c
    for k in range(m):
        p+=a[k]*b[k]
    if p>0:
        ans+=1
    
print(ans)




Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main(void){
  string s;
  getline(cin,s);
  string n;
  string maxs;
  string longs ="";
  int maxv;
  vector<string> ss;
  vector<int> ii;
  s += " ";
  for(int i = 0 ; i < s.size() ; i ++){
    if(s[i] == ' '){
      if(!ss.size()){
	maxv = 0;
	maxs = n;
      }
      if(longs.size() < n.size()){
	longs = n;
	//cout<<n<<endl;
      }
      bool used = false;
      for(int i = 0 ; i < ss.size() ; i ++){
	if(n == ss[i]){
	  ii[i] ++;
	  if(maxv < ii[i]){
	    maxv = ii[i];
	    maxs = n;
	  }
	  used = true;
	  break;
	}
      }
      if(!used){
	ii.push_back(1);
	ss.push_back(n);
      }
      n = "";
    }else{
      n += s[i];
    }
  }
  cout<<maxs<<" "<<longs<<endl;
}

Measured memory_bytes: 1204
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

bool valid_path(const vector<string> &dirlist, const set<string> &dirs) {
    string curpath = "";
    for(int i = 0; i < dirlist.size(); ++i) {
        curpath += "/";
        curpath += dirlist[i];
    }
    return curpath == "" || dirs.count(curpath) != 0;
}

bool absolute_path(const string &str, const set<string> &dirs, string &res) {
    vector<string> dirlist;
    int prev = 1;
    for(int i = 1; i < str.size(); ++i) {
        if(str[i] == '/') {
            string dir = str.substr(prev, i-prev);

            if(dir == "..") {
                if(dirlist.size() == 0) return false;
                dirlist.pop_back();
            }
            else if(dir != ".") {
                dirlist.push_back(dir);
                if(!valid_path(dirlist, dirs)) return false;
            }
            prev = i+1;
        }
    }

    if(str[str.size()-1] == '/') { 
        dirlist.push_back("index.html");
    }
    if(prev != str.size()) { //Trailing '/' omitted
        string last = str.substr(prev);
        if(last == "..") {
            if(dirlist.size() == 0) return false;
            dirlist.pop_back();
        }
        else if(last != ".") {
            dirlist.push_back(last);
        }

        if(valid_path(dirlist, dirs)) { //This is Directory
            dirlist.push_back("index.html");
        }
    }

    res = "";
    for(int i = 0; i < dirlist.size(); ++i) {
        res += "/";
        res += dirlist[i];
    }

    //cout << "Relative: " << str << ", Absolute: " << res << endl;
    return true;
}

int main() {
    while(true) {
        int N, M;
        cin >> N >> M;
        if(!N && !M) break;

        set<string> files;
        set<string> dirs;
        for(int i = 0; i < N; ++i) {
            string s;
            cin >> s;
            files.insert(s);

            for(int j = 1; j < s.size(); ++j) {
                if(s[j] == '/') {
                    string dirname = s.substr(0, j);
                    dirs.insert(dirname);
                }
            }
        }

        for(int i = 0; i < M; ++i) {
            string s1, s2;
            cin >> s1 >> s2;

            string res = "not found";
            string p1, p2;
            if(absolute_path(s1, dirs, p1) && absolute_path(s2, dirs, p2)) {
                if(files.count(p1) && files.count(p2)) {
                    if(p1 == p2) res = "yes";
                    else res = "no";
                }
            }

            cout << res << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[105],sum = 0;
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = 1;i <= n;){
		if(a[i] % 2 != 0){
			sum = sum + 1;
		}
		i = i + 2;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	ll N,K;

	scanf("%lld %lld",&N,&K);

	if(N > K){
		printf("0\n");
	}else{
		printf("1\n");
	}

	return 0;
}




Measured memory_bytes: 3148
import java.io.*;
import java.util.*;
import java.util.Map.Entry;

		
public class Main {
	public static void main(String[] args) throws Exception{
		MScanner sc = new MScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        pw.println(3l*n*n);
        pw.flush();
    }
	
	static class MScanner {
        StringTokenizer st;
        BufferedReader br;

        public MScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}		

Measured memory_bytes: 23252
// abc.111.c    C - String Transformation

#include <bits/stdc++.h>
using namespace std;

int main( void ) {

    string s, t;
    cin >> s >> t;

    bool            check = true;

	//それぞれの英小文字の対応をmapに格納
    map<char, char> c1,c2;
    
	for( int i = 0; i < s.size(); i++){
		char ss=s.at(i), tt=t.at(i);
        //c1にssがあり、c1[ss]がttでなかったらfalse
		if(c1.count(ss)){
            if( c1[ ss ] != tt ) check = false;
        }
        // c2にttがあり、c2[tt]がssでなかったらfalse
		if(c2.count(tt)){
            if( c2[ tt ] != ss ) check = false;
        }
        c1[ ss ] = tt, c2[ tt ] = ss;
    }
    if( check ) cout << "Yes" << endl;
	else
        cout << "No" << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int x =0;
  for(int i=0;i<N;i++){
    int a ,b ;
    cin>>a>>b;
    x+=b-a+1;
  }
  cout<<x<<endl;
}

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

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

	int a, b, c, k; cin >> a >> b >> c >> k;
	if (k - a >= 0)
	{
		k = k - a;
		if (k - b >= 0)
		{
			k = k - b;
			if (k - c >= k)
			{
				cout << a - c << endl;
			}
			else
				cout << a - k << endl;
		}
		else
			cout << a << endl;
	}
	else
		cout << k << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int i=1; i<=10; i++) {
    int t = i*1000;
    if(t >= n) {
      cout << t-n << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

void heap(int a[],int i,int n){
    int l,r,max,k;
    if(i*2+1>=n){
        return;
    }else if(i*2+2==n){
        if(a[i]<a[n-1]){
            r=a[i];
            a[i]=a[n-1];
            a[n-1]=r;
        }
        return;
    }else{
        l = i*2+1;
        r = i*2+2;
        max = i;
        if(a[i]<a[l]){
            max = l;
        }
        if(a[max]<a[r]){
            max = r;
        }
        if(max!=i){
            k=a[i];
            a[i]=a[max];
            a[max]=k;
            heap(a,max,n);
        }
    }
}

int main(void){
    int n,i,j,k;
    int *a;
    scanf("%d",&n);
    a = (int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n/2;i>=0;i--){
        heap(a,i,n);
    }
    for(i=0;i<n;i++){
        printf(" %d",a[i]);
    }
    printf("\n");
    free(a);
    return 0;
}


Measured memory_bytes: 3356
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	int i,l,count=0;
	char s[100],s1[100];
	scanf("%s%s",s,s1);
	l = strlen(s);
	for(i=0; i<l; i++)
	{
		if(s[i]==s1[i])
		{
			count++;
		}
	}
	if(count==l)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

class modint {
  ll n;

public:
  modint(): n(0) {};
  modint(ll _n): n((_n + MOD) % MOD) {}
  modint(const modint &i): n(i.n) {}
  operator ll() const { return n; }

  modint operator+(const modint &i) const { return modint(n + i.n); }
  modint operator-(const modint &i) const { return modint(n - i.n); }
  modint operator*(const modint &i) const { return modint(n * i.n); }
  modint operator/(const modint &i) const { return modint(n * i.inverse().n); }

  modint operator+=(const modint &i) { return *this = *this + i; }
  modint operator-=(const modint &i) { return *this = *this - i; }
  modint operator*=(const modint &i) { return *this = *this * i; }
  modint operator/=(const modint &i) { return *this = *this / i; }

  modint inverse() const {
    modint p = 1, q = n;
    for(ll t = MOD - 2; t > 0; t /= 2) {
      if(t % 2) p *= q;
      q *= q;
    }
    return p;
  }
};

int main(void) {
  ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;

  vector<modint> fact(N + 1);
  fact[0] = 1;
  REP(i, 1, N + 1) fact[i] = fact[i - 1] * modint(i);

  vector< vector<modint> > dp(N + 1, vector<modint>(B + 2, 0));
  REP(i, A, B + 2) dp[0][i] = 1;
  REP(i, 1, N + 1) {
    for(ll j = B; j >= A; j--) {
      modint comb = 1;
      for(ll k = 1; k <= D && i - j * k >= 0; k++) {
        comb *= fact[N - (i - j * k)] / fact[j] / fact[N - (i - j * k) - j];
        if(k >= C) dp[i][j] += dp[i - j * k][j + 1] * comb / fact[k];
      }
      dp[i][j] += dp[i][j + 1];
    }
  }
  cout << dp[N][A] << endl;
}


Measured memory_bytes: 8192
S=input()
a=int(S[:2])
b=int(S[2:])

if a==0 and b==0 :
    print("NA")
elif a > 13 and b > 13 :
    print("NA")
elif a * b ==0 and ( a > 13 or b > 13) :
    print("NA")
elif a <13 and b < 13 and a*b !=0:
    print("AMBIGUOUS")
elif 0 < a <13:
    print("MMYY")
elif 0 < b <13:
    print("YYMM")
    


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

#define double long double

double EPS = (1e-10);
#define equals(a, b) (fabs((a)-(b)) < EPS)
#define PI 3.141592653589793238

static const int CCW_COUNTER_CLOCKWISE = 1;
static const int CCW_CLOCKWISE = -1;
static const int CCW_ONLINE_BACK = 2;
static const int CCW_ONLINE_FRONT = -2;
static const int CCW_ON_SEGMENT = 0;

struct Point {
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  Point operator+(Point p) { return Point(x+p.x, y+p.y); }
  Point operator-(Point p) { return Point(x-p.x, y-p.y); }
  Point operator*(double k) { return Point(x*k, y*k); }
  Point operator/(double k) { return Point(x/k, y/k); }
  double norm() { return x*x + y*y; }
  double abs() { return sqrt(norm()); } 
};

typedef Point Vector;
typedef vector<Point> Polygon;

double norm(Vector a) {
  return a.x*a.x + a.y*a.y;
}

double abs(Vector a) {
  return sqrt(norm(a));
}

double dot(Vector a, Vector b) {
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a, Vector b) {
  return a.x*b.y - a.y*b.x;  
}

int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1-p0;
  Vector b = p2-p0;
  if ( cross(a, b) > EPS ) return CCW_COUNTER_CLOCKWISE;
  if ( cross(a, b) < -EPS ) return CCW_CLOCKWISE;
  if ( dot(a, b) < -EPS ) return CCW_ONLINE_BACK;  
  if ( a.norm() < b.norm() ) return CCW_ONLINE_FRONT;
  return CCW_ON_SEGMENT;
}

double area(Polygon s) {
  double res = 0;
  for ( int i = 0; i < (int)s.size(); i++ ) {
    res += cross(s[i], s[(i+1)%s.size()])/2.0;
  }
  return res;
}

Point rot(Point p, double a) {
  Point p1 = Point(0, 0);
  a = a*M_PI/180.0;
  p = p-p1;
  double x = p.x*cos(a) + p.y*(-sin(a)) + p1.x;
  double y = p.x*sin(a) + p.y*cos(a) + p1.y;			       
  return Point(x, y);  
}

signed main() {
  double r, x, y;
  int n;  
  cin >> r >> x >> y >> n;

  vector<int> p(n+1, 0);
  for ( int i = 0; i < n; i++ ) {
    cin >> p[i+1];
  }

  int sum = 0;
  double sum_area = 0;  
  Point p0 = Point(x, y);
  Point ori = Point(0, r);
  double c_area = r*r*PI;  
  for ( int i = 0; i < n; i++ ) {
    if ( i ) cout << " ";
    Point p1 = rot(ori, 360-(sum*3.6));
    sum += p[i+1];
    Point p2 = rot(ori, 360-(sum*3.6));
    double o_area = c_area * ((double)sum/100.0) - sum_area;
    sum_area += o_area;
    // cout << p1.x << " " << p1.y << endl;
    // cout << p2.x << " " << p2.y << endl;
    if ( ccw(p0, p1, p2) == CCW_CLOCKWISE ) {
      // cout << i << endl;
      Polygon s = {p0, p2, p1};
      double tri0 = area(s);
      s[0] = Point(0, 0);
      double tri1 = area(s);
      double now_area = (tri0 + (o_area-tri1));
      // cout << now_area << " " << o_area << endl;
      cout << (int)((now_area)/o_area*100.0);      
    } else {
      Polygon s = {p0, p2, p1};
      double tri0 = area(s);
      s[0] = Point(0, 0);
      double tri1 = area(s);
      double now_area = (tri0 + (o_area-tri1));
      // cout << now_area << " " << o_area << endl;
      cout << (int)(now_area/o_area*100.0);     
    }
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3548
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
#define ll long long
const ll N = 1e5+105;
ll n,i,sol;
string s[N];
unordered_map <string,ll> m;
unordered_map <string,bool> mapp;
int main()
{
    cin>>n;
    for (i=1; i<=n; ++i)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
        m[s[i]]++;
    }
    for (i=1; i<=n; ++i)
    {
        if (!mapp[s[i]])
        {
            sol+=(m[s[i]]*(m[s[i]]-1))/2;
            mapp[s[i]]=1;
        }
    }
    cout<<sol;
}



Measured memory_bytes: 27940
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	s := nextString()
	_ = nextString()
	a := nextInt()
	b := nextInt()
	u := nextString()

	if s == u {
		a--
	} else {
		b--
	}

	_, _ = fmt.Fprintf(writer, "%d %d", a, b)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int N = 10000 + 2;
const int mod = 1e9 + 7;

char s[N];
int dp[N][100][2], d, n;


int go(int id, int md, bool f = false) {
  if (id == n) {    
    return !md;
  }
  if (~dp[id][md][f]) return dp[id][md][f];
  long long ans = 0, dig = s[id] - '0';
  for (int i = 0; i < 10; ++i) {
    if (f == false && i > dig) break;
    ans += go(id+1, ((md+i)%d), f|(i<dig));
  }
  if (ans >= mod) ans %= mod;
  return dp[id][md][f] = ans;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> d;
  memset(dp, -1, sizeof dp);  
  n = strlen(s);  
  int ans =  go(0,0,0) - 1;
  if (ans < 0) ans += mod;
  cout << ans;  
  return 0;
}
// 1). Try forming/rearranging the equations if any
// 2). If problem asks to count, try counting in reverse(it can be easier sometimes)


Measured memory_bytes: 16768
#include <stdio.h>

int linerSearch(int *,int,int);

int main(){
  int S[10000],q,i,n,t,c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    if(linerSearch(S,n,t) == 1)c++;
  }
  printf("%d\n",c);
  return 0;
}

int linerSearch(int *S,int n,int key){
  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
    if(i==n) return 0;
  }
  return 1;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

const int maxn = 100123, mod = 1e9 + 7;
ll dp[maxn][2];
vector<int> G[maxn];

ll add(ll x, ll y) {
	x += y;
	if(x >= mod) x -= mod;
	return x;
}

void mul_self(ll &x, ll y) {
	x *= y;
	x %= mod;
}

void dfs(int u=0, int p=0) {
	dp[u][0] = dp[u][1] = 1;
	for(auto v:G[u]) {
		if(v == p) continue;
		dfs(v, u);
		mul_self(dp[u][1], dp[v][0]);
		mul_self(dp[u][0], add(dp[v][0], dp[v][1]));
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n - 1; ++ i) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs();
	cout << add(dp[0][0], dp[0][1]) << '\n';
}


Measured memory_bytes: 14208
alphabet = [i for i in "abcdefghijklmnopqrstuvwxyz"]
# print(alphabet)
S = input()
S_list = [i for i in S]
S_list = sorted(set(S_list),reverse=False)

ans = "a"

for index,i in enumerate(S_list):
    if S_list == alphabet:
        ans = None
        break
    else:
        if i != alphabet[index]:
            ans = alphabet[index]
            break
        else:
            ans = alphabet[index+1]

print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define int long long
#define endl "\n";
using namespace std;

void solve(){
	int k; cin >> k;
	string s; cin >> s;
	if (s.size() > k) cout << s.substr(0, k) << "...";
	else cout << s;

}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 1010
#define MAX_M MAX_N

ll N, M;
ll X[3][MAX_N] = {};
ll dp[MAX_N][MAX_M] = {};

ll dfs(ll i, ll j, ll pat) {
    if(i >= N || j >= M) { return 0; }

    ll& res = dp[i][j];
    if(~res) { return res; }

    ll x = X[0][i], y = X[1][i], z = X[2][i];
    if((pat >> 0) & 1) { x = -x; }
    if((pat >> 1) & 1) { y = -y; }
    if((pat >> 2) & 1) { z = -z; }
    res = dfs(i+1, j+1, pat) + x + y + z;
    if(N - i > M - j) {
        res = max(res, dfs(i+1, j, pat));
    }
    return res;
}

signed main()
{
    cin >> N >> M;
    REP(i, N) {
        cin >> X[0][i] >> X[1][i] >> X[2][i];
    }
    ll ans = 0;
    REP(pat, 8) {
        MINUS(dp);
        ans = max(ans, abs(dfs(0, 0, pat)));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 8320
N = input( )

if N[-1] == "3":
    print("bon")
if N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
    print("pon")
if N[-1] == "2" or N[-1] == "4" or N[-1] == "5" or N[-1] == "7" or N[-1] == "9":
    print("hon")

Measured memory_bytes: 9064
#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;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#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 = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll dp[200005][2];

int main() {
    string S;
    cin >> S;
    ll N = S.size();

    dp[1][0] = 1;
    repe(i, 1, N){
        if (S[i - 1] != S[i]) chmax(dp[i + 1][0], dp[i][0] + 1);
        chmax(dp[i + 1][0], dp[i][1] + 1);
        chmax(dp[i + 1][1], dp[i - 1][0] + 1);
    }

    cout << max(dp[N][0], dp[N][1]) << endl;
}

Measured memory_bytes: 6872
#include <stdio.h>
#include <limits.h>
#define N_MAX 5000

int main(void){
	long int max, sum; int a[N_MAX], n, i, j;
	
	while(scanf("%d",&n), n!=0){
		max=INT_MIN;
		
		for(i=0; i<n; i++) scanf("%d",&a[i]);
		
		for(i=0; i<n; i++){ /* ツ氾債暗債づーツ陛渉可サ */
			sum=0;
		
			for(j=i; j<n; j++){
				sum+=a[j];
				if(sum>max) max=sum;
			}
		}
		printf("%ld\n",max);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    
    int n, m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
from fractions import gcd
import math


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    a = int(input())
    print(3 * a * a)

main()


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

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

    int N;
    cin >> N;
    if(N%10 == (N-N%100)/100){cout << "Yes\n";}else{cout << "No\n";}

    return 0;
}

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

int main()
{
	int n; cin >> n;
	
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}

	int ans = 2147483647;
	for (int t = 1; t < n; t++) {		
		int s1 = 0;
		int s2 = 0;
		for (int i = 0; i < n; i++) {
			if (i + 1 <= t) s1 += w[i];
			else s2 += w[i];
		}
		ans = min(ans, abs(s1 - s2));
	}

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

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

int n,a[100],mx=0,sm=0;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
        sm+=a[i];
    }
    cout<<(mx<sm-mx ? "Yes":"No")<<endl;
    

    
}


Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.22 20:32:00
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 764