akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
#include<vector>
#include<map>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<algorithm>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int N,K; 

int main()
{
  cin >> N >> K;
  vector<vector<int> > G(10);
  int TypeMax[10][N+1];
  int dp[10][N+1];
  for(int i=0;i<N;i++)
    {
      P p;
      cin >> p.F >> p.S;
      p.S--;
      assert(0<=p.S && p.S <10);
      G[p.S].push_back(p.F);
    }
  for(int i=0;i<10;i++)
    {
      sort(G[i].begin(),G[i].end(),greater<int>());
      for(int j=0;j<N;j++)TypeMax[i][j] = dp[i][j] = 0;
    } 

  //TypeMax
  
  for(int i=0;i<10;i++)
    {
      if(G[i].empty())continue;
      TypeMax[i][1] = dp[i][1] = G[i][0];
      for(int j=2;j<=G[i].size();j++)
	TypeMax[i][j] = TypeMax[i][j-1]+G[i][j-1];
      for(int j=2;j<=G[i].size();j++)
	TypeMax[i][j] = dp[i][j] = TypeMax[i][j]+(j-1)*j;
    }
 
  int mex = 0;
  
  for(int i=0;i<10;i++)
    {
      if(!i)
	{
	  for(int j=1;j<=K;j++)
	    dp[i][j] = TypeMax[i][j],mex = max(mex,dp[i][j]);
	  
	  continue;
	}
      if(G[i].empty())
	{
	  for(int j=1;j<=K;j++)
	    dp[i][j] = dp[i-1][j];
	  continue;
	}
      for(int j=1;j<=K;j++)
	{	  
	  if(j == 1)
	    {
	      dp[i][j] = max(TypeMax[i][j],dp[i-1][j]);
	      mex = max(mex,dp[i][j]);
	      continue;
	    }
	  for(int k=1;k<min(j+1,(int)G[i].size()+1);k++)
	    {
	      if(!dp[i-1][abs(j-k)])continue;
	      dp[i][j] = max(dp[i][j],TypeMax[i][k]+dp[i-1][abs(j-k)]);
	      mex = max(mex,dp[i][j]);
	    }
	  if(dp[i-1][j]!=0)
	    {
	      dp[i][j] = max(dp[i-1][j],dp[i][j]);
	      mex = max(mex,dp[i][j]);
	    }

	}
    }
  
  cout << mex << endl;

  return 0;
}

Measured memory_bytes: 1392
import sys
input = sys.stdin.buffer.readline

n = int(input())
a = list(map(int,input().split()))

res = 0

for i in range(1,n):
    if a[i] >= a[i-1]:
        continue
    res += a[i-1] - a[i]
    a[i] = a[i-1]

print(res)

Measured memory_bytes: 92896
#include <string>
#include <iostream>
#define LESS() cout << "LESS" << endl
#define GREAT() cout << "GREATER" << endl
#define EQUAL() cout << "EQUAL" << endl
using namespace std;

int main(){
	string s,t;
	cin >> s >> t;
	if(s.length() < t.length()) LESS();
	else if(s.length() > t.length()) GREAT();
	else{
		if(s < t) LESS();
		else if(s > t) GREAT();
		else EQUAL();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)



int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    a.push_back(0);
    b.push_back(0);

    if(a[0] != n*m || b[0] != n*m){
        cout << 0 << endl;
        return 0;
    }
    ll lp = 1; ll rp = 1;
    ll ans = 1;
    ll num = n*m-1;
    while(lp != n || rp != m){
        if(a[lp] == b[rp] && a[lp] == num){
            lp++; rp++;
            num--;
        }else if(a[lp] == num){
            ans *= rp;
            ans %= MOD;
            lp++; num--;
        }else if(b[rp] == num){
            ans *= lp;
            ans %= MOD;
            rp++; num--;
        }else{
            ll candidate = lp*rp - (m*n-num);
            if(candidate<=0){
                cout << 0 << endl;
                return 0;
            }
            ans *= candidate;
            ans %= MOD;
            num--;
        }

          }
    for(int i = 1; i <= num; i++){
        ans *= i;
        ans %= MOD;
    }


    cout << ans << endl;

}


Measured memory_bytes: 256
X,Y = list(map(int,input().split()))

from operator import mul
from functools import reduce

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if (X+Y)%3 != 0:
    print(0)
elif (X//2)>Y or (Y//2)>X:
    print(0)
else:
    dx = X-(X+Y)//3
    dy = Y-(X+Y)//3
    print (cmb(dx+dy,dx)%int(1e9+7))

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

using Pair = pair<int, int>;
#define X first
#define Y second

void solve()
{
	int n;
	cin >> n;

	vector< vector<Pair> > saying(n, vector<Pair>());

	int a, x, y;
	for(int i = 0; i < n; ++i)
	{
		cin >> a;
		for(int j = 0; j < a; ++j)
		{
			cin >> x >> y;
			x--;
			saying[i].emplace_back(make_pair(x, y));
		}
	}

	int people = 1 << n; // bit 0で不親切, 1で正直者
	int ans = 0;
	while(people -= 1, people >= 0)
	{
		bitset<15> mask(people);
		if ((int)mask.count() <= ans) continue;

		bool ok = true;
		for(int i = 0; i < n; ++i)
		{
			if (mask[i])
			{
				for(const auto& s : saying[i])
				{
					ok &= ((int)mask[s.X] == s.Y);
				}
				if (!ok) break;
			}

		}
		if (ok)
		{
			ans = (int)mask.count();
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    int x;
    cin >> x;
    x -= 400;
    cout << 8 - x/200 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
  	int n,memo = 0,zero = 0;
  	cin >> n;
  	int cx[n] = {0},cy[n] = {0},ch[n] = {0};
  
  	rep(i,0,n){
      cin >> cx[i] >> cy[i] >> ch[i];
      if(!i) memo = ch[i];
      else memo = min(memo,ch[i]);
    }
  
  
  	rep(i,0,101){
      rep(j,0,101){
        rep(k,0,n){
          	if(ch[k]) memo = ch[k] + (int)abs(i-cx[k]) + (int)abs(j-cy[k]);
        }
        rep(k,0,n){
        	if(max(0,memo-abs(i-cx[k])-abs(j-cy[k])) != ch[k]){
              break;
            }
          	else if(k == n-1){
              cout << i << " "<< j << " " << memo << endl;
              return 0;
            }
        }
      }
    }
  	cout << -1 << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N;
    cin >> N;
  	if(N==0)cout << 0;
  	else{
    vector<int> a;
    while(N!=0){
        a.push_back(abs(N%2));
      	if(N%2!=0 && N<0)N--;
      	N=N/2;
      	N=-N;
      	cerr << N;
    }
    reverse(all(a));
  	for(auto x:a)cout << x;
    }
    


}

/*



 */



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

const int N = 2e5 + 5;
int cnta[N], cntb[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int ar[n], br[n];
    for (int i = 0; i < n; i++) {
        cin >> ar[i];
        cnta[ar[i]]++;
    }
    for (int i = 0; i < n; i++) {
        cin >> br[i];
        cntb[br[i]]++;
    }
    for (int i = 0; i < N; i++) {
        if (cnta[i]) {
            if (n - cntb[i] < cnta[i]) {
                cout << "No" << '\n';
                exit(0);
            }
        }
    }
    reverse(br, br + n);
    vector<int> sama, beda;
    int val_sama = -1;
    for (int i = 0; i < n; i++) {
        if (ar[i] == br[i]) {
            val_sama = ar[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if (ar[i] == br[i]) sama.pb(i);
        else if (ar[i] != val_sama && br[i] != val_sama) beda.pb(i);
    }
    assert(sama.size() <= beda.size());
    for (int i = 0; i < sama.size(); i++) {
        swap(br[sama[i]], br[beda[i]]);
    }
    cout << "Yes" << '\n';
    for (int i = 0; i < n; i++) {
        cout << br[i];
        if (i == n - 1) cout << '\n';
        else cout << ' ';
    }
    return 0;
}

Measured memory_bytes: 7840
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,si
    integer(int32):: abc(ichar('a'):ichar('z')), ans(ichar('a'):ichar('z'))
    character(50):: s

    read*, n
    read*, s
    ans(:) = 0
    do si=1,len_trim(s)
        ans(ichar(s(si:si)))=ans(ichar(s(si:si)))+1
    end do

    do i=2,n
        read*, s
        abc(:)=0
        do si=1,len_trim(s)
            abc(ichar(s(si:si)))=abc(ichar(s(si:si)))+1
        end do
        ans(:) = min(ans,abc)
    end do

    do i=ichar('a'),ichar('z')
        do si=1,ans(i)
            write(*,'(a)',advance='no') char(i)
        end do
    end do
    print*,''

end program name

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int INF = 1000000;


int main()
{  int n,k,r,s,p,w=0; cin>>n>>k>>r>>s>>p;
   string t; cin>>t;
   vector<string> te(n);
   ll res =0;

   REP(i,n){
     if(t[i]=='r')te[i]="p";
       if(t[i]=='s')te[i]="r";
      if(t[i]=='p')te[i]="s";
      if(i-k>=0&&te[i]==te[i-k]){
          te[i]="w";
      }
       if(te[i]=="r")res+=r;
       if(te[i]=="s")res+=s;
      if(te[i]=="p")res+=p;
     //cout<<i<<' '<<te[i]<<endl;
   }
   cout<<res<<endl;
}



Measured memory_bytes: 5888
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			int num = sc.nextInt();
			int prime_count = 0;
			int array[] = new int[num + 1];

			/*エラトステネスの篩*/
			for(int i = 2; i <= num; i++){
				array[i] = 0;
			}
			
			for(int i = 2; i <= num; i++){
				if(array[i] == 0){
					for(int j = i + i; j <= num; j = j + i){
						array[j] = 1;
					}
				}
			}
			
			for(int i = 2; i <= num; i++){
				if(array[i] == 0)
					prime_count++;
			}
			System.out.println(prime_count);
		}
	}
}

Measured memory_bytes: 54976
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main () {
  int n;
  cin >> n;
  for (int i = n; i < 1112; i++){
    if (i == 111 || i == 222 || i == 333 || i == 444 || i == 555 || i == 666 || i == 777 || i == 888 || i == 999 || i == 1111){
      cout << i << '\n';
      return 0;
    }
  }
  return 0;
}

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

typedef long long ll;

int main(){
        ll h;
        cin>>h;
        ll tmp=h,num=1,ans=1;
        while(tmp>1){
                tmp/=2;
                num*=2;
                ans+=num;
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  int ans = 1;
  auto f = [&](int i){ if(m/i>=n) ans = max(ans,i); };
  for(int i=1;i*i<=m;++i) {
    if(m%i==0) {
      f(i); f(m/i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> masu(N);
  for(int i = 0;i < N;i++){
    cin >> masu.at(i);
  }
  int count = 0;
  for(int i = 1;i <= N;i++){
    if(i % 2 == 1){
      if(masu.at(i - 1) % 2 == 1){
        count++;
      }
    }
  }
  cout << count << endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int, int>>> vvpp;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pair<int, int>> vpp;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define all(n) (n).begin(), (n).end()
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void out(Arg1&& arg1) {
    cout << arg1 << '\n';
}

template <typename Arg1, typename ...Args>
void out(Arg1&& arg1, Args&& ...args) {
    cout << arg1 << ' ';
    out(args...);
}


template <typename T>
void outarr(vector<T> arr) {
    for (int i = 0; i < arr.size() -1; ++i) cout << arr[i] << ' ';
    cout << arr.back() << '\n';
}

template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    map<int, int> count;
    for (int i = 0; i < n -1 ; ++i) {
        int boss; cin >> boss;
        cerr << boss << ' ' << count[boss] << endl;
        count[boss] += 1;
    }

    for (int i = 1; i <= n; ++i) {
        cout << count[i] << '\n';
    }

    return 0;
}



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

int main(){
    static bool bias[80][80][80*160];
    int h, w, a[80][80], b[80][80];

    cin >> h >> w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j) cin >> a[i][j];
    }
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j) cin >> b[i][j];
    }

    bias[0][0][abs(a[0][0]-b[0][0])] = true;
    
    for(int k=0;k<=h+w-2;++k){
        for(int i=max(k-w+1, 0);k-i>=0 && i<h;++i){
            int j = k-i;
            if(i+1 < h){
                for(int v=0;v<=(k+1)*80;++v){
                    if(!bias[i][j][v]) continue;
                    bias[i+1][j][abs(v+a[i+1][j]-b[i+1][j])] = true;
                    bias[i+1][j][abs(v+b[i+1][j]-a[i+1][j])] = true;
                }
            }
            if(j+1 < w){
                for(int v=0;v<=(k+1)*80;++v){
                    if(!bias[i][j][v]) continue;
                    bias[i][j+1][abs(v+a[i][j+1]-b[i][j+1])] = true;
                    bias[i][j+1][abs(v+b[i][j+1]-a[i][j+1])] = true;
                }
            }
        }
    }
    
    for(int k=0;k<=160*80;++k){
        if(bias[h-1][w-1][k]){
            cout << k << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 79360
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInt s = (read :: String -> Int) s

main = do
    n <- readLn :: IO Int
    t <- replicateM n getLine
    let t0 = map read t
    print $ solve t0

solve :: [Int] -> Int
solve t = foldr lcm 1 t

Measured memory_bytes: 1020
n=int(input())
a=list(map(int,input().split()))
mxn=0
mnn=0
mx=-10**10
mn=10**10
for i in range(n):
  if mx<a[i]:
    mx=a[i]
    mxn=i
  if mn>a[i]:
    mn=a[i]
    mnn=i
print(2*n-1)
if mx+mn>=0:
  for i in range(n):
    print(mxn+1,i+1)
  for i in range(1,n):
    print(i,i+1)
else:
  for i in range(n):
    print(mnn+1,i+1)
  for i in range(n,1,-1):
    print(i,i-1)

Measured memory_bytes: 62456
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
N, A, B = map(int, input().split())
v = [int(c) for c in input().split()]
v.sort(reverse=True)
m = 0
for i in range(A):
  m += v[i]
ans1 = m/A
ls = []
for j in range(A,B):
  m += v[j]
  if ans1!=m/(j+1):
    break
  ls += [j]
T = v[:A]
t = set(T)
dic1 = {}
dic2 = {}
for c in t:
  dic1[c] = T.count(c)
  dic2[c] = v.count(c)
ans2 = 1
for c in t:
  ans2 *= cmb(dic2[c],dic1[c])
for l in ls:
  dic1[v[l]] += 1
  ans2 += cmb(dic2[c],dic1[c])
print(ans1)
print(ans2)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
const ll mod=1000000007;
ll pow(ll x,ll y){
  ll res=1;
  for(ll i=0;i<y;i++){
    res*=x;
  }
  return res;
}

ll powmod(ll x,ll y){
  ll res=1;
  for(ll i=0;i<y;i++){
    res=res*x%mod;
  }
  return res;
}

main(){
  ll n;cin >> n;
  ll a[n];for(ll i=0;i<n;i++) cin >> a[i];
  ll f=0;
  for(ll i=0;i<n;i++){
    f+=a[i];
    f%=mod;
  }
  ll ans=0;
  for(ll i=0;i<n;i++){
    f-=a[i];
    if(f<0) f+=mod;
    ans+=f*a[i];
    ans=(ans+mod)%mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5188
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
bag = Counter(a)
label2diff = {}
fullcombi = 0
for label, freq in bag.most_common(n):
    #data.append((label, freq * (freq - 1) // 2 - (freq - 1) * (freq - 2) // 2))
    label2diff[label] = freq - 1
    fullcombi += freq * (freq - 1) // 2
for ai in a:
    print(fullcombi - label2diff[ai])

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

int main() {
  
  int n;
  cin >> n;
  
  string answer = "Three";
  
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    
    if(s == "Y"){
      answer = "Four" ;
      break;
    }    
  }  
  
  cout << answer <<endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
using ll=long long;


int main(){
	int n;
	ll num[1010]={},ans=1;
	cin>>n;
	rep(i,1,n+1){
		int x=i;
		int j=2;
		while(x!=1){
			if(x%j==0){
				x/=j;
				num[j]++;
				continue;
			}
			j++;
		}
	}
	rep(i,2,n+1)ans=(ans%1000000007)*(num[i]+1);
	cout<<ans%1000000007<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) throws IOException {
		Scanner scanner = new Scanner(System.in);
		char a = (char) System.in.read(); 
		char b = (char) System.in.read(); 
		char c = (char) System.in.read(); 
		char d = (char) System.in.read(); 
		int num = 0;
		if (a=='+') {
			num++;
		}
		else {
			num--;
		}
		if (b=='+') {
			num++;
		}
		else {
			num--;
		}
		if (c=='+') {
			num++;
		}
		else {
			num--;
		}
		if (d=='+') {
			num++;
		}
		else {
			num--;
		}
		System.out.println(num);
	}
}

Measured memory_bytes: 21844
main :: IO()
main = do
    _ <- getLine
    ls <- map read . words <$> getLine
    putStrLn $ if (getsolve ls) then "Yes" else "No"
    
getsolve :: [Int] -> Bool
getsolve ls
    | max < notmax			= True
    | otherwise				= False
    where max = maximum ls
          notmax = (sum ls) - (maximum ls)


Measured memory_bytes: 508
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	s := getNextLine(scanner)
	fmt.Println(chokudai(s))
}

func chokudai(s string) string {
	part1, _ := strconv.Atoi(s[0:2])
	part2, _ := strconv.Atoi(s[2:4])
	if part1 > 12 && part2 > 12 {
		return "NA"
	}
	if part1 == 0 && part2 == 0 {
		return "NA"
	}
	if part1 > 12 || part1 == 0 {
		if 1 <= part2 && part2 <= 12 {
			return "YYMM"
		}
		return "NA"
	}
	if part2 > 12 || part2 == 0 {
		if 1 <= part1 && part1 <= 12 {
			return "MMYY"
		}
		return "NA"
	}
	return "AMBIGUOUS"
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int N, K;
int a[101];
int dp[101010];
int dfs(int k) {
  if (dp[k] != -1)
    return dp[k];

  int f = true;
  rep(i, 0, N) {
    if (k - a[i] >= 0) {
      f &= dfs(k - a[i]);
    }
  }
  return dp[k] = !f;
}
signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  rep(i, 0, 101010) dp[i] = -1;
  cin >> N >> K;
  rep(i, 0, N) { cin >> a[i]; }
  cout<<(dfs(K)?"First":"Second")<<endl;

  return 0;
}


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

using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int n,m,nax = 0;
	cin >>n >>m;
	vector<vector<int> > edges(n+1);
	vector<int> dp(n+1,0),leaf(n+1,0);
	for(int i = 0,x,y;i<m;i++) {
		cin >>x>>y;
		edges[x].push_back(y);
		leaf[y]++;
	}
	queue <int> que;
	for(int i = 1;i<=n;i++) {
		if(leaf[i]==0) que.push(i);
	}
	while(!que.empty()) {
		int a,b;
		a = que.front();
		que.pop();
		b=(int)edges[a].size();
		for(int i = 0;i<b;i++){
			dp[edges[a][i]] = max(dp[a]+1,dp[edges[a][i]]);
			nax = max(nax,dp[edges[a][i]]);
			--leaf[edges[a][i]];
			if(leaf[edges[a][i]]==0) que.push(edges[a][i]);
		}
	}
	cout <<nax<<'\n';
	return 0;
}

Measured memory_bytes: 9352
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<(char)toupper(a[0])<<(char)toupper(b[0])<<(char)toupper(c[0])<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
ll dp[100001];
int main(){
	ll n,w;
	cin>>n>>w;
	vector<pii> v(n+1);
	for(int i=1;i<=n;i++){
		cin>>v[i].fi>>v[i].se;
	}
	for(int i=0;i<100001;i++)
	dp[i]=2*w;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(ll j=100000;j>=v[i].se;j--){
			dp[j]=min(dp[j],dp[j-v[i].se]+v[i].fi);
		}
	}
	ll ans=0;
	for(int i=1;i<=100000;i++){
		if(dp[i]<=w)
		ans=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
a = int(input())

#リストgcd
def list_gcd(l):
    from math import gcd
    if len(l)==1:
        raise
    else:
        ret = l[0]
        for i in l[1::]:
            ret = gcd(ret,i)
            if ret==1:
                break
    return ret

ret = 0
ret_1 = 0
ret_2 = 0
for i in range(1,a+1):
    ret_1+=i
for i in range(1,a+1):
    for j in range(1,a+1):
        if i!=j:
            ret_2+=(list_gcd([i,j]))*3
for i in range(1,a+1):
    for j in range(i+1,a+1):
        for k in range(j+1,a+1):
            ret+=list_gcd([i,j,k])
ret*=6
ret+=(ret_1+ret_2)
print(ret)

Measured memory_bytes: 74140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
bool judge(long a,long b,long h,long w){
    if(a<1) return false;
    if(a+2>h) return false;
    if(b<1) return false;
    if(b+2>w) return false;
    return true;
}
int main(){
    long long h,w,n;
    cin >> h >> w >> n;
    long a[n],b[n];
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    long long ans[10] = {0};
    set<pair<long,long>> st;
    map<pair<long,long>,int> mp;
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(judge(a[i]-j,b[i]-k,h,w)){
                    mp[make_pair(a[i]-j,b[i]-k)]++;
                    st.insert(make_pair(a[i]-j,b[i]-k));
                }
            }
        }
    }
    ans[0]=(h-2)*(w-2)-st.size();
    for(auto itr = st.begin();itr!=st.end();itr++){
        ans[mp[*itr]]++;
    }
    rep(i,10){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 114304
package main

import "fmt"

func minm(v ...int) (r int) {
	r = int(1e18) + 1
	for i := 0; i < len(v); i++ {
		if v[i] < r {
			r = v[i]
		}
	}
	return r
}

func main() {
	var N, A, B, C, D, E int
	fmt.Scan(&N, &A, &B, &C, &D, &E)
	minv := minm(A, B, C, D, E) // ボトルネック
	q := (N + minv - 1) / minv  // ボトルネックを通過するのにかかる時間(切り上げ)
	fmt.Println(q + 4)          // 残りの輸送機関にかかる時間
}


Measured memory_bytes: 512
#include<stdio.h>
int main(int i,char**v){
  long a,b,c,d;
  scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
  long val[4];
  val[0]=a*c;
  val[1]=a*d;
  val[2]=b*c;
  val[3]=b*d;
  long max=val[0];
  for(i=1;i<4;i++){
    if(val[i]>max)max=val[i];
  }
  printf("%ld\n",max);
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e4+7;
string s;
ll a[200005],b[200005];
ll c[200005],d[200005];
void solve() {
    int n;
	cin>>n;
	cin>>s;
	int one=0;
	reverse(s.begin(),s.end());
	for( int i=0;i<n;i++ ) one+=s[i]=='1';
	
	ll mod1=one+1,mod2=max(one-1, 1);
	ll res1=0,res2=0,now1=1,now2=1;
	for( int i=0;i<s.size();i++ )
	{
		if( s[i]=='1' )
		{
			res1=(res1+now1)%mod1;
			res2=(res2+now2)%mod2;	 
		}
		c[i]=now1%mod1;
		d[i]=now2%mod2;
		now1=(now1*2)%mod1;
		now2=(now2*2)%mod2;
	}
	
	vector<int> p;
	for( int i=0;i<n;i++ )
	{
		ll res,ans=0;
		if( one==1 && s[i]=='1' )
		{
			p.push_back(0);
			continue;
		}
		
		if( s[i]=='0' )	res=(res1+c[i])%mod1;
		else res=(res2-d[i]+mod2)%mod2;
		ans++;
		while( res )
		{
			res%=__builtin_popcount(res);
			ans++;
		}
		p.push_back(ans);
	}
	reverse(p.begin(),p.end());
	for( int v:p ) cout<<v<<endl;
}
int main()
{
	solve();
}


Measured memory_bytes: 7644
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int min=0;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') { min++; }
	}
	int num = min;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == 'W') { num++; }
		if (s[i] == 'E') { num--; }
		if (num < min) { min = num; }
	}
	cout << min << endl;
}

Measured memory_bytes: 900
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
  int N;
  cin >> N;
  string a = to_string(N);
  bool flag = false;
  for(int i = 0 ; i < a.size() ; i++)
  {
    if(a.at(i) == '7')
    {
      flag = true;break;
    }
  }
  
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3688
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

typedef long long ll;

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

const int N=1e5+5;

int n,m,cnt,q,k,a[N],b[N],c[N],fa[N];

int get(int x) {return fa[x]?fa[x]=get(fa[x]):x;}

void No() {puts("No");exit(0);}

int main() {
	n=cnt=read();m=read();q=read();
	fo(i,1,q) a[i]=read()+1,b[i]=read()+1,c[i]=read();
	if (m==n-1) {
		fo(i,1,q) if (c[i]) No();
		puts("Yes");
		return 0;
	}
	fo(i,1,q) 
		if (!c[i]) {
			int x=get(a[i]),y=get(b[i]);
			if (x==y) continue;
			fa[y]=x;cnt--;k++;
		}
	fo(i,1,q) 
		if (c[i]) {
			int x=get(a[i]),y=get(b[i]);
			if (x==y) No();
		}
	if (cnt==2) {
		fo(i,1,q) if (c[i]) No();
		return 0;
	}
	if (m<k+cnt||m>k+(ll)cnt*(cnt-1)/2) No();
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1664
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
z = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Measured memory_bytes: 7828
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define PI (acos(-1))
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
 
const int MOD = 1e9+7;
const int INF = 1001001001;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int odd[100005];
int even[100005];

int flg[100100];

signed main()
{
  int n; cin>>n;
  vi p(n);
  rep(i,n)cin>>p[i];
  int ans=0;
  rep(i,n){
    if(i+1==p[i]){
      if(flg[i]!=1){
        ans++;
        flg[i+1]=1;
      }
    }
  }
  cout<<ans<<endl;
}


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

from copy import deepcopy

N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

# ワーシャルフロイドで全頂点の最短距離
B = deepcopy(A)
for k in range(N):
    for i in range(N):
        for j in range(N):
            # 最短 > 経由 があればNG
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            # 最短 = 経由 があるなら、経由を使えば全長を減らせる
            elif A[i][j] == A[i][k] + A[k][j] and j != k and i != k and i < j:
                # 最短経路(仮)から直行ルートをなくす
                B[i][j] = 0

# 削減された最短経路の全長
sm = 0
for i in range(N):
    for j in range(i+1, N):
        sm += B[i][j]
print(sm)


Measured memory_bytes: 56540
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int l[n];
    rep(i, n){
        cin >> l[i];
    }

    sort(l, l+n);

    ll ans = 0;
    rep(i, n){
        reps(j, i+1, n){
            reps(k, j+1, n){
                if(l[i]+l[j] <= l[k]) continue;
                
                ans++;
            }
        }
    }

    cout << ans;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    ll inf = 1e18;
    vector<ll> X(N+2), Y(N+2), P(N+2, 0);
    vector<vector<ll>> house(N+2, vector<ll>(3, 0));
    for (int i = 1; i <= N; i++) cin >> house[i][0] >> house[i][1] >> house[i][2];
    house[0] = {-inf, -inf, 0};
    house[N+1] = {inf, inf, 0};
    sort(house.begin(), house.end());
    for (int i = 0; i <= N+1; i++) {
        X[i] = house[i][0];
        Y[i] = house[i][1];
        P[i] = house[i][2];
    }
    
    vector<ll> ans(N+1, inf);
    
    for (int i = 0; i < (1<<N); i++) {
        int tate = 0;
        vector<ll> dist(N+1, inf);
        for (int j = 1; j <= N; j++) dist[j] = min(abs(X[j]), abs(Y[j]));
        for (int j = 1; j <= N; j++) {
            if (((i>>(j-1))&1) == 0) continue;
            tate++;
            for (int k = 1; k <= N; k++) dist[k] = min(dist[k], abs(Y[j]-Y[k]));
        }
        vector<vector<vector<ll>>> dp(N+2, vector<vector<ll>>(N+2,vector<ll>(N+1, inf)));
        dp[0][0][tate] = 0;
        for (int j = 1; j <= N; j++) {
            for (int k = 0; k < j; k++) {
                ll newcost = 0;
                for (int l = k+1; l < j; l++) {
                    newcost += P[l]*min(dist[l], min(X[l]-X[k], X[j]-X[l]));
                }
                for (int l = 0; l <= N; l++) {
                    if (dp[j-1][k][l] == inf) continue;
                    dp[j][k][l] = dp[j-1][k][l];
                    if (l < N) dp[j][j][l+1] = min(dp[j][j][l+1], dp[j][k][l]+newcost);
                }
            }
        }
        for (int j = 0; j <= N; j++) {
            ll newcost = 0;
            for (int k = j+1 ; k <= N; k++) {
                newcost += P[k]*min(dist[k], X[k]-X[j]);
            }
            for (int k = 0; k <= N; k++) {
                ans[k] = min(ans[k], dp[N][j][k] + newcost);
            }
        }
    }
    
    for (int i = 0; i <= N; i++) cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3648
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

typedef long double Double;
const int N=60;
int cnt[N][N];
void main() {
    int n;
    R(n);
    REP(i,n) {
        Double x;
        R(x);
        LL y=x*1e9 + 0.5;
        int a=0, b=0;
        while ( y%2==0 ) { a++; y/=2; }
        while ( y%5==0 ) { b++; y/=5; }
        cnt[a][b]++;
    }
    LL ans=0;
    REP(i,N) REP(j,N) REP(ii,N) REP(jj,N) {
        if ( MP(i,j)<=MP(ii,jj) ) {
            if ( i+ii>=18 && j+jj>=18 ) {
                if ( i==ii && j==jj ) ans+=(LL)cnt[i][j]*(cnt[i][j]-1)/2;
                else ans+=(LL)cnt[i][j]*cnt[ii][jj];
            }
        }
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3856
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int h,w,m;
cin>>h>>w>>m;
int x[m],y[m];
map<int,int> mp,mp2;
map<pair<int,int>,int > pp;
vector<pair<int,int> > vc,vc2;
for(int i=0;i<m;i++)
{
cin>>x[i]>>y[i];
mp[x[i]]++;
mp2[y[i]]++;
pp[{x[i],y[i]}]=1;
}
int mx1=0,mx2=0;
for(int i=1;i<=h;i++)
{
if(mp.count(i))
{
vc.push_back({mp[i],i});
}
}
for(int i=1;i<=w;i++)
{
if(mp2.count(i))
{
vc2.push_back({mp2[i],i});
}
}
sort(vc.rbegin(),vc.rend());
sort(vc2.rbegin(),vc2.rend());
int ans=vc[0].first+vc2[0].first-1;
bool ok=0;
for(int i=0;i<vc.size()&& vc[i].first==vc[0].first&&!ok;i++)
{
for(int j=0;j<vc2.size()&&vc2[j].first==vc2[0].first;j++)
{
if(pp[{vc[i].second,vc2[j].second}]==0)
{
ok=1;
break;
}
}
}
cout<<ans+ok<<endl;
}
/*
 *||||

 */

Measured memory_bytes: 60844
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct uftree{
private:
  vector<ll> par,val,rnk;
public:
  uftree(ll n){
    par.resize(n+5);
    val.resize(n+5);
    rnk.resize(n+5);
    for(int i=0;i<=n;i++){
      par[i]=i;
      val[i]=0;
      rnk[i]=0;
    }
  }
  void set_val(ll pos,ll x){
    val[pos]=x;
  }
  ll find(ll pos){
    if(par[pos]==pos) return pos;
    else return par[pos]=find(par[pos]);
  }
  bool same(ll a,ll b){
    return find(a)==find(b);
  }
  ll sum(ll pos){
    return val[find(pos)];
  }
  void unite(ll a,ll b){
    a=find(a);
    b=find(b);
    if(same(a,b)) return;
    if(rnk[a]<rnk[b]){
      par[a]=b;
      val[b]+=val[a];
    }
    else{
      par[b]=a;
      val[a]+=val[b];
      if(rnk[a]==rnk[b]) rnk[a]++;
    }
  }
};
int main(){
  ll n,m;
  cin>>n>>m;
  vector<P> node;
  for(int i=0;i<m;i++){
    ll s,t;
    cin>>s>>t;
    node.push_back(P(s,t));
  }
  vector<ll> ansv;
  ll ans=n*(n-1)/2;
  uftree uf(n+5);
  for(int i=1;i<=n;i++) uf.set_val(i,1);
  for(int i=m-1;i>=0;i--){
    ansv.push_back(ans);
    ll s=node[i].first,t=node[i].second;
    if(uf.same(s,t)) continue;
    ll ss=uf.sum(s),ts=uf.sum(t);
    ans-=ss*ts;
    uf.unite(s,t);
  }
  sort(ansv.begin(),ansv.end());
  for(int i=0;i<m;i++) cout<<ansv[i]<<endl;
}


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

int INF = 1e9 + 1;

void count(INFO& info, vector<int>& v, int pattern) {
  rep(i, v.size()) {
    v[i] = 0;
    rep(j, 10) if (pattern & 1 << j && info[i][j] == 1) v[i]++;
  }
}

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

  INFO F(N, vector<int>(10));
  rep(i, N) rep(j, 10) cin >> F[i][j];

  vector<vector<int>> P(N, vector<int>(11));
  rep(i, N) rep(l, 11) cin >> P[i][l];

  vector<int> C(N);
  int ans = -INF;
  for (int pat = 1; pat < 1024; pat++) {
    count(F, C, pat);
    int profit = 0;
    rep(i, N) profit += P[i][C[i]];
    ans = max(ans, profit);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  string s[N];
  REP(i, N) {
    string ss;
    cin >> ss;
    sort(ALL(ss));
    s[i] = ss;
  }

  map<string, ll> same = map<string, ll>();
  REP(i, N) { same[s[i]] += 1; }
  ll ans = 0;
  for(auto x : same) {
    ans += x.second * (x.second - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11904
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	string s;
	cin>>s;
	if(s=="Sunny")
		cout<<"Cloudy"<<endl;
	else if (s=="Cloudy")
		cout<<"Rainy"<<endl;
	else cout<<"Sunny";
	return 0;
}


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

int main(){
    int A, B;
    string S;
    cin >> A >> B >> S;
    for(int i = 0; i < A; i++){
        if(S[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    if(S[A] != '-'){
        cout << "No" << endl;
        return 0;
    }
    for(int i = A + 1; i <= A + B; i++){
        if(S[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256