akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n-1;i++)
        cin>>a[i];
    int sum=2*a[0];
    for(int i=0;i<n-2;i++)
    {
        if(a[i+1]>=a[i])
            sum+=a[i+1];
        else
        {
            sum-=a[i];
            sum+=2*a[i+1];
        }

    }
    cout<<sum;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INFLL (1ll<<58)
static const int MAX=1e5;
int N,M;
ll maxn=-INFLL,a[MAX+2][3];

void solve(){
    for(int i=0;i<8;i++){
        vector<ll> vec;
        for(int j=0;j<N;j++){
            ll S=0;
            for(int k=0;k<3;k++){
                if((i>>k)&1) S+=a[j][k];
                else S-=a[j][k];
            }
            vec.push_back(S);
        }
        sort(vec.begin(),vec.end(),greater<ll>());
        ll ans = 0;
        for(int j=0;j<M;j++) ans += vec[j];
        maxn = max(maxn,ans);
    }
    cout<<maxn<<"\n";
}

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N>>M;
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++) cin>>a[i][j];
    }
    solve();
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
string s;
int f(char st){
    int tmp = 0;
    rep(i, s.size()){
        if(st != s[i]){
            tmp++;
        }
        st = st == '0' ? '1' : '0';
    }
    return tmp;
}
int main(){
    cin >> s;
    int t1 = f('0');
    int t2 = f('1');
    cout << min(t1, t2) << endl;
}



Measured memory_bytes: 512
n, m = map(int, input().split())
ps = [list(map(str, input().split())) for _ in range(m)]

str_l = ['WA'] * n
int_l = [0] * n

for pp, s in ps:
    p = int(pp)-1
    if s == 'AC':
        str_l[p] = 'AC'
    else:
        if str_l[p] != 'AC':
            int_l[p] += 1

num = 0
ac = 0
for i in range(n):
    if str_l[i] == 'AC':
        num += int_l[i]
        ac += 1
print(ac, num)


Measured memory_bytes: 69592
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int n;
void f(int data[20][20],int size){
    int tmp[20][20];
    rep(i,20)rep(j,20)tmp[i][j]=data[i][j];
    rep(i,size){
        rep(j,size){
            data[i][j] = tmp[size-j-1][i];
        }
    }
}

void turn(int data[20][20],int r,int c,int size,int angle){
    int tmp[20][20];
    for(int y=0,i=r;i<=r+size-1;i++,y++){
        for(int x=0,j=c;j<=c+size-1;j++,x++){
            tmp[y][x] = data[i][j];
        }
    }
    angle/=90;
    rep(i,angle)f(tmp,size);
    
    for(int y=0,i=r;i<=r+size-1;i++,y++){
        for(int x=0,j=c;j<=c+size-1;j++,x++){
            data[i][j] = tmp[y][x];
        }
    }
}

vector<pii> p;
void dfs(int data[20][20],int y,int x,bool used[20][20]){
    p.pb(pii(y,x));
    used[y][x]=true;
    
    int dy[]={1,0,-1,0};
    int dx[]={0,1,0,-1};

    rep(i,4){
        int ddy = y+dy[i];
        int ddx = x+dx[i];
        if( ddx>=0 && ddy>=0 && ddx<n && ddy<n && !used[ddy][ddx] && data[y][x] == data[ddy][ddx]){
            dfs(data,ddy,ddx,used);
        }
    }
}


int main(){
    int m;
    cin>>n>>m;
    int data[20][20];
    rep(i,n)rep(j,n)cin>>data[i][j];
    
    rep(i,m){
        int o;
        cin>>o;
        if(o==0){           //?????¢
            int r,c,size,angle;
            cin>>r>>c>>size>>angle;
            r--,c--;
            turn(data,r,c,size,angle);
        }else if(o==1){     //?????¢
            int r,c,size;
            cin>>r>>c>>size;
            r--,c--;
            for(int i=r;i<=r+size-1;i++){
                for(int j=c;j<=c+size-1;j++){
                    data[i][j] = !data[i][j];
                }
            }
        }else if(o==2){     //????????????
            int r;
            cin>>r;
            r--;
            data[r][n]=data[r][0];
            rep(i,n) data[r][i] = data[r][i+1];
            data[r][n]=0;
        }else if(o==3){     //????????????
            int r;
            cin>>r;
            r--;
            for(int i=n;i>0;i--)data[r][i]=data[r][i-1];
            data[r][0] = data[r][n];
            data[r][n]=0;
        }else if(o==4){     //??¶?????¢
            int r,c;
            cin>>r>>c;
            r--,c--;
            p.clear();
            bool used[20][20]={};
            dfs(data,r,c,used);
            rep(i,p.size()){
                int y=p[i].first,x=p[i].second;
                data[y][x] = !data[y][x];
            }
        }
    }
    
    
    
    rep(i,n){
        rep(j,n){
            if(j!=0)cout<<" ";
            cout<<data[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3112
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1000;
int n,m;
typedef long long ll;
struct CAKE
{
    ll A,B,C;
}cak[MAXN+5];
int i,j,k;
bool cmp(CAKE a,CAKE b)
{
    return a.A*i+a.B*j+a.C*k>b.A*i+b.B*j+b.C*k;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld%lld",&cak[i].A,&cak[i].B,&cak[i].C);
    ll ans=0;
    for(i=-1;i<=1;i+=2)
        for(j=-1;j<=1;j+=2)
            for(k=-1;k<=1;k+=2)
            {
                sort(cak+1,cak+n+1,cmp);
                ll tot[3]={};
                for(int p=1;p<=m;p++)
                    tot[0]+=cak[p].A,tot[1]+=cak[p].B,tot[2]+=cak[p].C;
                ans=max(ans,tot[0]*i+tot[1]*j+tot[2]*k);
            }
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> arr;
	vector<int> dp;
	int num;
	for(int i = 0; i < n; i++) {
		cin >> num;
		arr.push_back(num);
	}
	dp.push_back(0);
	dp.push_back(abs(arr[1] - arr[0]));
	for(int i = 2; i < n; i++) {
		dp.push_back(min(dp[i-2] + abs(arr[i] - arr[i-2]), dp[i-1] + abs(arr[i] - arr[i-1])));
	} cout << dp[n-1] << endl;
	return 0;
}

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

int main()
{
    ll n;
    string str;
    cin >> str;
    n = str.length();
    ll ans = 0;
    ll cnt = 0;
    for (ll i = n - 2; i >= 0; i--)
    {
        if (str[i] == 'B' && str[i + 1] == 'C')  cnt++;
        else if ((str[i] == 'B' && str[i + 1] == 'B') || (str[i] == 'C' && str[i + 1] == 'C') || (str[i] == 'A' && str[i + 1] == 'C') || (str[i] == 'B' && str[i + 1] == 'A'))    cnt = 0;
        if (str[i] == 'A')   ans += cnt;
    }
    cout << ans;
    return 0;
}


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

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

    if(a != b && b != c && a != c){
        cout << 3 << endl;
    }else if(a == b && b == c){
        cout << 1 << endl;
    }else{
        cout << 2 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

int dd[] = {1, -1, 4, -4};
map<string, int> done;

void dfs(){
    //その時のカードの状態をqueueに突っ込む
    queue<string> que;
    
    que.push("01234567");
    while(!que.empty()){
        string q = que.front(); que.pop();
        int x0 = q.find("0");
        for(int i=0; i<4; i++){
            string t = q;
            int nx = x0+dd[i];
            if(nx<0 || 7<nx || (x0==3&&i==0) || (x0==4&&i==1))
                continue;
            t[x0] = t[nx];
            t[nx] = '0';
            if(done.count(t))
                continue;
            done[t] = done[q] + 1;
            que.push(t);
        }
    }
}

int main(){
    string t;
    dfs();
    while(getline(cin,t)){
		t.erase(remove(t.begin(),t.end(),' '),t.end());
        cout << done[t] << endl;
	}
    return 0;
}

Measured memory_bytes: 3432
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var A = Number.parseInt(inputStr[0]);
  var B = Number.parseInt(inputStr[1]);
  var C = Number.parseInt(inputStr[2]);
  var i = 1;
  
  while( (B - (A*(i)) >= 0) && ((i) <= C) ){
    i += 1;
  }
  console.log(i-1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n, ma, mb = (int(x) for x in input().split())
ABC = [tuple(int(x) for x in input().split()) for _ in range(n)]
D1 = dict()
D2 = dict()
for (m, D, j) in ((n // 2, D1, 0), (n - n // 2, D2, n // 2)):
    for bit in range(1, 1<<m):
        sum_a = 0
        sum_b = 0
        sum_c = 0
        for i in range(m):
            if bit & 1<<i:
                a, b, c = ABC[i + j]
                sum_a += a
                sum_b += b
                sum_c += c
        s = mb * sum_a - ma * sum_b
        if s in D:
            D[s] = min(D[s], sum_c)
        else:
            D[s] = sum_c
ans = 10**18
if 0 in D1:
    ans = min(ans, D1[0])
if 0 in D2:
    ans = min(ans, D2[0])
for s in D1:
    if -s in D2:
        ans = min(ans, D1[s] + D2[-s])
if ans == 10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 73816
// This is the start of  template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define INF LONG_LONG_MAX
#define mod 1000000007
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
int power(int a,int n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a)%mod,n/2))%mod;
    }
    return power((a*a)%mod,n/2)%mod;
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
 // input();
 int a,b,c,d;
 cin>>a>>b>>c>>d;

 	cout<<max({a*c,a*d,b*d,b*c});
}

//

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ss s;
    ll count=0;
    cin >> s;
    rep(i,SIZE(s)){
        if(s[i] == 'o')count++;
    }
    cout << 700+100*count << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()

lis = [0]*N
count = 0

for i in range(N-1):
	if S[i] == "A" and S[i+1] == "C":
		lis[i+1] = 1

lis_acc = list(accumulate(lis))

for _ in range(Q):
	l, r = MAP()
	print(lis_acc[r-1]-lis_acc[l-1])


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

struct Card{ char suit, value;};

void bubbleSort(struct Card A[], int N){
  for (int i=0;i<N;i++){
    for (int j =N-1; j>=i+1;j--){
      if(A[j].value < A[j-1].value){
        Card t =A[j];A[j] = A[j-1];A[j-1] =t;
      }
    }
  }
}

void selectionSort(struct Card A[],int N){
  for (int i = 0; i<N;i++){
    int minj=i;
    for (int j = i; j<N;j++){
      if(A[j].value < A[minj].value){
        minj = j;
      }
    }
     Card t=A[i];A[i]=A[minj];A[minj]=t;
    
  }
}

void print(struct Card A[], int N){
  for (int i=0;i<N;i++){
    if(i>0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[],int N){
  for (int i =0; i<N; i++){
    if(C1[i].suit != C2[i].suit)return false;
  }
  return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >>N;
  for(int i=0; i<N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0;i<N;i++)C2[i]= C1[i];

  bubbleSort(C1,N);
  selectionSort(C2,N);

  print(C1,N);
  cout<< "Stable" << endl;
  print(C2,N);
  if (isStable(C1,C2,N)){
    cout << "Stable"<<endl;
  }
  else{
    cout << "Not stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>
int X[]={0,0,-1,1,-1,1,-1,1};
int Y[]={1,-1,0,0,-1,1,1,-1};
int u[510][510],c[510][510],n;
int a[510*510],b[510*510];
int lb(int l,int r,int n,int *d){
  int m=(l+r)/2;//printf("%d\n",m);
  if(l==r)return m;
  return n<=d[m]?lb(l,m,n,d):lb(m+1,r,n,d);
}
int f(int d[510][510],int y,int x){
  int i,j,k,c,ny,nx,w=0;
  d[y][x]=1;
  for(i=0;i<4;i++){
    for(k=c=0;k<2;k++){
      for(j=1;1;j++){
	ny=y+j*Y[i*2+k];
	nx=x+j*X[i*2+k];
	if(ny<0||n<=ny||nx<0||nx>=n)break;
	c+=d[ny][nx];
      }
    }
    if(c+1==n)w++;
  }
  if(n==1)w/=4;
  return w;
}
int R=1,C=1,H[2000010],N[2000010];
//ティツゥツ陛、ツセツ。テゥツ鳴「テヲツ閉ーテッツシツ暗」ツ??」ツ?セテ」ツ?ッMAXテッツシツ?
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//テヲツ個ソテ・ツ?・テゥツ鳴「テヲツ閉ー
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//テ・ツ渉姪」ツつ甘・ツ?コテ」ツ?凖ゥツ鳴「テヲツ閉ー
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int a,b,m,i,j,w,up[510*510],np[510*510],t[100010];
  int r[2][510*510],d[2][510*510]={};
  scanf("%d %d %d %d",&n,&a,&b,&m);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&w);
      up[R]=i*1000+j;
      hin(w);
    }
  }
  for(i=0;i<n*n;i++)d[0][i]=N[r[0][i]=hout()];
  //for(i=0;i<n*n;i++)printf("%d %04d\n",d[0][i],up[r[0][i]]);
  R=C=1;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&w);
      np[R]=i*1000+j;
      hin(w);
    }
  }
  for(i=0;i<n*n;i++)d[1][i]=N[r[1][i]=hout()];
  //for(i=0;i<n*n;i++)printf("%d %04d\n",d[1][i],np[r[1][i]]);
  for(i=0;i<m;i++)scanf("%d",&t[i]);
  for(i=w=0;i<m;i++){
    j=lb(0,n*n,t[i],d[0]);//printf("%d %d %d\n",t[i],j,d[0][j]);
    if(d[0][j]==t[i]){///printf("%d\n",up[r[0][j]]);
      a-=f(u,up[r[0][j]]/1000,up[r[0][j]]%1000);
      if(a<=0)w|=1;
    }
    j=lb(0,n*n,t[i],d[1]);//printf("%d %d\n",j,d[1][j]);
    if(d[1][j]==t[i]){
      b-=f(c,np[r[1][j]]/1000,up[r[1][j]]%1000);
      if(b<=0)w|=2;
    }
    /*printf("%d %d %d\n",a,b,w);
    for(j=0;j<n*n;j++){
      if(j%n==0)printf("\n");
      printf("%d ",u[j/n][j%n]);
    }printf("\n");
    for(j=0;j<n*n;j++){
       if(j%n==0)printf("\n");
      printf("%d ",c[j/n][j%n]);
    }
    printf("\n\n");//*/
    if(w)break;
  }
  printf("%s\n",w%3?w==1?"USAGI":"NEKO":"DRAW");
  return 0;
}

Measured memory_bytes: 13936
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc085.contest.atcoder.jp/tasks/arc085_a>
問題文============================================================
 高橋くんはプログラミングコンテストに出ていますが， YES か NO で答える問題でTLEしてしまいました。
 
 提出の詳細を見ると，テストケースは全てで N ケースあり，そのうち M ケースでTLEしていました。
 
 そこで高橋くんは, M ケースではそれぞれ実行に 1900 ms かかって 1⁄2 の確率で正解し，
 残りの N−M ケースではそれぞれ実行に 100 ms かかって必ず正解するプログラムへ書き換えました。
 
 そして，以下の操作を行います。
 
 このプログラムを提出する。
 全てのケースの実行が終わるまで待機する。
 もし M ケースのうちどれかで不正解だった場合，もう一度プログラムを提出する。
 これを，一度で全てのケースに正解するまで繰り返す。
 この操作が終了するまでの，プログラムの実行時間の総和の期待値を X msとした時，X を出力してください。
 
 なお，X は整数で出力してください。
=================================================================

解説=============================================================

 期待値の式をサンプルから推測する
 
================================================================
*/
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, M; cin >> N >> M;
    ll res = 1900 * M + 100 * (N - M);
    res *= pow(2, M);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int getgcd(int a,int b){if(!b)return a;return getgcd(b,a%b);}
int main()
{
	int a,b,c,g1,g2;
	scanf("%d%d%d",&a,&b,&c);
	if(c>=b){printf("NO\n");return 0;}
	if(a==0&&c!=0){printf("NO\n");return 0;}
	g1=getgcd(a,b);g2=getgcd(b,c);
	if(g2%g1==0)printf("YES\n");else printf("NO\n");
	return 0;
}


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

struct Peo
{
	int id;
	string name;
	int work;
};
bool operator<(const Peo &a,const Peo &b)
{
	if (a.work!=b.work)	return a.work>b.work;
	return a.id>b.id;
}
//==========template============
const string sez=" is not working now.";
const string working=" is working hard now.";
string name;
map<string,pair<int,int> > M; // name -> (id,work)
set<Peo> S;
set<Peo>::iterator it;
int num;
int n,m,ti;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int x;
		cin>>name;
		cin>>x;
		Peo tmp;
		tmp.name=name;
		tmp.work=x;
		tmp.id=i;
		M[name]=make_pair(i,x);
		S.insert(tmp);
	}
	ti=n;
	num=n/5;
	it=S.end();
	for (int i=1;i<=num;i++)
	{
		if (i==1)	it=S.begin();
		else it++;
	}
	cin>>m;
	for (int i=1;i<=m;i++)
	{
		char ch;
		cin>>ch;
		while (ch!='+' && ch!='-')	cin>>ch;
		if (ch=='+')
		{
			cin>>name;
			int x;
			cin>>x;
			Peo tmp;
			tmp.name=name;
			tmp.work=x;
			tmp.id=++ti;
			n++;
			M[name]=make_pair(ti,x);
			S.insert(tmp);
			int _num=n/5;
			if (num==0)
			{
				if (_num==0)
				{
					cout<< name << sez <<endl;
					it=S.end();
				}	else
				if (_num==1)
				{
					it=S.begin();
					if ((it->id)==ti)
					{
						cout<< name << working <<endl;
					}	else
					{
						cout<< name << sez <<endl;
						cout<<(it->name)<< working <<endl;
					}
				}
			}	else
			{
				int qaq=num;
				Peo las=*it;
				if (tmp<las)
				{
					cout<<name<< working <<endl;
					qaq++;
					while (qaq>_num)
					{
						qaq--;
						cout<<(it->name)<<  sez <<endl;
						it--;
					}
				}	else
				{
					if (qaq<_num)
					{
						qaq++;
						it++;
						if ((it->id) == ti)
						{
							cout<<name << working<<endl;
						}	else
						{
							cout<< name << sez << endl;
							cout<< it->name << working <<endl;
						}
					}	else
					{
						cout<< name << sez <<endl;
					}
				}
			}
			num=_num;
		}	else
		{
			cin>>name;
			pair<int,int> tmp1=M[name];
			Peo tmp;
			tmp.name=name;
			tmp.id=tmp1.first;
			tmp.work=tmp1.second;
			if (num!=0)
			{
				if (it->name==name)
				{
					num--;
					if (num==0)	it=S.end();else it--;
				}	else
				{
					if (tmp<(*it))	num--;
				}
			}
			S.erase(tmp);
			n--;
			int _num=n/5;
			while (num<_num)
			{
				if (num==0)
				{
					num++;
					it=S.begin();
					cout<< it->name << working <<endl;
				}	else
				{
					num++;
					it++;
					cout<< it->name << working <<endl;
				}
			}
			while (num>_num)
			{
				num--;
				cout<< it->name << sez << endl;
				if (num==0)	it=S.end();else it--;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 12552
N = int(input())
A = [input() for i in range(N)]
import collections
c = dict(collections.Counter(A))
max_value = max(list(c.values()))
ans = []
for k ,v in c.items():
    if max_value == v:
        ans.append(k)
for i in sorted(ans):
    print(i)

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

int main() {
    int a, b, count;
    count = 0;
    cin >> a >> b;

    for(int i = a; i <= b; i++) {
        if(i/10000 == i%10 && i%10000/1000 == i%100/10) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int ans = 0;
        int a[] = new int[n];
        int tmp = 0;
        int tmp2 = 0;
        for(int i = 0;i<n;i++){
            tmp = Integer.parseInt(sc.next());
            if(tmp == tmp2 + 1){
                a[tmp2] = 1;
            }
            tmp2 = tmp;
        }
        for(int i = 0;i<n;i++){
            ans += Integer.parseInt(sc.next());
        }
        for(int i = 1;i < n;i++){
            tmp = Integer.parseInt(sc.next());
            if(a[i] != 0){
                ans += tmp;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24020
#ABC083C
import math
X,Y=map(int,input().split())
def Binary(r,l):
	global X,Y
	while r<l-1:
		m=(r+l)//2
		if 2**m*X<=Y:
			r=m
		else:
			l=m
	return r
#print(int(math.log2(Y/X)+1))?
print(Binary(0,int(math.log2(Y/X)+1))+1)

Measured memory_bytes: 3060
input = STDIN.read.split("\n").map(&:chomp)
input.shift.to_i.times do
  a = input.shift.to_i
  b = input.shift.to_i

  sum = a + b
  puts(sum >= 10**80 ? 'overflow' : sum)
  # if (sum = a + b) >= 10**80
  #   puts 'overflow'
  # else
  #   puts sum
  # end
end

Measured memory_bytes: 8564
#include <stdio.h>

int bubbleSort(int A[], int N){
  int sw=0, i, j, flag=1, swap;
  for(i=0; flag; i++){
    flag = 0;
    for(j=N-1; j>=i+1; j--){
      if(A[j]<A[j-1]){
	//swap(A[j], A[j-1]);
	swap = A[j];
	A[j] = A[j-1];
	A[j-1] = swap;
	flag = 1;
	sw++;
      }
    }
  }
  return sw;
}

int main(){
  int A[100], N, sw, i;
  scanf("%d", &N);
  
  for(i=0; i<N; i++) scanf("%d", &A[i]);

  sw = bubbleSort(A, N);
  
  for(i=0; i<N; i++){
    if(i) printf(" ");
    printf("%d", A[i]);
  }

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



Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

int main()
{
    int a;
    string s;
    cin >> a >> s;

    if(a >= 3200)
        cout << s << "\n";
    else cout << "red\n";
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

void divisor(ll n,map<ll,ll> mp){
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			mp[i]++;
			mp[n/i]++;
		}
	}
	return;
}

int main(){
	ll n;cin>>n;
	map<ll,ll> mp;
	for(ll i=2;i<=n;i++){
		int j=i,k=2;
		while(j>=k){
			if(j%k==0){
				mp[k]++;
				j/=k;
			}
			else{
				k++;
			}
		}
	}
	//for(auto i:mp) cout<<i.first<<" : "<<i.second<<"\n";
	ll ans=1;
	for(auto i:mp){
		ans=ans*(i.second+1)%MOD;
	}

	cout<<ans<<"\n";

}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	p <- readInts
	q <- readInts
	let
		perms = sort $ permutations [ 1 .. n ]
		i = fromJust $ elemIndex p perms
		j = fromJust $ elemIndex q perms
	print $ abs ( i - j )

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

int main() {
  int N,P=0,J=1;
  cin >> N;
  vector<int> B(N);
  for (int i=0; i<N ; i++){
    cin >> B[i];
  }
  for (int i=0; i<N ; i++){
    J=B[J-1];
//    cout << B[J] << "aa" << endl;
//    cout << J << "bb" << endl;
    P++;
    if(J==2){
      cout << P << endl;
      return 0;
    }
  }
  if (P==N){
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}

static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;
static const LLONG LL_HUGE_DIVIDER = 1000000007LL;

//static void ABC111D_RobotArms();
static void ABC111B_AtCoderBeginnerContest111();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC111B_AtCoderBeginnerContest111();
	fflush(stdout);
	return 0;
}
#endif
static void ABC111B_AtCoderBeginnerContest111()
{
	int suit[] = { 111, 222, 333, 444, 555, 666, 777, 888, 999 };
	int N;
	scanf(" %d", &N);

	int ans = 0;
	int siz = sizeof(suit) / sizeof(suit[0]);
	for (int i = 0; i < siz; i++) {
		if (N <= suit[i]) {
			ans = suit[i];
			break;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
M = H.times.map { gets.chomp.chars }

queue = []

if M[0][0] == '#'
  queue << [0, 0, 1, '#']
else
  queue << [0, 0, 0, '.']
end

visited = Hash.new { |h, k| h[k] = Hash.new(false) }
DY = [1, 0]
DX = [0, 1]

until queue.empty?
  y, x, cost, mark = queue.shift

  next if visited[y][x]
  visited[y][x] = true

  if y == H - 1 && x == W - 1
    puts cost
    break
  end

  2.times do |i|
    ny = y + DY[i]
    nx = x + DX[i]

    next if ny < 0 || nx < 0 || H <= ny || W <= nx

    if M[ny][nx] == mark
      queue.unshift([ny, nx, cost, M[ny][nx]])
    else
      if M[ny][nx] == '.'
        queue.unshift([ny, nx, cost, M[ny][nx]])
      else
        queue << [ny, nx, cost + 1, M[ny][nx]]
      end
    end
  end
end


Measured memory_bytes: 3708
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	REP(i, 1, n) {
		int cnt = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			bool left = false, right = false;

			for (int j = 0; j<i; j++)
				if (s[j] == c)
					left = true;

			for (int j = i; j<n; j++)
				if (s[j] == c)
					right = true;

			if (left&&right)
				cnt++;


		}
		if (ans < cnt) ans = cnt;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    const int L = (1 << N);
    vector<int> As(L);
    for (auto & a : As) cin >> a;

    vector<int> dp1(L);
    vector<int> dp2(L);
    // dp1[k]  k の bit列 のサブセット i について、Aiが最大となるときの i
    // dp2[k]　k の bit列 のサブセット i について、Aiが２番目に大きい値となるときの i

    dp1[0] = 0;
    dp2[0] = -1;
    dp1[1] = (As[0] > As[1]) ? 0 : 1;
    dp2[1] = 1 - dp1[1];

    int ans = As[0] + As[1];
    cout << ans << '\n';

    for (int k = 2; k < L; ++k){
        if (As[0] > As[k]){
            dp1[k] = 0;
            dp2[k] = k;
        }else{
            dp1[k] = k;
            dp2[k] = 0;
        }
        for (int mask = 1; mask < k; mask <<= 1) {
            if ((mask & k) == 0) continue;
            int s = k ^mask;
            if (As[dp1[s]] > As[dp1[k]]) {
                dp2[k] = dp1[k];
                dp1[k] = dp1[s];
            }else if (As[dp1[s]] == As[dp1[k]]){
                if (dp1[s] != dp1[k]){
                    dp2[k] = dp1[s];
                }
            }else if (As[dp1[s]] > As[dp2[k]]){
                dp2[k] = dp1[s];
            }
            if (s > 0 and As[dp2[s]] > As[dp2[k]] ){
                dp2[k] = dp2[s];
            }
        }
        ans = max(ans, As[dp1[k]] + As[dp2[k]]);
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define int long long

/*************** using variables ***************/
int n;
vector<LL> t, a;
LL t_num = 0, a_num = 0;
/**********************************************/
signed main(){
    cin >> n;
    t.resize(n); a.resize(n);
    REP(i, n) cin >> t[i] >> a[i];
    
    t_num = t[0]; a_num = a[0];
    
    FOR(i, 1, n){
        LL j = max(t_num/t[i] + min(t_num%t[i], 1LL), a_num/a[i] + min(a_num%a[i], 1LL));
        t_num = t[i]*j; a_num = a[i]*j;
    }
    
    cout << t_num+a_num << endl;
}


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

#include <iostream>
#define pb push_back
#define sort_incr(v) sort(v.begin(),v.end());
#define sort_decr(v) {sort(v.begin(),v.end()); reverse(v.begin(),v.end());}
#define take_input(v,n) for(ll i=0,temp;i<n;i++){cin>>temp;v.pb(temp);}
#define fastio {ios_base::sync_with_stdio(false);    cin.tie(NULL);}
#define ALL(v) v.begin(),v.end()

typedef long long ll;
using namespace std; 

int main() 
{
    fastio;
    ll n;
    cin>>n;
    ll va=0;
    ll vaaa[200005];
    for(ll i=0;i<n;i++)
    {
        cin>>vaaa[i];
        va=va^vaaa[i];
    }
    for(ll i=0;i<n;i++)
    {
        cout<<(va^vaaa[i])<<" ";
    }
    
    return 0; 
} 

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j; ans %= MOD;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}

void solve(){
  int n; cin >> n;
  ll ans = 0;
  for(int i = 1; i < sqrt(n); ++i){
    ll a = i;
    ll b = i;
    while(a * b < n){
      if(a == b) ans++;
      else ans += 2;
      // cout << a << " " << b << " " << n-a*b << endl;
      b++;
    }
  }
  cout << ans <<endl;
}

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


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

int main() {
	int n; cin >> n;
    vector<int> alturas(n);
    for(int i = 0; i < n; i++) cin >> alturas[i];
    vector<int> dp(n,1000000009); dp[0] = 0;
    int values[2] = {1,2};
    for(int i =0; i < n; i++){
        for(int x: values){
            if(i+x >= n) break;
            dp[i+x] = min(dp[i+x], dp[i] + abs(alturas[i] - alturas[i+x]));
        }
    }
    cout << dp[n-1];
	return 0;
}


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

#define INF (int)(1e9)

signed main(){

  int N, M;
  int ans = 0, ans2 = 0;  vector<int> bit, bit2,  p, e, f;
  
  cin>>N>>M;

  bit.resize(N);
  p.resize(M);

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

  bit2 = bit;
  for(int i = 0; i < M; i++){
    cin>>p[i];
    if(i%2){
      for(int j = 0; j < p[i]; j++){
	e.push_back(0);
	f.push_back(1);
      }
    
    } else {
       for(int j = 0; j < p[i]; j++){
	e.push_back(1);
	f.push_back(0);
      }
    }
  }

  for(int i = 0; i < N; i++){
    int x = -1;
    // cout<<"ei  = "<<i<<" "<<e[i]<<" "<<bit[i]<<endl;
    for(int j = i; j < N; j++){
      if(e[i] == bit[j]){
	x = j;
	break;
      }
    }
    
    if(x == -1){
      ans = INF;
      break;
    }
    for(int j = x-1; j >= i; j--){
      bit[j+1] = bit[j];
    }
    ans += x-i;
  }

  
  for(int i = 0; i < N; i++){
    int x = -1;
    //  cout<<"fi  = "<<i<<" "<<f[i]<<" "<<bit2[i]<<endl;
    for(int j = i; j < N; j++){
      if(f[i] == bit2[j]){
	x = j;
	break;
      }
    }
    
    if(x == -1){
      ans2 = INF;
      break;
    }
    for(int j = x-1; j >= i; j--){
      bit2[j+1] = bit2[j];
    }
    ans2 += x-i;
  }

  cout<<min(ans,ans2)<<endl;

  
  return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <string>
int main(){
    std::string S;
    std::cin >> S;
    int ind = S.size();
    while(ind != 0){
        std::string s1, s2, s3;
        int flag = 0;
        if(ind >= 5) s1 = S.substr(ind - 5, 5);
        if(ind >= 6)s2 = S.substr(ind - 6, 6);
        if(ind >= 7)s3 = S.substr(ind - 7, 7);
        if(s3 == "dreamer"){
            ind -= 7;
            flag = 1;
        }
        else if(s2 == "eraser"){
            ind -= 6;
            flag = 1;
        }
        else if(s1 == "dream"){
            ind -= 5;
            flag = 1;
        }
        else if(s1 == "erase"){
            ind -= 5;
            flag = 1;
        }
        if(flag == 0){
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

int main() {
	char c;
	int X[26] = {};
	while (1) {
		if (scanf("%c", &c) == EOF) break;
		if ((65 <= c && c <= 90) || (97 <= c && c <= 122)) {
			X[(c - 1) % 32]++;
		}
	}
	for (int i = 0; i < 26; i++) {
		char C = i + 97;
		printf("%c : %d\n", C, X[i]);
	}
}


Measured memory_bytes: 3204
#include <stdio.h>

int main(){
  int x1, y1, x2, y2, x3, y3, x4, y4;
  scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  x3 = x2-(y2-y1);
  y3 = y2+(x2-x1);
  x4 = x3-(y3-y2);
  y4 = y3+(x3-x2);
  printf("%d %d %d %d\n", x3, y3, x4, y4);
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import numpy as np

N, M, C = map(int, input().split())
B = np.ndarray([M, 1])
B = list(map(int, input().split()))
A = np.ndarray([N, M])
for i in range(N):
    A[i, :] = list(map(int, input().split()))

ans = sum((np.dot(A,B) + C) > 0)

print(ans)


Measured memory_bytes: 21496
#include<iostream>
using namespace std;
long long a,b,c,d;
int main(){
    cin>>a>>b>>c>>d;
    if (a%d!=0)a=a/d+1;
    else a=a/d;
    if (c%b!=0)c=c/b+1;
    else c=c/b;
    if (a>=c)cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 3132
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }

   else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
   else if(s=="Rainy"){
        cout<<"Sunny"<<endl;
    }

    return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, x, m = map(int, input().split())
    sedic = dict()
    sedic[x] = 1
    wa=[x]
    for i in range(2, min(10**5+100,n+1)):
        x = (x**2) % m
        if x in sedic:
            ans=sum(wa)
            roop,amari=divmod(n-i,i-sedic[x])
            ans+=sum(wa[sedic[x]-1:])*roop
            ans+=sum(wa[sedic[x]-1:sedic[x]+amari])
            print(ans)
            break
        sedic[x]=i
        wa.append(x)
    else:
        print(sum(wa))

if __name__ == '__main__':
    main()


Measured memory_bytes: 15768
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC\n";
	else cout<<"ABC\n";
	return 0;	
}



Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int manhattan_dist(P from, P to){
	return abs(from.first - to.first) + abs(from.second - to.second);
}

int main(){
	int H, W, D, t;
	cin >> H >> W >> D;
	vector<P> point(H*W);
	REP(i,H){
		REP(j,W){
			cin >> t;
			--t;
			point[t] = make_pair(i,j);
		}
	}
	vector<ll> sum(H*W+1, inf);
	for(int i = 0; i < H*W; ++i){
		if(sum[i+1] != inf)break;
		sum[i+1] = 0;
		for(int j = 1; i+j*D < H*W; ++j){
			int to = i+j*D;
			int dist = manhattan_dist(point[to], point[to-D]);
			sum[to+1] = dist + sum[to-D+1];
		}
	}
	int Q, l, r;
	cin >> Q;
	rep(_,Q){
		cin >> l >> r;
		cout << sum[r] - sum[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 4524
#include <iostream>

size_t digit(size_t n)
{
  size_t result=1;
  for(;;)
  {
    if(n<10)
      return result;
      
    n/=10;
    result++;
  }
}

int main()
{
  size_t N;
  std::cin>>N;
  
  size_t t;
  size_t min=N;
  for(size_t i=1;i*i<=N;i++)
  {
    t=N/i;
    if(i*t==N)
    {
      min=t<min?t:min;
    }
  }
  
  std::cout<<digit(min)<<std::endl;

  return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
numbers = gets.chomp.split(' ').map(&:to_i)

count_1 = 0
sum = 0

# 奇数負
n.times do |i|
  sum += numbers[i]
  if i % 2 == 1
    next if sum < 0
    count_1 += sum + 1
    sum = -1
  else
    next if sum > 0
    count_1 += - sum + 1
    sum = 1
  end
end

count_2 = 0
sum = 0

n.times do |i|
  sum += numbers[i]
  if i % 2 == 0
    next if sum < 0
    count_2 += sum + 1
    sum = -1
  else
    next if sum > 0
    count_2 += - sum + 1
    sum = 1
  end
end

print [count_1, count_2].min.to_s + "\n"


Measured memory_bytes: 9612
n=int(input())
a0=10**10
b0=10**10
c0=10**10
d0=10**10
a1=-10**10
b1=-10**10
c1=-10**10
d1=-10**10
for i in range(n):
  x,y=map(int,input().split())
  a=x+y
  if a0>a:
    a0=a
  if a1<a:
    a1=a
  b=x-y
  if b0>b:
    b0=b
  if b1<b:
    b1=b
  c=-x+y
  if c0>c:
    c0=c
  if c1<c:
    c1=c
  d=-x-y
  if d0>d:
    d0=d
  if d1<d:
    d1=d
print(max(a1-a0,b1-b0,c1-c0,d1-d0))

Measured memory_bytes: 75064
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = "Yes";
		Set<String> set = new HashSet<>();
		String w = sc.next();
		set.add(w);
		char e = w.charAt(w.length()-1);

		for(int i=0; i<N-1; i++) {
			w = sc.next();
			if(set.add(w) && e==w.charAt(0)){
				e = w.charAt(w.length()-1);
		        set.add(w);
		     }else{
		        s = "No";
		      }
		}
		sc.close();
		System.out.println(s);
	}

}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;

    cout << "ABC" << N << endl;

    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var bi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var ai = new int[n];
            ai[0] = bi[0];
            ai[n - 1] = bi[bi.Length - 1];
            for (var i = 1; i < ai.Length - 1; i++)
            {
                ai[i] = Math.Min(bi[i - 1], bi[i]);
            }
            Console.WriteLine(ai.Sum());
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    ll N;
    cin >> N;
    ll ans = N * (N + 1) / 2 - N;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;
  char s[SIZE];

  scanf("%d%s", &n, s);

  int counter = 0;

  for(int i=0;i<n;i++){
    counter += s[i] == 'R';
  }

  if(counter * 2 > n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256