akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct Pony
{
    long a, b;
 
    Pony(long a_, long b_)
    {
        a = a_;
        b = b_;
    }
 
    bool operator<(const Pony &another) const
    {
        return b < another.b;
    };
};

int fac(int k){
    int sum = 0;
    for (int i = 1; i <= k; ++i)
    {
        sum += i;
    }
    return sum;
}

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

  long n;
  cin >> n;

  cout << n * (n-1) / 2 << endl;
}


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

int sumnumber(int n){
    int sum = 0;
    while (n > 0){   
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int total = 0;
    for (int i = 1; i < n+1; i++){
        int sum = 0;
        sum = sumnumber(i);
        if (sum <= b && sum >= a){
            total += i;
        }
    }
    cout << total << endl;
}

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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a[(a.size()-1)]==b[0]&&b[(b.size()-1)]==c[0])
        cout << "YES" <<endl;
    else
        { cout << "NO" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,s[100000],ans=(1LL<<60);
int main(void){
    cin>>n>>m;
    for(int i=1;i<100000;i++)s[i]=(1LL<<60);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        for(int j=0;j<n;j++){
            if(s[j]!=(1LL<<60)){
                //cout<<j<<"W"<<s[j]<<endl;
                s[j+a]=min(s[a+j],s[j]+b);
            }
        }
    }
    for(int i=n;i<100000;i++){
        ans=min(ans,s[i]);
        //cout<<s[i]<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 3001, w = 4;
int n, m, k;
ll a[mxn][mxn];
ll dp[mxn][mxn][w];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> k;
	
	for(int i = 0; i < k; i++){
	    int x, y;
	    cin >> x >> y >> a[x][y];
	}
	
	for(int i = 1; i <= n; i++)
	for(int j = 1; j <= m; j++){
	    dp[i][j][0] = max(dp[i][j - 1][0], dp[i - 1][j][w - 1]);
    	for(int l = 1; l < w; l++){
    	    dp[i][j][l] = max({
    	        dp[i - 1][j][w - 1] + a[i][j], 
    	        dp[i][j - 1][l],
    	        dp[i][j - 1][l - 1] + a[i][j]
    	    });
    	}
	}
	
	cout << dp[n][m][w - 1];

	return 0;
}

Measured memory_bytes: 355220
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    string s;
    cin>>s;
    string ans="";
    for(int i=0;i<s.size();i++){
        if(s[i]!=',')ans+=s[i];
        else ans+=' ';
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n,x,ans=1;
    cin>>n>>x;
    vector<int> l(n);
    rep(i,n) cin>>l[i];
    for(int i=1;i<n;i++)
        l[i]=l[i-1]+l[i];
    rep(i,n)
    {
        if(l[i]>x) break;
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3620
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let ai: Vec<u32> = (0..n).map(|_| read()).collect();

    let mut ans = "APPROVED";

    for a in ai {
        if a % 2 == 0 {
            if !(a % 3 == 0 || a % 5 == 0) {
                ans = "DENIED";
                break;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <boost/tuple/tuple.hpp>

boost::tuple<int,int,int> check(int Y2, int N)
{
  //x + y + z = N;
  //9x + 4y = M
  int x , y , z;
  x = y = z = -1;
  const int M = 10*Y2 - N;
  const int x_max = M / 9;
  for(int i = x_max; 0 <= i; i--) {
    if((M - 9*i) % 4 == 0) {
      x = i;
      y = (M - 9*i) / 4;
      z = N - (x + y);
      if(z >= 0)
        break;
    }
  }
  if(z < 0)
    x = y = z = -1;
  
  return boost::make_tuple(x,y,z);
}

int main(){
  char s[100];
  std::cin >> s;
  const int N = atoi(s);
  std::cin >> s;
  const int Y = atoi(s);
  const int R = Y % 10000;
  int x,y,z;
  boost::tie(x,y,z) = check(Y / 10000, N - R / 1000);
  if(x >= 0) {
    z += R / 1000;
  }
  else {
    if(R >= 5000) {
      boost::tie(x,y,z) = check(Y / 10000, N - (R - 5000)/ 1000 - 1);
      if(x >= 0) {
        y += 1;
        z += (R - 5000)/ 1000;
      }
    }
  }
  std::cout<<x<<" "<<y<<" "<<z<<std::endl; 
    
  return 0;
}


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

using namespace std;
#define BUF (1000)
#define ll long long 

ll a,b,c,k;

int main(void){
	cin >> a >> b >> c >> k;

	if(k%2==0){
		cout << a-b << endl;
	}else{
		cout << b-a << endl;
	}

	
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;
vector<int> bi;
vector< vector<char> > board;
int a, b, k, ans=0;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}


void bitgen(int len){

	//生成完了時の処理
	if(len==0){
		//for(int i=0;i<bi.size();i++) cout<< bi[i] << " ";
		//cout<< endl;

		int su=0;

		//for(int l=0;l<bi.size();l++){
			for(int i=0;i<a;i++){
				for(int j=0;j<b;j++){
					if(board[i][j]=='#' && bi[i]==0 && bi[j+a]==0) su++;
				}
			}
		//}

		if(su==k) ans++;

		return;
	}

	//再帰部分
	for(int i=0;i<2;i++){
		bi[len-1]=i;
		bitgen(len-1);
	}
}

int main(){

	cin>> a >> b >> k;

	board.resize(a);
	for(int i=0;i<a;i++) board[i].resize(b);

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

	bi.resize(a+b);
	bitgen(a+b);

	cout<< ans << endl;
 
	return 0;
}

Measured memory_bytes: 3624
total = 0
N, Y = map(int, input().split())
flag = 0
for a in range(N + 1):
    for b in range(N - a + 1):
        total = 10000 * a + 5000 * b + 1000 * (N - a - b)
        if total == Y:
            print(str(a) + " " + str(b) + " " + str(N - a - b))
            flag = 1
            break
    if flag == 1:
        break

if flag == 0:
    print("-1" + " " + "-1" + " " + "-1")


Measured memory_bytes: 3064
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int k;

	cin >> n >> k;

	int* w = (int*)malloc(n * sizeof(int));

	int max_w = 0;
	int sum_w = 0;
	int min_p = 0;
	int max_p = 0;
	int p = 0;
	if(n < 1){
		return 0;
	}

	for(int i = 0; i < n; i++){
		cin >> w[i];
		sum_w += w[i];
		if(w[i] > max_w){
			max_w = w[i];
		}
	}
	//????????????????°???????
	min_p = max(max_w, sum_w/k);
	//?????????????????§??????
	max_p = (max_w * n) /k;
	int result_min_p = max_p;
	int this_p;
	//????????¢?´¢
	while(max_p > min_p){
		int current_w = 0;
		int current_k = 1;
		this_p = 0;
		//???????????????
		p = (min_p + max_p) >> 1;
		for(int i = 0; i <= n; ++i){
			//p????¶?????????????????????????
			if(current_w > p){
				--i;
				if(this_p < current_w - w[i]) this_p = current_w - w[i];
				++current_k;
				current_w = 0;
			}
			//??????????????°???k????¶?????????¨??????p???????????´??°??????????????´???
			if(current_k > k){
				i = -1;
				current_w = 0;
				current_k = 1;
				min_p = p + 1;
				p = (min_p + max_p) >> 1;
				this_p = 0;
				continue;
			}
			current_w += w[i];
		}
		if(this_p < current_w - w[n]) this_p = current_w - w[n];
		//for?????????????????????????????????????????°???k??\????????¨???
		if(this_p < result_min_p) result_min_p = this_p;
		max_p = p;
	}
	//p??????
	cout << result_min_p <<endl;
	return 0;
}

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

//#define int long long

/*************** using variables ***************/
int n;
vector<int> a;
/**********************************************/

signed main(){
    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    REP(i, n){
        REP(j, n){
            if(i == j) continue;
            if(abs(a[i]-a[j]) % (n-1) == 0){
                cout << a[i] << " " << a[j] << endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 3096
sx, sy, tx, ty = map(int, input().split())
dx = tx-sx
dy = ty-sy
ans = []
for i in range(dx):
    ans.append('R')

for i in range(dy):
    ans.append('U')

for i in range(dx):
    ans.append('L')

for i in range(dy+1):
    ans.append('D')

for i in range(dx+1):
    ans.append('R')

for i in range(dy+1):
    ans.append('U')

ans.append("LU")
for i in range(dx+1):
    ans.append('L')

for i in range(dy+1):
    ans.append('D')

ans.append('R')
print("".join(ans))


Measured memory_bytes: 3188
s = input()
N = len(s)
s_trim = ''.join([c for c in s if c != 'x'])
N_trim = len(s_trim)

def check_anagram():
    for i in range(N_trim):
        j = N_trim - 1 - i
        if s_trim[i] != s_trim[j]:
            return False
    return True

def solve():
    if not check_anagram():
        return -1
    if N_trim == 0:
        return 0
    # Center of anagram
    pr = N_trim // 2
    pl = pr
    if N_trim % 2 == 0:
        pl -= 1

    xl = 0
    tl = 0
    while xl < N:
        if s[xl] != 'x':
            # assert s[xl] == s_trim[tl]
            if tl == pl:
                break
            tl += 1
        xl += 1

    if N_trim % 2 == 1:
        xr = xl
    else:
        xr = xl + 1
        while s[xr] == 'x':
            xr += 1

    cost = 0
    while True:
        # assert s[xl] == s_trim[pl]
        # assert s[xr] == s_trim[pr]
        # assert s[xl] == s[xr]
        # assert s_trim[pl] == s_trim[pr]
        pl -= 1; pr += 1
        while True:
            xl -= 1; xr += 1
            if not (xl >= 0 and xr < N and s[xl] == 'x' and s[xr] == 'x'):
                break
        while xl >= 0 and s[xl] == 'x':
            cost += 1
            xl -= 1
        while xr < N and s[xr] == 'x':
            cost += 1
            xr += 1
        if pl < 0 and pr >= N_trim and xl < 0 and xr >= N:
            return cost

print(solve())


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

using namespace std;
typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

string str = "abcdefghijklmnopqrstuvwxyz";


int main()
{
   ll n;
   cin >> n;
   map<ll,ll> a;
   ll sum=0;
   rep(i,0,n){
     ll temp;
     cin >> temp;
     sum += temp;
     if(a.count(temp)>0){
       a[temp]++;
     }
     else{
       a[temp]=1;
     }
   }

   ll q;
   cin >> q;
   ll b[q];
   ll c[q];
   ll ans[q];
   rep(i,0,q){
     cin >> b[i] >> c[i];
     if(a.count(b[i])>0){
       if(a.count(c[i])>0){
         a[c[i]] += a[b[i]];
       }
       else{
         a[c[i]] = a[b[i]];
       }
       sum += a[b[i]]*(c[i]-b[i]);
       ans[i] = sum;
       a[b[i]] = 0;
     }
     else{
       ans[i] = sum;
     }
   }
   rep(i,0,q){
     cout << ans[i] << endl;
   }

   return 0;
}


Measured memory_bytes: 11080
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  double x,T;
  cin >> T >> x;
  long double t=T/x;
  cout <<  t << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define Rep(i,a) for(int i = 0; i < (a); i++)
#define rep(i,a,b) for(int i = (a); i <= (b); i++)//(a)!
#define dep(i,a,b) for(int i = (a); i >= (b); i--)
#define ab(a) ((a) > 0 ? (a) : -(a))
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int N = 100010;
int a[N], ind[N], d[N], c[N], cl = 0;
bool vis[N];
int main() {
	int n; scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	int m; LL k; scanf("%d%lld",&m,&k);
	rep(i,1,n - 1) ind[i] = i;
	rep(i,1,m) { int x; scanf("%d",&x); swap(ind[x - 1], ind[x]); }
	rep(i,1,n - 1) if (!vis[i]) {
		cl = 0; c[cl++] = i; vis[i] = true;
		for(int x = ind[i]; x != i; x = ind[x]) c[cl++] = x, vis[x] = true;
		rep(j,0,cl - 1) {
			int t = c[(j + k) % cl];
			d[c[j]] = a[t + 1] - a[t];
		}
	}
	LL s = a[1];
	rep(i,1,n) printf("%lld\n",s), s += d[i];
	return 0;
}

Measured memory_bytes: 2944
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
int c[300001];
int main(){
	
	
	long long n;
	long long q;
	
	cin>>n>>q;
	
	int a;
	for(long long i=0;i<n;i++){
		cin>>a;
		c[a]=1;
	}
	int b=0;
	for(long long i=0;i<300001;i++){
		if(c[i])
			b=i;
		c[i]=b;
	}
	for(long long i=0;i<q;i++){
		long long m;
		cin>>m;
		long long ans=0;
		for(long long j=m-1;j<=300000;j+=m){
			ans=max(ans,c[j]-j+m-1);
		}
		cout<<ans<<endl;
	}
	
}

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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;


void solve(int z) {
    string s;
    cin >> s;
    if(s == "ARC") cout << "ABC";
    else cout << "ARC";
}

/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    
    return 0;
}
 



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int solve(int n, vector<char> const & c, vector<int> const & a) {
    auto delta_w = vectors(n + 1, n + 1, int());
    REP (w, n + 1) {
        REP (i, 2 * n) {
            if (c[i] == 'B') {
                delta_w[w][0] += 1;
                delta_w[w][a[i] + 1] -= 1;
            } else {
                if (a[i] == w) break;
                delta_w[w][0] += (a[i] >= w);
            }
        }
        REP (b, n) {
            delta_w[w][b + 1] += delta_w[w][b];
        }
    }

    auto delta_b = vectors(n + 1, n + 1, int());
    REP (b, n + 1) {
        REP (i, 2 * n) {
            if (c[i] == 'B') {
                if (a[i] == b) break;
                delta_b[0][b] += (a[i] >= b);
            } else {
                delta_b[0][b] += 1;
                delta_b[a[i] + 1][b] -= 1;
            }
        }
        REP (w, n) {
            delta_b[w + 1][b] += delta_b[w][b];
        }
    }

    auto dp = vectors(n + 1, n + 1, INT_MAX);
    dp[0][0] = 0;
    REP (w, n + 1) {
        REP (b, n + 1) {
            if (w - 1 >= 0) {
                chmin(dp[w][b], dp[w - 1][b] + delta_w[w - 1][b]);
            }
            if (b - 1 >= 0) {
                chmin(dp[w][b], dp[w][b - 1] + delta_b[w][b - 1]);
            }
        }
    }
    return dp[n][n];
}

int main() {
    int n; cin >> n;
    vector<char> c(2 * n);
    vector<int> a(2 * n);
    REP (i, 2 * n) {
        cin >> c[i] >> a[i];
        -- a[i];
    }
    cout << solve(n, c, a) << endl;
    return 0;
}


Measured memory_bytes: 47488
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(w: str):
    base = ord('a')
    b = [0] * 26
    for s in w:
        b[ord(s)- base] += 1
    for i in b:
        if i % 2 != 0:
            print(NO)
            return

    print(YES)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    w = next(tokens)  # type: str
    solve(w)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61932
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
    }

    println!("{}", n * n * n);
}



Measured memory_bytes: 4352
#include<stdio.h>

int main(void){
	int n=0;
	int i;
	int data[5];
	int sum=0;
	int max=0,min=500;

	scanf("%d",&n);
	while(n != 0){
		for(i=0;i<n;i++){
			scanf("%d %d %d %d %d",&data[0],&data[1],&data[2],&data[3],&data[4]);
			sum=data[0]+data[1]+data[2]+data[3]+data[4];
			if(max<sum){
				max=sum;
			}

			if(min>sum){
				min=sum;
			}
		}
		printf("%d %d\n",max,min);
		sum=0;
		max=0;
		min=500;
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

using ll = long long;
#define loop(i, n) for (int i = 0; i < (int)n; i++)

int main() {
	string s; cin >> s;
	loop(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i]) {
			cout << "No" << endl; return 0;
		}
	}
	loop(i, (s.size() / 2) / 2) {
		if (s[i] != s[s.size() / 2 - 1 - i]) {
			cout << "No" << endl; return 0;
		}
	}
	loop(i, (s.size() / 2) / 2) {
		if (s[s.size() / 2 + 1 + i] != s[s.size() - 1 - i]) {
			cout << "No" << endl; return 0;
		}
	}
	cout << "Yes" << endl;
}


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

int main() {
    int N;
    cin>>N;
    vector<int> d(N);
    rep(i,N){
        cin>>d.at(i);
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    int dansuu=0;
    rep(i,N){
        dansuu++;
        if(i==N-1){
            break;
        }
        if(d.at(i)==d.at(i+1)){
            dansuu--;
        }
    }
    cout<<dansuu<<endl;
}

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

using namespace std;

int main()
{
	//std::cout << "Hello World!\n"; 

	int N;
	string a, b, c;
	cin >> N >> a >> b >> c;

	int count = 0;
	for (int ic = 0; ic < N; ic++) {
		// aとｂが一緒
		if (a.c_str()[ic] == b.c_str()[ic] && a.c_str()[ic] == c.c_str()[ic]) {

		}
		else if (a.c_str()[ic] == b.c_str()[ic] && a.c_str()[ic] != c.c_str()[ic]) {
			count += 1;
		}
		else if (b.c_str()[ic] == c.c_str()[ic] && a.c_str()[ic] != b.c_str()[ic]) {
			count += 1;
		}
		else if (a.c_str()[ic] == c.c_str()[ic] && b.c_str()[ic] != c.c_str()[ic]) {
			count += 1;
		}
		else{
			count += 2;
		}

	}
	cout << count;

	return 0;
}

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

const ll m = 100 / 0.08 + 10;

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

    for (ll i = 1; i < m; i++)
    {
        if (floor(i * 0.08) == a && floor(i * 0.1) == b)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] str = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int k=sc.nextInt();
        sc.close();
        System.out.println(str[k-1]);
    }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> vc;
  vector<int> day[101010];
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    vc.push_back(P(b, a));
    if (0 <= m - a) {
      day[m - a].push_back(i);
    }
  }
  priority_queue<P> que;
  ll ans = 0;
  for (int i = m; i >= 0; --i) {
    REP(j, day[i].size()) {
      int tmp = day[i][j];
      que.push(vc[tmp]);
    }
    if (que.size()) {
      P p = que.top();
      que.pop();
      ans += p.first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8432
// finish date: 2019/06/09

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int H, W;
    cin >> H >> W;
    vs S(H + 2);
    FOR(i, 1, H + 1) {
        cin >> S[i];
        S[i] = "#" + S[i] + "#";
    }
    S[0] = "";
    S[H + 1] = "";
    rep(i, W + 2) {
        S[0] += "#";
        S[H + 1] += "#";
    }


    vvi left(H + 2, vi(W + 2, 0));
    vvi right(H + 2, vi(W + 2, 0));
    vvi up(H + 2, vi(W + 2, 0));
    vvi down(H + 2, vi(W + 2, 0));

    FOR(i, 1, H + 1) {
        FOR(j, 1, W + 1) {
            if (S[i][j] == '#') continue;
            if (S[i][j - 1] == '.') left[i][j] += left[i][j - 1] + 1;
        }
    }

    FOR(i, 1, H + 1) {
        for (int j = W; j >= 1; j--) {
            if (S[i][j] == '#') continue;
            if (S[i][j + 1] == '.') right[i][j] += right[i][j + 1] + 1;
        }
    }


    FOR(j, 1, W + 1) {
        FOR(i, 1, H + 1) {
            if (S[i][j] == '#') continue;
            if (S[i - 1][j] == '.') up[i][j] += up[i - 1][j] + 1;
        }
    }

    FOR(j, 1, W + 1) {
        for (int i = H; i >= 1; i--) {
            if (S[i][j] == '#') continue;
            if (S[i + 1][j] == '.') down[i][j] += down[i + 1][j] + 1;
        }
    }

    int ma = 0;

    FOR(i, 1, H + 1) {
        FOR(j, 1, W + 1) {
            ma = max(ma, 1 + left[i][j] + right[i][j] + up[i][j] + down[i][j]);
        }
    }
    cout << ma<< endl;

    return 0;
}


Measured memory_bytes: 71040
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const double eps = 1e-10;
const int maxn = 1e5 + 100;

int main() {
#ifdef ac
    //freopen("in.txt" , "r" , stdin);
//    freopen("out.txt" , "w" , stdout);
#endif
    int n;
    cin >> n;
    cout << n*(n+1)/2 <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        
        int[] A =new int[N];
        
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
        }
        long max =A[0]+(K-A[N-1]);
        
        for(int i=0;i<N-1;i++){
            max = Math.max(max, A[i+1]-A[i]);
        }
        System.out.println(K-max);
        
    }
}


Measured memory_bytes: 60860
N = int(input())
B = [int(i) for i in input().split()]
S = [0]*N
cnt = 0
for i in range(N-1, -1, -1):
  A = S[i::i+1]
  if sum(A)%2 == B[i]:
    continue
  elif sum(A)%2 == 0 and B[i] == 1:
    S[i] += 1
    cnt += 1
  elif sum(A)%2 == 1 and B[i] == 0:
    S[i] += 1
    cnt += 1
print(cnt)
l = []
for i in range(N):
  if S[i] == 1:
    l.append(i+1)
print(" ".join(map(str,l)))

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

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

    sort(A.begin(), A.end(), greater<int>());

    for(int i = 0; i <N; ++i){
       if(i % 2 == 0){
           Alice.push_back(A[i]);
       }else{
           Bob.push_back(A[i]);
       }
    }

    cout << accumulate(Alice.begin(), Alice.end(), 0) - accumulate(Bob.begin(), Bob.end(), 0) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin>>N>>S;
  bool answer=true;
  int a=N/2;
  if(N%2==1){
  cout<<"No"<<endl;
answer=false;
  }
  else{
  for(int i=0; i<a; i++){
  if(S.at(i)==S.at(a+i)){
  }
  else{
  cout<<"No"<<endl;
  answer=false;
  }
  }
  }
  if(answer==true){
  cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)

def f(i):
    if dp[i] != -1 and dp[i] != 0: return dp[i]
    if dp[i] == -1: return 0

    if i == -1:
        return f(i - 1)
    elif i > 1:
        dp[i] = f(i - 1) + f(i - 2)
    else:
        dp[i] = f(i - 1)
    return dp[i]

n,m = map(int,input().split())
dp = [0]*(n+1)
ary = [int(input()) for _ in range(m)]
dp[0] = 1
for i in ary:
    dp[i] = -1
    if dp[i-1] == -1 and dp[i] == -1:print(0);exit()
print(f(n)%(10**9+7))


Measured memory_bytes: 494196
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)



int main(void){
	int n,c,d,c_;
	cin>>n>>c;
	vector<vector<int> >D;
	vector<int> v;
	D.push_back(v);
	rep(i,c){
		vector<int> v;
		v.push_back(INF);
		rep(j,c){
			cin>>d;
			v.push_back(d);
		}
		D.push_back(v);
	}
	ll C[3][31];
	rep(i,3){
		rep(j,32){
			C[i][j] = 0;
		}
	}
	rep(i,n){
		rep(j,n){
			cin>>c_;
			C[(i+j)%3][c_]++;
		}
	}
	ll ans = LINF;
	reps(i,c){
		reps(j,c){
			if(i==j) continue;
			reps(k,c){
				if(i==k) continue;
				if(j==k) continue;
				ll memo = 0;
				reps(s,c){
					memo += D[s][i] * C[0][s];
				}
				reps(s,c){
					memo += D[s][j] * C[1][s];
				}
				reps(s,c){
					memo += D[s][k] * C[2][s];
				}
				ans = min(ans,memo);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

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

	ll res = 0;
	if (n % 2) res = 0;
	else {
		ll tmp = 10;
		while (tmp <= n) {
			res += n / tmp;
			tmp *= 5;
		}
	}
	cout << res << '\n';
    return 0;
}


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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n = 0;
	std::vector<int> a;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

	for(;;){
#if INPUT_FROM_FILE
		ifs >> n;
#else
		std::cin >> n;
#endif
		if(n == 0){ break; }

		a.resize(n);
		for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
			ifs >> a[i];
#else
			std::cin >> a[i];
#endif
		}

		long max_sum = -1000000000;

		for(int i = 0; i < n; i++){
			long sum = a[i];
			if(max_sum < sum){
				max_sum = sum;
			}
			for(int j = i + 1; j < n; j++){
				sum += a[j];
				if(max_sum < sum){
					max_sum = sum;
				}
			}
		}

		std::cout << max_sum << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3108
def resolve():
    a, b, c, x, y = map(int, input().split())
    ans = 0
    if a+b > 2*c:
        com = min(x, y)
        ans += 2*c*com
        if x > y:
            if a >= 2 * c:
                ans += 2 * c * (x-com)
            else:
                ans += a * (x-com)
        elif x < y:
            if b >= 2 * c:
                ans += 2 * c * (y-com)
            else:
                ans += b * (y-com)
    else:
        ans += a*x + b*y

    print(ans)

if __name__ == '__main__':
    resolve()

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

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

  ll ans = 0;
  rep(i, 0, (1 << (sz(S) - 1))) {
    ll total = 0;
    string num(1, S[0]);

    rrep(j, sz(S) - 1, 0) {
      if (i & (1 << j)) {
        total += stoll(num);
        num = "";
      }
      num += S[sz(S) - j - 1];
    }
    total += stoll(num);

    ans += total;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

int main() 
{
    int i;
    long  m,h[10000],n,s;
    m>=1;
    n>=1;
    m<=10000;
    n<=1000000;
    scanf("%ld%ld",&n,&m);
    s=n;
    for(i=0;i<m;i++)
	{
		scanf("%ld",&h[i]);
		
	}	
	for(i=0;i<m;i++)
	{
		s = s - h[i];
	}
	if(s>=0)
	  printf("%ld",s);
	else 
	   printf("-1");
	return 0;
}

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

ll N, C;
ll diff[35][35];
ll c[510][510];
ll cost[3][35];

int main(int argc, char **argv)
{
	cin >> N >> C;
	for (ll c1 = 0; c1 < C; ++c1)
		for (ll c2 = 0; c2 < C; ++c2)
			cin >> diff[c1][c2];
	for (ll n1 = 0; n1 < N; ++n1)
		for (ll n2 = 0; n2 < N; ++n2)
			cin >> c[n1][n2], --c[n1][n2];

	memset(cost, 0, sizeof(cost));
	for (ll n1 = 0; n1 < N; ++n1)
		for (ll n2 = 0; n2 < N; ++n2)
			for (ll ci = 0; ci < C; ++ci)
				cost[(n1+n2)%3][ci] += diff[(c[n1][n2])][ci];

	// std::cout << "----------"<< std::endl;
	// for (ll i = 0; i < 3; ++i)
	// {
	// 	std::cout << i << " : ";
	// 	for (ll ci = 0; ci < C; ++ci)
	// 		std::cout << cost[i][ci]<< " ";
	// 	std::cout << std::endl;
	// }
	// std::cout << "----------"<< std::endl;

	ll res{1ll<<60};
	for (ll c1 = 0; c1 < C; ++c1) // 0
	{
		for (ll c2 = 0; c2 < C; ++c2) // 1
		{
			if (c1 == c2) continue;
			for (ll c3 = 0; c3 < C; ++c3) // 2
			{
				if (c1 == c3 || c2 == c3) continue;
				ll tmp {0};
				tmp += cost[0][c1];
				tmp += cost[1][c2];
				tmp += cost[2][c3];
				res = min(res, tmp);
			}
		}
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
int a[N];
void solve_test_case(){
	int n,c = 0;
	cin>>n;
	for(int i = 0;i < n;++i){
		cin>>a[i];
	}
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 0;i < n;++i){
		for(int j: {i+1,i+2}){
			if(j < n){
				dp[j] = min(dp[j],dp[i] + abs(a[i] - a[j]));
			}
		}
	}
	cout<<dp[n-1]<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	for(int i = 0;i < t;++i){
		solve_test_case();
	}
}


Measured memory_bytes: 4020
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int n;cin>>n;
  vector<string> data(n);
  for(int i=0;i<n;i++){
    string tmp;cin>>tmp;
    sort(tmp.begin(),tmp.end());
    data[i]=tmp;
  }
  sort(data.begin(),data.end());
  string past=data[0];
  ll ans=0;
  ll gar=1;
  for(int i=1;i<data.size();i++){
    string now=data[i];
    if(now!=past){
      past=now;
      ans+=gar*(gar-1)/2;
      gar=1;
    }else{
      gar++;
    }
  }
  if(gar!=1){
    ans+=gar*(gar-1)/2;
  }
  cout<<ans<<endl;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;

constexpr int INF = 1e9;
constexpr ld pi = acos(-1);

int main() {
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    if(sx >= gx && sy >= gy) {
        swap(sx, gx);
        swap(sy, gy);
    }
    int lx = min(sx, gx);
    int ly = min(sy, gy);
    int rx = max(sx, gx);
    int ry = max(sy, gy);
    int N;
    cin >> N;
    vector<pii> v(N);
    ld res = abs(sx - gx) + abs(gy - sy);
    res *= 100;
    int dummy;
    bool f = false;
    for(int i = 0; i < N; ++i) {
        cin >> v[i].first >> v[i].second;
        if(sx == gx && sx == v[i].first && ly <= v[i].second && v[i].second <= ry || sy == gy && lx <= v[i].first && v[i].first <= rx && v[i].second == sy) {
            f = true;
        }
        if(sx <= gx && sy <= gy) {
            dummy = INF;
            continue;
        } else if(sx <= gx && sy >= gy) {
            v[i].second = -v[i].second;
            dummy = 1;
        } else if(sx >= gx && sy <= gy) {
            v[i].first = -v[i].first;
            dummy = INF;
        } else {
            v[i].first = -v[i].first;
            v[i].second = -v[i].second;
            dummy = 1;
        }
    }
    if(f) {
        res += 20.0 * (pi / 2 - 1);
        cout << fixed << setprecision(12) << res << endl;
        return 0;
    }
    sort(v.begin(), v.end());
    vector<int> LIS(N, dummy);
    for(auto& p : v) {
        if(lx <= abs(p.first) && abs(p.first) <= rx && ly <= abs(p.second) && abs(p.second) <= ry) {
            *lower_bound(LIS.begin(), LIS.end(), p.second) = p.second;
        }
    }
    int cnt = find(LIS.begin(), LIS.end(), dummy) - LIS.begin();
    if(cnt == ry - ly + 1 || cnt == rx - lx + 1) {
        cnt--;
        res += 20.0 * (pi / 2 - 1);
    }
    //cout << "cnt: " << cnt << endl;
    res -= 20.0 * cnt * (1.0 - pi / 4.0);
    cout << fixed << setprecision(12) << res << endl;
}


Measured memory_bytes: 2560
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int n,k,a[200000+1];
	cin>>n>>k;
	rb(i,1,n)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	LL res=0;
	rb(i,1,n-k){
		res+=a[i];
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(size_t i=l; i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int,int>;
using pii = pair<int,int>;
using ti3 = tuple<int,int,int>;

int main(){
	int k,n; cin>>k>>n;
    int a[n]; REP(i,n) cin>>a[i];
    int max_dist=a[0]+(k-a[n-1]);
    REP(i,n-1){
    	max_dist=max(max_dist,a[i+1]-a[i]);
    }
    cout<<k-max_dist<<endl;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N,X = map(int,input().split())
memo = {}
memo[(1,1)] = 1
def cost(N,X):
 L=2**(N+1)-3
 ans=0
 if X==1:
  ans=0
 elif X==2**(N+1)-3:
  ans=2**N-1
 elif X==(L+1)//2:
  if (N-1,X-2) in memo:
   ans=memo[(N-1,X-2)]+1
  else:
   ans=cost(N-1,X-2)+1
 elif X>(L+1)//2:
  if (N-1,X-((L+1)//2)) in memo:
   ans=2**(N-1)+memo[(N-1,X-((L+1)//2))]
  else:
   ans=2**(N-1)+cost(N-1,X-((L+1)//2))
 else:
  if (N-1,X-1) in memo:
   ans=memo[(N-1,X-1)]
  else:
   ans=cost(N-1,X-1)
 memo[(N,X)]=ans
 return ans
print(cost(N+1,X))

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

using namespace std;

int cards[55],n;

void init(){
	int i;
	for(i=0; i<n; i++){
		cards[i+1] = (n-i);
	}
}

void shuffle(int p,int c){
	int tmp[55],i;
	for(i=1; i<=n; i++){
		tmp[i] = cards[i];
	}
	for(i=0; i<c; i++){
		cards[i+1] = tmp[p+i];
	}
	for(i=1; i<p; i++){
		cards[c+i] = tmp[i];
	}
}

int main(void){
	int r,i,p,c;
	while(true){
		cin >> n >> r;
		if(n==0 && r==0){
			break;
		}
		init();
		for(i=0; i<r; i++){
			cin >> p >> c;
			shuffle(p,c);
		}
		cout << cards[1] << endl;
	}
	return 0;
}

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

int n,k,ans=inf, diff = 0;

int main(){
  cin >> n >> k;
  
  vector<int> h(n);
  rep(i,n) cin >> h.at(i);
  
  sort(h.begin(),h.end());
  
  for(int i = 0; i < n-k+1; i++){
    diff = abs(h.at(i+k-1)-h.at(i));
    ans = min(ans, diff);
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[13];
        int freeC = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[a / 400]++;
        }
        int ans = 0;
        for (int i = 0; i < 13; i++) {
            if (i >= 8 && ary[i] != 0) {
                freeC += ary[i];
            } else if (ary[i] != 0) {
                ans++;
            }
        }
        if (ans == 0 && freeC != 0) {
            System.out.println(1 + " " + freeC);
        } else {
            System.out.println(ans + " " + (ans + freeC));
        }
    }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int now=0,is=1;
    rep(i,10000){
        if(now%60+a>=c && c>=now%60){
            cout<<now/60*60+c;
            is=0;
            break;
        }else{
            now+=a+b;
        }
    }
    if(is)cout<<-1;
    cout<<endl;
}

Measured memory_bytes: 3096
#include <iostream>
#include <climits>
#include <cstdlib>
using namespace std;

string t = "753";
string s;

int solve(string x, bool isZero, int used) {
  if (x.size() == s.size()) {
    if (s >= x && used == (1 << 3) - 1) {
      return 1;
    }
    return 0;
  }

  int res = 0;
  
  if (isZero) {
    res += solve(x + "0", isZero, used);
  }
  for (int i = 0; i < 3; i++) {
    res += solve(x + t[i], false, used | (1 << i));
  }

  return res;
}

int main() {
  while (cin >> s) {
    cout << solve("", true, 0) << endl;
  }
}


Measured memory_bytes: 384
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]

ans = 0

for x in A:
    y = sum([x[i]*B[i] for i in range(M)]) + C
    if y>0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
import math
a,b,c = map(int,input().split())

#r_a = math.sqrt(a) 
#r_b = math.sqrt(b)
#r_c = math.sqrt(c)
#s = a+b+2*r_a*r_b
#t = r_a + r_b
d = c-a-b

if(d>0 and (d*d > 4*a*b)):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int[] c = new int[26];
    String ans = "yes";
    for (int i = 0; i < S.length(); i++) {
      char a = S.charAt(i);
      if (c[a-'a'] == 1) {
        ans = "no";
        break;
      }
      c[a-'a'] = 1;
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124