akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = ~(1<<31);
const double pi = acos(-1);
 
int main() {
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	map<char,int> og;
	string s;
	cin >> s;
	rep(i,0,s.size()) og[s[i]]++;
	rep(i,0,n-1) {
		cin >> s;
		map<char,int> ne;
		rep(a,0,s.size()) ne[s[a]]++;
		iter(it,og) {
			og[it->first] = min(it->second, ne[it->first]);
		}
	}
	string best = "";
	iter(it,og) {
		char da = it->first;
		rep(i,0,it->second) best+=da;
	}
	cout << best << endl;
	return 0;
}


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

int main(){
	int n;
	cin>>n;
	string s[n];
	int p[n];
	map<string,vector<pair<int,int>>> mp;
	rep(i,n){
		cin>>s[i]>>p[i];
		mp[s[i]].push_back(make_pair(p[i],i));
	}
	
	sort(s,s+n);
	
	for(auto a:mp){
		sort(mp[a.first].begin(),mp[a.first].end(),[](pair<int,int> x,pair<int,int> y){return x.first>y.first;});
	}
  	rep(i,n-1){
      	if(s[i]==s[i+1])continue;
		vector<pair<int,int>> v = mp[s[i]];
		for(auto a:v){
			puts(a.second+1);
		}
	}
      vector<pair<int,int>> v = mp[s[n-1]];
		for(auto a:v){
			puts(a.second+1);
		}

      
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
using namespace std;

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

    vector<ll> moves(n, 0);
    for(ll i = 0; i < n; i++) {
        cin>>moves[i];
    }

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

    ll i = 0;
    while(h > 0 && i < n) {
        h -= moves[i];
        i++;
    }

    if(h > 0) {
        cout<<"No"<<'\n';
    }
    else {
        cout<<"Yes"<<'\n';
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ll long long unsigned
#define pii pair<int,int>
#define tii tuple <int,int,int>
#define N 1000005
#define mod 2000003
#define X first
#define Y second
#define eps 0.0000000001
#define all(x) x.begin(),x.end()
#define tot(x) x+1,x+n+1
using namespace std;
string s;
int n,m,i;
int main()
{
    cin.sync_with_stdio(0);
    cout.sync_with_stdio(0);
    cin>>n>>m;
    for(i=1; i<n; i++)
    {
        cin>>s;
        cout<<s<<'\n'<<s<<'\n';
    }
    cin>>s;
    cout<<s<<'\n'<<s;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

ll dp[60][60][3000];

int main(void){
  ll n, k;
  cin >> n >> k;
  fill(dp[0][0], dp[0][0]+60*60*3000, 0LL);
  dp[0][0][0] = 1;
  for(int i = 0;i < n;++i){
    for(int j = 0;j <= i;++j){
      for(int k = 0;k < 3000;++k){
        if(k + 2*j < 3000) {
          ll delta = ((2*j+1) * dp[i][j][k]) % mod;
          dp[i+1][j][k + 2*j] += delta;
          dp[i+1][j][k + 2*j] %= mod;
        }
        if(j > 0 && k + 2*(j-1) < 3000){
          ll delta = ((j * j) * dp[i][j][k]) % mod;
          dp[i+1][j-1][k + 2*(j-1)] += delta;
          dp[i+1][j-1][k + 2*(j-1)] %= mod;
        }
        if(k + 2*(j+1) < 3000){
          dp[i+1][j+1][k + 2*(j+1)] += dp[i][j][k];
          dp[i+1][j+1][k + 2*(j+1)] %= mod;
        }
      }
    }
  }
  cout << dp[n][0][k] << endl;
  return 0;
}


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

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

    vector<int> vec(N),check(N,0);
    int ans = 0;

    for(int i = 0; i < N; i++) {
        cin >> vec.at(i);
        if(vec.at(i) > N) {
            ans++;
        }else {
            check.at(vec.at(i) - 1)++;
        }
    }

    for(int i = 0; i < N; i++) {
        if(check.at(i) > i + 1) {
            ans += check.at(i) - i - 1;
        }else if(check.at(i) < i + 1) {
            ans += check.at(i);
        }
    }

    // for(int i = 0; i < N; i++) {
    //     cout << check.at(i) << " ";
    // }
    cout << ans << endl;
    
    
 }


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#define N 1000000
int tl[N];

using namespace std;

void sort(int,int);
int syori(int,int);

int main(){
  int n,m,i,ans;
  while(1){
    for(i=0;i<N;i++){
      tl[i]=0;
    }
    


  cin >> n; 
  cin >> m;

  if(m==0 && n==0) break;

  for(i=1;i<=n;i++){
    cin >> tl[i];
  }

  for(i=n+1;i<=(m+n);i++){
    cin >> tl[i];
  }

  sort(m,n);


  ans=syori(n,m);

  cout << ans << endl;

  }
  return 0;
}


void sort(int m , int n){
  int i,j,max,hi;


  for(i=0;i<=(m+n);i++){
    max=i;
    for(j=i;j<=(m+n);j++){
      if(tl[j] < tl[max])max=j;
    }
    hi=tl[max];
    tl[max]=tl[i];
    tl[i]=hi;
  }


  //  for(i=0;i<=(m+n);i++){
  // cout << tl[i] << endl;;

  //}

}


int syori(int n, int m){
  int i,max=0;
  for(i=0;i<(m+n);i++){
    if(tl[i+1]-tl[i]>=max)max=tl[i+1]-tl[i];
  }

  return max;
}

Measured memory_bytes: 4772
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int X;
  cin >> X;
  for (int i = 1; i <= 10000; ++i) {
    int n = 360 * i;
    if (n % X == 0) {
      cout << n / X << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    reverse(all(s));
    //cout<<s<<endl;
    int i=0;
    while(i<s.size()){
        if(s.substr(i,5)=="maerd") i+=5;
        else if(s.substr(i,7)=="remaerd") i+=7;
        else if(s.substr(i,5)=="esare") i+=5;
        else if(s.substr(i,6)=="resare") i+=6;
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}



Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define df 0
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  string s; cin >>s;
  int n=s.size();
  cout << s.at(0) << n-2 << s.at(n-1);
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int asc(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int main(void) {
	int n;
	int p[50];
	int p1[50];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
		int tmp = p[i];
		p1[i] = tmp;
	}
	qsort(p1, n, sizeof(int), asc);
	int c = 0;
	int x[50];
	for (int i = 0; i< n; i++) {
		if (p1[i] != p[i]) {
			x[c] = i;
			c++;
		}
	}
	if (c == 0) {
		printf("YES");
	}else {
		if (c == 2) {
			int tmp = p[x[0]];
			p[x[0]] = p[x[1]];
			p[x[1]] = tmp;
		}
		c = 0;
		for (int i = 0; i < n; i++) {
			if (p1[i] != p[i]) {
				printf("NO");
				break;
			}
			c++;
		}
		if (c == n) {
			printf("YES");
		}
	}
	return 0;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll n;
    cin >> n;
    cout << (n * (n-1))/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> W(N);
    int ans = 100000000;
    for(int i = 0; i < N; i++)
    {
        cin >> W[i];
    }
    for(int i = 1; i < N; i++)
    {
        int S1 = 0;
        int S2 = 0;
        for(int j = 0; j < i; j++)
        {
            S1 += W[j];
        }
        for(int j = i; j < N; j++)
        {
            S2 += W[j];
        }
        if(abs(S1-S2)<ans)
        {
            ans = abs(S1-S2);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string N;
  const char *nd = NULL;
  int count = 1;
  int max = 0;
  cin >> N;
  nd = N.data();
  for (int i = 1; i < N.length(); i++) {
    if (nd[i - 1] == nd[i]) {
      count++;
      if (count > max) {
        max = count;
      }
    } else {
      count = 1;
    }
  }
  if (max >= 3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int a,b;
cin >> a >> b;
if(a <= 8 && b <= 8) cout << "Yay!" << endl;
else cout << ":(" << endl;

return 0;
}

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, X; cin >> K >> X;
    if (K * 500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
result = 0
target = 1
while target <= N:
    div, div_count = 1, 0
    while div <= N:
        if target % div == 0:
            div_count += 1
        div += 2
    if div_count == 8:
        result += 1
    target += 2
print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#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(){
    string a, b, c;
    vector<vector<int>> p(3, vector<int>(0));
    cin >> a >> b >> c;
    for(int i=a.size()-1; i>=0; i--){
        if(a.at(i) == 'a') p.at(0).push_back(0);
        if(a.at(i) == 'b') p.at(0).push_back(1);
        if(a.at(i) == 'c') p.at(0).push_back(2);
    }
    for(int i=b.size()-1; i>=0; i--){
        if(b.at(i) == 'a') p.at(1).push_back(0);
        if(b.at(i) == 'b') p.at(1).push_back(1);
        if(b.at(i) == 'c') p.at(1).push_back(2);
    }
    for(int i=c.size()-1; i>=0; i--){
        if(c.at(i) == 'a') p.at(2).push_back(0);
        if(c.at(i) == 'b') p.at(2).push_back(1);
        if(c.at(i) == 'c') p.at(2).push_back(2);
    }
    int pi = 0;
    vector<int> abc(3);
    abc.at(0) = a.size()-1;
    abc.at(1) = b.size()-1;
    abc.at(2) = c.size()-1;
    int win = 0;
    for(int i=0; i>=0; i){
        abc.at(pi)--;
        if(abc.at(pi) == -2){
            win = pi;
            break;
        }
        pi = p.at(pi).at(abc.at(pi)+1);
    }
    if(win == 0){
        cout << 'A' << endl;
    }else if(win == 1){
        cout << 'B' << endl;
    }else{
        cout << 'C' << endl;
    }
    return 0;
}


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

char a[200100];
int s,co;

main()
{
	s=0;
	co=0;
	scanf("%s",a);
	for(int i=0;a[i];i++)
	{
		if(a[i]=='S')
		{
			s++;
		}
		else
		{
			if(s)
			{
				s--;
			}
			else
			{
				co++;
			}
		}
	}
	printf("%d",s+co);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
vector<vector<int>> A(MAX);
int reward[MAX];

int main(){

    // 1. 入力情報取得.
    int N, M;
    scanf("%d %d", &N, &M);
    for(int i = 0; i < N; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(a <= M) A[a].push_back(b);
    }
    
    // 2. どの仕事を請けるか確定させる.
    //      (報酬支払日／仕事開始日)
    // No.1  M     日後 : 0日目
    // No.2  M - 1 日後 : 1日目まで.
    // No.3  M - 2 日後 : 2日目まで.
    // No.4  M - 3 日後 : 3日目まで.
    // ...
    // No.M      1 日後 : M - 1日目まで.
    // -> 仕事開始日が最も遅い, No.M から順に, 仕事出来るかどうかを決めていく.
    // -> 具体的には, 以下の流れで, 仕事を請けるか決定していくイメージ.
    // No.M       の 仕事 が, X(M)件     あれば, 一番報酬 の 大きい仕事 を 請ける.
    // No.(M - 1) の 仕事 が, X(M - 1)件 あれば, No.M の 残りの仕事 と 併せて, 一番報酬の大きい仕事を引き受ける.
    // 以下, 繰り返し.
    // ※N件の制約事項は, 4. で対応.
    priority_queue<int> pq;
    for(int d = M - 1; d >= 0; d--){
        // 2-1. d日目で, 可能な仕事の報酬を取得.
        for(auto &r : A[M - d]) pq.push(r);
        
        // 2-2. 仕事があれば, 報酬情報(1件)を, rewardテーブルに登録.
        if(pq.size() > 0){
            int r = pq.top();
            pq.pop();
            reward[d] = r;
        }
    }
    
    // 3. 報酬の大きい順に並べ替える.
    sort(reward, reward + MAX, greater<int>());
    
    // 4. 最大 N件 まで請けた場合に, 報酬の最大値を計算.
    int ans = 0;
    for(int i = 0; i < N; i++) ans += reward[i];
    
    // 5. 出力 ～ 後処理.
    printf("%d\n", ans);
    return 0;

}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    for (int i = min(a, b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
            if (cnt == k) {
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
n=int(input())
k=int(input())
x=list(map(int,input().split()))

ans=0
for i in range(n):
    if abs(x[i]-0)<abs(x[i]-k):
        ans+=abs(x[i]-0)*2
    else:
        ans+=abs(x[i]-k)*2

print(ans)


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

int main(){
    int in1, in2, temp;
    cin >> in1 >> in2;
    if(in1>in2) swap(in1, in2);
    while(in2>0){
        temp = in1%in2;
        in1  =in2;
        in2 = temp;
    }
    cout << in1 << endl;

    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;

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

int main(){
    int n,k;
    cin >> n >> k;
    int x;
    int ans = 0;
    rep(i,n){
        cin >> x;
        ans += min(x, k-x);
    }

    cout << ans * 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;
    ll mod=998244353;
ll pr( ll x , ll y)
{
    ll ans=1;
    if(y==0) return ans;
    while(y>1)
    {
        if(y&1) ans*=x;
        x*=x;
        y/=2;
        x%=mod;
        ans%=mod;
    }
    ans*=x;
    ans%=mod;
    return ans;
}
ll fact( ll n)
{
    ll ans=1,i;
    rep(i,1,n+1)
    {
        ans*=i;
        ans%=mod;
    }
    return ans;
}
ll in(ll x) { return  pr(x,mod-2);}

void solve()
{
 ll i,j=1,k,n,m=0,f,s1=0,x,c=1,y=0,a=0,b=0,d;
 cin>>n>>m;
 vector < ll > v(n);
 rep(i,0,n) cin>>v[i],y+=v[i];
 sort(all(v));
 reverse(all(v));
 if(4LL*m*v[m-1]>=y) {cout<<"Yes";} else cout<<"No";
}


 //}

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
        // cin>>t;
        while(t--)
        solve();
    }


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

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    vector<int> c(n), b((int)2e5, -1);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }

    vector<int> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        ll t = dp[i];
        if (b[c[i]] >= 0 && b[c[i]] + 1 != i) {
            t += dp[b[c[i]] + 1];
            if (t >= P) t -= P;
        }
        dp[i + 1] = (int)t;
        b[c[i]] = i;
    }

    cout << dp[n] << endl;

    //内側の情報は消されるから考えなくていい 食い込むこともない
    //たくさんの合法手のうち、重ならないいくつかを選ぶ
    //1121を1111にするとき左のどちらの1を選ぶかは結果に影響しない
    //左から選ぶものを決めていってDP
    //最初のi個で完結する操作で何通りあるか
    //加算するのは現在の位置を右端とする操作 すぐ右隣は違う色を強制する

    return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep (i, n) { cin >> a[i]; }
    sort(all(a));
    int ans = 1e9;
    FOR (i, *begin(a), *(end(a)-1)+1) {
        int k = 0;
        rep (j, n) {
            k += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, k);
    }
    printf("%d\n", ans);
    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const ll mod = 1777777777ll;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int r = 0, l = 0;
  for(auto c : s) {
    if(c == '(') ++r;
    else {
      if(r > 0) --r;
      else ++l;
    }
  }
  rep(i, r) s += ')';
  reverse(ALL(s));
  rep(i, l) s += '(';
  reverse(ALL(s));
  cout << s << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int Max = 1e5 + 5;

int lst[Max];
int sum[Max];


int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	int l = 0;
	for (int i = 1;i <= m;i++)
	{
		int t;
		scanf("%d", &t);
		for (int j = l;j <= t-1;j++)
		{
			sum[j+1] = sum[j];
		}
		sum[t]++;
		l = t;
	}
	cout << min(sum[x - 1], sum[l] - sum[x]);

		
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <queue>
#include <iostream>
const int maxn=1e5+10;
const int mod=1e9+7;
using namespace std;

int main()
{
    long long n,m;
    cin>>n>>m;
    if(n==1 || m==1)
        printf("1\n");
    else{
        if(n%2==0){
            printf("%lld\n",n*m/2);
        }
        else{
            printf("%lld\n",n/2*m+(m+1)/2);
        }
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(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 pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll ab = a + b;
    ll ans = 0;
    
    while(true){
        if(n >= ab){
            ans += a * (n/ab);
            n %= ab;
        }else{
            break;
        }
    }
    
    if(n > a){
        ans += a;
    }else{
        ans += n;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys


TEST_INPUT = [
    """
    5 3
    1 2 2 4 5
    """,
    """
    4 1
    6 6 6 6
    """,
    """
    10 4
    17 13 13 12 15 20 10 13 17 11
    """
]
ANSWER = [
    "7.0",
    "3.5",
    "32.0"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, k, p_list):
    res = sum(p_list[:k])
    res_temp = res
    for i in range(n - k):
        res_temp -= p_list[i]
        res_temp += p_list[i + k]
        if res_temp > res:
            res = res_temp
    return (res + k) / 2


def input_and_solve(ih):
    n, k = map(int, ih.input().split())
    p_list = list(map(int, ih.input().split()))
    res = solve(n, k, p_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert abs(float(res) - float(ans)) < 0.00000001


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 25172
def f(x, y)
  r = Float::INFINITY

  # A
  if x<=y 
    r = [r, y - x].min
  end

  # AB
  if x<=-y
    r = [r, 1-y-x].min
  end

  # BA
  if -x<=y
    r = [r, 1+x+y].min
  end

  # BAB
  if -x<=-y
    r = [r, 2+x-y].min
  end
  r
end

x, y = gets.split.map(&:to_i)
p f(x, y)



Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int a =rint();
        WriteLine(a-(a/2));
        

    
    }
    //各種読取
    static string rstr(){ return ReadLine(); }
    static int rint(){ return int.Parse(ReadLine()); }
    static long rlong(){ return long.Parse(ReadLine()); }
    static string[] stra(){ return ReadLine().Split(' '); }
    static int[] inta(){ string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static int[,] inta2(int num_array,int in_array){ int[,] int_array2 = new int[num_array,in_array]; for(int i=0;i<num_array;i++){ int[] temp_array = inta(); for(int j=0;j<in_array;j++){ int_array2[i,j] = temp_array[j]; } } return int_array2; }
    static long[] longa(){ string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea(){ string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; }
    // A/B小数点以下切上
    static long divideup(long divided,long divid){ long temp_divide = divided/divid; if(divided % divid > 0){ temp_divide++; } return temp_divide; }
    static long GCD(long a,long b){ if(a < b){ long temp = a; a = b; b = temp; } if(a % b == 0){ return b; } else{ long temp = b; b = a%b; a = temp; return GCD(a,b); } }
    static long LCM(long a,long b){ return a * b / GCD(a,b); }
}
//知見
// (string) hogestr -> (char[]) hoge
    // char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
    // string hoge = new string(hoge);
// Hashtable ×  Dictionary ○
// Dictionary hoge<string,int>
    // hoge.ContainsKey(string) -> return boolean
    // hoge[string] -> return int
    // hoge[int] -> CE
// Dictionary hoge<int1,int2>
    // hoge<int1,int2>: hoge[int1] -> return int2
    // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー　-> 幅優先 ???
// スタック -> 深さ優先 ???
// if (list?.Count > 0) リストが空でもnullでもない


Measured memory_bytes: 11092
#include<stdio.h>
int check(char s){
  if(s == 'a' || s == 'b' || s == 'c' || s == 'd' || s == 'e' || s == 'f' || s == 'g' || s == 'h' || s == 'i' || s == 'j' || s == 'k' || s == 'l' || s == 'm' || s == 'n' || s == 'o' || s == 'p' || s == 'q' || s == 'r' || s == 's' || s == 't' || s == 'u' || s == 'v' || s == 'w' || s == 'x' || s == 'y' || s == 'z'){
    return 0;
  }
  return 1;
}

int main(){
  int ans1 = 0,ans2 = 0,ans3 = 0;
  char s[20];
  scanf("%s",&s);
  if(s[0] == 'A'){
    ans1 = 1;
  }
  for(int i = 1;i < strlen(s);i++){
    if(i > 1 && i < strlen(s) - 1 && s[i] == 'C'){
      ans3++;
    }else{
      ans2 += check(s[i]);
    }
  }
  if(ans1 == 1 && ans2 < 1 && ans3 == 1){
    printf("AC\n");
    return 0;
  }
  printf("WA\n");
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<utility>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int n,a,b,c;

int main(){
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	scanf("%d",&c);
	vector<int> v;
	for(int i=0;i<n;i++){
		int self;
		scanf("%d",&self);
		v.push_back(self);
	}
	sort(v.begin(),v.end(),greater<int>());
	int ans = 0;
	for(int i=0;i<n;i++){
		int cal = c;
		int cost = a;
		for(int j=0;j<i;j++){
			cal += v[j];
			cost += b;
		}
		int s = cal / cost;
		if(ans < s){ans = s;}
	}
	printf("%d\n",ans);
}

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

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


int main()
{
    int a; cin >> a;
    cout << a + a * a + a*a*a << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, l, r;

int main(){
	cin >> n;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> l >> r;
		cnt += r-l + 1;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
taro = 0
hana = 0
for _ in range(n):
    t, h = input().split()
    if t > h:
        taro += 3
    elif t < h:
        hana += 3
    else:
        taro += 1
        hana += 1
print(taro, hana)


Measured memory_bytes: 5596
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int digits(ll x) {
  int d = 1;
  while (x >= 10) {
    d++;
    x /= 10;
  }
  return d;
}

int main() {
  //
  ll n;
  cin >> n;
  ll rn = (ll)sqrt(n);
  for (ll x = rn; x >= 1; x--) {
    if (n % x == 0) {
      cout << digits(n / x) << endl;
      return 0;
    }
  }
  return 0;
}


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

int main() {
  int start, end;
  cin >> start >> end;
  int count = 0;
  
  for (int i = start; i <= end; i++) {
    string normal = std::to_string(i);
    
    string reversed = "";
    for (int j = 1; j <= normal.length(); j++){
      reversed += normal[normal.length() - j];
    }
    
    if (normal == reversed) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
typedef long long ll;
using namespace std;
typedef pair<ll,ll> P;
ll n;
vector<P> x;
const ll mod = 1e9 + 7;
int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    x.push_back(P(a,1));
  }
  for(int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    x.push_back(P(b,-1));
  }
  sort(x.begin(),x.end());
  ll c = 0;
  ll ans = 1;
  for(int i = 0; i < x.size(); i++) {
    if((c != 0) && (x[i].second > 0) != (c > 0)) ans = ans *  abs(c) % mod;
    c += x[i].second;
  }

  cout << ans << endl;
}
    


Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    string s;cin>>s;
    int n=s.size();
    ll res=0;
    REP(i,1<<(n-1)){
        vector<int> v;
        v.push_back(0);
        REP(j,n-1){
            if((i>>j)&1)v.push_back(j+1);
        }
        v.push_back(n);
        REP(j,v.size()-1){
            res+=stoll(s.substr(v[j],v[j+1]-v[j]));
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=map(int,input().split())

babies=[(a,i) for i ,a in enumerate(a)]

babies.sort(reverse=True)

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

ans=0

for l in range(n):
    for r in range(n):
        if l+r==n:
            ans=max(ans,dp[l][r])
            break
        activeness,ind=babies[l+r]
        dp[l+1][r]=max(dp[l+1][r],dp[l][r]+abs(ind-l)*activeness)
        dp[l][r+1]=max(dp[l][r+1],dp[l][r]+abs(ind-(n-1-r))*activeness)

print(ans)

Measured memory_bytes: 100640
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){

    int n, k;
    int d[5555];
    while(cin >> n, n){
      
      memset(d, 0, sizeof(d));
      for(int i=1;i<=n;i++){
	cin >> k;
	d[i] = d[i-1] + k;
      }
      
      int ans = -1<<28;  
      for(int i=0;i<=n;i++){
	for(int j=i+1;j<=n;j++){
	  ans = max(ans, d[j]-d[i]);
	}
      }
      
      cout << ans << endl;
    }
}

Measured memory_bytes: 1188
import collections
n = int(input())
l = list(input())
l = collections.Counter(list(l))
for i in range (n-1):
    l_temp = list(input())
    l_temp = collections.Counter(list(l_temp))
    l = l & l_temp
alphabet = [chr(ord('a') + i) for i in range(26)]
ans = []
for i in range (len(alphabet)):
    if l[alphabet[i]]>0:
        ans.extend([alphabet[i]]*l[alphabet[i]])
print(''.join(ans))

Measured memory_bytes: 3316
N = int(input())
s = input()
t = input()
if s == t:
    print(len(s))


else:
    ans = N * 2
    for i in range(N):
        a = s[:i] + t
        if a[:N] == s:
            ans = min(ans, len(a))

        a = s + t[i:]
        if a[N:] == t:
            ans = min(ans, len(a))

    print(ans)


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

int main(){
    int H,W,K; cin >> H >> W >> K;
    vector<string> C(H);
    for(int i = 0; i < H; i++)cin >> C[i];
    int ans = 0;

    for(int bitH = 0; bitH < (1<<H); ++bitH){
        for(int bitW = 0; bitW < (1<<W); ++bitW){
            int con = 0;
            for(int i = 0; i < H; i++){
                if(bitH&(1<<i)){
                    for(int j = 0; j < W; j++){
                        if(bitW&(1<<j)){
                            if(C[i][j]=='#')con++;
                        }
                    }
                }
            }
            //cout << con << endl;
            if(con == K)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;


int main(){
    double t,x; cin>> t >> x;
    cout << t/x << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


const int MAX = 510000;
const int MOD = 1000000007;
long long fac[510000], finv[510000], inv[510000];

void COMinit() {
	fac[0] = fac[1] = 1; finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

	int N, b, c;
	cin >> N;
	int mp[100010];
	eREP(i, N)mp[i] = -1;

	REP(i, N + 1) {
		int a;
		cin >> a;
		if (mp[a] >= 0) {
			b = mp[a];
			c = i;
		}
		mp[a] = i;
		//	cout << a << " " << b << " " << c << endl;
	}

	//cout << b << " " << c << endl;
	COMinit();

	REP(i, N + 1) {
		int A = comb(N + 1, i + 1);

		A -= comb(b + N - c, i);
		//cout << A << " " << B << endl;
		cout << (A+MOD)%MOD << endl;
	}

	return 0;
}



Measured memory_bytes: 13952
def Grid(root): # マップxを最短経路で進む場合の数
    mod=10**9+7
    
    dp=[[0 for _ in range(w)] for _ in range(h)]
    dp[0][0]=1
    for i in range(h):
        for j in range(w):
            if root[i][j]=="#":
                dp[i][j]=0
            elif i>=1 and j>=1 and root[i-1][j]=="." and root[i][j-1]==".":
                dp[i][j]=( dp[i-1][j]+dp[i][j-1] ) % mod
            elif  i>=1 and j>=1 and root[i-1][j]=="#" and root[i][j-1]==".":
                dp[i][j]=( dp[i][j-1] ) % mod
            elif  i>=1 and j>=1 and root[i-1][j]=="." and root[i][j-1]=="#":
                dp[i][j]=( dp[i-1][j] ) % mod
            elif i==0 and j>=1:
                dp[0][j]=dp[0][j-1]
            elif i>=1 and j==0:
                dp[i][0]=dp[i-1][0]
    print(dp[h-1][w-1])

def main():
    global h,w
    h,w = map(int,input().split())
    root=[]
    for _ in range(h):
        root.append(list(input()))
    Grid(root)

    
if __name__ == "__main__":
    main()

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

int main() {
  const int64_t mod = 1000000007;
  string s;
  cin >> s;
  int digit = s.size(), d;
  cin >> d;
  vector<int> k(digit);
  for (int i = 0; i < digit; i++) k.at(i) = s.at(i) - '0';
  vector<vector<vector<int64_t>>> dp(digit + 1,
                                     vector<vector<int64_t>>(d, vector<int64_t>(2)));
  dp.at(0).at(0).at(0) = 1;
  for (int i = 0; i < digit; i++) {
    for (int j = 0; j < d; j++) {
      for (int m = 0; m < 10; m++) {
        if (m < k.at(i)) {
          (dp.at(i + 1).at((j + m) % d).at(1) += dp.at(i).at(j).at(0)
            + dp.at(i).at(j).at(1)) %= mod;
        } else if (m == k.at(i)) {
          (dp.at(i + 1).at((j + m) % d).at(0) += dp.at(i).at(j).at(0)) %= mod;
          (dp.at(i + 1).at((j + m) % d).at(1) += dp.at(i).at(j).at(1)) %= mod;
        } else {
          (dp.at(i + 1).at((j + m) % d).at(1) += dp.at(i).at(j).at(1)) %= mod;
        }
      }
    }
  }
  cout << (dp.at(digit).at(0).at(0) + dp.at(digit).at(0).at(1) + mod - 1) % mod << endl;
}


Measured memory_bytes: 55424
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
  int H,W;
  char C[101][101];
  scanf("%d %d",&H,&W);
  for(int i=1;i<=H;i++){
    scanf(" %c",&C[i][1]);
    for(int j=2;j<=W;j++) scanf("%c",&C[i][j]);
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=2;j++){
      for(int k=1;k<=W;k++){
        printf("%c",C[i][k]);
      }
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1010;
#define int long long
int n, m, a[maxn][3], c[maxn], ans;
signed main(){
	scanf("%lld%lld", &n, &m);
	for(int i = 1; i <= n; ++i) for(int j = 0; j < 3; ++j) scanf("%lld", &a[i][j]);
	for(int k = 0; k < 8; ++k){
		for(int i = 1; i <= n; ++i){
			c[i] = 0;
			for(int j = 0; j < 3; ++j){
				int x = a[i][j];
				if(k & (1 << j)) x = x * -1;
				c[i] += x; 
			}
		}
		sort(c + 1, c + n + 1);
		int cnt = 0;
		for(int i = n; i > n - m; --i) cnt += c[i];
		ans = max(ans, cnt);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
import java.awt.*;
import java.io.*;
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new TestB().doIt();
	}
	class TestB{
		void doIt() {
			int N = sc.nextInt();
			int cnt = 0;
			for(int i = 1;i < N;i++) {
				cnt = cnt + ((N - 1) / i);
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 35748
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  // 整数の入力
	  int a=sc.nextInt();
      int b=sc.nextInt();
      int h=sc.nextInt();
	  int Area=0;
      
      Area=(a+b)*h/2;
     //出力
      System.out.println(Area);

   }
}


Measured memory_bytes: 21332
from collections import defaultdict


N = int(input())
A = map(int, input().split())
A = list(A)

S = [0]*(N+1)
S[0] = 0
for i in range(N):
    S[i+1] = S[i] + A[i]

sum_dict = defaultdict(int)
for s in S:
    sum_dict[s] += 1

ans = sum([n*(n-1)/2 for n in sum_dict.values()])
print(int(ans))


Measured memory_bytes: 116168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; }     cout << "}" << endl; 

template<class T> void chmin(T &t, T f) { if (t > f) t = f; } //t=min
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } //t=max

using namespace std;

vector<string> train_names;

void pusher(string left_str, string right_str) {
	string reve_left_str = left_str;
	string reve_right_str = right_str;
	reverse(ALL(reve_left_str));
	reverse(ALL(reve_right_str));

	train_names.push_back(left_str + right_str);
	train_names.push_back(reve_left_str + right_str );
	train_names.push_back(left_str + reve_right_str );
	train_names.push_back(reve_left_str + reve_right_str);
}

int main() {
	int M;
	int left_len=0,right_len=0;
	string train_name;

	cin >> M;
	rep(m,M) {
		cin >> train_name;
		train_names.clear();
		REP(i,1,train_name.size()) {
			left_len = i;
			right_len = train_name.size() - i;
			string left_str(train_name,0,left_len);
			string right_str(train_name,left_len,right_len);

			pusher(left_str,right_str);
			pusher(right_str,left_str);
		}

		set<string> set_train_names(ALL(train_names));
		cout << set_train_names.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  deque<P> h(n);
  rep(i, n) cin >> h[i].first >> h[i].second;

  sort(h.begin(), h.end(), [&](const P& a, const P& b) {
    return a.first + a.second < b.first + b.second;
  });

  ll ta(0), ao(0);
  bool t = true;
  while (h.size() > 0) {
    if (t) {
      ta += h.back().first;
      h.pop_back();
    } else {
      ao += h.back().second;
      h.pop_back();
    }
    t = !t;
  }
  cout << ta - ao << endl;
}


Measured memory_bytes: 5208