akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int n;
char s[15];

void dfs(int dep,int mx){
    if(dep==n){
        puts(s);
        return;
    }
    for(int i=0;i<mx;i++){
        s[dep]=i+'a';
        dfs(dep+1,mx);
    }
    s[dep]=mx+'a';
    dfs(dep+1,mx+1);
}

int main(){

    scanf("%d",&n);
    dfs(0,0);

    return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
using namespace std;

char mark[4] = "+-*";

int oper(int cmd, int lhs, int rhs){
    switch(cmd){
        case 0: return lhs + rhs;
        case 1: return lhs - rhs;
        case 2: return lhs * rhs;
    }
    return 0;
}

int main(){
    int n[4];
    bool success;
    while( true ){
        success = false;
        scanf("%d %d %d %d", n, n+1, n+2, n+3);
        if( n[0] + n[1] + n[2] + n[3] == 0) break;
        sort(n, n + 4);
        int i, j, k;
        do{
            for(i = 0; !success && i < 3; i++){
                for(j = 0; !success && j < 3; j++){
                    for(k = 0; !success && k < 3; k++){
                        int res = oper(k, oper(j, oper(i, n[0], n[1]), n[2]), n[3]);
                        if( res == 10 ){
                            success = true;
                            break;
                        }
                    }
                }
            }
        }while( !success && next_permutation(n, n + 4) );
        if( success ){
            i--; j--;
            printf("(((%d %c %d) %c %d) %c %d)\n", n[0], mark[i], n[1], mark[j], n[2], mark[k], n[3]);
            continue;
        }
        do{
            for(i = 0; !success && i < 3; i++){
                for(j = 0; !success && j < 3; j++){
                    for(k = 0; !success && k < 3; k++){
                        int res = oper(k, oper(i, n[0], n[1]), oper(j, n[2], n[3]));
                        if( res == 10 ){
                            success = true;
                            break;
                        }
                    }
                }
            }
        }while( !success && next_permutation(n, n + 4) );
        if( success ){
            i--; j--;
            printf("((%d %c %d) %c (%d %c %d))\n", n[0], mark[i], n[1], mark[k], n[2], mark[j], n[3]);
            continue;
        }
        puts("0");
    }
    return 0;
}

Measured memory_bytes: 1056
P = [1 for _ in range(100)]
P[0]=0
P[1]=0
for i in range(2,11):
    for j in range(i**2,100,i):
        P[j] = 0
Q = []
for i in range(100):
    if P[i]==1:
        Q.append(i)
N = int(input())
C = {p:0 for p in Q}
for i in range(2,N+1):
    for p in Q:
        if i%p==0:
            x = i
            while x%p==0:
                x = x//p
                C[p] += 1
cnt = 0
for p in Q:
    if C[p]>=74:
        cnt += 1
cnt1 = 0
cnt2 = 0
for p in Q:
    if C[p]>=24:
        cnt2 += 1
    elif C[p]>=2:
        cnt1 += 1
cnt += cnt2*(cnt2-1)+cnt2*cnt1
cnt1 = 0
cnt2 = 0
for p in Q:
    if C[p]>=14:
        cnt2 += 1
    elif C[p]>=4:
        cnt1 += 1
cnt += cnt2*(cnt2-1)+cnt2*cnt1
cnt1 = 0
cnt2 = 0
for p in Q:
    if C[p]>=4:
        cnt2 += 1
    elif C[p]>=2:
        cnt1 += 1
cnt += (cnt2*(cnt2-1)*(cnt2-2))//2+((cnt2*(cnt2-1))//2)*cnt1
print(cnt)

Measured memory_bytes: 63704
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    double R;
    cin >> R;
    cout << setprecision(20) << 2.0*R*3.14159265358979323846264;
    return 0;
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				ans += __gcd(i,__gcd(j,k));
			}
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3616
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(n)]
list_CD = [ list(map(int,input().split(" "))) for i in range(m)]
ans = [[0, pow(10, 12)] for _ in range(n)]

for i, l in enumerate(list_AB):
    a = l[0]
    b = l[1]
    for j, k in enumerate(list_CD):
        c = k[0]
        d = k[1]
        if abs(a-c) + abs(b-d) < ans[i][1]:
            ans[i][1] = abs(a-c) + abs(b-d)
            ans[i][0] = j + 1

for i in range(n):
    print(ans[i][0])

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

int n, m, s, g;
const int INF = 1e9;

struct edge {
	int to;
	int cost;
	int lim;
};

struct va {
	double dist;
	int now;
	int speed;
	int prev;
	bool operator < (const va& o) const {
		return dist > o.dist;
	}
};


int main() {
	while (cin >> n >> m >> s >> g, n) {
		s--; g--;
		vector <vector <edge>> G(n);
		rep (i, m) {
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			x--; y--;
			G[x].push_back({y, d, c});
			G[y].push_back({x, d, c});
		}
		// 頂点, speed, prev

		vector <vector <vector <int>>> used(50, vector <vector <int>> (50, vector <int> (50, false)));
		vector <vector <vector <double>>> list(50, vector <vector <double>> (50, vector <double> (50, INF)));
		priority_queue <va> que;
		que.push({0.0, s, 0, s});
		list[s][0][s] = 0;
		while (!que.empty()) {
			va tmp = que.top(); que.pop();
			if (used[tmp.now][tmp.speed][tmp.prev] == true) continue;
			used[tmp.now][tmp.speed][tmp.prev] = true;

			rep (i, G[tmp.now].size()) {
				if (G[tmp.now][i].to == tmp.prev) continue;
				for (auto ds : {-1, 0, 1}) {
					int tmpDs = tmp.speed + ds;
					if (tmpDs < 1 || tmpDs > 30 || tmpDs > G[tmp.now][i].lim) continue;
					if (list[G[tmp.now][i].to][tmpDs][tmp.now] > tmp.dist + 1.0 * G[tmp.now][i].cost / tmpDs) {
						list[G[tmp.now][i].to][tmpDs][tmp.now] = tmp.dist + 1.0 * G[tmp.now][i].cost / tmpDs;
						que.push({tmp.dist + 1.0 * G[tmp.now][i].cost / tmpDs, G[tmp.now][i].to, tmpDs, tmp.now});
					}
				}
			}
		}

		double ans = INF;
		rep (i, n) ans = min(ans, list[g][1][i]);
		cout << (ans == INF ? "unreachable" : to_string(ans)) << endl;
	}
	return 0;
}


Measured memory_bytes: 5252
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

int main() {
  ll N,K,Q;
  cin >> N >> K >> Q;
  std::vector<ll> Avec(Q);
  std::vector<ll> Pvec(N, K-Q);
  {
    ll a, i = 0;
    while (cin >> a) {
      Avec[i] = a;
      i++;
    }
  }
  for (ll i = 0; i < Q; ++i) Pvec[Avec[i]-1]++;
  for (auto p = Pvec.begin(); p != Pvec.end(); ++p) {
    if (*p > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
import collections
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
    exit()

cnt = collections.Counter(D)
if cnt[0] != 1:
    print(0)
    exit()
    
ans = 1
limit = max(cnt.keys()) + 1
for i in range(0, limit):
    if i == limit - 1:
        break
    n = cnt[i]
    r = cnt[i + 1]
    if n == 0 or r == 0:
        ans = 0
        break
    ans *= n ** r

print(ans % 998244353)


Measured memory_bytes: 62004
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
ll nCr(ll n,ll r)
{
    ll p=1,k=1;
    if(n-r<r)
        r=n-r;
    if(r!=0){
        while(r){
            p*=n;
            k*=r;
            ll m=__gcd(p,k);
            p/=m;
            k/=m;
            n--;
            r--;
        }
    }
    else
        p=1;
    return p;
}
int main()
{
    ll n,m,res=0;
    cin>>n>>m;
    if(n>1)
        res+=nCr(n,2);
    if(m>1)
        res+=nCr(m,2);
    cout<<res;
}

void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 256
D=int(input())
C=list(map(int, input().split()))
S=[list(map(int,input().split())) for i in range(D)]

#T=[]
#for i in range(D):
#  T.append(int(input()))

#M=int(input())
#dq=[list(map(int,input().split())) for i in range(M)]

def dissat(day):
  dissat = 0
  for i in range(26):
    if T[day-1]-1 == i:
      continue
    dissat += C[i]*(day-lastdays[i])

  return dissat    
    
def last(day):
  lastdays[T[day-1]-1] = day

# 
def calcscore(D):
  sat = 0
  for i in range(D):
    # dayi
    last(i)
    sat += S[i][T[i]-1] - dissat(i+1)
  #print(sat)
  return sat

# main
#lastdays = [0]*26
#calcscore(D)


# change contenst
#for i in range(M):
#  T[dq[i][0]-1] = dq[i][1]
#  lastdays = [0]*26
#  calcscore(D)

#
import random

T = [0]*D
for i in range(D):
  T[i] = random.randrange(1,26)

lastdays = [0]*26
oldscore = calcscore(D)

count = 0
while count < 300:
  T = [0]*D
  for i in range(D):
    T[i] = random.randrange(1,26)

  lastdays = [0]*26
  newscore = calcscore(D)
  if oldscore > 0 and newscore > oldscore:
    oldscore = newscore
    break
  count += 1


count = 0
while count < 10000:
  count += 1
  d=random.randrange(1,D)
  q=random.randrange(1,26)
  old = T[d-1] # 後で戻せるように元の値を記憶しておく
  T[d-1] = q
  lastdays = [0]*26
  newscore = calcscore(D)
  if newscore < oldscore:
    T[d-1] = old
  else:
    oldscore = newscore

for i in range(D):
  print(T[i])


Measured memory_bytes: 83528
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

ll n, ans = 0;

void saiki(ll m, bool a, bool b, bool c){
  if(m > n) return;
  if(a && b && c) ans++;
  saiki(m*10+3, true, b, c);
  saiki(m*10+5, a, true, c);
  saiki(m*10+7, a, b, true);
  return;
}

int main() {
  cin >> n;
  saiki(0, false, false, false);
  cout << ans << endl;
  return 0;
}


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

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

memo = [0]*(2+10**5)

for i in range(N):
    tmp = a[i]
    memo[tmp-1] += 1
    memo[tmp] += 1
    memo[tmp+1] += 1

ans = max(memo)

print(ans)

Measured memory_bytes: 83300
#include <bits/stdc++.h>
using namespace std;
int q;
vector<int> ans(100010, 0);

vector<bool> primeno(100010, true);
void Eratosthenes(int n) {
    primeno.at(0) = primeno.at(1) = false;
    int limit = sqrt(n);
    for(int i = 2; i < limit; ++i) {
        if(primeno.at(i)) {
            for(int j = 0; i*(j+2) < n; ++j) {
                primeno.at(i*(j+2)) = false;
            }
        }
    }
}

int main() {
    cin >> q;
    Eratosthenes(100010);
    int cnt = 0;
    for(int i = 0; i < 100010; ++i) {
        if(primeno.at(i)) {
            int another = (i+1)/2;
            if(primeno.at(another)) {
                cnt++;
            }
        }
        ans.at(i) = cnt;
    }

    for(int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        int answer = ans.at(r)-ans.at(l-1);
        cout << answer << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int q,h,s,d,n;

int main(){
    read2i(q,h);
    read2i(s,d);

    if(2*q < h) h = 2*q;
    if(2*h < s) s = 2*h;
    if(2*s < d) d = 2*s;

    readi(n);
    ll ans = n/2ll*d;
    if(n&1) ans += s;
    cout <<ans;
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int t;
    cin >> t;
    while (t--) {
        int n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << "\n";
    }

    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    cout << max(0, abs(a-b) - w) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    ll N,A;
    cin >> N >> A;
    cout << N * N - A << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n;
    
    cin >> n;
    if(n <= 999)
        cout << "ABC" << endl;
    else
        cout << "ABD" << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int k, y;
long long x;
const long long maxi[] = {9, 99, 1999, 29999, 399999, 4999999, 59999999, 699999999LL, 7999999999LL, 89999999999LL, 999999999999LL, 9999999999999LL, 109999999999999LL, 1199999999999999LL, 100000000000000000LL};
long long ten[25];
int main()
{
#ifdef _noname
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &k);
	ten[0] = 1;
	for (int i = 1; i <= 16; i++) ten[i] = ten[i - 1] * 10;
	x = 0;
	for (int i = 1; i <= k; i++)
	{
		y = 0;
		while (x >= maxi[y]) y++;
		x += ten[y];
		printf("%lld\n", x);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}


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

i64 A, B, N; cin >> A >> B >> N;

i64 x = min(N, B-1);


cout << A * x / B - A * (x / B) << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int K = s.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = s.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

        dp[0] = 0;
        for (int i = 0; i < N; i++) {
            for (int k = i + 1; k <= i + K; k++) {
                if (k < N) {
                    dp[k] = Math.min(dp[k], dp[i] + Math.abs(h[i] - h[k]));
                }
            }
        }
        System.out.println(dp[N - 1]);
    }
}


Measured memory_bytes: 60972
#include <bits/stdc++.h>
using namespace std;
int main() {
    int D,E;
    while(scanf("%d %d",&D,&E),D) {
        double ans=100;
        for(int x=1;x<=D;x++) {
            int y=D-x;
            ans=min(ans,abs(sqrt(x*x+y*y)-E));
        }
        printf("%lf\n",ans);
    }
}

Measured memory_bytes: 3176
using System;
using System.Linq;

namespace AOJ.Volume2
{
    public class LeadTo6174
    {
        public static int Main()
        {
            while (true)
            {
                var input = Console.ReadLine();
                if (input == "0000") { break; }

                if (input[0] == input[1] && input[1] == input[2] && input[2] == input[3])
                {
                    // ????????°??????????????§????????´??????"NA"
                    Console.WriteLine("NA");
                    continue;
                }

                int answer = 0;
                while(input != "6174")
                {
                    answer++;
                    string l = "";
                    foreach (var c in input.OrderByDescending(x => x)) { l += c; }

                    string s = "";
                    foreach (var c in input.OrderBy(x => x)) { s += c; }

                    input = (int.Parse(l) - int.Parse(s)).ToString().PadLeft(4, '0');
                }

                Console.WriteLine(answer);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 10084
#include<stdio.h>

int main(void)
{
  int n,i,time[101],a,b,j;

  while(scanf("%d",&n)!=EOF)
    {
      a=0;
      for(i=0;i<n;i++)
	{
	  scanf("%d",&time[i]);
	}

      for(i=0;i<n;i++)
	{
	  for(j=i+1;j<n;j++)
	    {
	      if(time[i]>time[j])
		{
		  b=time[i];
		  time[i]=time[j];
		  time[j]=b;
		}
	    }
	}
      for(i=1;i<n;i++)
	{
	  time[i]=time[i]+time[i-1]; 
	}
      for(i=0;i<n;i++)
	{
	  a+=time[i];
	}
      printf("%d\n",a);
    }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int N = 1 << 17;
const int NIL = INT_MAX;

int mini[N * 2];
int lazy[N * 2];

void setLazy(int k, int v) {
    lazy[k] = v;
    mini[k] = v;
}

void push(int k) {
    // ?????¶?????????????????????????????°???????????????
    if (lazy[k] == NIL) {
        return;
    }
    setLazy(k * 2 + 0, lazy[k]);
    setLazy(k * 2 + 1, lazy[k]);

    // ????????????????????¬??????????????§????????????????????????
    lazy[k] = NIL;
}

void fix(int k) {
    // ?????????k?????????????????????????????§?????????????????????????????§????????¨????????????????????§??????????????§???
    mini[k] = min(mini[k * 2], mini[k * 2 + 1]);
}

// ??????[queryL,queryR)???val??§???????????¶???
void fill(int queryL, int queryR, int val, int k = 1, int nodeL = 0, int nodeR = N) {
    // ?????¨???????????¨????????????????????????????????????????????????????????\?????????????????????????????????
    if (nodeR <= queryL || queryR <= nodeL) {
        return;
    }
    // ???????????????????????¨?????????????????¨??????????????????????????¶????????????????????????????????£?????¨??°???
    if (queryL <= nodeL && nodeR <= queryR) {
        setLazy(k, val);
        return;
    }
    // ???????????????????????¨??????????????????push??????
    push(k);
    int nodeM = (nodeL + nodeR) / 2;
    fill(queryL, queryR, val, k * 2 + 0, nodeL, nodeM);
    fill(queryL, queryR, val, k * 2 + 1, nodeM, nodeR);
    // ???????????????????????¨??????????????±???fix??????
    fix(k);
}

// ??????[queryL, queryR)???????°????????±???????
int minimum(int queryL, int queryR, int k = 1, int nodeL = 0, int nodeR = N) {
    // ?????¨???????????¨???????????????????????????????????????
    if (nodeR <= queryL || queryR <= nodeL) {
        return INT_MAX;
    }
    // ???????????????????????¨?????????????????¨???????????????
    if (queryL <= nodeL && nodeR <= queryR) {
        return mini[k];
    }
    // ???????????????????????¨??????????????????push??????
    push(k);
    int nodeM = (nodeL + nodeR) / 2;
    int vl = minimum(queryL, queryR, k * 2 + 0, nodeL, nodeM);
    int vr = minimum(queryL, queryR, k * 2 + 1, nodeM, nodeR);
    return min(vl, vr);
}

int main()
{
    int n,q;
    cin >> n >> q;
    rep(i,2*N){
        mini[i] = INT_MAX;
    }
    rep(i,2*N){
        lazy[i] = NIL;
    }
    rep(i,q){
        int a;
        cin >> a;
        if(a == 0){
            int x,y,z;
            cin >> x >> y >> z;
            fill(x,y+1,z);
        }else{
            int x,y;
            cin >> x >> y;
            cout << minimum(x,y+1) << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 5144
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        int i,j,k,x,n,co=0;
        Scanner s = new Scanner(System.in);
        while(true){
            n = s.nextInt();
            x = s.nextInt();
            if(n==0&&x==0)break;
            for(i=1;i<=n;i++){
                for(j=i+1;j<=n;j++){
                    for(k=j+1;k<=n;k++){
                        if(i+k+j==x)co++;
                    }
                }
            }
            System.out.println(co);
            co =0;
        }
    }

}


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

int main()
{
	while (true)
	{
		int m, f, r;
		cin >> m >> f >> r;
		if (m == f && f == r && r == -1)
		{
			return 0;
		}
		if (m == -1 || f == -1)
		{
			cout << "F" << endl;
			continue;
		}
		if (m + f >=80)
		{
			cout << "A" << endl;
			continue;
		}
		if (m + f >= 65 && m + f < 80)
		{
			cout << "B" << endl;
			continue;
		}
		if (m + f >= 50 && m + f <65)
		{
			cout << "C" << endl;
			continue;
		}
		if (m + f >=30 && m + f < 50)
		{
			if (r >= 50)
			{
				cout << "C" << endl;
				continue;
			}
			cout << "D" << endl;
			continue;
		}
		if (m + f <30)
		{
			cout << "F" << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

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

int main() {
    ll A, B;
    cin >> A >> B;

    cout << lcm(A, B) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _0277
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 4; i++)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 1)
                {
                    Console.WriteLine(x[1] * 6000);
                }
                if (x[0] == 2)
                {
                    Console.WriteLine(x[1] * 4000);
                }
                if (x[0] == 3)
                {
                    Console.WriteLine(x[1] * 3000);
                }
                if (x[0] == 4)
                {
                    Console.WriteLine(x[1] * 2000);
                }
            }
        }
    }
}

Measured memory_bytes: 9548
n,t = map(int,input().split())
x = [list(map(int,input().split()))for _ in range(n)]

y = []

for i in x:
  if i[1] <= t:
    y.append(i)

y.sort()

if y == []:
  print("TLE")
else:
  print(y[0][0])

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

using namespace std;

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int mod1 = int(1e9) + 7;
const int inf = 0x3f3f3f3f;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

#define ri(X) scanf("%d", &(X))
#define rii(X, Y) scanf("%d%d", &(X), &(Y))
#define riii(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define rl(X) scanf(LLD, &(X))
#define rd(X) scanf("%lf", &(X))
#define rs(X) scanf("%s", (X))
#define pri(X) printf("%d\n", (X))
#define prii(X, Y) printf("%d %d\n", (X), (Y))
#define priii(X, Y, Z) printf("%d %d %d\n", (X), (Y), (Z))
#define all(a) (a).begin(),(a).end()

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

int main(){

    int a,b,c;
    riii(a,b,c);

    if(b-a==c-b) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vll da(n,0);
    ll count=n;
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll a;
            cin>>a;
            if(da[a-1]==0){
                count--;
                da[a-1]=1;
            }
        }
    }
    cout<<count<<endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define each(e, collection) for(auto& e: (collection))            // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

namespace NyaGadget
{

	struct Imos2D
	{
		vector<vector<ll>> grid;

		Imos2D(ll w, ll h)
		{
			grid.resize(h+1);
			each(e, grid)
				e.resize(w+1);
		}

		void Add(ll hmin, ll hmax, ll wmin, ll wmax, ll v)
		{
			grid[hmin  ][wmin  ] += v;
			grid[hmin  ][wmax+1] -= v;
			grid[hmax+1][wmin  ] -= v;
			grid[hmax+1][wmax+1] += v;
		}

		void Update(void)
		{
			rep(i, 0, size(grid))
			{
				rep(j, 1, size(grid[i]))
					grid[i][j] += grid[i][j -1];
			}

			rep(i, 1, size(grid))
			{
				rep(j, 0, size(grid[i]))
					grid[i][j] += grid[i-1][j];
			}
		}
	};
}

using namespace NyaGadget;

struct Range
{
	ll l;
	ll r;
};

int main(void)
{
	ll n, m, q; cin >> n >> m >> q;

	vector<Range> train(m);
	each(e, train)
	{
		cin >> e.l >> e.r;
		e.l--; e.r--;
	}

	vector<Range> query(q);
	each(e, query)
	{
		cin >> e.l >> e.r;
		e.l--; e.r--;
	}

	Imos2D imos(n, n);
	each(e, train)
		imos.Add(0, e.l, e.r, n-1, 1);

	imos.Update();

	each(e, query)
		cout << imos.grid[e.l][e.r] << endl;

	return 0;
}


Measured memory_bytes: 7552
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
 
int main(){
    ll L, R, sub;
    cin >> L >> R;
    int ans = 2019;
    for(ll i=L; i<R; i++){
        for(ll j=i+1; j<=R; j++){
            sub = (i*j)%2019;
            if(ans > sub) ans=sub;
            if(ans == 0) break;
        }
        if(ans == 0) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*problem B*/
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int n;
  scanf("%d",&n);
  int v[n];
  for(int i=1;i<=n;i++){
    scanf("%d",&v[i]);
  }
  int c[n];
  for(int i=1;i<=n;i++){
    scanf("%d",&c[i]);
  }

  int value=0;
  for(int i=1;i<=n;i++){
    if((v[i]-c[i])>0){
      value+=(v[i]-c[i]);
    }
  }

  printf("%d",value );
  return 0 ;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int X = scan.nextInt();
			
			int gohyaku = X/500;
			
			X = X-500*gohyaku;
			
			int goen = X/5;
			
			
			System.out.println(1000*gohyaku+5*goen);
		}
		
		
	}
		

}


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

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int res = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            double tmp = 0;
            for(int k = 0; k < d; k++) {
                tmp += pow(abs(x[i][k] - x[j][k]), 2);
            }
            tmp = sqrt(tmp);
            if(abs(round(tmp) - tmp) < 1e-5) {
                res++;
            }
        }
    }
    cout << res;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	if (n == 0) {
		cout << 0 << endl; return 0;
	}
	int i = 1;
	string s = "";
	while (n != 0) {
		if (n % (i * (-2)) != 0) {
			n -= i; s += '1';
		}
		else s += '0';
		i *= (-2);
	}
	reverse(ALL(s));
	cout << s << endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
string T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	FOR(i,4) {
		if(i==0) T="SS";
		if(i==1) T="SW";
		if(i==2) T="WS";
		if(i==3) T="WW";
		for(j=1;j<N-1;j++) {
			if((T[j]=='S') ^ (S[j]=='o')){
				T.push_back('S'+'W'-T[j-1]);
			}
			else {
				T.push_back(T[j-1]);
			}
		}
		
		if((T[N-1]=='S') ^ (S[N-1]=='o')){
			if(T[N-2]==T[0]) continue;
		}
		else {
			if(T[N-2]!=T[0]) continue;
		}
		if((T[0]=='S') ^ (S[0]=='o')){
			if(T[N-1]==T[1]) continue;
		}
		else {
			if(T[N-1]!=T[1]) continue;
		}
		cout<<T<<endl;
		return;
		
	}
	cout<<-1<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 720
a,b=map(int, input().split())
L = []

for i in range(1,a+1):
    L.append(b+i-1)

if L[0] >= 0:
    L[0] = 0
    print(sum(L))
if L[0] < 0 and L[a-1] > 0:
    print(sum(L))
if L[0] < 0 and L[a-1] <= 0:
    L[a-1] = 0
    print(sum(L))

Measured memory_bytes: 9124
#include <stdio.h>

int main(){
 int N , K;
 long ans=1;
 int i;
 scanf("%d", &N);
 scanf("%d", &K);
 ans=K;
 for(i=0; i<N-1; i++){
   ans *= K-1;
 }
 printf("%d\n" ,ans);

 return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  long long a,b,k,c,d;
  scanf("%lld",&a);
  scanf("%lld",&b);
  scanf("%lld",&k);
  c=a-k;
  d=(a+b)-k;
  if(a>k) d=b;
  if(0>d) d=0;
  if(0>c) c=0;
  printf("%lld",c);
  printf(" ");
  printf("%lld",d);
  return 0;
}
    
    
  

Measured memory_bytes: 128
n=int(input())
plus=[]
for i in range(n):
    plus.append(input())
m=int(input())
minus=[]
for j in range(m):
    minus.append(input())

score=[]
for i in range(n):
    score.append(plus.count(plus[i])-minus.count(plus[i]))
    
print(max(score) if max(score)>0 else 0)
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repz(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;
void debug_out(){ cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
// 1E+9 +7
const ll mod = 1000000000+7;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int x; cin >> x;
  cout << 1000*(x/500)+(x%500)/5*5 << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x,y,z,n;
    x = sc.nextInt();
    y = sc.nextInt();
    z = sc.nextInt();
    n = y/x;
    if(n<z){
      System.out.println(n);
    }
    else{
      System.out.println(z);
    }
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int n,m;
ll fac[N],inv[N];
ll ksm(ll a,ll n){
	ll ans=1;
	while(n){
		if(n&1) ans=ans*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans;
}
ll C(int m,int n){
	return fac[m]*inv[m-n]%mod*inv[n]%mod;
}
ll A(int m,int n){
	return fac[m]*inv[m-n]%mod;
}
int main(){
	scanf("%d%d",&n,&m); 
	fac[0]=1;
	for(int i=1;i<=m;i++) fac[i]=fac[i-1]*i%mod;
	inv[m]=ksm(fac[m],mod-2);
	for(int i=m-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	ll ans=0;
	for(int i=0;i<=n;i++){
		ans+=C(n,i)*((i&1)?-1:1)*A(m-i,n-i)%mod;
	}
	ans=(ans%mod+mod)%mod;
	printf("%lld\n",ans*A(m,n)%mod);
	return 0;
}


Measured memory_bytes: 11660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, i;
  int sum = 1;
  cin >> N >> A;
  for(i=0; i<N; i++){
    int s = sum + A;
    int t = sum * 2;
    if (s > t) sum = t;
    else sum = s;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
long long gcd(long long x, long long y){
  if(y > x) swap(x,y);
  if(!y) return x;
  return gcd(y, x%y);
}
              
int main(){
  int n;
  while(cin >> n, n){
    vector<long long> D(n), V(n);
    for(int i = 0; i < n; ++i) cin >> D[i] >> V[i];
    vector<long long> ans(n, 1);
    long long d_ = D[0], v_ = V[0];
    for(int i = 1; i < n; ++i){
      long long d = D[i], v = V[i], g = gcd(v*d_, v_*d);
      ans[i] = d_*v/g;
      for(int j = 0; j < i; ++j){
        ans[j] *= d*v_/g;
      }
      d_ *= d*v_/g;
    }
    for(int i = 0; i < n; ++i) cout << ans[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
//けんちょんさんの写経...
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N>>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include<iostream>
#include<string>
std::string S;
int main(){
    std::cin>>S;
    int ans=S.size();
    int ss=0;
    for(auto &u:S){
        if(u=='S'){
            ss++;
        }
        if(u=='T'&&ss){
            ss--;
            ans-=2;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 640
#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()
#define repi(i,a,n) for(int i = (int)a; i < (int)(n); i++)
#define ll long long

int main(void){
    int n,k,r,s,p;
    string t;
    std::cin >> n>>k>>r>>s>>p>>t;
    
    ll int ans=0;
    
    rep(i,n){
        if(i>=k&&t[i]==t[i-k]){
            t[i]=0;
        }
        if(t[i]=='s'){
            ans+=r;
        }
        if(t[i]=='p'){
            ans+=s;
        }
        if(t[i]=='r'){
            ans+=p;
        }
    }
    std::cout << ans << std::endl;

    
}

Measured memory_bytes: 512
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

void dfs(string s, int N, int c)
{
	if (s.size() == N)
	{
		cout << s << endl;
		return;
	}

	reple(i, 0, c + 1)
	{
		string t = s;
		t += 'a' + i;
		dfs(t, N, max(i, c));
	}
}

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

	set<string> s;

	dfs("", N, -1);
}

Measured memory_bytes: 1536
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;


typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

ll i,j,k,l,ii,jj;
ll a[2000];
ll n;
ll ans=0;
int main(){
    cin>>n;
    for(i=0;i<2*n;i++){
        cin>>a[i];
    }
    sort(a,a+2*n);
    reverse(a,a+2*n);
    for(i=1;i<2*n;i+=2){
        ans += a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int dp[151][11][80];

int n;
int v[10001];
int check(int p, int c){
	int up = p-1, down = p+1;
	int res = 0, cnt = 1;
	while(1){
		while(v[up] == c && up >= 0) up--, cnt++;
		while(v[down] == c && down < n) down++, cnt++;
		if(cnt < 4) return res;
		res += cnt;
		cnt = 0;
		if(up >= 0) c = v[up];
		else if(down < n) c = v[down];
	}
}

int main(){
	while(cin >> n, n){
		rep(i, n) cin >> v[i];
		int ans = 0;
		rep(i, n){
			FOR(j, 1, 3){
				ans = max(ans, check(i, j));
			}
		}
		cout << n-ans << endl;
	}
 
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int i,n,a=0,b=0;
  cin>>s;
  n = s.length();
  for(i=0;i<n;++i){
    if(s[i]=='A') {a=i; break;}
  }
  for(i=n-1;i>=0;--i){
    if(s[i]=='Z') {b=i; break;}
  }
  cout<<b-a+1;
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    z=0
    for j in range(i+1):
        z+=a[j]
    for j in range(i,n):
        z+=b[j]
    ans=max(ans,z)
print(ans)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(){
    int K, A, B;
    cin >> K >> A >> B;
    bool ans = 0;
    for(int i = A; i <= B; i++){
        if(i % K == 0){
            ans = 1;
            break;
        }
    }
    if(ans){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int dp[101][101];
signed main() {
  int n;
  cin>>n;
  rep(i,101){
    rep(j,101){
      dp[i][j]=0;
    }
  }
  vector<int>gyou(n+1);
  vector<int>retu(n+1);
  rep(i,n){
    cin>>gyou[1+i]>>retu[1+i];
  }
  for(int len=2;len<=n;len++){
    for(int l=1;l<=n-len+1;l++){
      int r=l+len-1;
      dp[l][r]=min(dp[l+1][r]+gyou[l]*retu[l]*retu[r],dp[l][r-1]+gyou[l]*gyou[r]*retu[r]);
      if(len>=4)for(int k=l+1;k<r-1;k++){dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+gyou[l]*retu[k]*retu[r]);}
    }
  }
  cout<<dp[1][n]<<endl;
}



Measured memory_bytes: 3164
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
vi g[N];
int n,err;

int dfs(int c,int fa){
    int remain = 1;
    for(auto t : g[c]) if(t != fa){
        remain -= dfs(t , c);
    }
    if(remain < 0) err = true;
    return max(0 , remain);
}

int main(){
    scanf("%d",&n);
    rep(i,1,n){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1 , 0);
    puts((n & 1) || err ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 5888