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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

ll m=55555;
vector<bool>ch(m+100,true);
vector<ll>p;

void f(){
    ch[0]=ch[1]=false;
    for(int i=2;i<m;i++){
        if(ch[i]){
            if(i%5==1)p.push_back(i);
            for (int j = 2*i; j < m; j+=i) {
                ch[j]=false;
            }
        }
    }
}

int main(){
    f();
//    cout <<p.size()<<endl;
    ll n;cin >>n;
    for (int i = 0; i < n; ++i) {
        cout <<p[i]<<" ";
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
unsigned long long a[200001];
unsigned long long b[200001];
int main() {
    fastio
    int N;
    unsigned long long ans=0;
    cin>>N;
    for(int i=1;i<=N;i++)
        cin>>a[i];
    b[1]=a[1];
    for(int i=2;i<=N;i++){
        b[i]=a[i]+b[i-1];
    }
    for(int i=1;i<N;i++){
        ans+=((a[i]%1000000007)*((b[N]-b[i])%1000000007))%1000000007;
        ans%=1000000007;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6768
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in(),k=in();
    vector<ll>a(n);for(ll i=0;i<n;++i)a[i]=in();

    for(ll i=0;i<k;++i){
        bool is_updated=false;
        vector<ll>imos(n+1);
        for(ll j=0;j<n;++j){
            ++imos[max(0ll,j-a[j])];
            --imos[min(n,j+a[j]+1)];
        }
        for(ll j=0;j<n;++j)imos[j+1]+=imos[j];
        for(ll j=0;j<n;++j){
            is_updated|=a[j]!=imos[j];
            a[j]=imos[j];
        }
        if(!is_updated)break;
    }

    for(ll i=0;i<n;++i){
        if(i!=0)cout<<' ';
        cout<<a[i];
    }
    cout<<endl;
}



Measured memory_bytes: 6424
if __name__ == '__main__' :
        while(True):
            H,W = [int(i) for i in input().split(" ")]
            if(H == 0 and W == 0) : break
            s1 = ['#' if i % 2 == 0 else "." for i in range(W)]
            s2 = ['#' if i % 2 == 1 else "." for i in range(W)]
            for i in range(H):
                if(i % 2 == 0):print("".join(s1))
                else:print("".join(s2))
            print()


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#include<iostream>
#include<string.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    double d,t,s;
    cin>>d>>t>>s;
    if(t>=d/s)
        cout<<"Yes";
    else
        cout<<"No";


}


Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int sum = 0, NN = N;
    while(N > 0)
    {
        sum += N % 10;
        N /= 10;
    }
    if(NN % sum == 0)
        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 vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  string t;
  for (ll i = 0; i < n; i++) t.push_back('#');
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (s[i] == '.') ans++;
  }
  vll v(1, ans);
  for (ll i = 0; i < n; i++) {
    t[i] = '.';
    if (s[i] == '.') v.push_back(v.back() - 1);
    else v.push_back(v.back() + 1);
  }
  for (ll i = 1; i <= n; i++) ans = min(ans, v[i]);
  cout << ans << endl;
}

Measured memory_bytes: 2940
#include<stdio.h>

int s(int A[],int N)
{
	int i,j,t,sw=0,minj;
	for(i=0;i<N-1;i++)
	{
		minj=i;
		for(j=i;j<N;j++)
		{
			if(A[j]<A[minj]) minj=j;
		}
		t=A[i];A[i]=A[minj];A[minj]=t;
		if(i!=minj) sw++;
	}
	return sw;
}
int main()
{
	int A[100],N,i,sw;
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	sw=s(A,N);
	for(i=0;i<N;i++)
	{
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",sw);
	return 0;
}

Measured memory_bytes: 2732
import math
a, b = map(int, input().split())
def tax(price, tax_rate):
  return int(price * (tax_rate / 100))
def range_of_price(tax_rate, target):
  entry_point = math.ceil(target / (tax_rate / 100))
  counter = entry_point
  if tax(entry_point, tax_rate) < target:
    for i in range(100):
      counter += i
      if tax(counter, tax_rate) == target:
        left = counter
        break
    for i in range(100):
      counter += 1
      if tax(counter, tax_rate) > target:
        right = counter - 1
        break
  elif tax(entry_point, tax_rate) == target:
    for i in range(100):
      counter -= i
      if tax(counter, tax_rate) < target:
        left = counter + 1
        break
    counter = entry_point
    for i in range(100):
      counter += 1
      if tax(counter, tax_rate) > target:
        right = counter - 1
        break
  elif tax(entry_point, tax_rate) > target:
    for i in range(100):
      counter -= i
      if tax(counter, tax_rate) == target:
        right = counter
        break
    for i in range(100):
      counter -= i
      if tax(counter, tax_rate) < target:
        left = counter - 1
        break
  #print(left, right)
  return left, right
      
left8, right8 = range_of_price(8, a)
left10, right10 = range_of_price(10, b)
if left8 > right10 or right8 < left10:
  print(-1)
else:
  print(max(left8, left10))


Measured memory_bytes: 38384
#include<cstdio>

using namespace std;

int main()
{
	long long n=0;scanf("%lld",&n);
	long long ans=0;
	for(int i=2;i<=1000000;i++)
	{
		int cnt=0;while(n%i==0){cnt++;n/=i;}
		int x=0;while((x+1)*(x+2)/2<=cnt)x++;
		ans+=x;
	}
	if(n>1)ans++;printf("%lld",ans);
}

Measured memory_bytes: 1732
A,B,AB,X,Y = map(int,input().split())

ans = min(X,Y)*min(2*AB, A+B)
cnt_A = min(X,Y)
cnt_B = min(X,Y)

#残り
if X > cnt_A:#Aが足りないときa
    ans += min(2*AB,A)*(X-cnt_A)
else:#Bが足りないとき
    ans += min(2*AB,B)*(Y-cnt_B)
    
print(ans)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 1 << 17;

int N, A, B;

void go(int s, int t, int mask)
{
  if(__builtin_popcount(mask) == N - 1){
    cout << s << ' ' << t << ' ';
    return;
  }
  int c = -1, e = -1;
  for(int i = 0; i < N; ++i) if(!(mask >> i & 1)){
    if(c == -1 && (s >> i & 1) != (t >> i & 1)) c = i;
    else e = i;
  }
  go(s, s ^ (1 << e), mask ^ (1 << c));
  go(s ^ (1 << e) ^ (1 << c), t, mask ^ (1 << c));
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> A >> B;
  if(__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2){
    cout << "NO";
  }
  else{
    cout << "YES\n";
    go(A, B, 0);
  }
}


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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    int cur = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] == cur + 1)
        {
            ++cur;
        }
    }
    if (cur == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n - cur << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
program hi;
type ars = array[1..200000] of string;
var 
    n, i, cnt: longint;
    s, tmp: ars;
 
procedure mSort(var a, tmp: ars; l, r: longint);
var m, i, i1, i2: longint;
begin
    if l < r then begin
        m := (l + r) div 2;
        mSort(a, tmp, l, m);
        mSort(a, tmp, m + 1, r);
        i := l; i1 := l; i2 := m + 1;
        while (i1 <= m) and (i2 <= r) do begin
            if a[i1] <= a[i2] then begin
                tmp[i] := a[i1];
                inc(i1);
            end else begin
                tmp[i] := a[i2];
                inc(i2);
            end;
            inc(i);
        end;
        while i1 <= m do begin
            tmp[i] := a[i1];
            inc(i1); inc(i);
        end;
        while i2 <= r do begin
            tmp[i] := a[i2];
            inc(i2); inc(i);
        end;
        for i := l to r do 
            a[i] := tmp[i];
    end;
end;
 
begin
    readln(n);
    for i := 1 to n do 
        readln(s[i]);
    mSort(s, tmp, 1, n);
    cnt := 1;
    for i := 1 to n - 1 do 
        if s[i] <> s[i + 1] then
            inc(cnt);
    writeln(cnt);
end.

Measured memory_bytes: 59980
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
dp=[[10**9 for _ in range(51)] for _ in range(1<<N)]
dp[0][0]=0
for S in range(1<<N):
 j=bin(S).count("1")
 c=0
 for i in range(N):
  if not (S&1<<i):
   k = A[i] if (i-j)%2==0 else B[i]
   for l in range(k+1):
    dp[S|1<<i][k] = min(dp[S|1<<i][k],dp[S][l]+c)
   c += 1
ans = min(dp[-1])
print(-1 if ans == 10**9 else ans)

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

int main(){
	int n, num, card[4][13] = {0};
	char c;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c>>num;
		if(c == 'S')      card[0][num-1]++;
		else if(c == 'H') card[1][num-1]++;
		else if(c == 'C') card[2][num-1]++;
		else if(c == 'D') card[3][num-1]++;
	}

	for(int i=0;i<4;i++){
		if(i == 0)      c = 'S';
		else if(i == 1) c = 'H';
		else if(i == 2) c = 'C';
		else if(i == 3) c = 'D';
		
		for(int j=0;j<13;j++){
			if(card[i][j] == 0){
				cout<<c<<" "<<j+1<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1164
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll H = 0, W =0, N=0;
    cin >> H >> W >> N;

    //本文
    ll l1 = max(H,W);
    ll l2 = min(H,W);
    //出力
    ll ans = N/l1;
    if(N%l1!=0) ans++;
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3496
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jeel Vaishnav
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DDivRemNumber solver = new DDivRemNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDivRemNumber {
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            long n = sc.nextLong();

            long ans = 0;

            for (long i = 1; i * i <= n; ++i) {
                if (n % i == 0) {
                    long div = n / i;
                    long val = div - 1;

                    if (i < val)
                        ans += val;
                }
            }

            out.print(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main() {
  int n, k;
  cin >> n >> k;

  int result = 1;

  for (int i=0;i<n;i++) {
    if (result + k < result * 2) {
      result += k;
    } else {
      result *= 2;
    }
  }

  cout << result << endl;

  return 0;
}

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

int main(){
  long long H,W;
  cin >> H >> W;

  if(H==1 || W==1){
    cout << 1 << endl;
    return 0;
  }

  if(H%2==1 && W%2==1)  cout << H*(W/2)+(H+1)/2 << endl;
  else  cout << H*W/2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long int
#define pi 3.1415926536
using namespace std;

void dfs(ll x,ll y,ll r,ll c,vector<string> &v,vector<vector<ll>> &v1)
{  
	if(x>=r||y>=c||x<0||y<0||v[x][y]=='#'||v1[x][y])
	return;
	v1[x][y]++;
	dfs(x+1,y,r,c,v,v1);
	dfs(x,y+1,r,c,v,v1);
	return;
}
void rdfs(ll x,ll y,ll r,ll c,vector<string> &v,vector<vector<ll>> &v2)
{  
	if(x>=r||y>=c||x<0||y<0||v[x][y]=='#'||v2[x][y])
	return;
	v2[x][y]++;
	rdfs(x-1,y,r,c,v,v2);
	rdfs(x,y-1,r,c,v,v2);
	return;
}
void solve()
{ll t,n,m=-1,k,z,x,y,l=INT_MIN,mini=1000000,maxi=INT_MAX,prev;
    cin>>t;
    t=t*t*t;
    cout<<t;;
}

int main()
{
  fast
ll t=1;

while(t--)
{solve();
 //cout<<ma<<endl;
}
return 0;}
/*
ll bfs(ll x)
{
	vector<ll> vis(100001,-1),papa(100001,-1);
	vis[x]=0; queue<ll> q;
	q.push(x);
	//cout<<"ok"<<endl;
	ll len=INT_MAX;
	while(!q.empty())
   { ll y=q.front();
     q.pop();
 	for( auto j:adj[y])
	{
		if(vis[j]==-1)
		{   //cout<<"ok"<<endl;
			vis[j]=vis[y]+1;
			papa[j]=y;
			q.push(j);
		}
		else if(j!=papa[y])
		{   //cout<<"chk"<<endl;
			len=min(len,vis[j]+vis[y]+1);
			break;
		}
	}
   }
   //cout<<len<<endl;
   return len;
}*/

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

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    if ((a + b) == c || (b + c) == a || (c + a) == b) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
while True:
    a, b = map(str,input().split())
    if b=='X':
        break
    if '_' in a:
        c = a.split('_')
    else:
        c=[]
        k = 0
        for i in range(1,len(a)):
            if a[i].isupper():
                c.append(a[k:i])
                k = i
        c.append(a[k:])
    if b=='D':
        c = '_'.join(map(str.lower,c))
    else:
        c = ''.join(map(str.capitalize,c))
        if b =='L':
            c = c[0].lower() + c[1:]
    print(c)


Measured memory_bytes: 5560
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        string s;
        cin >> s;

        ll ans = 0;
        int len = s.length();

        for (int mask = 0; mask < (1 << (len - 1)); mask++)
        {
                ll num = 0;
                for (int i = 0; i < len; i++)
                {
                        num = num * 10 + (s[i] - '0');
                        if (mask & (1 << i))
                        {
                                ans += num;
                                num = 0;
                        }
                }
                ans += num;
        }

        cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

int a,b,c;
int n,m,k,cnt;
string s,t;
ll ans;

main()
{
        cin>>n>>k;

        vi v(n);
        each(&it,v)cin>>it;

        sort(All(v));

        rep(i,n-k)ans+=v[i];
        cout<<ans<<endl;
}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A  = RD;
	auto op = RD!string;
	auto B  = RD;
	
	long ans;
	if (op == "+")
		ans = A + B;
	else
		ans = A - B;

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func abs(x float64) float64 {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]float64, n)
	avr := 0.0
	for i := range a {
		a[i] = nextFloat64()
		avr += a[i]
	}
	avr /= float64(n)
	ans := 0
	minDist := 100.0
	for i := range a {
		if abs(a[i]-avr) < minDist {
			ans = i
			minDist = abs(a[i] - avr)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n,a,b;
	cin>>n>>a>>b;
	vector<ll> x(n);
	for(ll& y:x) cin>>y;
	ll res=0;
	for(int i=1;i<n;++i)
		res+=min((x[i]-x[i-1])*a,b);
	cout<<res<<'\n';
}



Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  vector<int>arr(n);
  for(int i=0; i<n; i++) cin>>arr[i];
  int curr = 0;
  for(int i=0; i<n; i++){
    if(arr[i]==curr+1) curr++;
  }
  if(!curr) cout<<-1;
  else cout<<n-curr;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

map<lint, lint> prime_factorization(lint x){
    map<lint, lint> fac;
    for(lint k = 2; k*k <= x; k++){
        while(x % k == 0){
            fac[k]++;
            x /= k;
        }
    }
    if(x != 1) fac[x]++;
    return fac;
}

int main(){
    lint n; cin >> n;
    map<lint, lint> pf = prime_factorization(n);

    lint res = 0;
    for(auto p : pf){
        lint e = p.se;
        lint j = 1;
        while(1){
            if(j*(j+1)/2 > e){
                j--; break;
            } j++;
        }
        res += j;
    }
    out(res);
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ma,mi;
  cin>>n;
  long a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  mi=a[0];
  ma=a[1]-a[0];
  for(int i=1;i<n;i++){
    if(mi>a[i])mi=a[i];
    else if(ma<a[i]-mi)ma=a[i]-mi;
  }
  cout<< ma <<endl;
  return 0;
}

Measured memory_bytes: 4656
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
 
#define N  100005
signed main()
{
	fast;
	int k,n;
	cin>>k>>n;
	int arr[n];
	int i,j;
	int max=0;
	for(i=0;i<=n-1;i++)
	{
		cin>>arr[i];
	}
	for(i=0;i<=n-2;i++)
	{
		int x=arr[i+1]-arr[i];
		if(max<x)
		{
			max=x;
		}
	}
	if(max<k-arr[n-1]+arr[0])
	{
		max=k-arr[n-1]+arr[0];
	}
	cout<<k-max<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
ll se=0;
ll sume(vector<int> a,int n){

}
int main(){
    ll n,k;cin>>n>>k;
    ll ans=(n/k)*(n/k)*(n/k);
    if(k%2==0){
        ans+=(n/(k/2)-n/k)*(n/(k/2)-n/k)*(n/(k/2)-n/k);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int main(){
	int n=read(),k=read(),s=read(),x=0;
	if (s>=100){
		for (int i=1;i*i<=s;++i) if (s%i!=0){
			x=i;break;
		}
	} else x=s+1; 
	For(i,1,k) printf("%d ",s);
	For(i,1,n-k) printf("%d ",x);
}

Measured memory_bytes: 3772
n = gets.to_i
t,a = gets.split.map(&:to_f)
h = gets.split.map(&:to_f)
dif = 10000000
ans = -1
for num in 0..n-1 do
  k = t - h[num]* 0.006 
  if (k-a).abs < dif
    dif = (k-a).abs
    ans = num + 1 
  end
end
p ans

Measured memory_bytes: 1916
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define cmax(_i,_j) ((_i)<(_j)?(_i)=(_j):0)
#define cmin(_i,_j) ((_i)>(_j)?(_i)=(_j):0)
#define N 20005
using namespace std;
namespace runzhe2000
{
	int n, p[N], a[N], b[N], pa[N], pb[N];
	void main()
	{
		scanf("%d",&n);
		for(int i = 1; i <= n; i++) 
		{
			scanf("%d",&p[i]), a[i] = i, b[i] = n-i+1;
			
			int v = i;
			
			pa[p[i]] += v; pa[n+1] -= v;
			pb[1] += v; pb[p[i]+1] -= v;
		}
		for(int i = 1, tmp = 0; i <= n; i++) tmp += pa[i], a[i] += tmp;
		for(int i = 1, tmp = 0; i <= n; i++) tmp += pb[i], b[i] += tmp;
		
		for(int i = 1; i <= n; i++) 
		{	
			printf("%d ",a[i]); 
		}	
		puts("");
		for(int i = 1; i <= n; i++) 
		{
			printf("%d ",b[i]); 
		}
		puts("");
//for(int i = 1; i < n; i++) if(a[p[i]]+b[p[i]] >= a[p[i+1]]+b[p[i+1]]) {for(;;);}
		
	}
}
int main()
{
	runzhe2000::main();
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int n;
int a[110];

void print(void)
{
	for (int i = 0; i<n; i++) {
		if (i>0) cout << " ";
		cout << a[i];
	}
	cout << endl;
}

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

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

        print();
        cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1164
#include<iostream>

using namespace std;

int main(void) {
	int x, y, ans;
	bool bit;
	
	while(1) {
		cin >> x >> y;
		if(x == 0 && y == 0) { break; }
		char map[y][x];
		
		for(int i=0; i<y; i++) { cin >> map[i]; }
		do {
			bit = false;
			for(int i=0; i<y; i++) {
				for(int j=0; j<x; j++) {
					if(map[i][j] == '@') {
						if(j>0 && map[i][j-1] != '#' && map[i][j-1] != '@') { map[i][j-1] = '@'; bit = true; }
						if(i>0 && map[i-1][j] != '#' && map[i-1][j] != '@') { map[i-1][j] = '@'; bit = true; }
						if(j<x-1 && map[i][j+1] != '#' && map[i][j+1] != '@') { map[i][j+1] = '@'; bit = true; }
						if(i<y-1 && map[i+1][j] != '#' && map[i+1][j] != '@') { map[i+1][j] = '@'; bit = true; }
					}
				}
			}
		} while(bit);
		ans = 0;
		for(int i=0; i<y; i++) {
			for(int j=0; j<x; j++) {
				if(map[i][j] == '@') { ans++; }
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#define R 0
#define L 1
#define D 2
#define U 3

void searchfr(int i,int j,char y[5][5],char t[4][6],int *vec){
    if(j!=0){
        if(t[j-1][i]=='1'){
            printf("U");
            *vec=D;
            return;
        }
    }
    if(i!=4){
        if(y[j][i]=='1'){
            printf("R");
            *vec=R;
            return;
        }
    }
    if(j!=4){
        //printf("%c\n",t[j][i]);
        if(t[j][i]=='1'){
            printf("D");
            *vec=U;
        }
        else{
            printf("L");
            *vec=L;
        }
    }
}


void searchfl(int i,int j,char y[5][5],char t[4][6],int *vec){
    if(j!=4){
        if(t[j][i]=='1'){
            printf("D");
            *vec=U;
            return;
        }
    }
    if(i!=0){
        if(y[j][i-1]=='1'){
            printf("L");
            *vec=L;
            return;
        }
    }
    if(j!=0){
        if(t[j-1][i]=='1'){
            printf("U");
            *vec=D;
        }
        else{
            printf("R");
            *vec=R;
        }
    }
}

void searchfd(int i,int j,char y[5][5],char t[4][6],int *vec){
    if(i!=0){
        if(y[j][i-1]=='1'){
            printf("L");
            *vec=L;
            return;
        }
    }
    if(j!=0){
        if(t[j-1][i]=='1'){
            printf("U");
            *vec=D;
            return;
        }
    }
    if(i!=4){
        if(y[j][i]=='1'){
            printf("R");
            *vec=R;
        }
        else{
            printf("D");
            *vec=U;
        }
    }
}

void searchfu(int i,int j,char y[5][5],char t[4][6],int *vec){
    
    if(i!=4){
        if(y[j][i]=='1'){
            printf("R");
            *vec=R;
            return;
        }
    }
    if(j!=4){
        if(t[j][i]=='1'){
            printf("D");
            *vec=U;
            return;
        }
    }
    if(i!=0){
        if(y[j][i-1]=='1'){
            printf("L");
            *vec=L;
        }
        else{
            printf("U");
            *vec=D;
        }
    }
}


int main(int argc, const char * argv[]) {
    char y[5][5],t[4][6];
    int vec,i,j,k;
    
    for(k=0;k<4;k++){
        scanf("%s",y[k]);
        scanf("%s",t[k]);
    }
    scanf("%s",y[k]);
    printf("R");
    i=1;
    j=0;
    vec=R;
    while(i!=0||j!=0){
        //printf("(%d,%d)\n",i,j);
        if(vec==R){
            //printf("Rin\n");
            searchfr(i,j,y,t,&vec);
        }
        else if(vec==L){
            searchfl(i,j,y,t,&vec);
        }
        else if(vec==U){
            searchfu(i,j,y,t,&vec);
        }
        else {
            searchfd(i,j,y,t,&vec);
        }
        
        switch(vec){
            case R:
                i++;
                break;
            case L:
                i--;
                break;
            case U:
                j++;
                break;
            case D:
                j--;
                break;
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
//vector<long long int>v;
long long  ara[100005];
long long  cost=1000000003;
int main()
{

    int test,candle,t,high,low,i;
    cin>>test>>candle;
    for(i=0; i<test; i++)
    {
        cin>>ara[i];
//        v.push_back(t);

    }
    cost=1000000003;
    for(i=0; i+candle-1<test; i++)
    {
        low=i;
        high=i+candle-1;
        cost=min(cost,ara[high]-ara[low]+min(abs(ara[low]),abs(ara[high])));
        //cout<<cost<<endl;
//        cout<<min(abs(ara[low]),abs(ara[high]))<<endl;
//        cout<<ara[high]-ara[low]+min(abs(ara[low]),abs(ara[high]))<<endl;
//        cout<<cost<<endl;
    }
    cout<<cost<<endl;
    return 0;
}


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

int main(){
 while(1){
  int h,w;
  cin >> h >> w;
  if(h==0&&w==0) break;

  for(int i=1;i<=h;++i){
   for(int j=1;j<=w;++j){
    if((i+j)%2==0) cout << "#";
    else cout << ".";
   }
   cout << endl;
  }
  cout << endl;
 }
 return 0;
}

Measured memory_bytes: 3088
/***************************************** 
****       Solution by SlavicG        ****
*****************************************/
 
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm> 
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n) 
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool checkPrime(int n)
{
    if(n<2) return false;
    for(int x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
int binary_Search_Classic(int n, int arr[],int target){
	int l,r,mid;
	l=0;
	r=n-1;
	while(l<=r){
		mid= l+(r-l)/2;
		if(arr[mid] == target){
			return mid;
		}
		if(arr[mid] < target){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return -1;
	
}
int binary_Search_First_Greater(int n, int arr[],int target){
	int l,r,ans,mid;
	l = 0;
	r = n-1;
	ans=-1;
	while(l<=r){
		mid = l + (r-l)/2;
		if(arr[mid] > target){
			ans=mid;
			r=mid-1;
		}else{
			l = mid+1;
		}
	}
	return ans;
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m; 
    for (int i = 0; i < s.length(); i++) { 
        m[s[i]]++; 
    }
    return m.size(); 
} 
int main()
{
	int n,m;
	cin >> n >> m;
	int a[n];
	forn(i,n)cin>>a[i];
	sort(a,a+n);
	int x = 0;
	for(int i = 0;i<m;i++)
	{
		x += a[i]; 
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){ 
    int n,m,a_i,b_i;
    cin >> n >> m;
    int d[55]={0};

    for (int i=1;i<=m;i++){
        cin >> a_i >> b_i;
        d[a_i]++; d[b_i]++; 
    }
    for (int j=1; j<=n; j++){
        cout << d[j] << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,flg;
	char s[101];
	scanf("%d",&n);
	scanf("%s",s);
	flg=0;
	if(n%2!=0)	flg=1;
	for(i=0;i<n/2;i++){
		if(s[i]!=s[n/2+i])	flg=1;
	}
	if(flg==0)	printf("Yes\n");
	else	printf("No\n");
	return 0;
}


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

#define endl '\n'
#define mem(a,b) memset(a, b, sizeof(a) )
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int inf = 2000000000;



const int mx = 1e5+123;
int dp[mx], n, h[mx], k;

int solve ( int i )
{
  if ( i == n ) return 0;
  if ( dp[i] != -1 ) return dp[i];

  int ret = inf;
  for ( int j = 1; j <= k; j++ ) {
    if ( i + j <= n ) ret = min ( ret, abs ( h[i] - h[i+j] ) + solve ( i+j ) );
  }

  return dp[i] = ret;
}

int main()
{
  optimize();

  cin >> n >> k;
  for ( int i = 1; i <= n; i++ ) cin >> h[i];

  memset ( dp, -1, sizeof (dp) );
  cout << solve ( 1 ) << endl;


  return 0;
}

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

using namespace std;
const int N = 1e5 + 3 , OO = 0x3f3f3f3f ;
int arr1[N]  , arr2[N] , arr3[N], mem[N][5];
int n  ;
int solve(int idx , int pre){
    if(idx == n)
        return 0;
    int &ret = mem[idx][pre];
    if(~ret)
        return ret;
        if(pre == 0){
            ret = max(ret , arr1[idx] + solve(idx + 1 , 1));
            ret = max(ret , arr1[idx] + solve(idx + 1 , 2));
        }
         if(pre == 1){
            ret = max(ret , arr2[idx] + solve(idx + 1 , 0));
            ret = max(ret , arr2[idx] + solve(idx + 1 , 2));
        }
         if(pre == 2){
            ret = max(ret , arr3[idx] + solve(idx + 1 , 1));
            ret = max(ret , arr3[idx] + solve(idx + 1 , 0));
        }
    return ret;
}
int main()
{
    cin >> n ;
    for(int i = 0 ; i < n ; ++i) cin >> arr1[i] >> arr2[i] >> arr3[i];
    memset(mem , -1 , sizeof mem);
    cout << max({solve(0 , 0) , solve(0 , 1) , solve(0 , 2)});
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
    using namespace std;
    vector<long long> c[100000];
    long long ans;
    int main(){
    	ios::sync_with_stdio(0);
    	int n , m;
    	cin >> n >> m;
    	for (int i = 0; i < n; i++){
    		long long a , b;
    		cin >> a >> b;
    		if (a > m){
    			continue;
    		}
    		c[a - 1].push_back(b);
    	}
    	priority_queue<long long> q;
    	for (int i = 0; i < m; ++i){
    		for (long long b : c[i]){
    			q.push(b);
    		}
    		if (!q.empty()){
    			ans += q.top();
    			q.pop();
    		}
    	}
        cout << ans;
    	return 0;
    }

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    ll bx=0,ans=0;
    ll n=s.size();
    rep(i,n){
        if(s[i]=='B'){
            bx++;
        }
        else{
            ans+=bx;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for(int i = a; i <= n; i++)

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

// 第一引数 == 第二引数 ? true : false
template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

// 数字和
template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

typedef long long ll;


string solve() {
    string str = "";
//=============================================================================


    int k, n;
    cin >> n >> k;

    vector<int> l(n);
    rep(i, 0, n-1) cin >> l[i];

    sort(l.begin(), l.end());

    cout << accumulate(l.end()-k, l.end(), 0) << endl;


//=============================================================================
    return str;
}

int main() {	
    std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
    cout << solve() << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from itertools import product

def main():
  n = int(input())
  length_of_n = len(str(n))

  # length_of_n - 1 桁の時の七五三数の合計
  _sum = sum( [3**(i) - 3*(2**(i)) + 3*1 for i in range(3, length_of_n)] )

  # length_of_n 桁 かつ n 以下の七五三数
  for x in product(*([('3', '5', '7')]*length_of_n)):
    x = ''.join(x)
    if int(x) <= n and all([c in x for c in list('357')]):
      _sum += 1
  print(_sum)


  pass

if __name__=='__main__':
  main()

Measured memory_bytes: 3064
#include <atcoder/all>
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
using namespace atcoder;
int main() {
    int n, q;
    cin >> n >> q;
    dsu uf(n);
    for(int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if(t) {
            cout << uf.same(u, v) << endl;
        } else {
            uf.merge(u, v);
        }
    }
}

Measured memory_bytes: 3896
#include<iostream>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,k;
long long ans=0;
int main()
{
    int i,j;
    cin>>n>>k;
    
    long long r,c;
    long long n0;
    for(r=k+1;r<=n;r++)
    {
        n0=n/r*r;
        
        ans+=n/r*(r-k);
        
        c=n-n0;
        ans+=max(0ll,c-k+1);
        if(k==0)ans--;
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
class finite_field {
	const int md;
	const int sz;
	vector<int> fct, fnv;
	public :
		finite_field(
				const int md,
				const int init_factorial_size = 0
			) :
			md(md), sz(init_factorial_size),
			fct(sz), fnv(sz)
			{
				fct[0] = 1;
				for (int i = 1; i < sz; i++) fct[i] = mul(fct[i - 1], i);
				fnv[sz - 1] = inv(fct[sz - 1]);
				for (int i = sz - 1; i >= 1; i--) fnv[i - 1] = mul(fnv[i], i);
			}
		inline void add (int& a, const int b) const {
			a += b;
			if (a >= md) a -= md;
		}
		inline void sub (int& a, const int b) const {
			a -= b;
			if (a < 0) a += md;
		}
		template<class... A> int mul (A... args) const {
			long long ret = 1;
			for (int a : std::initializer_list<int>{args...}) {
				ret *= a;
				ret %= md;
			}
			return (int)ret;
		}
		inline int inv (int a) const {
			a %= md; if (a < 0) a += md;
			int b = md, u = 0, v = 1;
			while (a) {
				int t = b / a;
				b -= a * t; swap(a, b);
				u -= v * t; swap(u, v);
			}
			assert(b == 1);
			if(u < 0) u += md;
			return u;
		}
		inline int div (int a, int b) const {
			return mul(a, inv(b));
		}
		inline int binom (int n, int k) const {
			assert(0 <= n && n < sz);
			if (k < 0 || n < k) return 0;
			return mul(fct[n], fnv[k], fnv[n - k]);
		}
};
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int h, w, k;
	cin >> h >> w >> k;
	finite_field fld(1e9 + 7, h * w + 1);
	auto solve = [&] (int h, int w, int k) {
		int ret = 0, denom = 0;
		for (int i = 1; i < h; i++) {
			fld.add(ret, fld.mul(i, h - i));
			fld.add(denom, i);
		}
		ret = fld.mul(ret, w, w);
		denom = fld.mul(denom, w, w);
		fld.add(denom, fld.mul(h, fld.binom(w, 2)));
		ret = fld.div(ret, denom);
		return ret;
	};
	int ret = 0;
	fld.add(ret, solve(h, w, k));
	fld.add(ret, solve(w, h, k));
	ret = fld.mul(ret, fld.binom(k, 2));
	ret = fld.mul(ret, fld.binom(h * w, k));
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=dict()
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if b not in d:
        d[b]=0
    if c not in d:
        d[c]=0
    d[c]+=d[b]
    ans+=(c-b)*d[b]
    print(ans)
    d[b]=0

    



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

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

    sort(a.begin(), a.end());
    vector<int> v;
    for (int i = n - 1; i > 0; --i) {
        if (a[i] == a[i - 1]) {
            v.push_back(a[i]);
            --i;
        }
    }
    v.push_back(0);
    v.push_back(0);
    cout << (v[0] * (long long)v[1]) << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>


int main(){
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	int sum1=a+b;
	int sum2=a-b;
	int sum3=a*b;
	
	if(sum1>=sum2 && sum1>=sum3){
		printf("%d\n",sum1);
	}
	else if(sum2>=sum1 && sum2>=sum3){
		printf("%d\n",sum2);
	}
	else if(sum3>=sum1 && sum3>=sum2){
		printf("%d\n",sum3);
	}
	
	
	return 0;
}

Measured memory_bytes: 128