akhauriyash/Code-Regression huggingface dataset:
/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 105;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n , sum;
int a[N];

int main() {
	cin >> n >> sum;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i < n; i++) {
		sum -= a[i];
		if (sum < 0) {
			cout << i - 1 << endl;
			return 0;
		}
	}
	if (sum == a[n])
		cout << n << endl;
	else
		cout << n - 1 << endl;
	return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int n;
    cin>>n;
    Vi h(n);
    REP(i,n) cin>>h[i];

    REPD2(i,n-1,1){
        if(h[i]<h[i-1]){
            if(h[i-1]-h[i] != 1){
                cout<<"No"<<endl;
                return 0;
            }else{
                h[i-1]--;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 640
# Credits Geeks forGeeks
n=200001
k=2
C = [[0 for x in range(k+1)] for x in range(n+1)] 
for i in range(n+1): 
    for j in range(min(i, k)+1): 
        if j == 0 or j == i: 
            C[i][j] = 1
        else: 
            C[i][j] = C[i-1][j-1] + C[i-1][j]
t=int(input())
a=[int(x) for x in input().split()]
d=dict()
d2=dict()
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
total=0
for i in d:
    # print(i,d[i])
    count=d[i]
    if(count<2):
        d2[i]=0
    else:
        # ncr
        d2[i]=C[count][2]
    total+=d2[i]
# print("Total "+str(total))
# print(C[2][2])
for i in a:
    count=d[i]
    if(count<=2):
        ans=0
    else:
        ans=C[count-1][2]
    print(total-d2[i]+ans)




Measured memory_bytes: 69388
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int a, b;
    cin>>a>>b;
    if(a == b){
        f(i,b)cout<<a;
        return ;
    }
    if(a > b)swap(a,b);
    f(i,b)cout<<a;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
#include <cmath>
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    if (i > 0) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll ax = labs(x), ad = labs(d);
  if (ad >= ax) {
    if (k % 2 == 0) {
      cout << ax << '\n';
    } else {
      cout << ad - ax << '\n';
    }
    return 0;
  }
  ll t = ax / ad;
  if (k <= t) {
    cout << ax - ad * k << '\n';
  } else {
    if (((k ^ t) & 1) == 0) {
      cout << ax - ad * t << '\n';
    } else {
      cout << labs(ax - ad * (t + 1)) << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 3596
n, w = map(int, input().split())
wl = [0] * n
vl = [0] * n
for i in range(n):
  wl[i], vl[i] = map(int, input().split())

dp = [[]] * (n+1)
for i in range(n+1):
  dp[i] = [0] * (w+1)

for i in range(n):
  for j in range(w+1):
    if j >= wl[i]:
      dp[i+1][j] = max(dp[i][j], dp[i][j-wl[i]]+vl[i])
    dp[i+1][j] = max(dp[i][j], dp[i+1][j])

print(dp[n][w])
#for i in range(n+1):
#  print(dp[i])

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

const int M = 1000000007;

vector<int> grp;
vector<long long>val;
vector<vector<int>> lis;
void init(int n) {
    grp.resize(n);
    val.resize(n, 0);
    lis.resize(n);
    for (int i = 0; i < n; ++i) {
        grp[i] = i;
        lis[i].push_back(i);
    }
}
void merge(int p, int q, long long w) {
    if (grp[p] == grp[q]) return;
    if (lis[grp[p]].size() < lis[grp[q]].size()) {
        merge(q, p, -w);
        return;
    }
    long long d = w + val[p] - val[q];
    int g = grp[q];
    for (int i : lis[g]) {
        grp[i] = grp[p];
        val[i] += d;
        lis[grp[p]].push_back(i);
    }
    lis[g].clear();
}

int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;
        init(n);
        for (int i = 0; i < m; ++i) {
            char c;
            cin >> c;
            if (c == '!') {
                int p, q, w;
                cin >> p >> q >> w;
                merge(p - 1, q - 1, w);
            }
            else {
                int p, q;
                cin >> p >> q;
                --p;
                --q;
                if (grp[p] != grp[q])
                    puts("UNKNOWN");
                else
                    printf("%lld\n", val[q] - val[p]);
            }
        }
        for (int i = 0; i < n; ++i) {
            lis[i].clear();
        }
    }
}

Measured memory_bytes: 10708
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
	string s, t;
	cin >> s >> t;
	bool result = false;
	for (int i = 0; i < s.size(); ++i) {
		s = s.back() + s.substr(0, s.size() - 1);
		if (s == t) {
			result = true;
			break;
		}
	}
	if(result) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int a, b, c; cin >> a >> b >>c;
    cout << a*b/2 << endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int N=6002,M=302;
const int INF=123456789;

struct edge{int to,cost;};
vector<edge> G[N], g[M];

int d[N];
void dijkstra(int start)
{
    fill(d,d+N,INF);

    priority_queue<pi,vector<pi>,greater<pi>> que;
    d[start]=0;
    que.push(pi(0,start));
    while(!que.empty()){
        pi p=que.top();
        que.pop();
        int v=p.se;
        if(d[v]<p.fi) continue;
        rep(i,G[v].size())
        {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                que.push(pi(d[e.to],e.to));
            }
        }
    }
}

int solve()
{
    fill(d,d+M,INF);

    priority_queue<pi,vector<pi>,greater<pi>> que;
    d[0]=0;
    que.push(pi(0,0));
    while(!que.empty()){
        pi p=que.top();
        que.pop();
        int v=p.se;
        if(d[v]<p.fi) continue;
        rep(i,g[v].size())
        {
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                que.push(pi(d[e.to],e.to));
            }
        }
    }

    return d[1];
}

void init()
{
    rep(i,N) G[i].clear();
    rep(i,M) g[i].clear();
}

int main()
{
    int n,m,cap;
    while(cin >>n >>m >>cap,n)
    {
        init();

        string src,dest;
        cin >>src >>dest;

        map<string,int> name_to_id;
        name_to_id[src]=0;
        name_to_id[dest]=1;

        int now=2;
        rep(i,n)
        {
            string a,b;
            int D;
            cin >>a >>b >>D;

            if(name_to_id.find(a) == name_to_id.end()) name_to_id[a]=now++;
            if(name_to_id.find(b) == name_to_id.end()) name_to_id[b]=now++;

            int A=name_to_id[a], B=name_to_id[b];
            G[A].pb(edge{B,D});
            G[B].pb(edge{A,D});
        }

        vector<string> st(m);
        rep(i,m) cin >>st[i];

        dijkstra(0);
        rep(i,m)
        {
            int s=name_to_id[st[i]];
            if(s<=1) continue;

            if(d[s] <= cap*10) g[0].pb(edge{i+2,d[s]});

        }
        if(d[1] <= cap*10) g[0].pb(edge{1,d[1]});

        rep(i,m)
        {
            int s=name_to_id[st[i]];
            if(s<=1) continue;

            dijkstra(s);
            rep(j,m)
            {
                int t=name_to_id[st[j]];
                if(t<=1) continue;

                if(d[t] <= cap*10) g[i+2].pb(edge{j+2,d[t]});
            }
            if(d[1] <= cap*10) g[i+2].pb(edge{1,d[1]});
        }

        int ans=solve();
        if(ans==INF) ans=-1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5444
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100100;
struct Node{
	LL d;
	LL td;
	int i,sz,fa;
	vector<int> ch;
	Node():td(0),sz(1){}
	bool operator<(const Node o)const{
		return d<o.d;
	}
};
Node d[N];
map<LL,int> fd;
void GG(){
	puts("-1");
	exit(0);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&d[i].d);
		d[i].i=i;
	}
	sort(d+1,d+n+1);
	for(int i=1;i<=n;i++){
		fd[d[i].d]=i;
	}
	for(int i=n;i>1;i--){
		fd.erase(d[i].d);
		LL nd=d[i].d-(n-2*d[i].sz);
		if(!fd.count(nd)){
			GG();
		}
		int f=fd[nd];
		d[i].fa=d[f].i;
		d[f].sz+=d[i].sz;
		d[f].td+=d[i].td+d[i].sz;
	}
	if(d[1].td!=d[1].d){
		GG();
	}
	for(int i=2;i<=n;i++){
		printf("%d %d\n",d[i].fa,d[i].i);
	}
	return 0;
}

Measured memory_bytes: 13056
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    vector<int> vX(N); for(int i=0; i<N; ++i){ cin >> vX[i]; }
    vector<int> vXs = vX; sort(vXs.begin(), vXs.end());
    
    int med_idx = N/2 - 1;
    int med = vXs[med_idx];
    
    for(int i=0; i<N; ++i){
        if( vX[i] <= med ){ cout << vXs[med_idx+1] << endl;
        }      else       { cout << vXs[med_idx  ] << endl; }
    }
    
    return 0;
}

Measured memory_bytes: 3840
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_080_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N       PIC 9(9).
    01 D       PIC 9(9).
    01 R       PIC 9(1).
    01 harshad PIC 9(2).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.

    MOVE N TO D.

    MOVE 0 TO harshad.

    PERFORM UNTIL D = 0
        DIVIDE 10 INTO D GIVING D REMAINDER R
        ADD R TO harshad
    END-PERFORM.

    DIVIDE harshad INTO N GIVING D REMAINDER R.

    IF R = 0 THEN
        DISPLAY "Yes"
    ELSE
        DISPLAY "No"
    END-IF.

    STOP RUN.


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static  void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int x[] = new int[3];
        for(int i = 0; i < 3; i++){
            x[i] = scanner.nextInt();
        }
        int k = scanner.nextInt();
        int max = 0;
        int max_val = 0;
        for(int i = 0; i < 3; i++){
            if(max_val < x[i]){
                max_val = x[i];
                max = i;
            }
        }
        for(int i = 0; i < k; i++){
            max_val += max_val;
        }
        int ans = 0;
        for(int i = 0; i < 3; i++){
            if(i != max){
                ans += x[i];
            }
        }
        System.out.println(ans + max_val);
    }
}


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

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

  vector<int> r, g, b(n, 0);

  rep(i, n) {
    switch (s.at(i)) {
      case 'R': {
        r.push_back(i);
        break;
      }
      case 'G': {
        g.push_back(i);
        break;
      }
      case 'B': {
        b[i] = 1;
        break;
      }
    }
  }

  ll count = r.size() * g.size() * (n - r.size() - g.size());

  for (auto i : r) {
    for (auto j : g) {
      int diff = abs(i - j);
      int fail_a = min(i, j) - diff;
      int fail_b = max(i, j) + diff;
      int fail_c = (i + j) % 2 == 0 ? (i + j) / 2 : -1;

      for (auto fail : {fail_a, fail_b, fail_c}) {
        if (fail >= 0 && fail < n && b[fail] == 1) count--;
      }
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int n;
ll a[MAXN],b[MAXN];
ii sa[MAXN],sb[MAXN];
bool vst[MAXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	mset(vst,0);
	
	cin>>n;
	forn(i,0,n){
		cin>>a[i];
		sa[i]={a[i],i};
	}
	forn(i,0,n){
		cin>>b[i];
		sb[i]={b[i],i};
	}
	
	sort(sa,sa+n);	
	sort(sb,sb+n);
	
	forn(i,0,n){
		if(sa[i].F>sb[i].F){
			cout<<"No\n";
			return 0;
		}
	}
	
	forn(i,1,n){
		if(sa[i].F<=sb[i-1].F){
			cout<<"Yes\n";
			return 0;
		}
	}
	
	map<ll,ll> m;
	forn(i,0,n){
		m[sa[i].S]=sb[i].S;
	}
	
	int cnt=0;
	forn(i,0,n){
		if(vst[i]) continue;
		
		int cur=i;
		cnt++;
		while(!vst[cur]){
			vst[cur]=1;
			cur=m[cur];			
		}
	}
	
	if(cnt==1){
		cout<<"No\n";
	}
	else cout<<"Yes\n";
	
	return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    int n;
    cin >> n;

    int ans = 0;
    rep(i, n+1){
        int cnt = 0;
        rep(j, i)if(i % (j+1) == 0)cnt++;
        if(cnt == 8 && i&1)ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
program k_th_common_divisor
  implicit none
  integer :: a, b, k, i, m = 0
  read(*,*) a, b, k
  do i = 100, 1, -1
    if (mod(a,i) == 0 .and. mod(b,i) == 0) m = m+1
    if (m == k) then
      write(*,'(i0)') i
      stop
    end if
  end do
end program k_th_common_divisor

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n; cin >> n;
  if (n == 1) {cout << "Hello World" << endl;}
  if (n == 2) {
    ll a, b; cin >> a >> b;
    cout << a + b << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  char s[200];
  scanf("%d%*c",&k);
  scanf("%s",s);
  for(int i=0;s[i];i++)
  {
	if(i == k)
	{
		printf("...");
		break;
	}
	printf("%c",s[i]);
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);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 SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    IN(ll, n);
    VIN(ll, a, n);
    SORT(a);
    if (a[0] == 0) {
        COUT(0);
        return 0;
    }
    ll aja = 1000000000000000000;
    RREP(i, n){
        aja = (aja)/a[i];
        if (aja == 0) {
            COUT(-1);
            return 0;
        }
    }
    ll ans = 1;
    REP(i, n){
        ans *= a[i];
    }
    if (ans > 1000000000000000000) {
        COUT(-1);
        return 0;
    }
    COUT(ans);
}


Measured memory_bytes: 4056
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
F = [LIST() for _ in range(N)]
P = [LIST() for _ in range(N)]

ans = -INF
for i in range(1, 1<<10):
	i = list("{:b}".format(i).zfill(10))
	profit = 0
	for j in range(N):
		cnt = 0
		for k in range(10):
			if i[k] == "1" and F[j][k] == 1:
				cnt += 1
		profit += P[j][cnt]
	ans = max(ans, profit)

print(ans)

Measured memory_bytes: 5204
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prl puts("\n------------------\n")
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prl 
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    ll a, b;
    sf(a, b);
    if (b <= 1) {
        cout << 0 << endl;
        return 0;
    } 
    ll cnt = 0;
    ll ss = a;
    while (true) {
        ll s = a - cnt;
        pr(a);pr(cnt);prln(s);
        if (s >= b) break;
        else {
            a += ss;
            ++cnt;
        }
        
    }
    cout << cnt + 1 << endl;

    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int K = cin.nextInt();
		int T = cin.nextInt();
		int[] a = new int[T];

		for (int i = 0; i < T; i++)
		{
			a[i] = cin.nextInt();
		}
		int max = a.Max();
		Console.WriteLine(Math.Max(max - (K - max) - 1, 0));
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2904
n,c,k=map(int,input().split())
t=[]
for _ in range(n):
  t.append(int(input()))
if c==1:
  print(n)
  exit()

t.sort()
time=0
p=0
taiki=0
ans=0
for i in range(n):
  if taiki==0:
    p=t[i]
    time=0
    taiki+=1
    continue
  taiki+=1
  time+=t[i]-p
  p=t[i]
  if time > k :#i-1番目までの客をバスに乗せる。i番目の客は待機
    ans+=1
    taiki=1
    time=0
  elif taiki==c:#i番目までの客をバスに乗せる
    ans+=1
    taiki=0
ans += 1 if taiki > 0 else 0
print(ans)


Measured memory_bytes: 7384
n = int(input())
s = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x,y = map(int,input().split())
        s[i].append((x-1,y))

ans = 0
for i in range(1,2**n):
    ls = [0] * n
    
    for j in range(n):
        if (i >> j) & 1:
            ls[j] = 1
            
    fl = 1
    for j in range(n):
        for k,l in s[j]:
            if ls[j] == 1:
                if ls[k] != l:
                    fl = 0
    if fl == 1:
        ans = max(ans , sum(ls))
    
print(ans)

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

using namespace std;

const int N = 101;
const int W = 1e5 + 1;

using ll = long long;

int value[N], weight[N];
ll dp[N][W];

int main() {
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        cin >> weight[i] >> value[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            if (j - weight[i] >= 0) {
                dp[i][j] = dp[i - 1][j - weight[i]] + value[i];
            }
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }
    }
    cout << dp[n][w];
    return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n,k,a=0;
  cin>>n>>k;
  for(n--;n;n--){
    Int l=a,r=2e18;
    while(l+1<r){
      Int m=(l+r)>>1;
      Int y=(m-1)-(m-1)/k;
      if(y<=a) l=m;
      else r=m;
    }
    a=l;
  }
  cout<<a<<endl;
  return 0;
}



Measured memory_bytes: 3116
#include <cstdio>
#include <cstring>

int main(void)
{
    int n, scnt;
    char ind[100001];
    scanf("%s", ind);
    scanf("%d", &n);

    scnt=strlen(ind);
    for(int i=0, j=0 ; j<scnt ; j++) {
        i='z'+1-ind[j];
        if(ind[j]!='a' && i<=n) {
            n-=i;
            ind[j]='a';
        }
        if(j+1==scnt)
            ind[j]+=n%26;
    }
    printf("%s\n", ind);
    return 0;
}


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

int main(){
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2+y1-y2 << ' ' << y2+x2-x1 << ' ' << x1+y1-y2 << ' ' << y1+x2-x1;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
// #include <bits/stdc++.h>
#define req(i,k) for(int i = 0; i < k; i++)
using namespace std;


int main(void) {
int n;
cin >> n;
string s;
cin >> s;
vector<char> b(s.length());
req(i,s.length()) {
   b.at(i) = s.at(i) + n;
   if(b.at(i) <= 90) {
       cout << b.at(i);
   } else {
       b.at(i)= b.at(i) - 26;
       cout << b.at(i);
   }

}





    return 0;
}

Measured memory_bytes: 256
n = int(input())
ok = True
w = [input() for _ in range(n)]
s = [w[0]]
for i in range(n-1):
    if w[i+1] in s:
        ok = False
        break
    s.append(w[i+1])
    
    if w[i][-1] != w[i+1][0]:
        ok = False 
        break
if ok:print("Yes")
else:print("No")
    
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    int x,y;
    cin>>a>>b>>c;
    x=a.size();
    y=b.size();
    if(a[x-1]==b[0] && b[y-1]==c[0])
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 3620
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e6+9;
deque<char> s;
int q,t,f;
string c;
string tmp;
bool r;

int main(){
	cin>>tmp;
	for(auto u:tmp) {s.pb(u);}
	cin>>q;
	while(q--){
		cin>>t;
		if(t==1){
	 		r=!r;
		}else{
			cin>>f>>c;
			if(f==1){
				if(!r) s.push_front(c[0]);
				else s.pb(c[0]);
			}else{
				if(!r) s.pb(c[0]);
				else s.push_front(c[0]);
			}
		}
	}
	if(r){
		for(int i=s.size()-1;i>=0;i--) cout<<s[i];
	}else for(int i=0; i < s.size(); ++i){
		cout<<s[i]; 
	}
    return 0;
}

Measured memory_bytes: 896
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

S = rr()

if not 1 <= int(S[:2]) <= 12:
    if not 1 <= int(S[2:]) <= 12:
        print('NA')
    else:
        print('YYMM')
elif not 1 <= int(S[2:]) <= 12:
	print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
N, M, S, T = map(int, input().split())
S, T = S - 1, T - 1
G_yen = [[] for i in range(N)]
G_snuuk = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u - 1, v - 1
    G_yen[u].append([v, a])
    G_yen[v].append([u, a])
    G_snuuk[u].append([v, b])
    G_snuuk[v].append([u, b])


def dijkstra(graph, start, inf=float('inf')):
    import heapq
    n = len(graph)
    distances = [inf] * n
    fixed = [False] * n
    distances[start] = 0

    # 距離・頂点
    hq = [(0, start)]
    while hq:
        dist, fr = heapq.heappop(hq)
        fixed[fr] = True

        for to, cost in graph[fr]:
            new_dist = distances[fr] + cost
            if (fixed[to] is False) and (distances[to] > new_dist):
                distances[to] = new_dist
                heapq.heappush(hq, (new_dist, to))

    return distances


from_start_yen = dijkstra(G_yen, S)
from_goal_snuuk = dijkstra(G_snuuk, T)

ans = [0] * (N + 1)
for i, yen, snuuk in zip(reversed(range(N)), from_start_yen[::-1], from_goal_snuuk[::-1]):
    ans[i] = max(ans[i + 1], 10 ** 15 - (yen + snuuk))

print(*ans[:-1], sep='\n')


Measured memory_bytes: 124652
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

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

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

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

  ll n,k;
  std::cin>>n>>k;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  std::vector<P> sum(n+1,{0,0});
  rep(i,1,n+1){
    sum[i].first=(sum[i-1].first+a[i-1]-1)%k;
    sum[i].second=i;
  }

  std::sort(all(sum));

  ll ans=0;

  rep(i,0,n+1){
    ans+=(ll)(std::lower_bound(all(sum),P(sum[i].first,sum[i].second+k))-std::upper_bound(all(sum),sum[i]));
  }

  std::cout<<ans<<"\n";



  return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long int
#define tc int t; cin>>t; while(t--)
#define fora(i,n) for(int i=0;i<n;i++)
#define forb(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}
const int N=10000001;
int arr[N];
int32_t main()
{
    fastio

 	int n;
 	cin>>n;
 	fora(i,n+1)
 	arr[i]=1;
 	for(int i=2;i<=n;i++) {
 		for(int j=i;j<=n;j+=i) {
 			arr[j]++;
 		}
 	}
 	int sum=0;
 	for(int i=1;i<=n;i++) 
 	{
 		sum+=i*(arr[i]);
 	}
 	cout<<sum;
    return 0;


}

Measured memory_bytes: 81752
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

vector<ll> slidemax(const vector<ll> &seq, ll w) {
    vector<ll> ans;
    deque<ll> deq;
    ll l = 0, n = seq.size();
    REP(r, 0, n) {
        while(!deq.empty() && seq[deq.back()] <= seq[r]) {
            deq.pop_back();
        }
        deq.push_back(r);
        if (r >= w) {
            if (deq.front() == l) {
                deq.pop_front();
            }
            l++;
        }
        ans.push_back(seq[deq.front()]);
    }
    return ans;
}

ll dp[301][100010];

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    ll A[N];
    REP(i, 0, N) {
        cin >> A[i];
    }
    REP(i, 0, K + 1) {
        fill(dp[i], dp[i] + N + 1, 0);
    }
    REP(i, 1, K + 1) {
        vector<ll> seq;
        REP(j, 0, N) {
            seq.push_back(dp[i - 1][j]);
        }
        vector<ll> maxseq = slidemax(seq, M);
        // cout << maxseq.size() << " aaa ";
        // REP(j, 0, N) {
        //     cout << maxseq[j] << " ";
        // }
        // cout << endl;
        REP(j, 1, N + 1) {
            if (j >= i) {
                ll num = maxseq[j - 1];
                dp[i][j] = num + i * A[j - 1];
            }
        }
    }
    ll ans = 0;
    REP(i, 0, N + 1) {
        ans = max(ans, dp[K][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 239444
N = gets.chomp.to_i
S = gets.chomp.split('')
while N > 0
  (1..S.size).each do |j|
    if S[j - 1] == 'Z'
      S[j - 1] = 'A'
    else
      S[j - 1].succ!
    end
  end
  N = N - 1
end
puts S.join

Measured memory_bytes: 2812
N = int(input())
W = 'abcdefghij'
ans = set()

for i in range(1,N+1):
  if i == 1:
    ans.add('a')
  else:
    tmp = set()
    for a in ans:
      index = W.index(sorted(list(a))[-1])
      for i in range(index+2):
        tmp.add(a+W[i])
    ans = tmp
    
for a in sorted(ans):
  print(a)

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

const int N = 410;

int n, ma, mb, a[N], b[N], c[N], dp[50][N][N];

int main(){
	scanf("%d%d%d", &n, &ma, &mb);
	for (int i = 1; i <= n; ++ i){
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
	}
	memset(dp, -1, sizeof(dp));
	dp[0][0][0] = 0;
	for (int i = 1; i <= n; ++ i){
		for (int j = 0; j < N; ++ j){
			for (int k = 0; k < N; ++ k){
				dp[i][j][k] = dp[i - 1][j][k];
			}
		}
		for (int j = 0; j < N; ++ j){
			for (int k = 0; k < N; ++ k){
				if (dp[i - 1][j][k] == -1 || j + a[i] >= N || k + b[i] >= N){
					continue;
				}
				int x = dp[i - 1][j][k] + c[i], &u = dp[i][j + a[i]][k + b[i]];
				if (u == -1 || u > x){
					u = x;
				}
			}
		}
	}
	int ans = INT_MAX;
	for (int i = ma, j = mb; i < N && j < N; i += ma, j += mb){
		if (dp[n][i][j] >= 0){
			ans = std::min(ans, dp[n][i][j]);
		}
	}
	if (ans == INT_MAX){
		ans = -1;
	}
	return printf("%d\n", ans), 0;
}

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

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

	int sum = 0;
	for( int i = 0; i < M; i++ ) {
		sum += A[i];
	}
	int ans = N - sum;
	if( ans < 0 ) ans = -1;

	cout << ans << endl;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(void){
	int n,m,i,j,h=0;
	int cnt=0;
	int a[100000],b[100000],flg[100000],bt[100000];
	int max=0;
	scanf("%d",&n);
	scanf("%d",&m);
	while(n!=0 && m!=0){
		cnt=0;
		h=0;
		max=0;
		for(i=1;i<=n;i++){
			flg[i]=0;
		}
		for(i=1;i<=m;i++){
			scanf("%d %d",&a[i],&b[i]);
			if(a[i]==1){
				bt[h]=b[i];
				h++;
				max++;
			}
		}
		for(h=0;h<max;h++){
			flg[bt[h]]=2;
		}
		for(h=0;h<max;h++){
			for(i=1;i<=m;i++){
				if(a[i]==bt[h] && flg[b[i]]!=2){
					flg[b[i]]=1;
				}
				if(b[i]==bt[h] && flg[a[i]]!=2){
					flg[a[i]]=1;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(flg[i]>0){
				//printf("%d=%d\n",i,flg[i]);
				cnt++;
			}
		}
		printf("%d\n",cnt);
		scanf("%d %d",&n,&m);
	}
	return 0;
}

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

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

    if ((b-a)%2 == 0) cout << (b-a)/2 << endl;
    else if ((b-1) <= (n-a)) {
        if (b-a < 3) cout << b-1 << endl;
        else cout << b-1-(b-a-1)/2 << endl;
    }
    else {
        if (b-a < 3) cout << n-a << endl;
        else cout << n-a-(b-a-1)/2 << endl;
    }
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  set<char> s;
  for (int i = 0; i < N; i++) {
    char w;
    cin >> w;
    s.insert(w);
  }
  if (s.size() == 4) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
ID: flashysport101
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

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

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

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define n << "\n"
#define k << " " <<

const int MOD = 1000000007;
const ll INF = 1e18;
const int MAXN = 1e5;
const string name = "paintbarn";

int N, D;
bool square[1000001];
int points[10][10];
bool dist(int i, int j) {
  int sum = 0;
  FOR(l,D) {
    sum += (points[i][l] - points[j][l]) * (points[i][l] - points[j][l]);
  }
  return square[sum];
}
int main() {
  //ifstream cin(name + ".in"); ofstream fout(name + ".out");
  //ifstream cin("a.in");
  cin >> N >> D;
  FOR(i,1001) {
    square[i*i] = true;
  }
  FOR(i,N) FOR(j,D) cin >> points[i][j]; 
  int res = 0;
  FOR(i,N) FOR(j,i) if(dist(i,j)) res++;
  cout << res n;
}





Measured memory_bytes: 1280
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
tmp = 0

for i in range(1, N + 2):
    tmp += abs(A[i] - A[i-1])

for i in range(1, N + 1):
    if (A[i - 1] <= A[i] and A[i] <= A[i + 1]) or (A[i - 1] >= A[i] and A[i] >= A[i + 1]):
        print(tmp)
    else:
        print(tmp - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i+1] - A[i-1]))


Measured memory_bytes: 14172
#include<iostream>
using namespace std;
int main() {
	int N, A;
	int a = 0;
	cin >> N >> A;
	for (int i = 0; i <= A;i++) {
		if (N % 500 - i == 0) {
			cout << "Yes";
			a = 1;
			break;
		}
	}
	if (a==0) {
		cout << "No";

	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int v, e;
pair<int, int> a[200010];
int s[100001];
int g[100001];
int n[100001];
int p[100001];
int l[100001];
int u[100001]={};
int c, t;
int x, y;
int k;
int h[100001]={};

void dfs(int f, int z)
{
	n[f]=t;
	l[f]=t;
	t++;
	u[f]=1;
	for(int i=s[f]; i<=g[f]; i++)
	{
		if(u[a[i].second]==0)
		{
			p[a[i].second]=f;
			dfs(a[i].second, f);
			l[f]=min(l[f], l[a[i].second]);
		}
		else if(a[i].second!=z)
		{
			l[f]=min(l[f], n[a[i].second]);
		}
	}
}

int main()
{
	cin >> v >> e;
	for(int i=0; i<e; i++)
	{
		cin >> x >> y;
		a[2*i]=make_pair(x, y);
		a[2*i+1]=make_pair(y, x);
	}
	sort(a, a+(2*e));
	s[0]=0;
	g[v-1]=2*e-1;
	c=0;
	for(int i=1; i<2*e; i++)
	{
		if(a[i].first>a[i-1].first)
		{
			g[c]=i-1;
			c++;
			s[c]=i;
		}
	}
	t=0;
	dfs(0, -1);
	k=0;
	for(int i=1; i<v; i++)
	{
		if(p[i]==0)
		{
			k++;
		}
		if(n[p[i]]<=l[i])
		{
			h[p[i]]++;
		}
	}
	if(k>1)
	{
		cout << 0 << endl;
	}
	for(int i=1; i<v; i++)
	{
		if(h[i]>0)
		{
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4528
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;
use num_bigint::*;
use num_traits::{Zero, One};

#[fastout()]
fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }
    let m = 1_000_000_007u64.to_biguint().unwrap();

    let mut l = a[0].to_biguint().unwrap();
    for &v in &a {
        l = lcm(l, v.to_biguint().unwrap());
    }

    let mut ans: BigUint = Zero::zero();
    for &v in &a {
        let v = v.to_biguint().unwrap();
        ans += (l.clone() / v) % m.clone();
        ans %= m.clone();
    }
    println!("{}", ans);
}
#[allow(dead_code)]
pub fn gcd(a: BigUint, b: BigUint) -> BigUint {
    if b == Zero::zero() {
        a
    } else {
        gcd(b.clone(), a % b)
    }
}
#[allow(dead_code)]
pub fn lcm(a: BigUint, b: BigUint) -> BigUint {
    a.clone() / gcd(a, b.clone()) * b
}

Measured memory_bytes: 3200
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int A[3],tmp,cou=0;
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  switch(A[0]%2 + A[1]%2 + A[2]%2){
  case 0:
    break;
  case 1:
    REP(i,3){
      if(A[i]%2 == 0)
        A[i]++;
    }
    cou++;
    break;
  case 2:
    REP(i,3){
      if(A[i]%2 == 1)
        A[i]++;
    }
    cou++;
    break;
  case 3:
    break;
  }

  cout << ((A[2]-A[0])/2 + (A[2]-A[1])/2 + cou) << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

        String str = br.readLine();
        int num = Integer.parseInt(br.readLine());

        for(int i = 0; i < num; i++){
            String[] s = br.readLine().split(" ");
            int a = Integer.parseInt(s[1]);
            int b = Integer.parseInt(s[2]);

            switch(s[0]){
                case "print":
                    System.out.println(str.substring(a , b+1));
                    break;
                case "reverse":
                    int box = (b-a)/2;
                    char[] c = str.toCharArray();
                    for(int j = 0; j <= box; j++){
                        char tmp = str.charAt(a+j);
                        c[a+j] = c[b-j];
                        c[b-j] = tmp;
                    }
                    str = String.valueOf(c);
                    break;
                case "replace":
                    StringBuilder sb = new StringBuilder(str);
                    sb.replace(a , b+1 , s[3]);
                    str = sb.toString();
                    break;
            }
        }
    }
}


Measured memory_bytes: 24532
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

//const long long MOD = 998244353;
//const long long MOD = 1000000007;

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

    ll ans=0, b=0;
    for(ll i=0; i<N; ++i){
        if(S[i]=='B'){
            ++b;
        }else{
            ans+=b;
        }
    }
    std::cout << ans;
    return 0;
}


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

int main(){
    //入力
    string A,B;
    cin >> A;
    cin >> B;

    //処理
    if(A.size()>B.size()){
        cout << "GREATER" << endl;
    }else if(A.size()<B.size()){
        cout << "LESS" << endl;
    }else{
        for(int i=0;i<A.size();i++){
            if(A.at(i)>B.at(i)){
                cout << "GREATER" << endl;
                break;
            }else if(A.at(i)<B.at(i)){
                cout << "LESS" << endl;
                break;
            }
            if(i==A.size()-1){
                cout << "EQUAL" << endl;
            }
        }
    }    
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int ans = 0;
    for(int i=0;i<4;i++){
      if(S.charAt(i)=='+'){
        ans++;
      }
      else if(S.charAt(i)=='-'){
        ans--;
      }
    }
    System.out.println(ans);
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  int want = 1;
  int cnt = 0;
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    if(a.at(i) == want){
      want++;
      cnt++;
    }
  }
  int ans = -1;
  if(cnt > 0){
    ans = N - cnt;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 1024