akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;


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

	freopen("output.txt", "w", stdout);
#endif

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

	ll n, m, x;
	cin >> n >> m >> x;

	vector<vector<ll> >v(n);
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j <= m; j++)
		{
			ll x;
			cin >> x;
			v[i].pb(x);
		}
	}

	ll k = 1 << n;
	ll ans = INT_MAX;
	for (ll i = 1; i < k; i++)
	{
		vector<ll>u;
		for (ll j = 0; j <= 13; j++)
		{
			if ((1 << j)&i)
			{
				u.pb(j);
			}
		}
		ll f = 0;
		for (ll i = 1; i <= m; i++)
		{
			ll temp = 0;
			for (auto z : u)
			{
				temp += v[z][i];
			}
			if (temp < x)
			{
				break;
			}
			else
			{
				f++;
			}
		}
		if (f == m)
		{
			ll yo = 0;
			for (auto z : u)
			{
				yo += v[z][0];
			}
			ans = min(ans, yo);
		}

	}
	if (ans == INT_MAX)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}


}



Measured memory_bytes: 3664
#include<stdio.h>
int main(){
	
	int N,i,j,count=0;
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		
		for(j=0;j<N;j++){
			if(i*7+j*4==N){
			count++;
			}
		}
	}
	
	
	if(count>0){
	printf("\nYes\n\n");
	}else {
		printf("\nNo\n\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
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;
typedef vector<cd> vcd;
 
#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 trav(a,x) for (auto& a : x)
 
#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 ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M;
 
    ll K; cin >> K;
    ll A[N], B[M]; F0R(i, N) cin >> A[i];
    F0R(i, M) cin >> B[i];
 
    ll as = 0; F0R(i, N) as += A[i];
    ll bs = 0;
    int bp = 0;
    int ans = 0;
    F0Rd(i, N+1) {
        if (i < N) as -= A[i];
        if (as <= K) {
            while (bp < M && as + bs + B[bp] <= K) {
                 bs += B[bp]; bp++;
            }
            ckmax(ans, i + bp);
        }
//        cout << as << " " << bs << " " << bp << nl;
    }
    cout << ans << nl;
	
	return 0;
}

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

int main() {
  int n, x, y, count = 0;
  bool ans = false;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == y) {
      count++;
    }
    else {
      count *= 0;
    }
    if (count == 3) {
      ans = true;
    }
  }
  if (ans == true) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw3(15,1);vector<ll> pw10(19,1);
int main(){
    {rep1(i,14) pw3[i]=3*pw3[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll K,A,B; cin>>K>>A>>B;
    
    if(B-A<=2) cout<<K+1<<endl;
    else{
        ll rem=K; //のこり回数
        ll now=1;
        if(A-1<K){
            rem-=(A-1);
            now=A;
        }
        
        now+=(rem/2)*(B-A);
        now+=rem%2;
        
        cout<<now<<endl;
    }
}


Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
	int y, m, d;
	while(scanf("%d%d%d", &y, &m, &d)!=EOF) {
		if(y == 1989) {
			if( (m == 1 && d >= 8) || (m > 1) ) printf("heisei 1 %d %d\n", m, d);
			else printf("showa 64 %d %d\n", m, d);
		}
		else if(y > 1989) printf("heisei %d %d %d\n", y-1988, m, d);
		else if(y == 1926) {
			if( (m == 12 && d >= 25) || (m > 12) ) printf("showa 1 %d %d\n", m, d);
			else printf("taisho 15 %d %d\n", m, d);
		}
		else if(y > 1926) printf("showa %d %d %d\n", y-1925, m, d);
		else if(y == 1912) {
			if( (m == 7 && d >= 30) || (m > 7) ) printf("taisho 1 %d %d\n", m, d);
			else printf("meiji 45 %d %d\n", m, d);
		}
		else if(y > 1912) printf("taisho %d %d %d\n", y-1911, m, d);
		else if(y == 1868) {
			if( (m==9 && d >= 8) || (m > 9) ) printf("meiji 1 %d %d\n", m, d);
			else printf("pre-meiji\n");
		}
		else if(y > 1868) printf("meiji %d %d %d\n", y-1867, m, d);
		else printf("pre-meiji\n");
	}
	return 0;
}


Measured memory_bytes: 608
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

iter_list = list(range(1, N+1))
permutations_list = list(itertools.permutations(iter_list, N)) #辞書順でリストに格納される

a = permutations_list.index(P)
b = permutations_list.index(Q)

print(abs(a-b))

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

long long int n,i;
string s,t;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s>>t;
	n=s.size();
	for (i=0;i<n;i++) if (s[i]!=t[i])
	{
		cout<<"No";return 0;
	}
	cout<<"Yes";
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
const int N=5000000;
long long n,m,a1,b1,i,tmp,ans;
long long p[N],p1[N],s[N],s1[N],a[N];
void update(int x,int k)
{ p1[x*2]+=p1[x]; p1[x*2+1]+=p1[x];
   p[x*2]+=p1[x]; p[x*2+1]+=p1[x];
  p1[x]=0;
  s1[x*2]+=s1[x]; s1[x*2+1]+=s1[x];
  s[x*2]+=s1[x]; s[x*2+1]+=s1[x];
  s1[x]=0;}
void renew(int x)
{
   p[x]=min(p[x*2],p[x*2+1]);
	s[x]=min(s[x*2],s[x*2+1]); 
}
void getmin(int q,int l,int r,int pos,long long  zhi)
{
	update(q,2);
	if (l==r) 
	{  p[q]=1ll*zhi+pos; s[q]=1ll*zhi-pos; 	return;}
    int mid=(l+r)/2;
    if (pos<=mid)  getmin(q*2,l,mid,pos,zhi);
              else getmin(q*2+1,mid+1,r,pos,zhi);
    renew(q);
}
long long query(int q,int l,int r,int x,int y,int k)
{
	if (x>y) return 1e18; 
	if ((x<=l)&&(r<=y))  {  	return (k)? p[q]:s[q];}
	else
	{     update(q,k);
		int mid=(l+r)/2;
		//long long ans1=1e10,ans2=1e10;
		if (x>=mid+1) return query(q*2+1,mid+1,r,x,y,k);
	else if (y<=mid)  return query(q*2,l,mid,x,y,k);
	else return(min(query(q*2+1,mid+1,r,mid+1,y,k),query(q*2,l,mid,x,mid,k)));  }
	}
int main()
{
  cin>>n>>m>>a1>>b1;
  for (int i=1;i<=m;i++)
  scanf("%d",&a[i]);
  memset(p,0x3f,sizeof(p));
  memset(s,0x3f,sizeof(s));
  getmin(1,1,n,a1,0);  a[0]=b1;
  for (int i=1;i<=m;i++)
  { // cout<<a[i]<<' '<<query(1,1,n,1,a[i],0)<<' '<<query(1,1,n,a[i]+1,n,1)<<endl;
      tmp=min(query(1,1,n,1,a[i],0)+a[i],query(1,1,n,a[i]+1,n,1)-a[i]);
      //cout<<a[i-1]<<' '<<tmp<<endl;
     // for (int j=1;j<=n;j++)
      //{ cout<<i<<' '<<j<<' '<<query(1,1,n,j,j,0)+j<<endl;}
      p[1]+=abs(a[i]-a[i-1]); s[1]=abs(a[i]-a[i-1]); p1[1]+=abs(a[i]-a[i-1]);s1[1]+=abs(a[i]-a[i-1]);
      //cout<<p1[1]<<' '<<s1[1]<<endl;
      getmin(1,1,n,a[i-1],tmp);
  }
  ans=1e18;
  for ( i=1;i<=n;i++)
  {ans=min(ans,query(1,1,n,i,i,0)+i); }
  cout<<ans;
}

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

int main(){
	double n,m,d;cin>>n>>m>>d;
	if(d==0){
		printf("%.12lf\n",1/n*(m-1));
	}
	else if(2*d<=n){
		printf("%.12lf\n",(2*d+(n-2*d)*2)/(n*n)*(m-1));
	}
	else{
		printf("%.12lf\n",1/(n*n)*(m-1));
	}
}

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


int solve(int A, int B, int C, vector<int>& cal) {
  sort(cal.begin(), cal.end(), greater<int>());

  auto c = C;
  double result = c / A;

  for (auto i = 0; i < cal.size(); ++i) {
    c += cal[i];
    auto p = A + B * (i + 1);
    double next = max(result, (double)c / p);
    if (next < result) break;
    
    result = next;
  }

  return (int)result;
}

int main() {
  int N, A, B, C;
  cin >> N;
  cin >> A >> B;
  cin >> C;
  vector<int> cal(N);
  for (auto i = 0; i < N; ++i) {
    cin >> cal[i];
  }

  cout << solve(A, B, C, cal) << endl; 
}


Measured memory_bytes: 3152
#include<stdio.h>
 
int main(void){
  int A,B,i=0;
  scanf("%d %d",&A,&B);
 int out=1;
  
  if(A==B){
    printf("1\n");
    return 0;
  }
  
  while(out<B){
    out--;
    out+=A;
    i++;
  }
    
  printf("%d\n",i);
      
      
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1002
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int sum[MAXN][MAXN];
int cntIt(int l, int r, int u, int d, int k) {
    int c = sum[d][r] - sum[u - 1][r] - sum[d][l - 1] + sum[u - 1][l - 1];
    if (c > k && (l == r)) return -1;
    if (c > k) return inf;
    return c;
}
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    char c;
    int res = inf;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> c;
            sum[i][j] = (c - '0') + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }
    for (int i = 1; i < (1 << (h + 1)) - 1; i++) {
        vector<int> indexs;
        indexs.pb(1);
        for (int j = 2; j <= h; j++) {
            if ((i & (1 << j)) != 0) {
                indexs.pb(j);
            }
        }
        indexs.pb(h + 1);
        int cur = 0;
        int lastIndex = 1;
        bool found = true;
        for (int j = 1; j <= w && found; j++) {
            int mx = 0;
            for (int kk = 0; kk < sz(indexs) - 1 && found; kk++) {
                int c = cntIt(lastIndex, j, indexs[kk], indexs[kk + 1] - 1, k);
                if (c == -1) {
                    found = false;
                    break;
                }
                mx = max(mx, c);
            }
            if (mx == inf) {
                cur++;
                lastIndex = j;
            }
        }
        if (found)
            res = min(res, cur + sz(indexs) - 2);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    N,Q = map(int,input().split()) 
    q = deque([])
    for _ in range(N):
        name,time = input().split()
        q.append((name,int(time)))
    
    ans = []
    t = 0
    while q:
        name,time = q.popleft()
        if time <= Q:
            t += time
            ans.append((name,t))
        else:
            t += Q
            time -= Q
            q.append((name,time))
    print('\n'.join(' '.join(map(str,a)) for a in ans))
if __name__ == '__main__':
    main()


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];

  map<int, int> mp;
  for(int i = 0; i < N; i++) {
    mp[a[i]]++;
  }
  int ans = 0;
  for(auto p : mp) {
    int x = p.first;
    int n = p.second;
    if(n < x)
      ans += n;
    else
      ans += n - x;
  }

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

Measured memory_bytes: 5120
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)
 
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(i, a, b) for(int i = a; i <= b; i++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, b, a) for(int i = b; i >= a; i--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(m) repp(i, 1, m){ll a, b; cin >> a >> b; v[a].pb(b), v[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define endl "\n"
#define bitsf(n) __builtin_popcount(n)
ll power(ll x, ll y); 

const ll MOD = 1000000007;

string s = "10";
int n = 2;
vector<string> v;
int cnt = 9;

void rec(int cur)
{
	int nxt = cur + 1;
	for(char c = s[cur] - 1; c <= s[cur] + 1; c++){
		if(c < '0' || c > '9') continue;
		s[nxt] = c;
		if(cur <= n - 3){
			if(cnt <= 100000) rec(nxt);
		}
		if(cur == n - 2){
			v.pb(s);
			cnt++;
		}
	}
	if(cur == 0){
		if(s[0] == '9'){
			n++;
			s = "1";
			rep(i, 1, n) s+='0';
		}else{
			s[0]++;
		}
			if(cnt <= 100000) rec(0);
	}
}
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
	string str = "0";
	for(char ch = '1'; ch <= '9'; ch++){
		str[0] = ch;
		v.pb(str);
	}
	rec(0);

	// rep(i, 0, 15) cout << v[i] << endl;
	int k;
	cin >> k;
	cout << v[k - 1];
	
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 5748
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC121B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            var M = ReadInt;
            var C = ReadInt;
            var B = ReadInts;

            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                int sum = 0;
                var A = ReadInts;
                for (int j = 0; j < M; j++)
                {
                    sum += A[j] * B[j];
                }
                sum += C;
                if (sum > 0) ans++;
            }

            Console.WriteLine(ans);

        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int N;
vector<string> groups;
vector<vector<string>> names;
vector<set<string>> dp;

int getNum(string name) {
    rep(i, N) {
        if (name == groups[i]) {
            return i;
        }
    }
    return -1;
}

void merge(set<string> &s, set<string> t) {
    for (auto x : t) s.insert(x);
}

set<string> dfs(int i = 0, set<string> st = set<string>{}) {
    if (!dp[i].empty()) return dp[i];

    for (auto name : names[i]) {
        int ni = getNum(name);
        if (ni == -1) {
            st.insert(name);
        } else {
            merge(st, dfs(ni, st));
        }
    }
    return dp[i] = st;
}

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

    while (cin >> N, N) {
        groups.clear();
        groups.resize(N);
        names.clear();
        names.resize(N);
        dp.clear();
        dp.resize(N);
        rep(i, N) {
            string s;
            cin >> s;
            s.back() = ',';
            stringstream ss(s);
            getline(ss, groups[i], ':');
            string t;
            while (getline(ss, t, ',')) {
                names[i].emplace_back(t);
            }
        }
        
        cout << dfs().size() << endl;
    }
}

Measured memory_bytes: 5596
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    //とりあえずif文で大文字を小文字に変換する
    //a~zのデータセットを用意する
    
    string str;
    int num[30]={};
    while(getline(cin,str))
    {
        for(int i=0;i<str.size();i++)
        {
            if(str[i]>='A'&&str[i]<='Z')str[i]+='a'-'A';//全て小文字
            
            num[str[i]-'a']++;
            /*int a{};
            a=str[i];
            cout<<a<<" ";*/
        }
    }
    for(int i=0;i<26;i++)
    {
        char ch;
        ch=i+'a';
        cout<<ch<<" : "<<num[i]<<endl;
    }
    return 0;
    
}


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

int find(int a, int b){
    if(a < b) return find(b,a);
    if(a % b == 0) return b;
    return find(b, a%b);
}

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    int lcm = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        if(i == 0){
            lcm = x;
        }else{
            lcm = find(lcm,x);
        }
        
    }
    
    cout << lcm << endl;

    return 0;
}

Measured memory_bytes: 640
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#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 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    double N, D; cin >> N >> D;
    cout << ceil(N/(2*D+1)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 300000
vector<int>g[MAX];
int dfs(int u,int p){
    int l=0;
    for(int v:g[u]){
        if(v!=p){
         l^=1+dfs(v,u);   
        }
    }
    return l;
}
int main() {
	int n,u,v;
	cin>>n;
	for(int i=0;i<n-1;i++){
	    cin>>u>>v;
	    g[u].push_back(v);
	    g[v].push_back(u);
	}
	cout<<(dfs(1,0)?"Alice":"Bob");
	return 0;
}

Measured memory_bytes: 15104
#include <iostream>

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

int main(){
    long long a, b;
    std::cin >> a >> b;

    long long limit = gcd(a, b), val = limit, i = 2, count = 1;
    while(i * i < limit){
        if(0 == val % i){
            while(0 == val % i){
                val /= i;
            }
            ++count;
        }else{
            ++i;
        }
    }

    if(1 < val){
        ++count;
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
while v=gets
	a,b,c,d,e,f=v.split.map(&:to_f)
	x=(c*e-b*f)/(a*e-b*d)+0.000
	y=(a*f-c*d)/(a*e-b*d)+0.000
	printf "%.3f %.3f\n",x,y
end

Measured memory_bytes: 6132
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

int main() {
  string T;
  cin >> T;
  for (auto &c: T) {
    if (c == '?') c = 'D';
  }
  cout << T << endl;
  return 0;
}


Measured memory_bytes: 3760
#include <stdio.h>

int main (void){
  int H[100], W[100], i = 0, j, x, y;

  while(1){
    scanf("%d %d", &H[i], &W[i]);
    if(H[i] == 0 && W[i] == 0) break;
    i++;
  }

  for(j = 0; j < i; j++){
    for(y = 0; y < H[j]; y++){
      for(x = 0; x < W[j]; x++){
        if(y == 0 || y == (H[j] - 1) || x == 0 || x == W[j] - 1){
          printf("#");
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 1788
N=int(input())
X= N*(2+(N -1)) / 2
k1=N//3
k2=N//5
k3=N//15
a=k1*(3+(k1)*3)/2
b=k2*(5+(k2)*5)/2
c=k3*(15+(k3)*15)/2
print(int(X-a-b+c))

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

int main()
{
    int n, k, q;

    cin >> n >> k >> q;

    vector<int> pointList(n, 0);

    for (int i = 0; i < q; i++)
    {
        int input;
        cin >> input;

        pointList.at(input - 1)++;
    }

    for (int i = 0; i < n; i++)
    {
        cout << (pointList.at(i) > (q - k) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e18 + 7LL;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1;
    char prev = '#';
    ll ans = 0;
    REP(i, s1.size())
    {
        if (s1[i] != prev){
            ++ans;
            prev = s1[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (b - a <= k && c - b <= k && d - c <= k && e - d <= k && c - a <= k && d - b <= k && e - c <= k && d - a <= k && e - b <= k && e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//Author: Heltion
//Date: 2019-05-04 
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 240000;
char S[maxn], T[maxn];
void print(int r1, int c1, int r2, int c2, int H, int W){
	for(int i = 1; i <= H; i += 1){
		for(int j = 1; j <= W; j += 1) cout << ((i >= r1 and i <= r2 and j >= c1 and j <= c2) ? "#" : ".");
		cout << endl;
	}
	cout << endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int H, W, N, sr, sc;
	cin >> H >> W >> N >> sr >> sc >> S >> T;
	int r1 = 1, c1 = 1, r2 = H, c2 = W;
	for(int i = N - 1; ~i; i -= 1){
		if(T[i] == 'U') r2 = min(H, r2 + 1);
		if(T[i] == 'D') r1 = max(1, r1 - 1);
		if(T[i] == 'L') c2 = min(W, c2 + 1);
		if(T[i] == 'R') c1 = max(1, c1 - 1);
		//print(r1, c1, r2, c2, H, W);
		if(S[i] == 'U') r1 += 1;
		if(S[i] == 'D') r2 -= 1;
		if(S[i] == 'L') c1 += 1;
		if(S[i] == 'R') c2 -= 1;
		if(r1 > r2 or c1 > c2) break;
		//print(r1, c1, r2, c2, H, W);
	}
	if(sr >= r1 and sr <= r2 and sc >= c1 and sc <= c2) cout << "YES";
	else cout << "NO";
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  string T, P;
 
  cin >> T;
  cin >> P;
 
  vector< int > latte[26];
  for(int i = 0; i < T.size(); i++) {
    latte[T[i] - 'a'].push_back(i);
  }
 
  vector< int > beet(P.size(), -1);
  int last = 0;
  for(int i = 0; i < P.size(); i++) {
    auto &p = latte[P[i] - 'a'];
    auto q = lower_bound(begin(p), end(p), last);
    if(end(p) == q) {
      cout << "no" << endl;
      return (0);
    }
    beet[i] = *q;
    last = *q + 1;
  }
 
  last = T.size() - 1;
  for(int i = P.size() - 1; i >= 0; i--) {
    auto &p = latte[P[i] - 'a'];
    auto q = upper_bound(begin(p), end(p), last);
 
    if(begin(p) == q) {
      cout << "no" << endl;
      return (0);
    }
    --q;
 
    if(beet[i] != *q) {
      cout << "no" << endl;
      return (0);
    }
    last = *q - 1;
  }
 
  cout << "yes" << endl;
 
}

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

int main() {
  int n;
  while(cin >> n, n) {
    int p[n];
    for(int i = 0; i < n; i++) cin >> p[i];

    for(int i = 0; i < n-1; i++) {
      cout << p[i];
      if(p[i]+1 == p[i+1]) {
        cout << '-';
        for(int j = i+1; j < n-1; j++) {
          if(p[j]+1 != p[j+1]) {
            cout << p[j];
            i = j;
            break;
          }
          if(j+1 == n-1) i = j;
        }
      }
      if(p[i]+1 != p[i+1]) cout << ' ';
    }
    cout << p[n-1] << endl;
  }
}

Measured memory_bytes: 1160
n = int(input())
an = list(map(int, input().split()))
sa = sorted(((a, i) for i, a in enumerate(an)), reverse=True)
sa.append((0, 0))

result = [0] * n
prev_a, min_i = sa[0]
for j, (a, i) in enumerate(sa[1:]):
    result[min_i] += (j + 1) * (prev_a - a)
    min_i = min(min_i, i)
    prev_a = a

for cnt in result:
    print(cnt)


Measured memory_bytes: 23452
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX = 500000;

int A[MAX], n;
// ??????
int partition(int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}
int main() {

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);

	// ??°???Ar?????????
	int p = partition(0, n - 1);

	for (int i = 0; i < n; i++) {
		if(i == p)
			printf("[%d]%c", A[i], i == n - 1 ? '\n' : ' ');
		else
			printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
	}
	return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

template <int M> class ModInt {
    int x;

  public:
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    constexpr ModInt &operator+=(const ModInt p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt p) {
        x = (int)(1LL * x * p.x % M);
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt p) {
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt p) const {
        return ModInt(*this) += p;
    }
    constexpr ModInt operator-(const ModInt p) const {
        return ModInt(*this) -= p;
    }
    constexpr ModInt operator*(const ModInt p) const {
        return ModInt(*this) *= p;
    }
    constexpr ModInt operator/(const ModInt p) const {
        return ModInt(*this) /= p;
    }
    constexpr bool operator==(const ModInt p) const { return x == p.x; }
    constexpr bool operator!=(const ModInt p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t = 0;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(int64_t k) const {
        ModInt ret(1), mul(x);
        while(k > 0) {
            if(k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    constexpr friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    constexpr friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t = 0;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using mint = ModInt<Mod>;

int n, s;
int a[3009];
mint dp[3009][3009];

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

    cin >> n >> s;
    rep(i, n) cin >> a[i];

    dp[0][0] = mint(2).pow(n);

    mint inv2 = mint(2).inverse();

    rep(i, n) rep(j, s + 1) {
        dp[i + 1][j] += dp[i][j];
        if(j + a[i] <= s) dp[i + 1][j + a[i]] += dp[i][j] * inv2;
    }

    cout << dp[n][s] << endl;

    return 0;
}

Measured memory_bytes: 38892
from collections import defaultdict



N = int(input())
A = list(map(int, input().split()))

cnt = defaultdict(int)
for i in range(N):
    a = A[i]
    cnt[a] += 1

sel = defaultdict(int)
total = 0
for k, v in cnt.items():
    total += v*(v-1)//2

for i in range(N):
    a = A[i]
    c = cnt[a]
    before = c*(c-1)//2
    after = (c-1)*(c-2)//2
    print(total-before+after)



Measured memory_bytes: 26780
#include<iostream>
#include<map>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    map<unsigned long long,int>num;
    unsigned long long tmp;
    for(int i = 0; i < n; i++){
        cin>>tmp;
        num[tmp]++;
    }
    for(auto x:num)if((x.second)%2)ans++;
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll m;
  cin >> m;
  ll key, ans = 0;
  rep(i, m) {
    cin >> key;
    ll left = 0, right = n;
    while (left < right) {
      ll mid = (left+right)/2;
      if (key == v.at(mid)) {
        ans++;
        break;
      } else if (v.at(mid) < key) {
        left = mid+1;
      } else {
        right = mid;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3504
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new long[n+2];
  foreach (i; 1 .. n + 1) {
    readf (" %d", &a[i]);
  }
  long s = 0;
  foreach (i; 1 .. n + 2) {
    s += abs (a[i] - a[i-1]);
  }
  foreach (i; 1 .. n + 1) {
    writeln (s - (abs (a[i] - a[i-1]) + abs (a[i] - a[i+1])) + abs (a[i-1] - a[i+1]));
  }
}


Measured memory_bytes: 3964
#include <iostream>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <utility>
#include <queue>
#include <array>
#include <list>
#include <cmath>
#include <algorithm>
using namespace std;

#define pb push_back
#define pii pair<int, int>

vector<string> all;

void func(string s){
	vector<char> x;
	int len = s.size();
	for(int i = 0;i < len;i++)
		x.pb(s[i]);
	sort(x.begin(), x.end());
	string tmp(x.begin(), x.end());
	all.pb(tmp);
}

int main(){
	int n;
	cin >> n;
	string tmp;
	for(int i = 0;i < n;i++){
		cin >> tmp;
		func(tmp);
	}
	sort(all.begin(),all.end());
	long long ans = 0;
	int len = all.size();
	long long temp = 1;
	// cout << len << endl;
	for(int i = 1;i < len;i++){
		if(all[i-1].compare(all[i]) == 0){
			temp++;
			// cout << i << ' ' << temp << endl;
		}
		else{
			ans = ans + (temp*(temp-1))/2;
			// cout << i << ' ' << ans << endl;
			temp = 1;
		}
	}
	if(temp != 1){
		ans += (temp*(temp-1))/2;
	}
	cout << ans;
	return 0;
}

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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 998244353

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    ll n,i;
    string s;
    cin>>n;
    cin>>s;

    vvll A(3);

    fr(i,0,n)
    {
        if(s[i]=='R')
            A[0].pb(i);
        else if(s[i]=='G')
            A[1].pb(i);
        else
            A[2].pb(i);
    }
    i=0;
    ll j;
    ll ans=0;
    while(i<A[0].size())
    {
        ll i1=A[0][i];
        fr(j,0,A[1].size())
        {
            ll k1;            
            ll j1=A[1][j];

            ll kp = A[2].size();
            ll index_2;

            index_2 = lower_bound(A[2].begin(),A[2].end(),j1+(j1-i1))-A[2].begin();
            ll index_3 = lower_bound(A[2].begin(),A[2].end(),i1+(i1-j1))-A[2].begin();
            ll index_4,d=-1;
            if(abs(i1-j1)%2==0)
            {
                d = j1+((i1-j1)/2);
                index_4 = lower_bound(A[2].begin(),A[2].end(),d)-A[2].begin();
            }

            ll w=0;
            if(index_2>=0 && index_2<A[2].size() && A[2][index_2]== j1+(j1-i1))
                w++;
            if(index_3>=0 && index_3<A[2].size() && A[2][index_3]== i1+(i1-j1))
                w++;
            if(index_4>=0 && index_4<A[2].size() && A[2][index_4]== d)
                w++;
            
            ans+=kp-w;
            // cout<<i1<<" "<<j1<<" "<<ans<<endl;
        }
        i++;       
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3692
N,x=gets.chomp.split(" ").map(&:to_i)
array=gets.chomp.split(" ").map(&:to_i)
ret=0
pre=0
array.each do |a|
    diff=pre+a-x
    if diff > 0
        pre = a-diff
        ret+=diff
    else
        pre = a
    end
end
puts ret


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

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()
#define BETWEEN(a, x, b) (a) <= (x) && (x) <= (b) 

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;


void solve()
{
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(ALL(a));
    if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main()
{
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
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;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************
 


signed main()
{
	//IOS();
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	auto a = make_v<int>(H,W);
	if(H%h==0&&W%w==0){
		cout<<"No"<<endl;
		return 0;
	}
	fill_v(a,1000);
	rep(i,0,H){
		if(i%h==h-1){
			rep(j,0,W){
				if(j%w==w-1){
					a[i][j]=-1-(h*w-1)*1000;
				}
			}
		}
	}
	//cout<<sum<<endl;
	{
		cout<<"Yes"<<endl;
		rep(i,0,H){
			rep(j,0,W){
				if(j)cout<<" ";
				cout<<a[i][j];
			}
			cout<<endl;
		}
	}
}
//3 4 2 2

Measured memory_bytes: 3584
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
for i in range(0,N-1):
    ans += B[A[i]-1]
    if A[i+1] - A[i] == 1:
        ans += C[A[i]-1]
ans += B[A[N-1]-1]
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i = 0;i<H;i++){
                for(int j = 0;j<W;j++) {
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 61044
N, M = map(int, input().split())
pyi = [[] for _ in range(N)]

for i in range(M):
    p, y = map(int, input().split())
    pyi[p-1].append((y, i))

for i in range(N):
    pyi[i].sort()

O = [None for _ in range(M)]
for p, yis in enumerate(pyi):
    for j, yi in enumerate(yis):
        y, i = yi
        O[i] = (p+1, j+1)

for p, i in O:
    p = ('000000' + str(p))[-6:]
    i = ('000000' + str(i))[-6:]
    print(p+i)


Measured memory_bytes: 39144
#include <iostream> 
#include <cmath> 
 
 using namespace std; 
  int main() { 
 	int n; 
 	cin >> n; 
 	for (int i = 0; i < n; i++) { 
 		double ax,ay,ar,bx,by,br; 
 		cin >> ax >> ay >> ar >> bx >> by >> br; 
 		double dd = (ax-bx)*(ax-bx) + (ay-by)*(ay-by); 
 		double rsum = (ar+br)*(ar+br); 
 		double rdiff = (ar-br)*(ar-br); 
 		if (dd > rsum) 
 			cout << 0 << endl; 
 		else if (dd < rsum && dd > rdiff) 
 			cout << 1 << endl; 
 		else if (dd < rdiff) 
 			cout << (ar > br ? 2 : -2) << endl; 
 		else 
 			cout << 1 << endl; 
 	} 
 	return 0; 
 } 

Measured memory_bytes: 1232
#include <iostream>
 
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
 
using namespace std;
 
int main() {
    LL N, H[100], r = 1;
    cin >> N;
    rep(i, N) cin >> H[i];
    for (LL i = 1; i < N; ++i) {
        bool check = true;
        if (H[i] < H[0]) check = false;
        for (LL j = 1; j < i; j++) {
            if (H[i] < H[j]) {
                check = false;
            }
        }
        if (check) r++;
    }
 
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
def solution():
    s = input()
    T = ['dreamer', 'dream', 'eraser', 'erase']

    while True:
        match = False
        for ss in T:
            if s.endswith(ss) :
                s = s[:-1*len(ss)]
                if not s:
                    print('YES')
                    return
                match = True
                break
        if not match:
            print('NO')
            return

solution()

Measured memory_bytes: 133984
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()

    for (h in 1..3500L) {
        for (n in 1..3500L) {
            val x1 = (N * h * n)
            val x2 = (4 * h * n - N * n - N * h)
            if (x2 > 0 && x1 % x2 == 0L) {
                val w = x1 / x2
                println("$h $n $w")
                return
            }
        }
    }

}


Measured memory_bytes: 31716
#pragma GCC optimize("Ofast")
#pragma GCC optimize("3")
#pragma GCC optimize("2")
#include<cstdio>
char ch[101],l;

int main(){
    scanf("%s",ch);
    for(int i=0;ch[i];i++){
        if(l==0){
            if(ch[i]=='C'){
                l=1;
            }
        }
        else{
            if(ch[i]=='F'){
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
}


Measured memory_bytes: 128
def matrix_chain_order(input_array)
  n = input_array.length-1
  array = Array.new(n+1).map{Array.new(n+1,0)}
  2.upto n do |l|
    1.upto n-l+1 do |i|
      j = i+l-1
      array[i][j] = Float::INFINITY
      i.upto j-1 do |k|
        q = array[i][k] + array[k+1][j] + input_array[i-1]*input_array[k]*input_array[j]
        array[i][j] = (array[i][j] > q) ? q : array[i][j]
      end
    end
  end
  puts array[1].last
end

array = []

n = gets.to_i
n.times do |i|
  input = gets.split(" ")
  array << input[0].to_i if i == 0
  array << input[1].to_i
end

matrix_chain_order(array)



Measured memory_bytes: 6928
// ABC 085 C - Otoshidama
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	int N,Y;
	scanf("%d %d",&N,&Y);
	int A; //1000円の数
	int B; //5000円の数
	int C; //10000円の数

	int money = 0;
	for(A=0; A<=N; A++){ //NはA+B+C
		int M = N - A; //MはN-AつまりB+Cの合計枚数
		for(int B=M; B>=0; B--){ //MはB+Cの合計枚数
			C = M - B;
			money = 1000*A + 5000*B + 10000*C;
			if(money == Y){
				printf("%d %d %d\n",C,B,A);
				return 0;
			}
		}

	}
	printf("%d %d %d\n",-1,-1,-1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int a[101];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int sum=0;
    int ma=1e9;
    for(int i=-100;i<=100;i++)
    {
        sum=0;
        for(int j=0;j<n;j++)
        {
            sum+=(a[j]-i)*(a[j]-i);
        }
        if(ma>sum)
            ma=sum;
    }
    printf("%d\n",ma);
    return 0;
}


Measured memory_bytes: 256