akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 K;
  cin >> K;
  i64 ans = 0;
  for (i64 i = 1; i <= K; i++)
    for (i64 j = 1; j <= K; j++)
      for (i64 k = 1; k <= K; k++)
        ans += gcd(i, gcd(j, k));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std; 

int main(){
	int n, x, t;

	cin >> n >> x >> t;
	int ans = 0, some = 0;
	while (some < n){
		some += x;
		ans += t;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	int n,k,S;
	scanf("%d%d%d",&n,&k,&S);
	if(S+1<=1000000000)
	{
		for(int i=0;i<k;i++) printf("%d ",S);
		for(int i=k;i<n;i++) printf("%d ",S+1);puts("");
	}
	else
	{
		for(int i=0;i<k;i++) printf("%d ",S);
		for(int i=k;i<n;i++) printf("%d ",1);puts("");
	}
	return 0;
}

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

void solve(long long x){
    if (x < 1200) cout << "ABC" << '\n';
    else cout << "ARC" << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long x;
    scanf("%lld",&x);
    solve(x);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 100000
#define MAXL 100
typedef long long int lli;

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

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;

    string s;
    bool used[10];
    bool dp[10][10][10];
    REP(i,1000)dp[i%10][i/10%10][i/100]=false;
    REP(i,10)used[i]=false;
    int st[10];
    REP(i,10)st[i]=-1;
    int st1[10][10];
    REP(i,100)st1[i%10][i/10]=-1;
    cin>>n;
    cin>>s;
    REP(i,s.size()){
        int a=s[i]-'0';
        if(st[a]!=-1)continue;
        st[a]=i;
    }
    REP(k,10){
        if(st[k]==-1)continue;
        for(int i=st[k]+1;i<s.size();i++){
            int a=s[i]-'0';
            if(st1[k][a]!=-1)continue;
            st1[k][a]=i;
        }
    }
    REP(a,10){
        REP(b,10){
            if(st1[a][b]==-1)continue;
            for(int i=st1[a][b]+1;i<s.size();i++){
                dp[a][b][s[i]-'0']=true;
            }
        }
    }
    int cnt=0;
    REP(i,1000)if(dp[i%10][i/10%10][i/100])cnt++;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

string s, t;

int main()
{
	FIO;
	cin >> s >> t;
	LL ans = 0;
	rep(i,0,s.length()-1) {
		if(s[i] != t[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3872
N = int(input())
V = list(map(int,input().split()))
V.sort()
while True:
    if len(V) > 1:
        V.append((V[0]+V[1])/2)
        V.pop(0)
        V.pop(0)
    if len(V) == 1:
        break
    V.sort()
print(*V)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int A[4][3][10] = {0};
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        A[b-1][f-1][r-1] += v;
    }
 
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                cout << ' ' << A[i][j][k];
            }
            cout << endl;
        }
        if (i < 3){
            cout << "####################" << endl;
        }
    }
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3+10;
const int mod=1000000007;
char a[maxn][maxn];
int sum[maxn][maxn];
int date[maxn][maxn*2];
int dates[maxn][maxn*2];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            scanf(" %c",&a[i][j]);
    for(int i=1; i<n+1; i++)
    {
        int num=0;
        for(int j=1; j<=m; j++)
        {
            if(a[i][j]=='.')
                num++;
             else
             num=0;
            date[i][j]=num;//zuobian
           // cout<<date[i][j]<<' ';
        }
      //  cout<<endl;
        num=0;
         for(int j=m; j>=1; j--)
        {

            if(a[i][j]=='.')
                 num++;
            else
             num=0;
             date[i][j+m]=num;//youbiA

        }
    }
    for(int i=1;i<=m;i++)
    {   int num=0;
        for(int j=1;j<=n;j++)
        {

            if(a[j][i]=='.')
                num++;
            else
              num=0;
             dates[i][j]=num;
        }
       // cout<<endl;
        num=0;
         for(int j=n;j>=1;j--)
        {

            if(a[j][i]=='.')
            {
                num++;
            }
            else
            num=0;
             dates[i][j+n]=num;
        }

    }
      int maxs=0;
  //  cout<<dates[6][2]<<' '<<dates[6][2+8]<<endl;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        maxs=max(maxs,date[i][j]+date[i][j+m]+dates[j][i]+dates[j][i+n]);
    }
    if(maxs==0)
        puts("0");
    else
        printf("%d\n",maxs-3);


        return 0;
    }


Measured memory_bytes: 68736
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    N = II()
    A = LMIIS()
    B = LMIIS()
    count = 0
    for i in range(N-1,-1,-1):
        if A[i+1] <= B[i]:
            count += A[i+1]
            B[i] -= A[i+1]
            if A[i] <= B[i]:
                count += A[i]
                A[i] = 0
            else:
                count += B[i]
                A[i] -= B[i]
        else:
            count += B[i]
    print(count)





    pass
if __name__ == '__main__':
    main()

Measured memory_bytes: 73316
a= input().split(" ")

N=int(a[0])

#d=[int(input()) for _ in range(N)]
d=input().split(" ")
for i in range(N):
  d[i] = int(d[i])

sum=0
#print(d)

for i in range(N-1):
  for j in range(N-1-i):
    sum = sum + d[i]*d[i+j+1]
  
print(sum)


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

using namespace std;

int main() {
	int N;
	vector<int> datas;
	int ans = 0;

	cin >> N;

	for (int i = 0; i < 2 * N; i++) {
		int buff;
		cin >> buff;
		datas.push_back(buff);
	}

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

	for (int i = 2 * N - 1; i > 0 ; i -= 2) {
		ans += datas[i - 1];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};



int main(){
    int N;
    cin >> N;
    vector<vector<ll>> A(N, vector<ll>(3));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++) cin >> A[i][j];
    }
    vector<vector<ll>> dp(100100, vector<ll>(3));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + A[i][k]);
            }
        }
    }
    ll res = 0;
    for(int i = 0; i < 3; i++) chmax(res, dp[N][i]);
    cout << res << endl;
}

Measured memory_bytes: 14348
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(0) 
typedef long long int ll;
using namespace std;
const int MOD=1e9+7;
const int size=1e5+5;

ll a[size],b[size];

int main()
{
	string s;
	ll ans=0;
	cin >>s;
	ll l=0,r=s.length()-1;
	while(r>l)
	{
		if(s[l]==s[r])
		{
			r--;l++;
		}
		else
		{
			if(s[l]=='x')
				l++;
			else if(s[r]=='x')
				r--;
			else
			{
				cout << -1;
				return 0;
			}
			ans++;
		}
	}
	cout <<ans;

}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n),b(n),c(m),d(m);
    for (ll i=0;i<n;++i){
        cin >> a[i] >> b[i];
    }
    for (ll i=0;i<m;++i){
        cin >> c[i] >> d[i];
    }
    for (ll i=0;i<n;++i){
        vector<vector<ll>> x(m);
        for (ll j=0;j<m;++j){
            x[j]={abs(a[i]-c[j])+abs(b[i]-d[j]),j+1};
        }
        sort(x.begin(),x.end());
        cout << x[0][1] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n, 0);
  map<int, int> p;
  p[0] = 1;
  int s = 0;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    s += a[i];
    s %= m;
    //cout << s << ' ';
    if (p.count(s))
      ans += p[s];
    p[s] ++;
  }
  printf("%lld", ans);
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const ll INF = (ll)(1e14);

const int MAX_N = 11234;
const int MAX_M = 11234;
const int MAX_D = 112;
ll P[MAX_N];
ll A[MAX_M];

ll w[MAX_D][MAX_N];
ll dp[MAX_D][MAX_N];

struct Line {
  int id;
  ll a, b;
  ll f(ll x) { return a*x + b; }
};

bool check(Line l1, Line l2, Line l3) {
  return (l2.a - l1.a)*(l2.b - l3.b) <= (l3.a - l2.a)*(l1.b - l2.b) ||
    (l1.a == l2.a && l1.b <= l2.b) ||
    (l2.a == l3.a && l2.b >= l3.b);
}

int main2() {
  int N, M;
  ll D, X;
  cin >> N >> M >> D >> X;
  REP(i, N) cin >> P[i+1]; // 1-indexed

  CLR(w, 0);
  REP(_, M) {
    int a, b; cin >> a >> b;
    a -= abs(b);
    for (int i = 1; i <= N; i++) {
      ll D = (P[i]-a+X+X-1)/X;
      if (D < 0) D = 0;
      w[D][i]++;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int d = 1; d < MAX_D; d++) {
      w[d][i] += w[d-1][i];
    }
  }

  REP(i, MAX_D) REP(j, MAX_N) dp[i][j] = INF;
  dp[1][1] = 0;
  for (int d = 1; d <= D; d++) {
    deque<Line> deq;
    for (int i = 1; i <= N; i++) {

      // ll val = INF;
      // for (int j = 1; j <= i; j++) {
      //   chmin(val, dp[d][j] + (P[i] - P[j]) * w[d][j]);
      //   ll cur = dp[d][j] + (P[i] - P[j]) * w[d][j];
      //   cout << d << " " << j << " ->" << i << " " << cur << endl;
      // }
      // dp[d+1][i] = val;

      Line line = (Line){ i, w[d][i], dp[d][i] - P[i] * w[d][i] };
      while (deq.size() >= 2 && check(deq[deq.size()-2], deq[deq.size()-1], line)) deq.pop_back();
      deq.push_back(line);
      ll x = P[i];
      while (deq.size() >= 2 && deq[0].f(x) >= deq[1].f(x)) deq.pop_front();
      ll val = deq[0].f(x);
      dp[d+1][i] = val;
    }
  }
  ll ans = dp[D+1][N];
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}



Measured memory_bytes: 22904
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;

main() {
    int N,K; cin >> N >> K;
    int ans=0;
    rep(i,N){
        int a; cin >> a;
        if(a>=K) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# 高橋君が食品をおいしく感じた場合 delicious を、
# おいしくは感じなかったがお腹は壊さなかった場合 safe を、
# お腹を壊した場合 dangerous を出力する

X, A, B = map(int, input().split())

# print(X)
# print(A)
# print(B)

if A - B >= 0:
    print('delicious')
elif A + X >= B:
    print('safe')
else:
    print('dangerous')

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

long long N;
int dp[61][2][2];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  dp[0][0][0] = 1;
  int B = 0;
  rep(i, 61) if (N & (1LL<<i)) B = i+1;
  rep(i, B) {
    // i->i+1
    rep(j, 2) {
      rep(k, 2) {
        int s = dp[i][j][k];
        rep(a, 2) {
          rep(b, 2) {
            if (a > b) continue;
            int u = a^b, v = a+b+j;
            int nj = v>=2;
            v %= 2;
            int n = (N & (1LL<<i)) != 0;
            int nk = k;
            if      (n > v) nk = 0;
            else if (n < v) nk = 1;

            dp[i+1][nj][nk] += s;
            dp[i+1][nj][nk] %= MOD;
          }
        }
      }
    }
  }
  cout << dp[B][0][0] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef unsigned long long ull;

const ull M=(1e9+7);
string s;
int q;
ull H[N], D[N];

void cal_hash(){
  ull h=0;
  for(int i=0;i<s.size();i++){
    h=h*M+s[i];
    H[i+1]=h;
  }
  h=1;
  for(int i=0;i<N;i++){
    D[i]=h;
    h*=M;
  }
  s='X'+s;
}

int get_first_diff_idx(int l, int r, int t){
  
  int L=0, R=r-l-t+2;
  
  while(L<R){
    
    int Mid=(L+R)/2;
    ull v1=H[l+Mid]-H[l-1]*D[Mid+1];
    ull v2=H[l+Mid+t]-H[l+t-1]*D[Mid+1];
    
    if(v1==v2) L=Mid+1;
    else R=Mid;
  }
  
  return L;
}

bool isSame(int l, int r, int t, int A, int B){
  
  int i1=l+t, i2=r;
  ull h1=0, h2=0;
  
  if(i1<=A&&A<=i2){
    
    if(i1<A&&A<i2) h1=H[i2]-H[A]*D[i2-A]+((H[A-1]-H[i1-1]*D[A-i1])*D[1]+s[B])*D[i2-A];
    else if(A==i1) h1=H[i2]-H[i1]*D[i2-i1]+s[B]*D[i2-i1];
    else if(A==i2) h1=s[B]+(H[i2-1]-H[i1-1]*D[i2-i1])*D[1];
    
  }else h1=H[i2]-H[i1-1]*D[i2-i1+1];
  
  i1=l, i2=r-t;
  
  if(i1<=A&&A<=i2){
    
    if(i1<A&&A<i2) h2=H[i2]-H[A]*D[i2-A]+((H[A-1]-H[i1-1]*D[A-i1])*D[1]+s[B])*D[i2-A];
    else if(A==i1) h2=H[i2]-H[i1]*D[i2-i1]+s[B]*D[i2-i1];
    else if(A==i2) h2=s[B]+(H[i2-1]-H[i1-1]*D[i2-i1])*D[1];
    
  }else h2=H[i2]-H[i1-1]*D[i2-i1+1];
  
  return h1==h2;
}

bool check(int l, int r, int t){
  
  int idx=get_first_diff_idx(l, r, t);

  int i1=l+idx, i2=l+t+idx;
  
  return isSame(l, r, t, i1, i2) | isSame(l, r, t, i2, i1);
}

int main(){
  
  cin>>s;
  
  cal_hash();
  
  cin>>q;
  
  int l, r, t;
  
  for(int i=0;i<q;i++){
    scanf("%d %d %d", &l, &r, &t);
    if(check(l, r, t)) printf("Yes\n");
    else printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 4936
#include<bits/stdc++.h>                
using namespace std;
string S;
long long K;
int main(void){
	cin >> S >> K;
	for(int i = 0; i < min((long long)S.size(), K); i++){
		if(S[i] >= '2'){
			cout << S[i] << endl;
			return 0;
		}
	} 
	cout << '1' << endl;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;
llvec A,B;

void input() {
	cin>>N;
	resiz(N,A,B);
	for(int i=0; i<N; i++) {
		ll x,y; cin>>x>>y;
		A[i]=x+y;
		B[i]=x-y;
	}
}

void solve() {
	sort(rall(A)); sort(rall(B));
	cout<<max(A[0]-A[N-1],B[0]-B[N-1])<<endl;
}

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


Measured memory_bytes: 6376
s = input()
l = []
b = 0

for i in s:
    if b == 1:
        l.append(i)
    if i == 'A' and b == 0:
        l.append(i)
        b = 1

z = [i for i, x in enumerate(l, 1) if x == 'Z']
print(max(z))


Measured memory_bytes: 14812
n, m = map(int, input().split())
K = []
for i in range(n):
  K.append(list(map(int,input().split())))
for i in range(n):
  del(K[i][0])
l = 0
for j in range(1, m+1):
  k = 0
  for i in range(n):
     if K[i].count(j) == 1:
        k += 1
  if k == n:
    l += 1
print(l)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
 
 
public class Main {
    public static void main(String[] args) throws IOException {
//        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//        String[] s=br.readLine().split(" ");
//        System.out.println(10e9 > Integer.MAX_VALUE);
//        long N=Long.parseLong(s[0]);
//        long C=Long.parseLong(s[1]);
//        long K=Long.parseLong(s[2]);
//        long[]arr=new long[(int)N];
//        for (int i = 0; i <N ; i++) {
//            arr[i]=Long.parseLong(br.readLine());
//
//
//        }
//        Arrays.sort(arr);
//        long start=arr[0];
//        long totalbuses=0;
//
//        totalbuses=1;
//        long cc=0;
//        for (int i = 0; i <N ; i++) {
//            if(start+K>=arr[i] && cc<C){
//                cc++;
//                continue;
//            }
//            else{
//                totalbuses++;
//                start=arr[i];
//                cc=0;
//            }
//        }
//        System.out.println(totalbuses);
//
//    }
//        public static void main(String[] args) throws IOException {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String[] s=br.readLine().split(" ");
            long N=Long.parseLong(s[0]);
            long C=Long.parseLong(s[1]);
            long K=Long.parseLong(s[2]);
            long[]arr=new long[(int)N];
            for (int i = 0; i <N ; i++) {
                arr[i]=Long.parseLong(br.readLine());
 
 
            }
            Arrays.sort(arr);
            long start=arr[0];
            int totalbuses=0;
 
            totalbuses=1;
            long cc=0;
            for (int i = 0; i <N ; i++) {
                if(start+K<arr[i] || cc>=C){
                    totalbuses++;
                    start=arr[i];
                    cc=0;
                  //  System.out.println("start="+start);
                    i--;
                    continue;
                }
                else{
 
                    cc++;
                }
            }
            System.out.println(totalbuses);
 
        }
}

Measured memory_bytes: 30724
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}









int main() {
  int N,Y;
  cin>>N>>Y;
  for(int i=0;10000*i<=Y;i++){
    for(int j=0;10000*i+5000*j<=Y;j++){
      if(10000*i+5000*j+1000*(N-i-j)==Y){
        printf("%d %d %d\n",i,j,N-i-j);
        return 0;
      }

    }
  }
  printf("%d %d %d",-1,-1,-1);
  
  
  
  

  





  

  


  

    


  

  
  
  
  
}


  
  

  

  


Measured memory_bytes: 256
from itertools import product
c = [list(map(int, input().split())) for _ in range(3)]

b2 = c[0][1]
b3 = c[0][2]
a2 = c[1][0] - c[0][0]
a3 = c[2][0] - c[0][0]

if (a2 + b2 == c[1][1] and
    a2 + b3 == c[1][2] and
    a3 + b2 == c[2][1] and
    a3 + b3 == c[2][2]):
    print("Yes")
else:
    print("No")


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

typedef long long int LLI;
typedef pair<LLI, int> Pair;

int N;
LLI as[114514];
LLI bs[114514];
LLI cs[114514];
LLI ds[114514];

int main() {
  scanf("%d", &N);

  LLI sigma = 0;
  LLI tot = 0;
  for (int i=0; i<N; i++) {
    scanf("%lld", &as[i]);
    sigma += i+1;
    tot += as[i];
  }

  if (tot%sigma) {
    puts("NO");
    return 0;
  }

  for (int i=0; i<N; i++) {
    bs[i] = as[(i+1)%N] - as[i];
  }

  for (int i=0; i<N; i++) {
    cs[i] = bs[(i+1)%N] - bs[i];
  }

  for (int i=0; i<N; i++) {
    if (llabs(cs[i])%LLI(N)) {
      puts("NO");
      return 0;
    }
    ds[i] = cs[i]/LLI(N);
  }

  LLI debt = 0;
  LLI cnt = 0;
  for (int j=0; j<2; j++) {
    for (int i=0; i<N; i++) {
      if (ds[i] < 0) {
        debt += -ds[i];
        ds[i] = 0;
      } else if (ds[i] > debt) {
        ds[i] -= debt;
        debt = 0;
      } else {
        debt -= ds[i];
        ds[i] = 0;
      }
      cnt += debt;
    }
  }

  if (cnt <= tot/sigma) {
    if ((tot/sigma - cnt)%LLI(N) == 0) {
      puts("YES");
      return 0;
    }
  }

  puts("NO");
}


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

using namespace std;

#define llong long long 
int a, b;
int n;
int ba, bb;
int area[17][17];
bool notgo[17][17];

void solve(){
	area[1][1] = 1;
	for(int i = 1; i <= a; i++){
		for(int j = 1; j <= b; j++){
			if(i == 1 && j == 1) continue;
			if(notgo[i][j] == true)continue;
			int left;
			int down;
			if(i - 1 == 0) left = 0;
			else left = area[i - 1][j];
			if(j - 1 == 0) down = 0;
			else down =  area[i][j - 1];

			area[i][j] = left + down;
		}
	}

	return;
}

int main(){
	while(cin >> a >> b, a){
		fill_n(*area, 17 * 17, 0);
		fill_n(*notgo, 17 * 17, false);

		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> ba >> bb;
			notgo[ba][bb] = true;
		}

		solve();
		cout << area[a][b] << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
<?php
list($s) = strs();
if ($s === 'RRR') exit('3');
if ($s === 'SRR' || $s === 'RRS') exit('2');
if ($s === 'RSS' || $s === 'SRS' || $s === 'SSR' || $s === 'RSR') exit('1');
echo '0';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16168
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)







int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), cnt(60);
    REP(i, n){
        cin >> a[i];
        for(ll j = 59; j >= 0; j--){
            if(!(a[i] & (1LL << j))){
                cnt[j]++;
            }
        }
    }
    vector<pair<ll, ll>> v;
    REP(i, 60){
        if(cnt[i] <= n / 2) continue;
        v.push_back({(1LL << i) * cnt[i], i});
    }
    sort(v.begin(), v.end(), greater<pair<ll, ll>>());
    ll xxor = 0;
    REP(i, v.size()){
        if((xxor | (1LL << v[i].second)) > k) continue;
        xxor |= (1LL << v[i].second);
    }
    ll ans = 0;
    REP(i, n){
        ans += a[i] ^ xxor;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
s=gets.chop
k=gets.to_i
res=[]
i=0
s.bytes{|b|
    x=b-97
    if x>0 and k>=26-x
        res<<?a
        k-=26-x
    else
        res<<s[i]
    end
    i+=1
}
res[-1]=((res[-1].ord-97+k%26)+97).chr
puts res*''


Measured memory_bytes: 7036
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100010;
int n,m;
vector<int> gra[MAXN];
int inde[MAXN];
int f[MAXN];
void topo()
{
	queue<int> q;
	for(int i=1;i<=n;++i)
	{
		if(!inde[i]) q.push(i);
	}
	int p,t;
	while(!q.empty())
	{
		p=q.front();
		q.pop();
		for(int i=0;i<gra[p].size();++i)
		{
			f[gra[p][i]]=max(f[gra[p][i]],f[p]+1);
			if(--inde[gra[p][i]]==0)
				q.push(gra[p][i]); 
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		ans=max(f[i],ans);
	}
	cout<<ans<<endl;
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=m;++i)
	{
		int x,y;
		cin>>x>>y;
		gra[x].push_back(y);
		++inde[y];
	}
	topo();
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint a[200005], b[200005];
llint dp[4009][4009];
const int Zero = 2004;

const int FACT_MAX = 10005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	
	for(int i = 1; i <= n; i++) dp[Zero+a[i]][Zero+b[i]]++;
	
	for(int i = Zero+2000; i >= Zero-2000; i--){
		for(int j = Zero+2000; j >= Zero-2000; j--){
			dp[i][j] += dp[i+1][j] + dp[i][j+1];
			dp[i][j] %= mod;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		ans += dp[Zero-a[i]][Zero-b[i]];
		ans %= mod;
	}
	
	for(int i = 1; i <= n; i++){
		ans += mod - comb(2*(a[i]+b[i]), 2*a[i]);
		ans %= mod;
	}
	ans *= modpow(2, mod-2), ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 129024
<?php
fscanf(STDIN, "%d", $n);
for($i = 0; $i < $n; $i++){
	$str[$i] = str_replace("\n", "", str_split(fgets(STDIN)));
  	natsort($str[$i]);
  	$str[$i] = implode($str[$i]);
}
$count = array_count_values($str);

$cnt = 0;
foreach($count as $value){
  if($value > 1){
    $tmp = $value * ($value - 1) / 2;
    $cnt += $tmp;	
  }
}
echo $cnt;
?>

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n; cin >> n;
    vector<ll> v(n); cin >> v;
    vector<ll> cnt(2, 0);
    REP(i, n) cnt[v[i]%2]++;
    if (cnt[1] % 2 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

void A_147()
{
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  if (A1 + A2 + A3 > 21) cout << "bust" << endl;
  else cout << "win" << endl;
}

int main()
{
  //C_140();
  //C_141();
  //C_142();
  //C_143();
  //C_144();
  //C_145();
  //C_146();
  //C_147();
  //C_148();
  //C_149();
  //A_149();
  //B_149();
  //A_148();
  //B_148();
  A_147();
  return 0;
}


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

int main() {
    int i = 1;
    int x;

    while (1) {
        cin >> x;
        // 0のときは抜ける
        if (x == 0) break;
        cout << "Case " << i << ": " << x << endl;
        ++i;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

long long ston(string s){
  long long n;
  sscanf(s.c_str(), "%lld", &n);
  return n;
}

int main(){
	ll n;
	cin>>n;
	ll yen = 0;
	ll btc = 0;
	rep(i,0,n){
		string a,b;
		cin>>a>>b;
		if(b[0]=='J'){
			yen += ston(a);
		}
		else{
			string c;
			rep(i,0,a.sz){
				if(a[i]=='.')continue;
				c += a[i];
			}
			ll d = 0;
			rep(i,0,c.sz){
				d += (c[c.sz-1-i]-'0')*pow(10,i);
			}
			btc += d;
		}
	} 
	double ans = 1.*yen + 1.*btc*380000./100000000.;
	printf("%20.20f\n", ans);
	return 0;
}

Measured memory_bytes: 384
mod = 10 ** 9 + 7
x = 1
y = 0
for c in input():
	if c == "1":
		y *= 3
		y %= mod
		y += x
		y %= mod
		x *= 2
		x %= mod
	else:
		y *= 3
		y %= mod
print((x + y) % mod)

Measured memory_bytes: 3188
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]
d = {}
for i in range(n):
    for j in range(m):
        d[j] = abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1])
    t = sorted(d.items(), key=lambda x:x[1])
    print(t[0][0]+1)
    d = {}

Measured memory_bytes: 3064
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
using ll = long long;
const int INF = 1e8;

int main() {
  int K;
  string S;
  cin >> K;
  cin >> S;
  if (S.size() <= K) {
    cout << S << endl;
    return 0;
  }

  for (int i = 0; i < K; i++) {
    cout << S[i];
  }
  cout << "..." << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>

auto main () -> int
{
    int n , m;
    std::cin >> n >> m;
    std::vector <std::vector <int>> a (n , std::vector <int> (m , 0));
    for (auto i = 0; i < n; ++ i)
    {
        for (auto j = 0; j < m; ++ j)
        {
            std::cin >> a [i] [j];
        }
    }
    std::vector <int> v (m);
    for (auto j = 0; j < m; ++ j)
    {
        std::cin >> v [j];
    }
    std::vector <int> ans (n);
    for (auto i = 0; i < n; ++ i)
    {
        ans [i] = 0;
        for (auto j = 0; j < m; ++ j)
        {
            ans [i] += a [i] [j] * v [j];
        }
        std::cout << ans [i] << std::endl;
    }
}

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

int main()

{
    int i,N,X,A[200],D,h=0,g;
    scanf("%d%d%d",&N,&D,&X);
    for(i=1;i<=N;i++)
        scanf("%d",&A[i]);
    for(i=1;i<=N;i++)
    {
        for(g=1;A[i]*g+1<=D;g++)
        h++;

    }
    printf("%d\n",X+h+N);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    int ans;
    int maxi = 0;
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        if (A > maxi) ans = A + B, maxi = A;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
#define min(a,b) (a<b)?a:b

int count(int x, int y){
    int count6 = 0;
    int count9 = 0;
    while(x!=0){
        count6 += x % 6;
        x /= 6;
    }
    while(y!=0){
        count9 += y % 9;
        y /= 9;
    }
    return count6 + count9;
}

int main()
{
    int n;
    scanf("%d", &n);
    int min;
    int i;
    min = count(n,0);
    for(i=1;i<=n;i++) min = min(min, count(n-i,i));
    printf("%d", min);
    
    return 0;
}

Measured memory_bytes: 128
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
int bs_cnt_less(vl& A, const ll X, bool equal) {
    if (equal) return upper_bound(A.begin(), A.end(), X) - A.begin();
    else return lower_bound(A.begin(), A.end(), X) - A.begin();
}

int bs_idx_greater(vl& A, const ll X, bool equal) {
    if (equal) return bs_cnt_less(A, X, false);
    else return bs_cnt_less(A, X, true);
}
#endif


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

    string S, T; cin >> S >> T;
    int SL = S.size(), TL = T.size();
    
    set<char> ss;
    REP(i, SL) ss.insert(S[i]);
    
    bool ok = true;
    REP(i,TL) {
        if (ss.count(T[i]) == 0) {
            ok = false;
            break;
        }
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }


    vvl idxs(26);
    REP(i, SL) idxs[S[i] - 'a'].push_back(i);
    REP(i, SL) idxs[S[i] - 'a'].push_back(SL + i);

    ll ans = 0;
    int pos = 0;
    REP(i,TL) {
        int c = T[i] - 'a';
        int j = bs_idx_greater(idxs[c], pos, true);
        pos = idxs[c][j] + 1;
        if (pos >= SL) {
            pos -= SL;
            ans += SL;
        }
    }
    ans += pos;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2756
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  ll n, a, b, blue;
  cin >> n >> a >> b;
  blue = (n / (a + b)) * a + (n % (a + b) > a ? a : n % (a + b));
  cout << blue << endl;

  return 0;
}


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


int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
char S[1000][1000];
int vis[1000][1000];

int main(){
	int h,w,sum=0,ans=1e9;
	cin >> h >> w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> S[i][j];
			if(S[i][j]=='.') sum++;
		}
	}
	sum--;
	
	queue<pair<int,int>> q;
	queue<int> q2;
	q.push(make_pair(0,0));
	q2.push(0);
	vis[0][0]=1;
	while(!q.empty()){
		int x=q.front().first,y=q.front().second,z=q2.front();
		q.pop();
		q2.pop();
		if(x==h-1&&y==w-1){
			ans=z;
			break;
		}
		for(int i=0;i<4;i++){
			int xx=x+dx[i],yy=y+dy[i];
			if(xx>=0&&yy>=0 && xx<h&&yy<w && S[xx][yy]!='#'&&!vis[xx][yy]){
				q.push(make_pair(xx,yy));
				q2.push(z+1);
				vis[xx][yy]=1;
			}
		}
	}
	
	cout << (ans==1e9?-1:sum-ans) << endl;
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    int n=a.size()-b.size();
    if (n==0){
        for(int i=0;i<a.size();i++){
            cout<<a[i]<<b[i];
        }
    }
    else if(n!=0){
        for(int i=0;i<b.size();i++){
            cout<<a[i]<<b[i];
        }
        cout<<a[a.size()-1];
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < k; i++) {
                int di = in.nextInt();
                for (int j = 0; j < di; j++) {
                    set.add(in.nextInt());
                }
            }

            out.println(n - set.size());
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 35284
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#define INF 1000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
ll mod = 1000000007;
bool dp[50010][11][11][11];

int main() {
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
		cout << "infinity" << endl;
		return 0;
	}
	if (a1 > b1) {
		swap(a1, b1);
		swap(a2, b2);
	}
	if (a2 <= b2) {
		cout << 0 << endl;
		return 0;
	}
	ll dis = t1 * a1 + t2 * a2 - t1 * b1 - t2 * b2;
	if (dis < 0) {
		cout << 0 << endl;
		return 0;
	}
	ll p = (t1*(b1 - a1)) / dis;
	ll x = p * (t1 * a1 + t2 * a2);
	ll y = p * (t1 * b1 + t2 * b2);
	if (x + t1 * a1 < y + t1 * b1) cout << 2 * p + 1 << endl;
	else cout << 2 * p << endl;
}

Measured memory_bytes: 256
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=2000+5;
int n,X,Y;
int dist[N][N];
int ans[N];
void print()
{
	int i,j;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			cout<<dist[i][j]<<" ";	
		cout<<endl;	
	}

}
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i,j;
	cin>>n>>X>>Y;
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			dist[i][j]=abs(i-j);
		dist[i][j]=INF;
	}
//	print();
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(dist[i][X]+dist[Y][j]+1<=dist[i][j])
				dist[i][j]=dist[i][X]+dist[Y][j]+1;
		}
	}
//	print();
	for(i=1;i<=n;i++)	
		for(j=i+1;j<=n;j++)
			ans[dist[i][j]]++;
	
	for(i=1;i<=n-1;i++)
		cout<<ans[i]<<endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int a; cin >> a;
    string s; cin >> s;
    Ans(a >= 3200, s, "red");

    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define mod 1000000007
#define f first
#define sec second
#define gcd(x,y) __gcd(x, y)
using namespace std;
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	ll x=0;
	sort(a,a+n);
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			for(ll k=j+1;k<n;k++)
			{
				if(a[i]!=a[j] && a[j]!=a[k])
				if( ( (a[i]+a[j])>a[k]) && ((a[k]+a[j])>a[i]) && ((a[k]+a[i])>a[j]))
                {
 
                    x++;
                }
			}
		}
	}
	cout<<x<<endl;

}

Measured memory_bytes: 3600