akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
using namespace std;


/*
const int MAX=1000;
vector<vector<int> > memo(MAX,vector<int>(MAX));
vector<vector<int> > done(MAX,vector<int>(MAX));
int dfs(vector<vector<int> > vi,int i,int j,int sum);
int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int m,n;
	while(cin>>m>>n&&m!=0&&n!=0){
		vector<vector<int> > ice(m,vector<int>(n));
		int ans=0;
		/*
		for(int i=0; i<MAX; ++i){
			for(int j=0; j<MAX; ++j){
				memo[i][j]=0;
				done[i][j]=0;
			}
		}
		*/
/*
		for(int i=0; i<n; ++i){
			for(int j=0; j<m; ++j){
				cin >> ice[j][i];
			}
		}
		for(int i=0; i<n; ++i){
			for(int j=0; j<m; ++j){
				if(ice[j][i]==1) {
					ans=max(ans,dfs(ice,j,i,0));
					/*for(int k=0; k<n; ++k){
						for(int l=0; l<m; ++l){
							memo[j][i]=0;
							done[j][i]=0;
						}
					}*/
/*
				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

int dfs(vector<vector<int> > vi,int i,int j,int sum){
	vector<int> f(4);
	//if(done[i][j]==1) return memo[i][j];

	if(i+1>=vi.size()) {
		f[0]=1;
	}else if(vi[i+1][j]==0) {
		f[0]=1;
	}

	if(j+1>=vi[i].size()){
		f[1]=1;
	} else if(vi[i][j+1]==0){
		f[1]=1;
	}

	if(i-1<0){
		f[2]=1;
	}else if(vi[i-1][j]==0){
		f[2]=1;
	}

	if(j-1<0){
		f[3]=1;
	} else if(vi[i][j-1]==0){
		f[3]=1;
	}

	if(f[0]==1&&f[1]==1&&f[2]==1&&f[3]==1) return sum;

	int res=0;
	//done[i][j]=1;
	if(i+1<vi.size()){
		if(vi[i+1][j]==1){
			res=max(res,dfs(vi,i+1,j,sum+1));
		}
	}
	if(j+1<vi[i].size()) {
		if(vi[i][j+1]==1){
			res=max(res,dfs(vi,i,j+1,sum+1));
		}
	}
	if(i-1>=0){
		if(vi[i-1][j]==1){
			res=max(res,dfs(vi,i-1,j,sum+1));
		}
	}
	if(j-1>=0) {
		if(vi[i][j-1]==1){
			res=max(res,dfs(vi,i,j-1,sum+1));
		}
	}
	//done[i][j]=0;
	return res;
}
*/

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

void dfs(vector<string>& vss,int x,int y){
	vss[x][y]='0';
	for(int i=0; i<4; ++i){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(0<=nx&&nx<12&&0<=ny&&ny<12&&vss[nx][ny]=='1'){
			dfs(vss,nx,ny);
		}
	}
}

int main(){
	vector<string> land(12);
	int n=0;
	while(cin >> land[0]){
		int cnt=0;
	for(int i=1; i<12; ++i){
		cin >> land[i];
	}
	for(int i=0; i<12; ++i){
		for(int j=0; j<12; ++j){
			if(land[i][j]=='1'){
				++cnt;
				dfs(land,i,j);
			}
		}
	}
	cout << cnt << "\n";
	}
	return 0;
}

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

int main() {
  int N;
  scanf("%d", &N);
  list<int> l;
  for (int i = 0; i < N; i++) {
    char com[20];
    scanf("%s", &com);
    if (com[0] == 'i') {
      int key;
      scanf("%d", &key);
      l.push_front(key);
    } else if (com[0] == 'd') {
      if (com[6] == 'F') {
        l.pop_front();
      } else if (com[6] == 'L') {
        l.pop_back();
      } else {
        int key;
        scanf("%d", &key);
        for(auto iter = l.begin(); iter != l.end(); iter++) {
          if (*iter == key) {
            l.erase(iter);
            break;
          }
        }
      }
    }
  }
  int i = 0;
  for (auto iter = l.begin(); iter != l.end(); iter++) {
    if (i++) printf(" ");
    printf("%d", *iter);
  }
  printf("\n");
};



Measured memory_bytes: 34412
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;cin>>n;
  V<ll> d(n+2,-inf);
  V<ll> a(3*n);
  for(int i=0;i<3*n;i++){
      cin>>a[i];
  }
  priority_queue<ll,V<ll>,greater<ll>> pq;
  ll sum=0;
 for(int i=0;i<2*n;i++){
      if(pq.size()<n){
          pq.emplace(a[i]);
          sum+=a[i];
      }
      else{
          if(pq.top()<a[i]){
              sum-=pq.top();
              pq.pop();
              sum+=a[i];
              pq.emplace(a[i]);
          }
      }
     if(pq.size()>=n)d[i-n+1]=sum;
  }
  priority_queue<ll> p;
  sum=0;
  ll ans=-inf;
   for(int i=3*n-1;i>=n;i--){
      if(p.size()<n){
          p.emplace(a[i]);
          sum+=a[i];
      }
      else{
          if(p.top()>a[i]){
              sum-=p.top();
              p.pop();
              sum+=a[i];
              p.emplace(a[i]);
          }
      }
    if(p.size()>=n)chmax(ans,d[i-n]-sum);
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 8668
#include <iostream>

using namespace std;

int main(){
    int S;
    int h,m,s;
    
    cin >> S;
    h = S / (60 * 60);
    m = (S / 60) % 60;
    s = S % 60;
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


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

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;
const  double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
/*ios_base::sync_with_stdio(false);cin.tie(0);*/

/*
vi vec;

ll count(ll in, ll n )
{


    vector<ll> table(n) ;

    table[0]=abs((vec[1]-vec[0]));

    ll cur =0,cc=0;
    for (ll i = 1; i < n-1 ; i++)
    {


            cur =abs((vec[i+1]-vec[i-1]));
            cc=abs((vec[i]-vec[i-1]));
            int ctr=(cc>cur) ? 2 : 1 ;
            table[i]=(cc>cur) ? cur : cc ;
            //table[i]+=table[i-ctr];
    }

    for (ll i = 0; i < n ; i++)
    {

            cout<<table[i]<<" ";


    }
/*
    if(i == n){
        return mn;
    }

    return count(i,n,mn);

    return 0;
 }


int main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);
    ll n;
    cin >>n;
    vec.resize(n);

    for (int i = 0; i <n ; ++i) {
        cin>>vec[i];
    }
    ll sum =0;
    for (int j = 0; j <n ; ++j) {
        sum+=vec[j];
    }


    cout << count(1,n);
    return 0;
}
*/


int dp[MX];

int main (){
    ll n;
    cin >> n;
    vi vec(n);
    for(auto &el :vec)cin>>el;
    for (int i = 0; i <n ; ++i) {
        dp[i]=INF;
    }
    dp[0]=0;
    for (int i = 0; i <n ; ++i) {
        dp[i+1]=min(dp[i+1] , dp[i]+abs((vec[i]-vec[i+1])));
        dp[i+2]=min(dp[i+2] , dp[i]+abs((vec[i]-vec[i+2])));
    }
    
    cout <<dp[n-1];
    //cout<<vec;
    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

const int MAX = 1e5;

ll num[MAX + 1];

int main() {
    ll n, k;
    cin >> n >> k;
    for (int i = 0, a, b; i < n; i++) {
        cin >> a >> b;
        num[a] += b;
    }
    ll sum = 0;
    for (int i = 1; i <= MAX; i++) {
        sum += num[i];
        if (k <= sum) {
            cout << i << endl;
            break;
        }
    }
}

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

using namespace std;

#define MAX 10000
#define INFTY (1 << 29)

class DisjointSet {
    public:
    vector<int> rank, p;
    
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }
    
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }
    
    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }
    
    void link(int x, int y) {
        if ( rank[x] > rank[y] ) {
            p[y] = x;
        } else {
            p[x] = y;
            if ( rank[x] == rank[y] ) {
                rank[y]++;
            }
        }
    }
    
    int findSet(int x) {
        if ( x != p[x] ) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

class Edge {
    public:
    int source, target, cost;
    Edge(int source = 0, int target = 0, int cost = 0):
    source(source), target(target), cost(cost) {}
    bool operator < ( const Edge &e ) const {
        return cost < e.cost;
    }
};

int kruskal(int N, vector<Edge> edges) {
    int totalCost = 0;
    sort(edges.begin(), edges.end());
    
    DisjointSet dset = DisjointSet(N + 1);
    
    for ( int i = 0; i < N; i++ ) dset.makeSet(i);
    
    int source, target;
    for ( int i = 0; i < edges.size(); i++ ) {
        Edge e = edges[i];
        if ( !dset.same( e.source, e.target ) ) {
            totalCost += e.cost;
            dset.unite( e.source, e.target );
        }
    }
    return totalCost;
}

int main() {
    int N, M, cost;
    int source, target;
    
    cin >> N >> M;
    
    vector<Edge> edges;
    for ( int i = 0; i < M; i++ ) {
        cin >> source >> target >> cost;
        edges.push_back(Edge(source, target, cost));
    }
    
    cout << kruskal(N, edges) << endl;
    
    return 0;
}


Measured memory_bytes: 5444
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

  int d[n + 1];
  d[0] = 1;
  d[1] = 1;
  for (int i = 2; i < n + 1; ++i) {
    d[i] = d[i - 1] + d[i - 2];
  }

  cout << d[n] << endl;

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int l,r;
int dp[65][2][2][2];
int solve(int rem,bool MSB,bool sr,bool gl){
	if(rem<0){
		if(!MSB)return 0;
		else return 1;
	}
	if(dp[rem][MSB][sr][gl]!=-1)
		return dp[rem][MSB][sr][gl];
	int ans=0;
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < 2; ++j)
		{
			if(j>i)continue;
			if(!MSB&&(i!=j))continue;
			int I=!!(l&(1LL<<rem)),J=!!(r&(1LL<<rem));
			if(gl&&j<I)continue;
			if(sr&&i>J)continue;
			ans=((ans%MOD)+(solve(rem-1,MSB||i,sr&&(i==J),gl&&(j==I))%MOD))%MOD;
		}
	return dp[rem][MSB][sr][gl]=ans%MOD;
}
int32_t main(){
	boost;
	memset(dp,-1,sizeof dp);
	cin>>l>>r;
	cout<<solve(60,0,1,1)%MOD;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var l = S.Length;
            var a = new string[l + 1];
            var ans = string.Join("x", a);
            Write(ans);
            Read();
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}

public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}



Measured memory_bytes: 13140
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=998244353;
const ll MAXN=1e4+5;
const ll inf=1e17;

int main()
{
    fastio;
    ll n;
    cin >> n;
    vector<ll > x(n);
    for(int i = 0; i< n; i++) cin >> x[i];
    ll ans = inf;
    for(int j = 1; j<= 100; j++){
        ll b = 0;
        for(int i = 0 ; i < n; i++){
            b += (x[i] - j)*(x[i] - j);
        }
        ans = min (ans, b);
    }
    cout << ans << endl;
}


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

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

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

    long long S;
    if (N % 2 == 0){
        int c = N / 2;
        S = -2 * accumulate(A.begin(), A.begin() + c, 0LL) + 2 * accumulate(A.begin() + c, A.end(), 0LL) + A[c-1] - A[c];
    }
    else{
        int c = (N - 1) / 2;
        long long tmp1 = -2 * accumulate(A.begin(), A.begin() + c, 0LL) + 2 * accumulate(A.begin() + c + 2, A.end(), 0LL) + A[c] + A[c+1];
        long long tmp2 = -2 * accumulate(A.begin(), A.begin() + c-1, 0LL) + 2 * accumulate(A.begin() + c + 1, A.end(), 0LL) - A[c-1] - A[c];
        S = max(tmp1, tmp2);
    }

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 1152
n, x = map(int, input().split())
a = input().split()
result = 0
for i in range(n):
    a[i] = int(a[i])

for i in range(1, n):
    total = a[i-1] + a[i]
    sa = total - x
    if sa > 0:
        result += sa
        a[i-1] = 0
        a[i] -= sa - a[i-1]
        if a[i] < 0:
            a[i] = 0

    else:
        a[i-1] = 0
print(result)


Measured memory_bytes: 11176
N = int(input())

ans = 'Yes'
nt = 0; nx = 0; ny = 0

for i in range(N):
    t, x, y = map(int, input().split())
    dt = t - nt; dx = abs(x - nx); dy = abs(y - ny)
    if dx + dy > dt or (dx + dy - dt)%2 == 1:
        ans = 'No'
        break
    nt = t; nx = x; ny = y

print(ans)

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

using namespace std;

typedef long long lli;

const lli MAX_V = 1000;
const lli M = 1000000007;

lli V, E;
vector<lli> G[MAX_V];
vector<lli> rG[MAX_V];
vector<lli> vs;
bool used[MAX_V];
lli cmp[MAX_V];

void add_edge(lli from, lli to){
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(lli v){
  used[v] = true;
  for(lli i=0;i<G[v].size();i++){
    if(!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}

void rdfs(lli v, lli k){
  used[v] = true;
  cmp[v] = k;
  for(lli i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
}

lli scc(){
  fill(used, used+V, false);
  vs.clear();
  for(lli v = 0;v<V;v++){
    if(!used[v]) dfs(v);
  }
  fill(used, used+V, false);
  lli k = 0;
  for(lli i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}

lli V2;
vector<lli> G2[MAX_V];
lli dp[MAX_V];

void make_graph(lli v){
  used[v] = true;
  for(lli i=0;i<G[v].size();i++){
    lli to = G[v][i];
    if(cmp[v] != cmp[to]) G2[cmp[v]].push_back(cmp[to]);
    if(!used[to]) make_graph(to);
  }
}

lli rec(lli v){
  used[v] = true;
  lli res = 1;
  for(lli i=0;i<G2[v].size();i++){
    lli to = G2[v][i];
    if(!used[to]){
      if(dp[to] != -1) res = (res * dp[to]) % M;
      else res = (res * rec(to)) % M;
    }
  }
  res = (res + 1) % M;
  dp[v] = res;
  return res;
}

main(){
  cin >> V >> E;
  for(lli i=0;i<E;i++){
    lli a, b;
    cin >> a >> b;
    add_edge(b-1, a-1);
  }
  V2 = scc();
  for(lli i=0;i<V;i++) rG[i].clear();
  fill(used, used+V, false);
  for(lli i=0;i<V;i++) make_graph(i);
  fill(used, used+V, false);
  fill(dp, dp+V2, -1);
  lli ans = 1;
  for(lli i=0;i<V2;i++){
    if(!used[i]) ans = (ans * rec(i)) % M;
  }
  cout << ans << endl;
}

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

int main(){
 int M,N;
 cin >> N >> M;
 vector<vector<int>> job(M);
 for(int i=0;i<N;i++){
   int A,B;
   cin >> A >> B;
   if(A > M) continue;
   job.at(M-A).push_back(B);
 }
 priority_queue<int> pq;
 int ans = 0;
 for(int i=M-1;i>=0;i--){
   for(int j:job.at(i)){
     pq.push(j);
   }
   if(!pq.empty()){
     ans += pq.top();
     pq.pop();
   }
 }
 cout << ans;
 system("pause");
 return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
	ll argH, argW;
	cin >> argH >> argW;
	vector<string> argS(argH);
	for (ll i = 0; i < argH; ++i) {
		cin >> argS.at(i);
	}

	vector<vector<char>> matS(argH, vector<char>(argW));
	for (ll i = 0; i < argH; ++i) {
		for (ll j = 0; j < argW; ++j) {
			ll counter = 0;
			
			if (argS.at(i).at(j) == '#') {
				continue;
			}

			if (i - 1 >= 0) {
				counter = argS.at(i-1).at(j) == '#' ? counter + 1 : counter;
			}
			if (i + 1 < argH) {
				counter = argS.at(i+1).at(j) == '#' ? counter + 1 : counter;
			}
			if (j - 1 >= 0) {
				counter = argS.at(i).at(j-1) == '#' ? counter + 1 : counter;
			}
			if (j + 1 < argW) {
				counter = argS.at(i).at(j+1) == '#' ? counter + 1 : counter;
			}
			if (i - 1 >= 0 && j - 1 >= 0) {
				counter = argS.at(i-1).at(j-1) == '#' ? counter + 1 : counter;
			}
			if (i - 1 >= 0 && j + 1 < argW) {
				counter = argS.at(i-1).at(j+1) == '#' ? counter + 1 : counter;
			}
			if (i + 1 < argH && j - 1 >= 0) {
				counter = argS.at(i+1).at(j-1) == '#' ? counter + 1 : counter;
			}
			if (i + 1 < argH && j + 1 < argW) {
				counter = argS.at(i+1).at(j+1) == '#' ? counter + 1 : counter;
			}

			argS.at(i).at(j) = '0' + counter;
		}
	}

	for (ll i = 0; i < argH; ++i) {
		cout << argS.at(i) << endl;
	}
}

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

int main() {
int A; int B; int C; int K;
  cin>>A>>B>>C>>K;
  int D=0; int X=0;
  while(D<K){
  if(D<A){
    X++;
  }
    else if(D<A+B){
      X+=0;
    }
    else X--;
    D++;
  }
 cout<<X<<endl;
}
  

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum = 0;
    for(int i = 0; i < 10; i++)
    {
        int x; cin >> x;
        sum += x;
    }
    cout << sum << endl;
    return 0;
}




Measured memory_bytes: 3200
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int[] num = new int[101];
		TreeMap<Integer, Integer> sr = new TreeMap<Integer, Integer>();
		TreeSet<Integer> set = new TreeSet<Integer>();
		for (int i = 0; i < 100 ; i++) {
			String[] input = scan.next().split(",");
			if(input[0].equals("0")) break;
			num[Integer.parseInt(input[0])]=Integer.parseInt(input[1]);
			set.add(Integer.parseInt(input[1]));
		}
		for (int i = 0,j = set.size(); i < j; i++) {
			sr.put(set.pollLast(),i+1);
		}
		while(scan.hasNext()){
			out.println(sr.get(num[si()]));
		}
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

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

int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    int ans=a>b?a-b-1:b-a-1;
    if(ans%2==1)
    cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;
}



Measured memory_bytes: 256
n, m, l = map(int, input().split())
matrix1 = [list(map(int, input().split())) for _ in range(n)]
matrix2 = [list(map(int, input().split())) for _ in range(m)]
table = [[0]*l for _ in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            table[i][j] += matrix1[i][k] * matrix2[k][j]
for row in table:
    print(' '.join(map(str, row)))


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

#define endl '\n'

map <int, int> A;
int n;

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

    cin >> n;
    for(int i = 0; i < n; i++) {
        int v;
        cin >> v;
        A[v]++;
    }
    int res = 0;
    vector < pair <int, int> > B;
    for(auto v : A) {
        B.push_back(make_pair(v.first, v.second));
    }
    if(B.size() == 1) {
        res = B[0].second;
    }
    else if(B.size() == 2) {
        if(B[1].first - B[0].first == 1) {
            res = B[0].second + B[1].second;
        }
        else {
            res = max(B[0].second, B[1].second);
        }
    }
    else {
        for(int i = 2; i < B.size(); i++) {
            int carry = max(B[i].second, max(B[i - 2].second, B[i - 1].second));
            if(B[i].first - B[i - 1].first == 1 && B[i - 1].first - B[i - 2].first == 1) {
                carry = max(carry, B[i].second + B[i - 1].second + B[i - 2].second);
            }
            else if(B[i].first - B[i - 1].first == 1 && B[i - 1].first - B[i - 2].first != 1){
                carry = max(carry, B[i].second + B[i - 1].second);
            }
            else if(B[i].first - B[i - 1].first != 1 && B[i - 1].first - B[i - 2].first == 1){
                carry = max(carry, B[i - 1].second + B[i - 2].second);
            }
            res = max(res, carry);
        } 
    }
    

    cout << res;
    
    return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>
int main()
{
	int a,b,c,d,h,q,k,p,hiro,ken;
	scanf("%d %d",&h,&q);
	scanf("%d %d",&k,&p);
	scanf("%d %d %d %d",&a,&b,&c,&d);
	hiro=(h*a)+(q*b)+(h/10*c)+(q/20*d);
	ken=(k*a)+(p*b)+(k/10*c)+(p/20*d);
	if(hiro>ken){
		printf("hiroshi\n");
	}
	else if
		(hiro<ken){
			printf("kenjiro\n");
		}
		else if(hiro==ken){
			printf("even\n");
		}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s,t; cin>>s>>t;
	t=t.substr(0,t.length()-1);
	if(s==t)	
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>

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

  std::string S;
  std::cin >> S;
  int n = S.size();
  std::string ans = "yes";
  for(int i=0; i<n; i++)
    for(int j=i+1; j<n; j++)
      if(S[i] == S[j]) ans = "no";

  std::cout << ans <<'\n';
}


Measured memory_bytes: 256
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


void print_vec(vll a)
{
	cout << "start printing the vector\n";
	for (ll i = 0; i < a.size(); i++)
		cout << a[i] << " ";
	cout << "\n";
}
void print_mat(vector<vll> a)
{
	cout << "start printing the matrix\n";
	for (ll i = 0; i < a.size(); i++)
	{
		for (ll j = 0; j < a[i].size(); j++)
		{
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}



void solve()
{
	ll n;
	cin >> n ;
	string s, t;
	cin >> s;
	cin >> t;
	for (ll i = 0; i < n; i++)
	{
		cout << s[i] << t[i];
	}
	cout << "\n";

}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 3628
use std::cmp::max;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: i32 = read();

    let mut ans = 0;
    for i in 1..1000i32 {
        for j in 2..1000u32 {
            if i.pow(j) > x {
                break;
            } else {
                ans = max(ans, i.pow(j));
            }
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
#define MAX 100000
using namespace std;
int main(){
	long long int data[MAX];
	for(int i=0;i<MAX;i++){
		data[i]=0;
	}
	long long int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		long long int a,b;
		cin>>a>>b;
		data[a-1]+=b;
	}
	long long int count=0;
	for(int i=0;;i++){
		count+=data[i];
		if(count>=m){
			cout<<i+1<<endl;
			break;
		}
	}
	return 0;
}

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

int main(){
	string S;
	int ans = 0, ans_max = 0;
	cin >> S;

	for(int i = 0; i < S.length(); i++){
		switch(S[i]){
			case 'A': case 'C': case 'T': case 'G':
				ans++;
				if(ans > ans_max) ans_max = ans;
				break;
			default:
				ans = 0;
				break;
		}
	}

	cout << ans_max << endl;

	return 0;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll tree[100001],n,m,a[100001],b[100001],t1,t2,d[100001];
pair<ll,ll>c[100001];
ll quyu(ll aa,ll bb)
{
	return (aa+bb)%mod;
}
void add(ll under,ll v)
{
	for(;under<=n;under+=under&-under)tree[under]=quyu(tree[under],v);
}
ll sum(ll x)
{
	ll ans=0;
	for(;x;x-=x&-x)ans=quyu(ans,tree[x]);
	return ans;
}
bool cmp(pair<ll,ll>one,pair<ll,ll>two)
{
	if(one.first!=two.first)return one.first<two.first; 
	return one.second>two.second;
}
int main()
{
	scanf("%lld %lld",&n,&m);
	for(ll u=1;u<=n;u++)
		scanf("%lld",&a[u]);
	for(ll u=1;u<=m;u++)
		scanf("%lld",&b[u]);
	for(ll u=1;u<=n;u++)
		if(a[u]<b[m]&&a[u]>b[1])
		{
			int xia=lower_bound(b+1,b+m+1,a[u])-b;
			if(a[u]==b[xia])continue; 
			c[++t1]=make_pair(a[u]-b[xia-1],b[xia]-a[u]);
			d[++t2]=b[xia]-a[u];
		}
	sort(d+1,d+t2+1);
	t2=unique(d+1,d+t2+1)-d-1;
	for(ll u=1;u<=t1;u++)
		c[u].second=lower_bound(d+1,d+t2+1,c[u].second)-d;
	sort(c+1,c+t1+1,cmp);
	t1=unique(c+1,c+t1+1)-c-1;
	ll ans=1;
	for(ll u=1;u<=t1;u++) 
	{
		ll s=sum(c[u].second-1)+1; 
		ans+=s;
		add(c[u].second,s);
	}
	ans%=mod;
	printf("%lld",ans);
	return 0;
}

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

#define ll long long int
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;


int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n;
    cin>>n;

    for(int i=1; i<=sqrt(n); i++){
        if(n%i == 0){
            int a = n/i, b = i;
            if(a>=1 && a<=9 && b>=1 && b<=9){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    vi s(n+1);
    rep(i,n)s[i+1]=(s[i]+a[i]-1)%k;
    map<int,int> mp;
    int ans=0;
    rep(i,n+1){
        if(i>=k)mp[s[i-k]]--;
        ans+=mp[s[i]]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
deque<char>s;
char c;
int main()
{
	while(scanf("%c",&c)&&c!='\n')
	{
		if(c=='B')
		{
			if(!s.empty()) s.pop_back();
		}
		else s.push_back(c);
	}
	while(!s.empty())
	{
		cout<<s.front();
		s.pop_front();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int eratosthenes(int n, vector<bool>& prime) {
    int ret = 0; prime.assign(n + 1, false);
    vector<bool> chk(n + 1, false);
    for (auto i = 2; i <= n; i++) {
        if(chk[i]) continue;
        ret++; prime[i] = true;
        chk[i] = true;
        for (auto j = 2 * i; j <= n; j += i) chk[j] = true;
    }
    return ret;
}

int main(){
    int q; cin >> q;
    vector<bool> prime; eratosthenes(100000, prime);
    vector<int> c(100000 + 1, 0);
    for (auto i = 1; i <= 100000; i += 2) if(prime[i] and prime[(i + 1) / 2]) c[i]++;
    for (auto i = 1; i <= 100000; i++) c[i] += c[i - 1];
    for (auto i = 0; i < q; i++) {
        int l, r; cin >> l >> r; cout << c[r] - c[--l] << endl;
    }

    return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,m;
LL sum,ans;
map<LL,LL>mp;
int main()
{
	cin>>n>>m;
	int t;
	rep(i,1,n)
	{
		cin>>t;
		sum+=t;
		sum%=m;
		mp[sum]++;
	}
	for(auto i:mp)
	{
		LL f=i.first;
		LL s=i.second;
	    if(f==0)ans+=s*(s+1)/2;
	    else ans+=s*(s-1)/2;
	}
	cout<<ans;

}


Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);
		if(a+b==c || a+c==b || b+c==a){
			sb.append("Yes");
		}else{
			sb.append("No");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 8148
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))
char ar[100][100];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, m, k;
		cin >> n >> m >> k;
		ll i, j;
		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++)
				cin >> ar[i][j];

		ll a = 1 << n;
		ll b = 1 << m;
		ll x, y, ans = 0;
		for (i = 0; i < a; i++)
		{
			for (j = 0; j < b; j++)
			{
				ll c = 0;
				for (x = 0; x < n; x++)
				{
					for (y = 0; y < m; y++)
					{
						if ((i & (1 << x)) || (j & (1 << y)))
							continue;
						if (ar[x][y] == '#')
							c++;
					}
				}
				if (c == k)
					ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3500
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    eqs = [S[0]]
    for i in range(1, len(S)):
        c = S[i]
        nex = []
        for eq in eqs:
            nex.append(eq + '+' + c)
            nex.append(eq + c)
        eqs = nex
    #print(eqs)
    ret = 0
    for eq in eqs:
        nums = eq.split('+')
        for n in nums:
            ret += int(n)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};



int main() {
	int n;
	for(;;){
		cin>>n;
		if(n==0)break;
		int res=0;
		rep(i,1000){
			if(i*i*i>n)break;
			rep(j,1000){
				if(i*i*i+j*(j+1)*(j+2)/6>n)break;
				chmax(res,i*i*i+j*(j+1)*(j+2)/6);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

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

int main()
{   char s[1000];
    int a=0,i;
    gets(s);
    for(i=0;i<4;i++)
        {if(s[i]=='+')
        a++;
        if(s[i]=='-')
            a--;}
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c;
    char d,e;
  	string s;
  	cin>>a;
  b= a/2;
  c= (a+1)/2;
    cout<<b*c<<endl;
 
 
 /* else if(a==23)
    cout<<"Christmas Eve Eve"<<endl;
  else
    cout<<"Christmas Eve Eve Eve"<<endl;
  */

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, a[114514], b[114514];
signed main() {
	cin >> n;
	rep(i, n + 1)cin >> a[i];
	rep(i, n)cin >> b[i];
	int ans = 0;
	rep(i, n) {
		if (a[i] <= b[i]) {
			ans += a[i]; b[i] -= a[i];
		}
		else {
			ans += b[i]; b[i] = 0;
		}
		if (a[i + 1] <= b[i]) {
			ans += a[i + 1]; a[i + 1] = 0;
		}
		else {
			ans += b[i]; a[i + 1] -= b[i];
		}
	}
	cout << ans << endl;
}

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

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

	cin >> a >> b >> c;

	if(a==b and a==5) {
		if(c==7)
			cout << "YES" << endl;
	}
	else if(b==c and b==5) {
		if(a==7)
			cout << "YES" << endl;
	}
	else if(c==a and c==5) {
		if(b==7)
			cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
int K;
int a[25][25];
ll dp[(1<<21)+ 1][25]={0};
int temochi;
vi masks[25];
int main(){
	cin>>N;
	rep(i,N){
		rep(j,N){
			cin>>a[i][j];
		}
	}
	temochi = (1<<N)-1;
	dp[temochi][0]=1;
	for(int i=0;i<(1<<N);i++){
		int bitcnt=0;
		int temp=i;
		while(temp){
			bitcnt+=temp%2;
			temp/=2;
		}
		//cout<<bitcnt<<" "<<i<<endl;
		masks[bitcnt].pb(i);
	}
	for(int dan=0;dan<N;dan++){
		for(int k=0;k<masks[N-dan-1].size();k++){
			int mask=masks[N-dan-1][k];
			for(int j=0;j<N;j++){
				if((a[dan][j] ==1) && ((mask>>j)%2==0)){
					dp[mask][dan+1]=(dp[mask][dan+1]+dp[mask+(1<<j)][dan])%MOD;
				}
			}
			//cout<<dp[mask][dan+1]<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[0][N]<<endl;
}

Measured memory_bytes: 419260
/*
   Aizu Vol-1 0122: Summer of Pyonkichi
   2017.8.15 bal4u@uu
   ??±???????????¢?´¢
*/

#include <stdio.h>
#include <string.h>

#define MAX 1000
typedef struct { char x, y, k; } QUE; QUE Q[MAX + 10]; int top;
int n;
char map[10][10][10];

int move[12][2] = {
	{ -1, -2 }, {  0, -2 }, {  1, -2 },
	{  2, -1 }, {  2,  0 }, {  2,  1 },
	{  1,  2 }, {  0,  2 }, { -1,  2 },
	{ -2,  1 }, { -2,  0 }, { -2, -1 } };

int main()
{
	int px, py, x, y;
	int i, k, xx, yy;

	while (1) {
		scanf("%d%d", &px, &py); if (!px && !py) break;
		scanf("%d", &n);
		memset(map, 0, sizeof(map));
		for (i = 0; i < n; i++) {
			scanf("%d%d", &x, &y);
			for (xx = x - 1; xx <= x + 1; xx++) for (yy = y - 1; yy <= y + 1; yy++) {
				if (xx >= 0 && yy >= 0 && xx <= 9 && yy <= 9) map[i][xx][yy] = 1;
			}
		}
		Q[0].x = px, Q[0].y = py, Q[0].k = 0, top = 1;
		while (top) {
			x = Q[--top].x, y = Q[top].y, k = Q[top].k;
			for (i = 0; i < 12; i++) {
				xx = x + move[i][0], yy = y + move[i][1];
				if (xx >= 0 && yy >= 0 && xx <= 9 && yy <= 9 && map[k][xx][yy]) {
					if (k + 1 < n) Q[top].x = xx, Q[top].y = yy, Q[top].k = k + 1, top++;
					else { puts("OK"); goto NEXT; }
				}
			}
		}
		puts("NA");
NEXT:;
	}
	return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <vector>
#include <utility>
#include <climits>

#define REP(i,n) for(int i=0; i<n; ++i)
#define INF LONG_MAX

using namespace std;

long V, E, r;
vector< vector< pair<long,long> > > to;
vector<long> path;

void bellman_ford(){
    path.resize(V, INF);
    path[r] = 0;

    bool flag = true;
    while(flag){
        flag = false;

        REP(i, V){
            REP(j, to[i].size()){
                long f = i;
                auto t = to[i][j];

                if(path[f] < INF && path[t.first] > path[f] + t.second){
                    path[t.first] = path[f] + t.second;
                    flag = true;
                }
            }
        }
    }
}

int main(void){
    std::cin >> V >> E >> r;

    to.resize(V);

    long s, t, d;
    REP(i,E){
        std::cin >> s >> t >> d;
        to[s].push_back(make_pair(t,d));
    }

    bellman_ford();
    for(auto l : path){
        if(l == INF){
            std::cout << "INF" << std::endl;
        }else{
            std::cout << l << std::endl;
        }
    }
}

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


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

	rep(i,n+1){
	    rep(j,n-i+1){
            if((n-i-j)*10000 + j*5000 + i*1000 == y){
                cout << (n-i-j) << " " << j << " " << i << "\n";
                return 0;
	        }
	    }
	}
	cout << -1 << " " << -1 << " " << -1 << "\n";
}


Measured memory_bytes: 256
/*
  Contest 104
  A - Rated for Me
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

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

    int r = 0;
    std::cin >> r;
    if (r < 1200)
        std::cout << "ABC" << std::endl;
    else if (r < 2800)
        std::cout << "ARC" << std::endl;
    else
        std::cout << "AGC" << std::endl;

    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100000
#define POINT_MAX (NUM_MAX*10)

struct point2d {
    int x;
    int y;
};

int asc(const void *a1, const void *a2) {
    struct point2d *p1 = (struct point2d*)a1;
    struct point2d *p2 = (struct point2d*)a2;
    if(p1->x == p2->x) {
        return p1->y - p2->y;
    }
    return p1->x - p2->x;
}

int check(struct point2d p, int row, int col) {
    if(p.x < 0 || p.y < 0) return 0;
    if(p.x >= row-2 || p.y >= col-2) return 0;
    return 1;
}

#define HASH_SIZE 65536

struct list {
    struct point2d p;
    int idx;
    struct list *next;
};

struct list *create_htable(void) {
    static struct list htable[HASH_SIZE];
    int i;
    for(i = 0; i < HASH_SIZE; i++) {
        htable[i].next = &htable[i];
    }
    return htable;
}

int is_equal(struct point2d p1, struct point2d p2) {
    return p1.x == p2.x && p1.y == p2.y;
}

int get_key(struct point2d p) {
    return (p.x*p.y+p.x+p.y) & (HASH_SIZE-1);
}

struct list* find(struct list *htable, struct point2d p) {
    struct list *head = &htable[get_key(p)];
    struct list *elem;
    for(elem = head->next; elem != head; elem = elem->next) {
        if(is_equal(elem->p, p)) {
            return elem;
        }
    }
    return NULL;
}

void add_elem(struct list *htable, struct point2d p) {
    struct list *elem = malloc(sizeof(struct list));
    struct list *head = &htable[get_key(p)];
    elem->next = head->next;
    elem->p = p;
    head->next = elem;
}

int main(void) {
    int row, col, num;
    get_int2(&row, &col);
    num = get_int();
    int i, j, k;
    struct list* htable = create_htable();
    static struct point2d cands[POINT_MAX];
    int cidx = 0;
    for(k = 0; k < num; k++) {
        int x, y;
        get_int2(&x, &y);
        // 1-indexed -> 0-indexed
        x--; y--;
        add_elem(htable, (struct point2d){x, y});
        // put into stack
        for(i = 0; i <= 2; i++) {
            for(j = 0; j <= 2; j++) {
                struct point2d np = (struct point2d){x-i, y-j};
                if(check(np, row, col)) cands[cidx++] = np;
            }
        }
    }
    qsort(cands, cidx, sizeof(struct point2d), asc);

    static int64_t map[10];
    int64_t total = 0;
    struct point2d prev = {-1, -1};
    for(k = 0; k < cidx; k++) {
        struct point2d cur = cands[k];
        if(is_equal(cur, prev)) continue;
        total++;
        int cnt = 0;
        for(i = 0; i < 3; i++) {
            for(j = 0; j < 3; j++) {
                struct point2d np = {cur.x+i, cur.y+j};
                cnt += (find(htable, np) != NULL);
            }
        }
        map[cnt]++;
        prev = cur;
    }
    int64_t rem = (int64_t)(row-2)*(col-2) - total;
    map[0] += rem;
    for(i = 0; i < 10; i++) {
        printf("%lld\n", map[i]);
    }
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans;
string s;
map<string,int> m;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> s;
        sort(all(s));
        m[s]++;
    }
    for(auto i : m) {
        ans += i.se*(i.se-1)/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136