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

int main(){
  string S;
  cin>>S;
  int j=0,k;
  for(int i=0;i<S.size();i++){
    k=i;
    for(;k<S.size();k++){
      if(S.at(k)!='A' && S.at(k)!='C' && S.at(k)!='G' && S.at(k)!='T')
        break;
    }
    j=max(j,k-i);
    i=k;
  }
  cout<<j<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>

using namespace std;

int main(){
  char S[10];
  int i,rennzoku=0,max=0,count=0;
  for(i=0;i<10;i++){
    S[i]='-';
  }
  cin >> S;
  for(i=0;S[i]!='-';i++){
    if(rennzoku>0){
      if(S[i]=='A'||S[i]=='T'||S[i]=='C'||S[i]=='G'){
        count++;
      }
      else{
        rennzoku=0;
        if(max<count){
          max=count;
        }
        count=0;
      }
    }
    else if(rennzoku==0){
      if(S[i]=='A'||S[i]=='T'||S[i]=='C'||S[i]=='G'){
        count++;
        rennzoku++;
      }
    }
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a,b;
	string s;
	cin>>a>>b;
	cin>>s;

	for(int i=0;i<a;i++)
	{
		if(!('0'<=s[i]&&s[i]<='9'))
		{
			puts("No");
			return 0;
		}
	}
	if(s[a]!='-')
	{
		puts("No");
		return 0;
	}
	for(int i=a+1;i<a+b+1;i++)
	{
		if(!('0'<=s[i]&&s[i]<='9'))
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");

}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class BAToZString {
public:
  static void solve(istream &cin, ostream &cout) {
    string s;
    cin >> s;
    int a = 0, z = 0;
    rep(i, s.size()) {
      if (s[i] == 'A') {
        a = i;
        break;
      }
    }
    rep(i, s.size()) {
      if (s[i] == 'Z') z = i;
    }
    cout << z - a + 1 << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  BAToZString solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

llong calc(string s)
{
  int len = s.length();
  llong ret = stoll(s);
  for (int i=1; i<len; i++) {
    string sl = s.substr(0, i);
    ret += stoll(sl) * pow(2, (len-i-1));
    string sr = s.substr(i, len-1);
    ret += calc(sr);
  }
  return ret;
}

void solve()
{
  string s;
  cin >> s;

  cout << calc(s) << endl;
}

int main()
{
  solve();
  return 0;
}


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

int main(){
	int H, W;
	cin >> H >> W;
	char s[H+2][W+2];
	rep(i,H+2)rep(j,W+2) s[i][j] = '.';
	for (int i=1; i<=H; i++) for (int j=1; j<=W; j++) {
		cin >> s[i][j];
	}

	for (int i=1; i<=H; i++) for (int j=1; j<=W; j++) {
		if (s[i][j] == '#') {
			if (s[i-1][j] == '#' || s[i+1][j] == '#') continue;
			if (s[i][j-1] == '#' || s[i][j+1] == '#') continue;
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;	

	return 0;
}


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

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

    int p, q, r;
    cin >> p >> q >> r;
    vector<int> vi{p + q, q + r, r + p};
    auto ans = min_element(vi.begin(), vi.end());
    cout << *ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int a,b;
	int tmp=0;
	cin>>a>>b;
	
	for(int i =1;i<=999;i++){
		tmp+=i;
		if(i == (b-a)){
			cout<<tmp - b<<endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

const int maxn = 10000;
const double eps = 1e-11;
double minx, miny, maxx, maxy;
struct Point
{
	double x, y;
	Point() {}
	Point(double _x, double _y)
	{
		x = _x;
		y = _y;
	}
	Point operator -(const Point &b)const
	{
		return Point(x - b.x, y - b.y);
	}
	double operator *(const Point &b)const
	{
		return x * b.x + y * b.y;
	}
};

Point p[maxn];
int T;

double dist(Point a, Point b)
{
	Point x = a - b;
	return sqrt(x * x);
}

double f(double x, double y)
{
	Point ans1 = Point(x, y);
	double sum = -1.0;
	for (int i = 0; i<T; i++)
	{
		sum = max(dist(ans1, p[i]), sum);
	}
	return sum;
}
double three_search2(double x)
{
	double l = miny, r = maxy;
	while (r - l>eps)
	{
		double lmid = l + (r - l) / 3;
		double rmid = r - (r - l) / 3;
		if (f(x, lmid) >= f(x, rmid))
		{
			l = lmid;
		}
		else
		{
			r = rmid;
		}
	}
	return l;
}

Point three_search()
{
	double l = minx, r= maxx;
	while (r - l>eps)
	{
		double lmid = l + (r - l) / 3;
		double rmid = r - (r - l) / 3;
		if (f(lmid, three_search2(lmid)) >= f(rmid, three_search2(rmid)))
		{
			l = lmid;
		}
		else
		{
			r = rmid;
		}
	}
	return Point(l, three_search2(l));
}

int main()
{
		scanf("%d", &T);
		minx = 1000000.0,maxx= -1000000.0;
		miny = 1000000.0, maxy = -1000000.0;
		for (int i = 0; i<T; i++)
		{
			scanf("%lf %lf", &p[i].x, &p[i].y);
			minx = min(minx, p[i].x), maxx = max(maxx, p[i].x);
			miny = min(miny, p[i].y), maxy = max(maxy, p[i].y);
		}
		Point ans = three_search();
		printf("%.7f\n",f(ans.x, ans.y));
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if ((a + b) > (c + d)) printf("Left\n");
	else{
		if ((a + b) < (c + d)) printf("Right\n");
		else printf("Balanced\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ

int main(){
    //input
    int N,K;cin >> N >> K;
    const LL inf = 1LL << 60;
    vector<LL> h(N+101);
    rep(i,N)cin >> h[i];

    //DP_stand
    vector<LL> DP(N+101,inf);
    DP[0] = 0;

    rep(i,N) for(int j = 1;j <= K;j++){
        chmin(DP[i+j],DP[i] + abs(h[i] - h[i+j]));
    }

    cout << DP[N-1] << endl;
}

Measured memory_bytes: 1792
// Author:: Mohammad Faisal
// BEGINNING WITH THE NAME OF ALMIGHTY GOD 
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  int res = a*b;
  (res&1) ? cout<<"Yes": cout<<"No";
  return 0;
}

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

const int N = 100;

int main() {
  int n;

  while (cin >> n, n != 0) {
    char f[N];
    for (int i = 0; i < n; i++) {
      cin >> f[i];
    }

    int cnt[26] = {};
    char c1 = 'A';
    char c2 = 'B';

    for (int i = 0; i < n; i++) {
      cnt[f[i] - 'A']++;
      if (cnt[f[i] - 'A'] > cnt[c2 - 'A'] && f[i] != c1) {
	c2 = f[i];
      }

      if (cnt[c2 - 'A'] > cnt[c1 - 'A']) {
	char tmp = c1;
	c1 = c2;
	c2 = tmp;
      }

      if (cnt[c1 - 'A'] > cnt[c2 - 'A'] + n - i - 1) {
	cout << c1 << ' ' << i + 1 << endl;
	break;
      }

      if (i == n - 1) {
	cout << "TIE" << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3076
N=int(input())
C=[0,0,0,0,0,0]
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
ans+=C[0]*C[1]*C[2]
ans+=C[0]*C[1]*C[3]
ans+=C[0]*C[1]*C[4]
ans+=C[0]*C[2]*C[3]
ans+=C[0]*C[2]*C[4]
ans+=C[0]*C[3]*C[4]
ans+=C[1]*C[2]*C[3]
ans+=C[1]*C[2]*C[4]
ans+=C[1]*C[3]*C[4]
ans+=C[2]*C[3]*C[4]
print(ans)


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

void solver() {
  string s;
  cin >> s;

  int ans = 0;
  int pre = 0;
  int cnt = 0;
  for (auto c: s) {
    if (c == 'L') {
      cnt--;
    } else {
      cnt++;
    }

    if (cnt % 4 == 0) {
      if (pre < cnt) ans++;
      pre = cnt;
    }
  }

  cout << ans << endl;
}

int main() {
  solver();
}



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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    ll d, n;
    cin >> d >> n;

    if((d == 2) && (d < 1000000)){
        if(n != 100){
            cout << 100 * 100 * n << endl;
        }
        else{
            cout << 1010000 << endl;
        }
    }
    else if(d == 1){
        if(n != 100){
            cout << 100 * n << endl;
        }
        else{
            cout << 10100 << endl;
        }
    }
    else{
        if(n != 100){
            cout << n << endl;
        }
        else{
            cout << 101 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
lr = [list(map(int,input().split())) for i in range(M)]
for l,r in lr:
    num[l-1][r-1] += 1

for j in range(N):
    for i in range(N-1,0,-1):
        num[i-1][j] += num[i][j]
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
pq = [list(map(int,input().split())) for i in range(Q)]
ans = []
for p,q in pq:
    ans.append(num[p-1][q-1])
print(*ans,sep='\n')

Measured memory_bytes: 75540
#include<iostream>
using namespace std;
int main()
{
	int t, h, m, s;
	cin >> t;
	h = t / 3600;
	m = t % 3600 / 60;
	s = t % 3600 % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

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

	vector<ll> memo = a;
	for (int i = 1; i < n; i++) {
		memo[i] += memo[i - 1];
	}

	map<ll, ll> mp;
	mp[0]++;

	ll ans = 0;
	for (auto v : memo) {
		ans += mp.count(v) != 0 ? mp[v] : 0;
		mp[v]++;
	}

	cout << ans << endl;
	// 0 1 3 -4 2 2 -2
	// 0 1 4  0 2 4  2
	return 0;
}


Measured memory_bytes: 15872
#include <stdio.h>
#include <string.h>
    
#define Max 500000
    
void insert(int); 
void find(int, int);
int successor(int);
void delete(int);
void Preorder(int);  
void Inorder(int);  
    
    
typedef struct{    /* p = parent, l = child, s = brother */
  int key;
  int p;
  int h[2];
} Node;
    
Node D[Max];
    
int main(){
  int i, n, y;
  char s[7];
    
  scanf("%d", &n);
    
  D[0].key = -1;
    
     
  for(i = 0; i < n; i++){
    D[i].h[0] = -1;
    D[i].h[1] = -1;
    
    scanf("%s", s);
    
    if(strcmp(s, "insert") == 0){
      scanf("%d", &D[i].key);
      insert(i);
    }
    else if(strcmp(s, "print") == 0){
      Inorder(0);
      printf("\n");
      Preorder(0);
      printf("\n");
    }
    else if(strcmp(s, "find") == 0){
      scanf("%d", &y);
      find(0, y);
    }
    else if(strcmp(s, "delete") == 0){
      scanf("%d", &y);
      delete(y);
    }
  }
      
  return 0;
}
    
    
void insert(int z){
  int x, y;
    
  y = -1;
  x = 0;
    
  if(z != 0){
    while(x != -1){
      y = x;
      if(D[z].key < D[x].key) x = D[x].h[0];
      else x = D[x].h[1];
    }
  }
    
  D[z].p = y;
    
  if(y != -1){
    if(D[z].key < D[y].key) D[y].h[0] = z;
    else D[y].h[1] = z;
  }
}
    
void find(int x, int k){
    
  if(x == -1) printf("no\n");
  else if(D[x].key == k) printf("yes\n");
  else if(k < D[x].key) find(D[x].h[0], k);
  else find(D[x].h[1], k);
}
    
int successor(int x){
  int y;
    
  if(D[x].h[1] != -1){
    x = D[x].h[1];
    while(D[x].h[0] != -1) x = D[x].h[0];
    return x;
  }
      
  else {
    y = D[x].p;
    while(y != -1 && x == D[y].h[1]){
      x = y;
      y = D[y].p;
    }
    return y;
  }
}
    
void delete(k){
  int x, y, z = 0;
    
  while(1){
    if(D[z].key == k) break;
    else if(k < D[z].key) z = D[z].h[0];
    else z = D[z].h[1];
  }
    
  if(D[z].h[0] == -1 || D[z].h[1] == -1) y = z;
  else y = successor(z);
    
  if(D[y].h[0] != -1) x = D[y].h[0];
  else x = D[y].h[1];
    
  if(x != -1) D[x].p = D[y].p;
    
  if(D[y].p != -1){
    if(y == D[D[y].p].h[0]) D[D[y].p].h[0] = x;
    else D[D[y].p].h[1] = x;
  }
    
  if(y !=  z) D[z].key = D[y].key;
    
}
    
    
void Preorder(int a){
  printf(" %d", D[a].key);
    
  if(D[a].h[0] != -1) Preorder(D[a].h[0]);
  if(D[a].h[1] != -1) Preorder(D[a].h[1]);
}
    
    
void Inorder(int a){
  if(D[a].h[0] == -1){
    printf(" %d", D[a].key);
    if(D[a].h[1] != -1) Inorder(D[a].h[1]);
  }
  else{
    Inorder(D[a].h[0]);
    printf(" %d", D[a].key);
    if(D[a].h[1] != -1) Inorder(D[a].h[1]);
  }
}



Measured memory_bytes: 9604
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const ll mod=1e9+7;
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>ok(n+1,1);
    for(int i=0;i<m;i++)
    {
        int k;
        cin>>k;
        ok[k]=0;
    }
    vector<ll>dp(n+1);
    dp[0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=min(n,i+2);j++)
        {
            if(ok[j])
            {
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
    }
    cout<<dp[n]<<endl;






}














































Measured memory_bytes: 4576
c, d, e = map(int, input().split())
if c > d:
    max_num = c
    min_num = d
else:
    max_num = d
    min_num = c

li = []
for i in range(1, min_num+1):
    if max_num % i == 0 and min_num % i == 0:
        li.append(i)

list_num = abs(e - len(li))
print(li[list_num])

Measured memory_bytes: 3060
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
alst = list(map(int, input().split()))
ans = 0
loop1 = k * (k - 1) // 2
loop2 = (k + 1) * k // 2
loop1 %= MOD
loop2 %= MOD

for i, num in enumerate(alst):
    for j, num2 in enumerate(alst):
        if num > num2:
            if i < j:
                ans += loop2
                ans %= MOD
            else:
                ans += loop1
                ans %= MOD
print(ans)

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){

	int a,b;cin >> a >> b;cout << a + b/2 << endl;
	return 0;
}


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

int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int cnt=0;
  while(a>=b && cnt<k){
    b*=2;
    cnt++;
  }
  while(b>=c && cnt<k){
    c*=2;
    cnt++;
  }
  if(a<b && b<c) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int N;
	int d[100];
	scanf("%d", &N);
	for(int i=0;i<N;i++) scanf("%d", &d[i]);

	sort(d,d+N);
	int ans = 1;
	for(int i=1;i<N;i++) if(d[i-1]!=d[i]) ans++;

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int xx[103];
int sum[10003];
int i,x,y,n,now=1;
int main()
{
  scanf("%d%d",&x,&y);
  scanf("%d",&n);
  for (int j=1;j<=n;j++)
  {
    scanf("%d",&sum[j]);
  }
  for (int j=1;j<=x;j++)
  {
    for (int k=1;k<=y;k++)
    {
      if (sum[now]>0)xx[k]=now;else xx[k]=++now;
      sum[now]--;
      //printf(".%d.  ",now);
    }
    if (j%2==1)
      for (int k=1;k<=y;k++)
      {
        printf("%d ",xx[k]);
      }else
      for (int k=y;k>=1;k--)
      {
        printf("%d ",xx[k]);
      }
    printf("\n");
  }
  return 0;
}


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<ll> P(n);
    for(i=0;i<n;i++){
        cin >> P[i];
    }
    ll ret = 1;
    ll now = P[0];
    for(i=1;i<n;i++){
        if(P[i]<=now){
            ret++;
            now = P[i];
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cstring>

#define pb push_back
#define mp make_pair
#define l(x) x << 1
#define r(x) x << 1 | 1
#define scan(x) do {while((x=getchar())<'0') ; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0') ; } while(0)
char _;
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<float, float> pff;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

int H, W, N, a[10005], g[105][105];

int main() {
    scanf("%d %d", &H, &W);
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
    }
    int k = 0, f = 1;
    for (int i = 0; i < H; i++) {
        for (int j = f == 1 ? 0 : W - 1; j < W && j >= 0; j += f) {
            g[i][j] = k + 1;
            if (--a[k] == 0) {
                k++;
            }
        }
        f = f == 1 ? -1 : 1;
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            printf("%d ", g[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int a, b;
	char op;

	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op == '?')      break;
		else if(op == '+') cout<<a+b<<endl;
		else if(op == '-') cout<<a-b<<endl;
		else if(op == '*') cout<<a*b<<endl;
		else if(op == '/') cout<<a/b<<endl;
	}

	return 0;
}

Measured memory_bytes: 1208
from collections import deque

N,Q = map(int,input().split())
dist = {i:[] for i in range(1,N+1)}
oya = [-1 for i in range(N+1)]
oya[1] = 0

for i in range(N-1):
  a,b = map(int,input().split())
  dist[a].append(b)
  dist[b].append(a)

kouho = deque([1])
sumi = [0 for i in range(N+1)]

while len(kouho) > 0:
  a = kouho.popleft()
  sumi[a] += 1
  for t in dist[a]:
    if sumi[t] != 0:
      continue
    else:
      kouho.append(t)
      oya[t] = a

ans = [0 for i in range(N+1)]
for q in range(Q):
  a,b = map(int,input().split())
  ans[a] += b
  
kouho = deque([1])
sumi = [0 for i in range(N+1)]

while len(kouho) > 0:
  a = kouho.popleft()
  sumi[a] += 1
  for t in dist[a]:
    if sumi[t] != 0:
      continue
    else:
      kouho.append(t)
      p = oya[t]
      ans[t] += ans[p]
      
print(*ans[1:])

Measured memory_bytes: 121056
import sys

N = int(input())
dpa, dpb, dpc = 0, 0, 0
for _ in range(N):
    a, b, c = map(int, sys.stdin.readline().split())
    dpa1 = a + max(dpb, dpc)
    dpb1 = b + max(dpc, dpa)
    dpc1 = c + max(dpa, dpb)
    dpa, dpb, dpc = dpa1, dpb1, dpc1 
print(max(dpa, dpb, dpc))

Measured memory_bytes: 43244
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
const int nax = 405;
ll dp[nax][nax];
ll a[nax];
ll prefix[nax];

ll sum(int l,int r){
	return prefix[r] - ((l-1)>=0?prefix[l-1]:0);
}

ll min(ll a, ll b){
	return a<=b?a:b;
}

ll rec(int i , int j){
	if(i==j)return 0;
	if(j==i+1)return a[i]+ a[j];	

	ll& ans = dp[i][j];
	if(ans!=-1)return ans;
	ans = 1e18;

	for(int idx = i; idx < j ; ++idx){
		ans = min(ans, rec(i,idx) + rec(idx+1,j) + sum(i,j));
	}
	return ans;
}


int main(){
	memset(dp,-1,sizeof(dp));
	IOS;
	int n;
	cin >> n;
	for(int i= 0 ; i < n ; ++i){
		cin >> a[i];
		if(i==0) prefix[i] = a[i];
		else prefix[i] = prefix[i-1] + a[i];
	}

	for(int i=n-1;i>=0 ; --i){
		for(int j = i; j<n ; ++j){
			if(i==j) dp[i][j] = 0;
			else{
				dp[i][j] = 1e18;
				for(int c=i ; c<j ; ++c){
					dp[i][j] = min(dp[i][c] + dp[c+1][j] + sum(i,j), dp[i][j]);
				}
			}
		}
	}

	cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
ll n,s[N],a[N],size[N],used[N],d[N];
bool cmp(int x, int y){return a[x]>a[y];}
map<ll,int>Map;Vi b,c;
int main() {
	read(n);rep(i,1,n)read(a[i]),s[i]=i;sort(s+1,s+n+1,cmp);
	rep(i,1,n)size[i]=1,Map[a[i]]=i;
	rep(i,1,n-1){
		int u=s[i];used[u]=1;
		int f=Map[a[u]-(n-2*size[u])];d[f]+=d[u]+size[u];
		if(!f||used[f]){puts("-1");return 0;}
	//	printf("e %d %d\n",u,f);
		b.pb(u);c.pb(f);size[f]+=size[u];
	}
	if(d[s[n]]!=a[s[n]]){puts("-1");return 0;}
	per(i,SZ(b)-1,0)printf("%d %d\n",b[i],c[i]);
//	rep(i,1,n-1)if(a[s[i]])
//	rep(i,1,n-1)printf("%lld %lld\n",s[i],s[i+1]);
	return 0;
}

Measured memory_bytes: 19700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main () {
  double cnt;
  cin >> cnt;
  cout << fixed << setprecision(6);
  cout << 2*cnt*3.1415926 << endl;
}

Measured memory_bytes: 3788
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;
int x[1001];
void primefactor(int n){

  bool flag=true;
  for( int i=2LL ;i*i<=n;i++){
    while(n%i==0){
      x[i]++;
      n/=i;
      flag=false;
    }
  }
  if(n!=1)x[n]++;
}


int main(){
  string s;
  cin>>s;
  int n=0;
  vector<string> ss(5);
  
  ss[0]="remaerd";
  ss[1]="resare";
  ss[2]="esare";
  ss[3]="maerd";
  reverse(s.begin(),s.end());
  int now=0;
  bool fff=true;
  while(1){
    int  f2=-1;
    for(int i=0;i<4;i++){
      if(now+ss[i].size()<=s.size()){
        bool f=true;
        for(int j=0;j<ss[i].size();j++){
          if(s[now+j]!=ss[i][j])f=false;
        }
        if(f){f2=ss[i].size();break;}
      }
    }
    if(f2!=-1)now+=f2;
    else{fff=false;break;}
    if(now>=s.size())break;
  }
  if(fff)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


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

int main() {
    string S, T;
    cin >> S >> T;
    ll cntmax = 0;
    vector<vector<string>> A;
    for (int i = 0; i + T.size() <= S.size(); i++){
      ll idx = 0;
      ll tmp = 0;
      for (int j = i; j < i + T.size(); j++) {
        if (T[idx]==S[j]){
          tmp++;
        }
        idx++;
      }
      //cout << "tmp" <<tmp <<endl;
      cntmax = max(cntmax, tmp);
    }
    ll size = T.size();
    cout << size - cntmax << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
//unordered_map<int,int> mapp;
int n,a[101],mi=101,mx=0;
int read() {
	char ch = getchar();
	int x = 0, f = 1;
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') x = x*10 + ch - 48, ch = getchar();
	return x * f;
}
int main() {
	n=read();
	for(int i=1; i<=n; i++)
		a[i]=read(),mi=min(mi,a[i]),mx=max(mx,a[i]);
	int ans=2e9;
	for(int k=mi; k<=mx; k++) {
		int tot=0;
		for(int i=1; i<=n; i++)
			tot+=(a[i]-k)*(a[i]-k);
		ans=min(ans,tot);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "QWERTYASDFZXCV" ].parse.expand.solve == 5 );
	assert( [ "ZABCZ" ].parse.expand.solve == 4 );
	assert( [ "HASFJGHOGAKZZFEGA" ].parse.expand.solve == 12 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front;
	return tuple( s );
}

auto solve( string s )
{
	return s.find( 'A' ).retro.find( 'Z' ).walkLength;
}


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

struct grid{
  char g[12][12];
  int cost;
};

void paint(grid& gr,char l_u_cell,char changecolor,int p_x,int p_y){
  if(gr.g[p_y][p_x]!=l_u_cell){
    return ;
  }
  gr.g[p_y][p_x]=changecolor;
  paint(gr,l_u_cell,changecolor,p_x+1,p_y);
  paint(gr,l_u_cell,changecolor,p_x-1,p_y);
  paint(gr,l_u_cell,changecolor,p_x,p_y+1);
  paint(gr,l_u_cell,changecolor,p_x,p_y-1);
}
bool chacker(grid& gr,char l_u_cell,int X,int Y){
  bool flag=true;
  for(int i=1;i<=Y;i++){
    for(int j=1;j<=X;j++){
      if(l_u_cell!=gr.g[i][j]){flag=false;break;}
    }
  }
  return flag;
}

int main(){
  while(1){
    int X,Y;
    cin>>X>>Y;
    if(X==0&&Y==0)break;
    grid first;
    for(int i=1;i<=Y;i++){
      for(int j=1;j<=X;j++){
        cin>>first.g[i][j];
      }
    }

    first.cost=0;
    queue<grid> que;
    que.push(first);

    while(1){
      grid Grid=que.front();que.pop();
      char l_u_cell;
      l_u_cell=Grid.g[1][1];
      if(chacker(Grid,l_u_cell,X,Y)){
        cout<<Grid.cost<<endl;
        break;
      }
      if(l_u_cell != 'R'){
        grid tmp=Grid;
        tmp.cost=tmp.cost+1;
        paint(tmp,l_u_cell,'R',1,1);
        que.push(tmp);
      }
      if(l_u_cell != 'G'){
        grid tmp=Grid;
        tmp.cost=tmp.cost+1;
        paint(tmp,l_u_cell,'G',1,1);
        que.push(tmp);
      }
      if(l_u_cell != 'B'){
        grid tmp=Grid;
        tmp.cost=tmp.cost+1;
        paint(tmp,l_u_cell,'B',1,1);
        que.push(tmp);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 40260
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 2e5 + 5;
int n;
ll a[Maxn], b[Maxn];
int main()
{
	ll tmp = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		scanf("%lld", &a[i]);
	for (int i = 1; i < n; ++i)
		tmp += (i & 1 ? -1 : 1) * a[i];
	b[1] = a[n] - tmp;
	for (int i = 2; i <= n; ++i)
		b[i] = a[i - 1] * 2 - b[i - 1];
	for (int i = 1; i <= n; ++i)
		printf("%lld ", b[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

double entropy(int N, const vector<int> &x) {
    double H = 0;
    for (int i=0; i<256; ++i) {
        if (x[i] != 0) {
            H -= (double)x[i] / N * log((double)x[i] / N);
        }
    }
    return H;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    while (cin >> N && N) {
        vector<int> I(N+1);
        for (int i=1; i<=N; ++i) cin >> I[i];
        int M = 256;
        double Hmin = 100000.0;
        vector<int> ans(3);
        for (int S=0; S<=15; ++S) {
            for (int A=0; A<=15; ++A) {
                for (int C=0; C<=15; ++C) {
                    vector<int> x(256, 0);
                    int R = S;
                    int O;
                    int cnt = 0;
                    int upper = N;
                    for (int i=1; i<=N; ++i) {
                        R = (A * R + C) % M;
                        O = (I[i] + R) % M;
                        cnt += x[O] == 0;
                        x[O] ++;
                    }
                    if (upper < cnt) continue;
                    upper = cnt;
                    double H = entropy(N, x);
                    if (H + 1e-8 < Hmin) {
                        Hmin = H;
                        ans[0] = S;
                        ans[1] = A;
                        ans[2] = C;
                    }
                }
            }
        }
        cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
    }
    return 0;
}

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

class Program
{
    public static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        string[] w = new string[n];
        w[0] = Console.ReadLine();
        for (int i = 1; i < n; i ++) {
            w[i] = Console.ReadLine();
            if (w.Where(x => x == w[i]).Count() != 1 || w[i-1].Substring(w[i-1].Length-1,1) != w[i].Substring(0,1)) {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 13268
def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d


n,k=map(int,input().split())
d=dict()
for i in map(int,input().split()):
    d=mycounter(d,i)
p=0
f=len(d)
#print(f)
#l=sorted(d.values())
for i in sorted(d.values()):
    if f>k:
        p+=i
        f-=1
    else:
        print(p)
        break

Measured memory_bytes: 41120
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a[][];
		int x, y, d;
		String st;

		a = new int[15][15];
		for (int i = 0; i < 9; i++) {
			st = sc.next();
			for (int j = 0; j < st.length(); j++) {
				a[i][j] = st.charAt(j) - '0';
			}
		}
		x = 2;
		y = 1;
		d = 1;
		boolean flag = true;
		while (flag || x != 2 || y != 1) {
			flag = false;
			if (d == 1) {
				System.out.print("R");
				if (1 < y && a[(y - 1) * 2 - 1][x - 1] == 1) {
					d = 4;
				} else if (a[(y - 1) * 2][x - 1] == 1) {
					x++;
				} else if (a[(y - 1) * 2 + 1][x - 1] == 1) {
					x++;
					y++;
					d = 2;
				} else {
					y++;
					d = 3;
				}
			} else if (d == 2) {
				System.out.print("D");
				if (a[(y - 1) * 2][x - 2] == 1) {
					d = 1;
				} else if (a[(y - 1) * 2 + 1][x - 2] == 1) {
					y++;
				} else if (2 < x && a[(y - 1) * 2][x - 3] == 1) {
					x--;
					y++;
					d = 3;
				} else {
					x--;
					d = 4;
				}
			} else if (d == 3) {
				System.out.print("L");
				if (a[(y - 1) * 2 - 1][x - 2] == 1) {
					d = 2;
				} else if (2 < x && a[(y - 1) * 2 - 2][x - 3] == 1) {
					x--;
				} else if (2 < y && a[(y - 1) * 2 - 3][x - 2] == 1) {
					x--;
					y--;
					d = 4;
				} else {
					y--;
					d = 1;
				}
			} else {
				System.out.print("U");
				if (1 < x && a[(y - 1) * 2 - 2][x - 2] == 1) {
					d = 3;
				} else if (2 < y && a[(y - 1) * 2 - 3][x - 1] == 1) {
					y--;
				} else if (1 < y && a[(y - 1) * 2 - 2][x - 1] == 1) {
					x++;
					y--;
					d = 1;
				} else {
					x++;
					d = 2;
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 11000
#include<stdio.h>
int main(void)
{
	int n,max,i,p[10000],d1,d2,d[10000],x;
	while(1){
		max=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&p[i],&d1,&d2);
			d[i]=d1+d2;
		}
		for(i=0;i<n;i++){
			if(max<d[i]){
				max=d[i];
				x=p[i];
			}
		}
		printf("%d %d\n",x,max);
	}
	return 0;
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, x, n;
  string s, t, u;
  in(s);
  a = 0;
  t = "";
  n = s.size();
  while(a < n){
    if(s[a] == 'A'){
      u = 'A';
      t = t + u;
    }
    else if(s[a] == 'B'){
      if(a < n - 1 && s[a + 1] == 'C'){
        u = 'T';
        t = t + u;
        a++;
      }
      else{
        u = 'B';
        t = t + u;
      }
    }
    else{
      u = 'C';
      t = t + u;
    }
    a++;
  }
  x = 0;
  t += "XXX";
  n = t.size();
  a = 0;
  x = 0;
  rep(i, n){
    if(t[i] == 'A')
      a++;
    else if(t[i] == 'T')
      x += a;
    else
      a = 0;
  }
  out(x);
  memi;
}

Measured memory_bytes: 1436
n=int(input())
mod=10**9+7

s1=input()
s2=input()

if n==1:
    print(3)
    exit(0)

if s1[0]==s1[1]:
    l=1
    ans=6
    i=2
else:
    l=0
    ans=3
    i=1

while i<n:
    if i==n-1:
        if l==0:
            ans*=2
            ans%=mod
        break

    if s1[i+1]==s1[i]:
        c=1
        i+=2
    else:
        c=0
        i+=1
    
    if l==0:
        ans*=2
    if l==1 and c==1:
        ans*=3
    
    ans%=mod
    
    l=c
    
print(ans)


Measured memory_bytes: 61756
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     int n;cin >> n;
     vector<ll>a(n);
     for(int i = 0;i<n;i++) cin >> a[i];
     int cnt = 0;ll sum = 0;ll mini = INT_MAX;
     for(int i = 0;i<n;i++){
        if(a[i]<0) cnt++;
        sum += abs(a[i]);
        mini = min(abs(a[i]),mini);
       // cout << sum <<endl;
     }
     if(cnt%2) cout << sum - 2*mini;
     else cout << sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3980
a = list(map(int,input().split()))
evil = 0
odd = 0
ans = 0
for i in a:
    if i%2==0:
        evil += 1
    else:
        odd += 1
if evil==3 or odd==3:
    a = [max(a)-i for i in a]
    ans += sum(a)//2
else:
    if evil==2:
        ans += 1
        for i in range(3):
            if a[i]%2==0:
                a[i] += 1
    else:
        ans += 1
        for i in range(3):
            if a[i]%2==1:
                a[i] += 1
    a = [max(a)-i for i in a]
    ans += sum(a)//2
print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll w,h,n;
    cin >> w >> h >> n;
    int ar[4];
    ar[0]=0;
    ar[1]=w;
    ar[2]=0;
    ar[3]=h;
    int x,y,a;
    for(int i=0;i<n;i++){
      cin >> x >> y >> a;
      if(a==1)ar[0]=max(ar[0],x);
      if(a==2)ar[1]=min(ar[1],x);
      if(a==3)ar[2]=max(ar[2],y);
      if(a==4)ar[3]=min(ar[3],y);
    }
    if(ar[1]>ar[0]&ar[3]>ar[2])cout << (ar[1]-ar[0])*(ar[3]-ar[2]);else cout << 0;
    return 0;
}


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

int main()
{
	int n;

	while( cin >> n && n ){
		vector< int > line;
		for( int i = 0; i < n; ++i ){
			int d;
			cin >> d;
			line.push_back( d );
		}
		sort( line.begin(), line.end() );
		long long output = 0;
		for( int i = 0; i < n - 1; ++i ){
			output += ( line[ i ] * ( n - i - 1 ) );
		}
		cout << output << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

vector<int> zf(string s) {
	int n = (int)s.size();
	vector<int> z(n);
	int l = 0;
	int r = 0;
	// cerr << "cz " << s << endl;
	for (int i = 1; i < n; i++) {
		z[i] = max(0, min(r - i, z[i - l]));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			z[i]++;
		}
		if (i + z[i] > r) {
			r = i + z[i];
			l = i;
		}
	}
	// cerr << "zok" << endl;
	return z;
}

int gcdd(int a, int b) {
	if (b == 0) {
		return a;
	} else {
		return gcdd(b, a % b);
	}
}

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

	string s;
	string t;
	cin >> s >> t;
	int n = (int)s.size();
	int m = (int)t.size();
	{	
		string ws = s;
		while (n <= m) {
			s += ws;
			n += (int)ws.size();
		}
	}
	// cerr << s << '\n' << t << '\n';
	auto to = zf(t + "#" + s + s);
	vector<int> z(n);
	for (int i = m + 1; i < n + m + 1; i++) {
		z[i - m - 1] = to[i];
		z[i - m - 1] = (to[i] == m);
	}
	// for (auto x : z) {
	// 	cerr << x;
	// }
	// cerr << endl;
	int g = gcdd(n, m);
	// cerr << "g: " << g << endl; 
	vector<int> used(n);
	int ans = 0;
	for (int i = 0; i < g; i++) {
		int pnt = i;
		vector<int> v;
		for (int j = 0; j < n / g; j++) {
			// cerr << pnt << endl;
			v.push_back(z[pnt]);
			pnt += m;
			pnt %= n;
		}
		if (*min_element(v.begin(), v.end()) == 1) {
			cout << -1 << endl;
			exit(0);
		}
		int vs = (int)v.size(); 
		for (int j = 0; j < vs; j++) {
			v.push_back(v[j]);
		}
		// if (i == 0) {
		// 	cerr << "v: " << endl;
		// 	for (auto x : v) {
		// 		cerr << x;
		// 	}
		// 	cerr << endl;
		// }
		vs *= 2;
		for (int j = 0; j < vs; j++) {
			if (v[j] == 0) continue;
			int r = j;
			while (r + 1 < vs && v[r + 1]) r++;
			ans = max(ans, r - j + 1);
			j = r;
		}
	}
	cout << ans << endl;
}


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

int main (){
  int n,m;
  cin >> n >> m;
  vector<int>s[m];
  rep(i,m){
    int k;
    cin >> k;
    rep(j,k){
      int t;
      cin >> t;
      s[i].push_back(t);
    }
  }
  int p[m];
  rep(i,m)cin >> p[i];
  int ans=0;
  //cout << pow(2,n) << endl;
  int N = pow(2,n);
  for(int i=0;i<N;i++){
    int sw[n];
    int num = i;
    rep(j,n){
      sw[j]=num%2;
      num = num/2;
    }
    //rep(a,n)cout << sw[a] << endl;
    bool ok = 1;
    rep(mm,m){
      int a = 0;
      for(int l:s[mm]){
        a += sw[l-1];
      }
      // cout << a << endl;
      if(a%2!=p[mm])ok = 0;
    }
    if(ok==1)ans += 1;
    //cout << ok << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//Circle
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

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

    cout << r * r << endl;

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
struct A{
	int num,typ;
}ans[4],cnt[100005];
int n,v[100005];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}
bool comp(A x,A y){
	return x.num>y.num;
}
int main(){
	n=read();for(int i=1;i<=n;++i)v[i]=read();
	for(int i=1;i<=100000;++i)cnt[i].typ=i;
	for(int i=1;i<=n;i+=2)cnt[v[i]].num++;
	sort(cnt+1,cnt+100001,comp);
	ans[0]=cnt[1],ans[1]=cnt[2];
	for(int i=1;i<=100000;++i)cnt[i].typ=i,cnt[i].num=0;
	for(int i=2;i<=n;i+=2)cnt[v[i]].num++;
	sort(cnt+1,cnt+100001,comp);
	ans[2]=cnt[1],ans[3]=cnt[2];
	if(ans[0].typ!=ans[2].typ)printf("%d",n-ans[0].num-ans[2].num);
	else printf("%d",min(n-ans[0].num-ans[3].num,n-ans[1].num-ans[2].num));
}

Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val strs = Array(N, { i -> readLine()!!.toCharArray().sorted().toString() }).sorted()

    var cnt:Long = 0
    var ren:Long = 1
    for(i in 1 until N) {
        if (strs[i] == strs[i-1]) {
            ren += 1
        } else {
            cnt += (ren * (ren-1) / 2).toLong()
            ren = 1
        }
    }
    cnt += (ren * (ren-1) / 2).toLong()
    println(cnt)
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

bool was[60];
bool graph[60][60];
int N, M; 

void dfs(int v){
	if(was[v]) return ;

	was[v] = true;
	REP(i,N) if(graph[v][i]) dfs(i);

}



int main(void){

	cin >> N >> M;

	vector<int> a(M);
	vector<int> b(M);
	REP(i,M) cin >> a[i] >> b[i];

	REP(i,M) a[i]--;
	REP(i,M) b[i]--;


	int ans = 0;

	REP(i,M){
		REP(i,60) REP(j,60) graph[i][j] = false;
		REP(i,60) was[i] = false;

		REP(j,M){
			if(i == j) continue;
			graph[a[j]][b[j]] = true;
			graph[b[j]][a[j]] = true;
		}

		dfs(0);

		bool ok = false;
		REP(i,N) if(!was[i]) ok = true;

		if(ok) ans++;

	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int N, K;
    cin >> N >> K;
    ll h[N];
    rep(i, 0, N) cin >> h[i];

    ll dp[N + 1];
    rep(i, 0, N + 1) dp[i] = INF;
    dp[0] = dp[1] = 0;

    rep(i, 1, N) {
        rep(k, 1, K + 1) {
            if(0 <= i + 1 - k and i + 1 - k <= N) {
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - k] + abs(h[i] - h[i - k]));
            }
        }
    }
    cout << dp[N] << endl;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n, d[2], col[2][360007];
vector<pair<int, int> >e[2];
int id(int a, int b) { return a * 2 * n + b; }
int check(int pos) { return pos >= 0 && pos < 2 * n; }
int dfs(int p, int a, int b)
{
	for (int i = 0, lim = e[p].size(); i < lim; i++)
	{
		int c = a + e[p][i].first, d = b + e[p][i].second;
		if (!check(c) || !check(d))continue;
		if (!col[p][id(c, d)])
		{
			col[p][id(c, d)] = -col[p][id(a, b)];
			dfs(p, c, d);
		}
	}
	return 0;
}
int main()
{
	cin >> n >> d[0] >> d[1];
	for (int p = 0; p <= 1; p++)
		for (int i = 0; i <= d[p]; i++)
		{
			int j = sqrt(d[p] - i * i);
			if (i * i + j * j != d[p])continue;
			e[p].push_back(make_pair(i, j));
			e[p].push_back(make_pair(-i, j));
			e[p].push_back(make_pair(i, -j));
			e[p].push_back(make_pair(-i, -j));
		}
	for (int i = 0; i < 2 * n; i++)
		for (int j = 0; j < 2 * n; j++)
			for (int p = 0; p <= 1; p++)
				if (!col[p][id(i, j)])
				{
					col[p][id(i, j)] = 1;
					dfs(p, i, j);
				}
	int cnt = 0;
	for (int i = 0; i < 2 * n; i++)
		for (int j = 0; j < 2 * n; j++)
			if (col[0][id(i, j)] == 1 && col[1][id(i, j)] == 1)
			{
				printf("%d %d\n", i, j);
				if (++cnt == n * n)return 0;
			}
	return 0;
}

Measured memory_bytes: 31872
#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() {
  int n;
  cin >> n;
  ll ans=0;
  rep(i,n) {
    int x;
    cin >> x;
    ans += (x-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>B>>A;
    vec h(N+1);
    reps(i,1,N+1) cin>>h[i];
    ll comp = 1e+11;
    B *= 1000;
    A *= 1000;
    ll ans = 0;
    reps(i,1,N+1){
        ll temp = B - 6LL * h[i];
        if(abs(temp - A) < comp){
            comp = abs(temp - A);
            ans = i;
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
	char str[1001],cmd[10],c,s[1001];
	int i,j,q,a,b;
	
	scanf("%s",&str);
	scanf("%d",&q);
	
	for(i=0;i<q;i++){
		scanf("%s",&cmd);
		if(strcmp(cmd,"print") == 0){
			scanf("%d %d",&a,&b);
			for(j=a;j<=b;j++){
				printf("%c",str[j]);
			}
                        printf("\n");
		}else if(strcmp(cmd,"reverse") == 0){
			scanf("%d %d",&a,&b);
			while(a<b){
				c = str[a];
				str[a] = str[b];
				str[b] = c;
				a++;
				b--;
			}
		}else if(strcmp(cmd,"replace") == 0){
			scanf("%d %d %s",&a,&b,&s);
			for(j=0;j<b-a+1;j++){
				str[j+a] = s[j];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 572