akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int main(){
  int n,p; string s; cin >>n >>p >>s; ll ans=0;
  if(p==2||p==5){
    for(int i=0; i<n; i++) if((s[i]-'0')%p==0) ans+=i+1;
    cout <<ans;
  }
  else{
    int x=1,v=0; vector<ll>r(p,0);
    for(int i=1; i<=n; i++){
      v=(v+x*(s[n-i]-'0'))%p;
      r[v]++; x=(x*10)%p;
    }
    for(int i=0; i<p; i++) ans+=r[i]*(r[i]-1)/2;
    cout <<ans+r[0];
  }
return 0;}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int N;
  int c=1;
  int d[11];
  d[1]=1;d[9]=1;d[7]=1;d[4]=1;
  
  for(int i=0;i<4;i++){
    scanf("%d",&N);
    if(d[N]!=1) c=0;
    d[N]--;
  }
  
  if(c==1) printf("YES\n");
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 1616
#include<iostream>
using namespace std;
int a,b,c,d,e,f,z;
int main(){
    cin>>a>>b>>c;
    cin>>d>>e>>f;
    if(a-b!=d-e||b-c!=e-f||a-d!=b-e||b-e!=c-f)z=1;
    cin>>d>>e>>f;
    if(a-b!=d-e||b-c!=e-f||a-d!=b-e||b-e!=c-f)z=1;
    cout<<(z?"No":"Yes")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2,s3,s4;
    cin>>s1>>s2;
    reverse(s1.begin(),s1.end());
    if(s1==s2) cout<<"YES"<<endl;
    else                  cout<<"NO"<<endl;

    return 0;
}


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

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  static int h[100005];
  rep(i, n){
    int tmp;
    cin >> tmp;
    ++h[tmp];
  }
  int ans = 0;
  for(int i = 1; i < 100005; ++i) ans = max(ans, h[i-1]+h[i]+h[i+1]);
  cout << ans << "\n";
}  

Measured memory_bytes: 640
/************************************************
 *Author*        :skyNebula
 *Created Time*  : 六 10/20 13:43:57 2018

*********************************************/

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>


using namespace std;

char s[15];
vector<char> ans;



int main()
{
    while(~scanf("%s",s)){
        int len = strlen(s);
        for(int i = 0; i < len; i++){
            if(s[i] == '0' || s[i] == '1'){
                ans.push_back(s[i]);
            }
            else {
                if(ans.empty())continue;
                ans.pop_back();
            }
        }
        for(int i = 0; i < ans.size(); i++){
            printf("%c",ans[i]);
        }
        printf("\n");

    }

    return 0;
}


Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let a = read int
    let s = read string
    if a >= 3200 then
        s
    else
        "red"
    |> printfn "%s"
    0

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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    long long a;
	long double b;
    cin >> a >> b;
    long long ans=a*b*(long long)1;
    cout  << fixed  << ans << endl;
    return 0;
} 

Measured memory_bytes: 3748
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long counter = 0;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            counter++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    for (int h = 1;;) {
        if (h > n) break;
        G.push_back(h);
        h = 3 * h + 1;
    }

    for (int i = G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

// TODO: 写経になってしまったので、解説を読み込んで理解に落とし込む
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);

    shellSort(A, n);
    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if (i) printf(" ");
    }
    printf("\n");
    printf("%d\n", counter);
    for (int i = 0; i < n; i++) printf("%d\n", A[i]);

    return 0;
}


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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	string s;
	string t;
	cin >> s >> t;

	int count = 0;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			count++;
		}
	}
	cout << count;

	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
const int N=205,up=128;
int n,m,len,vis[N],b[N];
char s[N],ans[N];
int f(char c)
{
    if(c>='a'&&c<='z') return c-'a';
    if(c>='A'&&c<='Z') return c-'A'+f('z')+1;
    return c-'0'+f('Z')+1;
}
char g(int x)
{
    if(x<26) return 'a'+x;
    if(x<52) return 'A'+x-26;
    return '0'+x-52;
}
int query()
{
    m++;assert(m<=850);
    printf("? %s\n",s+1);
    fflush(stdout);
    int ans;scanf("%d",&ans);
    return ans;
}
vector<int>v;
bool cmp(int x,int y)
{
    for(int i=1;i<=n;i++) s[i]=ans[i];
    s[1+n]=g(x);
    for(int i=2;i<=vis[y]+1;i++)
        s[i+n]=g(y);
    s[vis[y]+2+n]='\0';
    return len-query()==vis[y]+n+1;
}
void msort(int l,int r)
{
    if(l==r) return;
    int m=l+r>>1;
    msort(l,m);msort(m+1,r);
    int i=l,j=m+1,k=l;
    while(i<=m&&j<=r)
        if(cmp(v[i],v[j])) b[k++]=v[i++];
        else b[k++]=v[j++];
    while(i<=m) b[k++]=v[i++];
    while(j<=r) b[k++]=v[j++];
    for(int i=l;i<=r;i++) v[i]=b[i];
}
string ss="Atcod3rIsGreat";
int q(char c)
{
    int ans=0;
    for(int i=0;i<ss.size();i++)
        if(c==ss[i]) ans++;
    return ans;
}
int main()
{
    for(int i=0;i<=61;i++)
    {
        for(int j=1;j<=128;j++) s[j]=g(i);
        s[129]='\0';
        vis[i]=128-query();
        //vis[i]=q(g(i));
        len+=vis[i];
        if(vis[i]) v.push_back(i);
    }
    msort(0,v.size()-1);
    int l=0,r=v.size()-1;
    while(l<=r)
    {
        ans[++n]=g(v[l]);
        vis[v[l]]--;
        if(!vis[v[l]]) l++;
        else if(l!=r)
        {
            int pos=l;
            for(int i=128;i;i>>=1)
                if(pos+i<=r&&cmp(v[pos+i],v[l]))
                pos+=i;
            int x=v[l];
            for(int i=l;i<pos;i++) v[i]=v[i+1];
            v[pos]=x;
        }
    }
    ans[n+1]='\0';
    printf("! %s\n",ans+1);
}
//Atcod3rIsGreat
/*
? ac
13
? cd
12
? ad
13
? eo
13
? orr
11
? err
13
? co
12
? do
13
? drr
11
? arr
13
? ae
13
? stt
13
? tA
13
? GI
13
? I3
13
? A3
12
? t3
12
? s3
13
? sI
13
? sG
12
? cA
13
? ctt
13
? c3
12
? o3
12
? d3
12
? r3
13
? rI
12
? eI
13
? es
13
? eG
13
? AtGt
10
? Atat
10
? Atcod3rer
13
? Atcod3rsr
5
? Atcod3rGr
5
! Atcod3rIsGreat
*/


Measured memory_bytes: 3776
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String word = input.next();
        for (int i = 0; i < word.length(); i++) {
            if ((i + 1) % 2 == 0) {
                if (word.charAt(i) == 'R') {
                    System.out.println("No");
                    return;
                }
            } else {
                if (word.charAt(i) == 'L') {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 35128
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int arr[MAXN][3];
int dp[MAXN][3];
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    dp[0][0] = arr[0][0], dp[0][1] = arr[0][1], dp[0][2] = arr[0][2];
    for(int i = 0; i < n; i++){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + arr[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + arr[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + arr[i][2];
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n';
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
  int main(){
   
      lint N;
      lint ans=1;
      cin>>N;
      lint A[N];
      rep(i,N){
          cin>>A[i];
      }
      lint x=A[0];
        rep(i,N-1){
            if(A[i+1]<x){ans++;
                x=A[i+1];
            }
            
        }
        cout<<ans;
  }
  

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();

    if (s.substring(0, n / 2).equals(s.substring(n / 2)))
      System.out.println("Yes");
    else
      System.out.println("No");

  }
}

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (true)
    {
        C -= B;
        if (C <= 0)
        {
            puts("Yes");
            break;
        }
        A -= D;
        if (A <= 0)
        {
            puts("No");
            break;
        }
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n; cin >> n;
  vector<int> ans(n, 0);
  vector<long long int> h(n,0);

  int counter = 0;
  for(int i = 0; i < n; i++){
    long long int temp; cin >> temp;
    h[i] = temp;

    if(i > 0 && h[i-1] >= h[i]){
      ans[counter]++;
    } else if(i == 0) {
      
    } else {
      counter++;
    }
  }

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

  cout << ans[0] << endl;

  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
int n, a[300010];
long long sl[300010], sr[300010];

int main() {
	cin >> n;
	for (int i = 1; i <= 3 * n; i++)cin >> a[i];

	priority_queue<int, vector<int>, greater<int>>q;
	long long s = 0;
	for (int i = 1; i <= 2 * n; i++) {
		q.push(a[i]);
		s += a[i];
		if (q.size() > n) {
			s -= q.top(); q.pop();
		}
		sl[i] = s;
	}
	priority_queue<int>que;
	s = 0;
	for (int i = 3 * n; i >= n; i--) {
		que.push(a[i]);
		s += a[i];
		if (que.size() > n) {
			s -= que.top(); que.pop();
		}
		sr[i] = s;
	}
	long long res = -1e15;
	for (int i = n; i <= 2 * n; i++)res = max(res, sl[i] - sr[i + 1]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
	int main(){
	vector<int> king(5);
	for(int i = 0 ; i <5 ; i++){
	cin >> king[i] ;
	}
	int k ;
	cin >> k ;
	sort (king.begin(),king.end());
	reverse(king.begin(),king.end());
	int x; 
	x = king[0] -king [4];
	if ( x > k){
	cout << ":(" << endl;
	}
	else {
	cout << "Yay!" <<endl;
	}
	}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <fstream>

std::vector<int> primes(const int upper) {
	std::vector<bool> is_prime(upper + 1, true);
	for (auto i = 2; i * i <= upper; ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j <= upper; j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i <= upper; ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}
int main(){
	const auto prime = primes(100000 / 2);
	while (true) {
		int m, a, b; std::cin >> m >> a >> b;
		if (m == 0) break;
		int max_area = 0;
		std::pair<int, int> result{ 2, 2 };
		for (auto i = 0; prime[i] * prime[i] <= m; ++i) {
			const auto ratio = std::prev(std::upper_bound(prime.begin(), prime.end(), prime[i] * b / a));
			const auto area = std::prev(std::upper_bound(prime.begin(), prime.end(), m / prime[i]));
			const auto min = std::min(*ratio, *area);
			if (max_area < min * prime[i]) {
				max_area = min * prime[i];
				result = std::make_pair(prime[i], min);
			}
		}
		std::cout << result.first << ' ' << result.second << '\n';
	}
}



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}

ll comb(int a, int b){
	ll ret = 1;
	rip(i,b,0){
		ret*=a-i;
		ret/=i+1;
	}
	return ret;
}

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	vector<ll> da(n);
	rip(i,n,0){
		cin >> da[i];
	}
	map<ll,int> mp;
	rip(i,n,0){
		if(mp.count(da[i])){
			mp[da[i]]++;
		}
		else{
			mp[da[i]]=1;
		}
	}
	auto itr = mp.end();
	--itr;
	if((*itr).second > a){
		ll ans = 0;
		cout << (*itr).first << endl;
		rip(i,min(b,(*itr).second)+1,a){
			ans += comb((*itr).second,i);
		}
		cout << ans << endl;
	}
	else{
		int co = a;
		ll ret = 0;
		while((*itr).second < a){
			ret += (ll)(*itr).first * (*itr).second;
			a-=(*itr).second;
			--itr;
		}
		ret += (ll)(*itr).first * a;
		printf("%.07f\n",(double)ret/co);
		cout << comb((*itr).second,a) << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>

class dictionary{
private:
    std::set<std::string> words;

public:
    dictionary(){

    }

    void insert(std::string readStr){
        words.insert(readStr);
    }

    bool isFound(std::string readStr){
        auto itr = words.find(readStr);
        if(words.end() != itr){
            std::cout << "yes" << std::endl;
            return true;
        }else{
            std::cout << "no" << std::endl;
            return false;
        }
    }
};

int main(){
    int n;
    std::cin >> n;

    dictionary dict;

    for(int i = 0; i < n; ++i){
        std::string cmd, str;
        std::cin >> cmd >> str;
        if("insert" == cmd){
            dict.insert(str);
        }else{
            dict.isFound(str);
        }
    }

    return 0;
}


Measured memory_bytes: 32160
S = [
    (1, 2, 4, 3), # 0
    (0, 3, 5, 2), # 1
    (0, 1, 5, 4), # 2
    (0, 4, 5, 1), # 3
    (0, 2, 5, 3), # 4
    (1, 3, 4, 2), # 5
]

*L, = map(int, input().split())
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    for i in range(6):
        if L[i] == a:
            for k in range(4):
                if L[S[i][k]] == b:
                    print(L[S[i][k-3]])




Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define _GLIBCXX_DEBUG

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    for (int i=0; i<n; ++i) cin >> w[i], sum += w[i];
    int l = 0;
    int r = sum;
    int abs_mn = abs(r - l);
    for (int i=0; i<n; ++i) {
        l += w[i];
        r -= w[i];
        abs_mn = min(abs_mn, abs(r - l));
    }
    cout << abs_mn << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    sort(a.begin(), a.end());
    int ans = 0;

    ans += a[2]-a[1];
    a[0] += a[2]-a[1];
    a[1] = a[2];

    if((a[2]-a[0])%2 == 0) cout << ans + (a[2]-a[0])/2 << endl;
    else cout << ans + (a[2]-a[0])/2 + 2 << endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int a[5]; string s;
int main() {
	cin >> s;
	for (int i = 0; i < 4; i++) {
		a[i] = s[i] - 48;
	}
	for (int i = 0; i < 8; i++) {
		int res = a[0];
		for (int j = 0; j < 3; j++) {
			if (i & (1 << j)) res += a[j + 1];
			else res -= a[j + 1];
		}
		if (res == 7) {
			cout << a[0];
			for (int j = 0; j < 3; j++) {
				if (i & (1 << j)) cout << "+";
				else cout << "-";
				cout << a[j + 1];
			}
			cout << "=7";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int H = in.nextInt();
        int N = in.nextInt();
        for(int i = 0; i < N; i++){
            int A = in.nextInt();
            H = H - A;
        }
        if(H <= 0){
            println("Yes");
        }
        else{
            println("No");
        }

        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 31768
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
#define ses   "\n"
#define whp   " "
#define mxi 200003
#define mp make_pair
#define PII pair<long long, long long>
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a));
#define PI acos(-1)
#define what_is(x) cout<<x<<ses;
//set <int, greater <int> > ::iterator it;
//vector<pair<int,int> >a;
//memset(arr,0,sizeof(hg));
//priority_queue <int, vector<int>, greater<int> > pq;
///  string single character erase-
///             s.erase(s.begin()+x); where s is st ring name
///               ans x is index;
///    transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
///    transform(su.begin(), su.end(), su.begin(), ::toupper);
typedef long long v99;
typedef unsigned long long ull;
using namespace std;
v99 fx[4]= {1,-1,0,0};
v99 fy[4]= {0,0,1,-1};
v99 ox8[] = {0, 0, 1, 1, 1, -1, -1, -1};
v99 oy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
bool sort2val(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.second==b.second)return a.first<b.first;
    return a.second<b.second;
}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
/**bool prime[10000020];vector<v99>prm;
void SieveOfEratosthenes(v99 n)
{
	memset(prime, true, sizeof(prime));
	for(v99 i=4;i<=n;i+=2)prime[i]=false;
	for (v99 p=3; p*p<=n; p+=2)
	{
		if (prime[p] == true)
		{
			/// Update all multiples of p
			for (v99 i=p*p; i<=n; i += 2*p)
				prime[i] = false;
		}
	}
	rep1(i,2,n)if(prime[i])prm.push_back(i);

}*/
v99 pw(v99 a, v99 b)
{
	v99 ans = 1;
	for(v99 i = 1; i <= b; ++i)
		ans = (ans * a);
	return ans;
}

template <class T> inline T bigmod(T n,T p,T m)
{
    if(p==0)return 1;
    else if(p%2==0)
    {
        v99 val=bigmod(n,p/2,m);
        return (T)((val*val)%m);
    }
    else return (T)(((v99)n*(v99)bigmod(n,p-1,m))%m);
}
///-------------------------------------------------------------------------------------------------------



void solve()
{
    /// code is here->
    v99 n;cin>>n;
    if(n>=400 && n<=599)cout<<8<<ses;
    else if(600<=n && n<=799)cout<<7<<ses;
    else if(800<=n && n<=999)cout<<6<<ses;
    else if(1000<=n && n<=1199)cout<<5<<ses;
    else if(1200<=n && n<=1399)cout<<4<<ses;
    else if(1400<=n && n<=1599)cout<<3<<ses;
    else if(1600<=n && n<=1799)cout<<2<<ses;
    else if(1700<=n && n<=1999)cout<<1<<ses;
    else cout<<7<<ses;
}






int main()
{

    //freopen("data.out","w",stdout);
    //while(1)
    //test
    solve();

    return 0;
}



      ///  Alhamdulillah...


Measured memory_bytes: 3580
program A320A
    implicit none
    integer(8)::N,i,flg
    integer(8),allocatable,dimension(:)::L
    read*,N
    allocate(L(N))
    read*,L
    call heapsort(N,L)
    flg=L(N)
    do i=1,N-1
        flg=flg-L(N-i)
    end do

    if(flg<0)print'(A)',"Yes"
    if(flg>=0)print'(A)',"No"
end program A320A

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
  end subroutine heapsort

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

#define reps(i,j,k) for(int i=j;i<k;i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define mk make_pair

using namespace std;

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

int dp[305][305];
bool al[305][305]
;
int main(){
	int n;
	while(cin >> n, n){
		vi w(n);
		rep(i, n) cin >> w[i];
		fill(dp[0], dp[305], 0);
		fill(al[0], al[305], 0);
		reps(j, 2, n+1){
			rep(i, n - j + 2){
				int ij = i + j;
				if(j==2) al[i][ij] = abs(w[i]-w[i+1]) < 2;
				else{
					al[i][ij] = al[i+1][ij-1] && abs(w[i]-w[ij-1]) < 2;
					reps(k, i+1, ij){
						al[i][ij] = al[i][ij] ||  al[i][k] && al[k][ij];
					}
				}
				dp[i][ij] = al[i][ij] * j;
				rep(k, i) dp[k][ij] = max(dp[k][ij], dp[i][ij]);
				reps(k, ij+1, n+1) dp[i][k] = max(dp[i][k], dp[i][ij]);
			}
		
		}
		/*
		rep(i,n+1){
			rep(j,n+1){
				cout << al[i][j] << " ";
			}
			cout << endl;
		}*/

		rep(j, n+1){
			rep(i, n - j + 2){
				int ij = i + j;
				reps(k, i+1, j){
					dp[i][j] = max(dp[i][k] + dp[k][j], dp[i][j]);
				}

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

	}
	return 0;
}

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

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> h(n+1);
    for(int i=0;i<n;i++){
        cin >> h[i+1];
    }
    for(int i=0;i<n;i++){
        ans += max(0, h[i+1]-h[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
 
 
int main() {
  long int N,C,K;
  vector<long int> T;
  long int bus=0;
  cin >> N >>C >>K;
  T.resize(N);
  for(long int i=0;i<N;i++){
    cin >> T[i];
  }
  sort(T.begin(),T.end());
  long int j=0;/*current index*/
  while(j!=N){
    if(N-j<C){C=(N-j);}
      for(int i=0;i<=C;i++){
  	if((T[j+C-i-1]-T[j])<=K){
  	  j=j+C-i;
  	  bus=bus+1;
  	  break;
  	}
      }
  }   
 
  cout << bus <<endl;
 
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;

int n;
pi a[100005];

int solve(){
    int s = 0, e = 400000;
    while (s != e) {
        int m = (s+e)/2;
        int xl = 1e9, yl = 1e9, xh = -1e9, yh = -1e9;
        for (int j=0; j<n; j++) {
            if(a[j].first > m || a[j].second > m){
                xl = min(xl,a[j].first);
                xh = max(xh,a[j].first);
                yl = min(yl,a[j].second);
                yh = max(yh,a[j].second);
            }
        }
        if(yh - yl <= m && xh - xl <= m) e = m;
        else s = m+1;
    }
    return s;
}

int main(){
    scanf("%d",&n);
    int minv1 = 1e9, minv2 = 1e9, maxv1 = 0, maxv2 = 0;
    for (int i=0; i<n; i++) {
        int x,y;
        scanf("%d %d",&x,&y);
        a[i] = pi(x+y,x-y);
        maxv1 = max(maxv1,x+y);
        maxv2 = max(maxv2,x-y);
        minv1 = min(minv1,x+y);
        minv2 = min(minv2,x-y);
    }
    maxv1 -= minv1;
    maxv2 -= minv2;
    for (int i=0; i<n; i++) {
        a[i].first -= minv1;
        a[i].second -= minv2;
    }
    int ret = solve();
    for (int i=0; i<n; i++) {
        a[i].first = maxv1 - a[i].first;
    }
    ret = min(ret,solve());
    printf("%d\n",ret);
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PI 3.14159265358979
		#define EPS 1e-8
		#define mod  998244353
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define endl "\n"
			 
		const ll INF=1e15;	
		const int N=2e5+50;
		 

		 
		long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
				a = a * a % m;
				b >>= 1;
			}
			return res;
		}
		
		ll modinverse(ll a,ll m)
		{
			return binpow(a,m-2,m);
		}
		
			
		
		
		int main()
		{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);cout.tie(0);
		
					
			ll n;
			cin>>n;
			
			vector<ll> v(n+1,0),v1(n+1,0);
			
			for(ll i=1;i<=n;i++)
			{
				cin>>v[i];
				
				v[i]+=v[i-1];
				v1[i]=v[i];
			}
			
			ll ans1=0,ans2=0;
			ll val1=0,val2=0;
			
			
			for(ll i=1;i<=n;i++)
			{
				
				v[i]+=val1;
				v1[i]+=val2;
				
				
				
				if(i%2==1)
				{
					
					if(v[i]<=0)
					{
						ans1+=(1-v[i]);
						val1+=(1-v[i]);
					}
					if(v1[i]>=0)
					{
						ans2+=(v1[i]+1);
						val2-=(v1[i]+1);
					}
				}
				else
				{
					if(v1[i]<=0)
					{
						
						
						ans2+=(1-v1[i]);
						val2+=(1-v1[i]);
					}
					if(v[i]>=0)
					{
						ans1+=(v[i]+1);
						val1-=(v[i]+1);
					}
				}
			}
		
			cout<<min(ans1,ans2);
			
			
			
			
			
		}
			
			
		


Measured memory_bytes: 4744
S = input()
Q = int(input())

is_reverse = False
sento = []
matubi = []
for i in range(Q):
    s = input().split()
    if s[0] == '1':
        is_reverse = not is_reverse
    else:
        if (s[1] == '1' and not is_reverse) or (s[1] == '2' and is_reverse):
            sento.append(s[2])
        else:
            matubi.append(s[2])

ans = ''.join(sento[::-1]) + S + ''.join(matubi)
if is_reverse:
    ans = ans[::-1]
print(ans)

Measured memory_bytes: 6252
x = list(map(int, input().split()))

list_size = len(x)
for i in range(list_size):
    for j in range(list_size-i-1):
        if x[j] > x[(j+1)]:
            t = x[j]
            x[j] = x[(j+1)]
            x[(j+1)] = t
        
print(x[0],x[1],x[2])


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

using namespace std;
const int N=200010;
int n,a[N];
int cnt=0;

int main(){
    cin>>n;
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int j=1;
    for(int i=0;i<n;i++){
        if(a[i]==j){
            cnt++;
            j++;
        }
    }
    if(cnt==0) cout<<"-1"<<endl;
    else cout<<n-cnt<<endl;
    return 0;
}

Measured memory_bytes: 1024
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    vector<int> ans(n + 1, 0);
    for (int i = n; i > 0; --i) {
        int md = 0;
        for (int k = i + i; k <= n; k += i) {
            md += ans[k];
        }
        // DD(i, md);
        if (md % 2 != a[i - 1]) ans[i] = 1;
    }
    int m = 0;
    REP(i, n + 1) m += ans[i];
    cout << m << endl;
    bool first = true;
    if (m > 0) {
        REP(i, n + 1) {
            if (ans[i] == 1) { cout << (first ? "" : " ") << i; first = false; }
        }
        cout << endl;
    }
}


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

using namespace std;

const int md = 1e9 + 7;

using ll = long long;
ll solve(vector<vector<int>> &tree, int k, int cur = 0, int p = -1) {
  ll ans = 1, base = k - (p != -1);

  for (int i = 0, nth = 1; i < tree[cur].size(); ++i, ++nth) {
    if (tree[cur][i] == p) {
      nth--;
      continue;
    }

    ans = ans * (base - nth) % md;
    ans = ans * (solve(tree, k, tree[cur][i], cur) % md) % md;
  }

  return ans % md;
}

int main(int argc, const char *argv[]) {
  int n, k;
  cin >> n >> k;

  vector<vector<int>> tree(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  cout << solve(tree, k) * k % md << '\n';
  return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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;
}

// const int MAX = 1010;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
    return 0;
}

Measured memory_bytes: 3628
N = gets.to_i 
A = gets.split.map(&:to_i)

freq = A.inject(Hash.new(0)) {|h, a| h[a] += 1; h}
z = freq.values.inject(0) {|x, r| x += 1 if r % 2 == 0; x}
puts freq.size - (z % 2 == 1 ? 1 : 0)


Measured memory_bytes: 15364
// n_i + n_j || m_i + m_j

#include <stdio.h>

int main(void)
{
  int n, m;
  scanf("%d %d", &n, &m);
  
  int ans;
  ans = (n * (n - 1) / 2) + (m * (m - 1) / 2);
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,x,y,z,sum,v,f[45][1<<18],ans=1;
int main(){
	scanf("%lld%lld%lld%lld",&n,&x,&y,&z);
	memset(f,0,sizeof(f));
	sum=(1<<x+y+z-1)|(1<<y+z-1)|(1<<z-1);
	v=(1<<(x+y+z))-1;
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		ans=(ans*10)%mod;
		for(int j=0;j<=v;j++){
			if(f[i-1][j]==0)continue;
			for(int k=1;k<=10;k++){
				int now=v&((j<<k)|(1<<k-1));
				if((now&sum)!=sum)f[i][now]=(f[i][now]+f[i-1][j])%mod;
			}
		}
	}
	for(int i=0;i<=v;i++)ans=(ans-f[n][i]+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 95964
#include<iostream>
#include <map>
using namespace std; 
typedef long long ll;

int main()
{    
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;cin>>n;
    cout<<a[n-1]<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    
    rep(m,n){
        
        if(c*(n-1-m)-d*m<=b-a && b-a<=-c*m+(n-1-m)*d){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    
    cout<<"NO"<<endl;
    return 0;
}




Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func nextFloat64() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func norm2(x, y float64) float64 {
	return x*x + y*y
}

func main() {
	scanner.Split(bufio.ScanWords)

	p1x, _ := nextFloat64()
	p1y, _ := nextFloat64()
	p2x, _ := nextFloat64()
	p2y, _ := nextFloat64()

	intercept := 0.0
	if p1x == p2x {
		intercept = 0
	} else {
		intercept = (p2x*p1y - p1x*p2y) / (p2x - p1x)
	}
	p1y -= intercept
	p2y -= intercept

	norm2 := norm2(p1x-p2x, p1y-p2y)

	nQueries := nextInt()
	for i := 0; i < nQueries; i++ {
		p3x, _ := nextFloat64()
		p3y, _ := nextFloat64()
		p3y -= intercept

		dot := (p2x-p1x)*p3x + (p2y-p1y)*p3y
		// fmt.Println(dot, norm2)
		fmt.Println(dot*(p2x-p1x)/norm2, dot*(p2y-p1y)/norm2+intercept)
	}
}



Measured memory_bytes: 1156
#include <stdio.h>

int judge(int a,int b,int k)
{
	for (int i = a;i <= b;i++){
			if (i % k == 0)return 1;
		}

	return 2;
}

int main()
{
	int A,B,K;

	scanf("%d",&K);
	scanf("%d %d",&A,&B);

	if (judge(A,B,K) == 1){
		printf("OK\n");
	}else{
		printf("NG\n");
	}

	return 0;
}


Measured memory_bytes: 1644
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,M=rl()
DIV = 10**9 + 7

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

l = factorize(M)

ans = 1
for _, i in l:
    res = 1
    for j in range(i):
        res *=(N-1+i-j)%DIV
    for j in range(i):
        res = res//(j+1)
    ans *= res
    ans %= DIV

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
signed main() {
	ll n, a, b, c, cnt = 0, ans1 = 0;
	cin >> n; c = n % 10; b = n % 100 / 10; a = n % 1000 / 100; n /= 1000;
	if (n + a + b + c == 7) {
		cout << n << '+' << a << '+' << b << '+' << c << '=' << 7 << endl; return 0;
	}
	if (n + a + b - c == 7) {
		cout << n << '+' << a << '+' << b << '-' << c << '=' << 7 << endl; return 0;
	}
	if (n + a - b + c == 7) {
		cout << n << '+' << a << '-' << b << '+' << c << '=' << 7 << endl; return 0;
	}
	if (n - a + b + c == 7) {
		cout << n << '-' << a << '+' << b << '+' << c << '=' << 7 << endl; return 0;
	}
	if (n - a - b - c == 7) {
		cout << n << '-' << a << '-' << b << '-' << c << '=' << 7 << endl; return 0;
	}
	if (n - a - b + c == 7) {
		cout << n << '-' << a << '-' << b << '+' << c << '=' << 7 << endl; return 0;
	}
	if (n - a + b - c == 7) {
		cout << n << '-' << a << '+' << b << '-' << c << '=' << 7 << endl; return 0;
	}
	if (n + a - b - c == 7) {
		cout << n << '+' << a << '-' << b << '-' << c << '=' << 7 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

int gcd(int a, int b) {
  if (a < b) { swap(a, b); }
  if (b == 0) { return a; }
  return gcd(b, a % b);
}

bool prime(int n) {
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) { return false; }
  }
  return n != 1;
}

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

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// 1 << MSB(n) is the most significant set bit of n.
// e.g. (1 << 3) = 1000 is the most significant set bit of 10 = 1010
int MSB(int n) {
  if (n == 0) { return 0; }

  int r = -1;
  for (; n > 0; n >>= 1) {
    ++r;
  }
  return r;
}

int main(int argc, char** argv) {
  int N;
  cin >> N;

  if (!(N & N - 1)) { // N is 2 ** x
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  cout << 1 + N << " " << 3 + N << endl;
  for (int i = 2; i < N + 1; ++i) {
    if (N % 2 == 0 && i == N) {
      int t = 1 << MSB(N);
      cout << N << " " << t << endl;
      cout << N + N << " " << (t ^ N ^ 1) << endl;
    } else {
      cout << 1 << " " << i << endl;
      cout << i << " " << (i ^ 1) + N << endl;
    }
  }
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 2e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n, a[N];
int32_t main()
{
	IOS
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n, greater<int>());
	int ans = a[0];
	n -= 2;
	int i;
	for(i=1; i<=n/2; i++) ans += 2*a[i];
	if (n&1) ans += a[i];
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 5224
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

int W, H;
bool edge[33][33][33][33];

int bfs() {
  static int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
  vector< vector< int > > used(H + 1, vector< int >(W + 1, INF));
  queue< iP > que;
  used[0][0] = 0;
  que.push(iP(0, 0));
  while(!que.empty()) {
    iP p = que.front(); que.pop();
    for(int i = 0; i < 4; i++) {
      int nx = p.fr + dx[i], ny = p.sc + dy[i];
      if(edge[p.sc][p.fr][ny][nx] && 0 <= nx && nx < W && 0 <= ny && ny < H && used[p.sc][p.fr] + 1 < used[ny][nx]) {
        que.push(iP(nx, ny));
        used[ny][nx] = used[p.sc][p.fr] + 1;
      }
    } 
  }
  return (used[H - 1][W - 1] == INF ? 0 : used[H - 1][W - 1] + 1);
}

int main(){
  
  while(cin >> W >> H, W) {
    memset(edge, true, sizeof(edge));
    for(int i = 0; i < H * 2 - 1; i++) {
      if(i % 2 == 0) {
        for(int j = 0; j < W - 1; j++) {
          int mas; cin >> mas;
          if(mas) edge[i / 2][j][i / 2][j + 1] = edge[i / 2][j + 1][i / 2][j] = false;
        }
      }
      else {
        for(int j = 0; j < W; j++) {
          int mas; cin >> mas;
          if(mas) edge[i / 2][j][i / 2 + 1][j] = edge[i / 2 + 1][j][i / 2][j] = false;
        }
      }
    }
    
    cout << bfs() << endl;
  }
}

Measured memory_bytes: 2388
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 55;
const LL MOD = 1000000007;

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(const mat &m1, const mat &m2) {
	mat res = mat(m1.size(), vec(m2[0].size(), 0));
	for (int i = 0; i < m1.size(); i++) {
		for (int j = 0; j < m2[0].size(); j++) {
			for (int k = 0; k < m2.size(); k++) {
				res[i][j] = (res[i][j] + (LL)m1[i][k] * m2[k][j]) % MOD;
			}
		}
	}
	return res;
}

mat qpow(const mat &m, LL pw) {
	if (pw == 1) return m;
	mat res = qpow(m, pw >> 1);
	res = mul(res, res);
	if (pw & 1) res = mul(res, m);
	return res;
}

LL K, N;
mat adj;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> K;
	adj.resize(N, vec(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> adj[i][j];
		}
	}
	
	LL ans = 0;
	adj = qpow(adj, K);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans = (ans + adj[i][j]) % MOD;
		}
	}
	
	cout << ans << "\n";
}


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

#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define all(v) v.begin(),v.end()
#define mod %
#define pb push_back

const ll N = (ll)(100007);


int main()
{
	FIO
	ll p = 1;
	int cnt = 0;
	while(p <= (ll)(1e18)) {
		cnt+=1;	
		p = p * 5;
	}

	ll n;
	cin >> n;
	if(n mod 2 == 1) {
		cout << 0 << "\n";
	} else {
		ll ans = 0;
		ll prev = 0;
		while(cnt>0) {
			ll cur = n/p;
			cur/=2;
			p = p/5;
			ans = ans + (cnt * (cur - prev));
			prev = cur;
			cnt-=1;
		}
		cout << ans << "\n";
	}
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll dp[2200][2200];
int main() {
    ll N; cin >> N;
    vpll A;
    rep(i, N) {
        ll a; cin >> a;
        A.emplace_back(a, i);
    }
    sort(A.begin(), A.end(), greater<pll>());

    ll cnt;
    ll ans = 0;
    rep(l, N) rep(r, N) {
        if(l+r == N) {
            chmax(ans, dp[l][r]);
            break;
        }
        cnt = l + r;
        chmax(dp[l+1][r], dp[l][r] + abs(A[cnt].second - l) * A[cnt].first);
        chmax(dp[l][r+1], dp[l][r] + abs(A[cnt].second - (N-1-r)) * A[cnt].first);
    }
    cout << ans << endl;
}


Measured memory_bytes: 26936