akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

void findHitAndBlow(int imagineNum[],int guessNum[]);

int main()
{
    int imagineNum[50][4]={0},guessNum[50][4]={0};
    int counts=0;
    bool isHit[4] = {false};
       int hit = 0;
       int blow = 0;
    while (cin >> imagineNum[counts][0] >> imagineNum[counts][1] >> imagineNum[counts][2] >> imagineNum[counts][3] >> guessNum[counts][0] >> guessNum[counts][1] >> guessNum[counts][2] >> guessNum[counts][3]){

       isHit[0] = false;
       isHit[1] = false;
       isHit[2] = false;
       isHit[3] = false;
        hit =0;
        blow = 0;
       for(int i = 0; i< 4;i++){
            if(imagineNum[counts][i] == guessNum[counts][i]){
                hit++;
                isHit[i] = true;
            }
       }
        for(int i = 0;i < 4;i++){
            if(isHit[i]) {
                continue;
            }
            for(int j = 0;j < 4;j++){
                if(isHit[j]){
                    continue;
                }
                if(imagineNum[counts][i] == guessNum[counts][j]){
                    blow++;
                }
            }
        }
        cout << hit << " " << blow << endl;
        counts++;
    }

//    for(int i = 0; i< counts ; i++){
//        findHitAndBlow(imagineNum[i],guessNum[i]);
//    }
    return 0;
}
void findHitAndBlow(int imagineNum[],int guessNum[]){
   bool isHit[4] = {false};
   int hit = 0;
   int blow = 0;
   for(int i = 0; i< 4;i++){
        if(imagineNum[i] == guessNum[i]){
            hit++;
            isHit[i] = true;
        }
   }
    for(int i = 0;i < 4;i++){
        if(isHit[i]) {
            continue;
        }
        for(int j = 0;j < 4;j++){
            if(isHit[j]){
                continue;
            }
            if(imagineNum[i] == guessNum[j]){
                blow++;
            }
        }
    }
    cout << hit << " " << blow << endl;
}

/*
Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:
•	The number of numbers which have the same place with numbers A imagined (Hit)
•	The number of numbers included (but different place) in the numbers A imagined (Blow)
For example, if A imagined numbers:
9 1 8 2
and B chose:
4 1 5 9
A should say 1 Hit and 1 Blow.
Write a program which reads four numbers A imagined and four numbers B chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.
Input
The input consists of multiple datasets. Each dataset set consists of:
a1 a2 a3 a4
b1 b2 b3 b4
, where ai (0 ≤ ai ≤ 9) is i-th number A imagined and bi (0 ≤ bi ≤ 9) is i-th number B chose.
The input ends with EOF. The number of datasets is less than or equal to 50.
Output
For each dataset, print the number of Hit and Blow in a line. These two numbers should be separated by a space.
Sample Input
9 1 8 2
4 1 5 9
4 6 8 2
4 6 3 2
Output for the Sample Input
1 1
3 0
*/



Measured memory_bytes: 3000
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = [0]*N

for _ in range(min(K, 100)):
    b = [0]*(N+1)
    for i, a in enumerate(A):
        b[max(i-a, 0)] += 1
        b[min(i+a+1, N)] -= 1
    
    x = 0
    for i in range(N):
        x += b[i]
        A[i] = x

print(" ".join(str(a) for a in A))

Measured memory_bytes: 175540
N = int(input())
A = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        x -= 1
        A[i][x] = y 

ans = 0
for b in range(2**N):
    bit = bin(b)[2:].zfill(N)
    flg = True
    for i in range(N):
        if bit[i] == '0': continue
        for j in range(N):
            if A[i][j] == -1: continue
            if A[i][j] != int(bit[j]):
                flg = False
                break
        
        if not flg: break

    ans = max(bit.count('1'), ans) if flg else ans

print(ans)

Measured memory_bytes: 74160
N, M = map(int, input().split())
maxL = 1
minR = N
for i in range(M):
    L, R = map(int, input().split())
    if maxL < L:
        maxL = L
    if minR > R:
        minR = R

if minR - maxL >= 0:
    print(minR - maxL + 1)
else:
    print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define sq(a) (a)*(a)
#define ms(a,v)	memset(a,v,sizeof a)
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;

vector<ll>fac;

void find_fac(ll n){
  for(ll i=2;i*i<=n;i++){
    if (n%i==0){
      if (n/i!=i){
        fac.pb(i);
        fac.pb(n/i);
      }
      else
        fac.pb(i);
    }
  }
}


int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n,count=0; cin>>n;
  if (n==2){
    cout<<1<<"\n";
    return 0;
  }
  find_fac(n-1);
  // for(ll i=0;i<fac.size();i++){
  //   if (n%fac[i]==1)  count++;
  // }
  count+=fac.size()+2;
  fac.clear();
  find_fac(n);
  for(ll i=0;i<fac.size();i++){
    ll m=n;
    while (m%fac[i]==0) {
      m/=fac[i];
    }
      if (m%fac[i]==1){
        ++count;
      }
      // else if (m%fac[i]==1){
      //   count++;
      //   break;
      // }
    //}
  }
cout<<count<<"\n";
    return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{s<<"{";if(SZ(v))s<<join(v,", ");s<<"}";return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    string S; cin >> S;
    ll N = LEN(S);
    
    string ans = "";
    REP(i, N) {
        if (S[i] == 'B') {
            if (LEN(ans) > 0) {
                ans = ans.substr(0, LEN(ans)-1);
            }
        } else {
            ans += S[i];
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    set<char> se;
    rep(i, S.size()) { se.insert(S[i]); }
    if(S.size() == se.size()) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    S = input()
    answer = 0
    while S:
        if S[0] == S[-1]:
            S = S[1:-1]
        elif S[0] == "x":
            S = S + "x"
            answer += 1
        elif S[-1] == "x":
            S = "x" + S
            answer += 1
        else:
            print(-1)
            return
    print(answer)


if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  map <long long, int> w;
  w[0] = 1;
  long long sum = 0;
  long long ans = 0;
  while (n--) {
    int foo;
    scanf("%d", &foo);
    sum += foo;
    if (w.count(sum) != 0) {
      ans += w[sum];
    }
    ++w[sum];
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 12800
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"

	"strconv"
	"strings"
)

func countToOperation(txts []string) (int64, error) {
	var res int64 = 0

	for _, txt := range txts {
		num, err := strconv.ParseInt(txt, 0, 64)
		if err != nil {
			return res, err
		}

		// 何回割り切れたか
		var cnt int64 = 0
		for {
			if num == 0 || num%2 == 1 {
				break
			}
			cnt++
			num = num / 2
		}

		// １回も割り切れないなら終了
		if cnt == 0 {
			return 0, nil
		}

		// 最終結果が現在値よりも低い場合は更新
		if res == 0 || cnt < res {
			res = cnt
		}
	}
	return res, nil
}

func Run(in io.Reader, out io.Writer) error {
	sc := bufio.NewScanner(in)

	_ = sc.Scan()
	for sc.Scan() {
		line := sc.Text()
		a := strings.Split(line, " ")
		cnt, err := countToOperation(a)
		if err != nil {
			return err
		}
		fmt.Fprintf(out, "%d\n", cnt)
		return nil
	}

	return nil
}

func main() {
	err := Run(os.Stdin, os.Stdout)

	if err != nil {
		log.Fatal(err)
	}
}


Measured memory_bytes: 640
let solve n t =
  let ar = Array.init n (fun _ ->
      Scanf.scanf "%d " (fun a -> a)) in
  let rec aux i sum =
    if i >= n then sum + t
    else
      let pre = ar.(i-1) and now = ar.(i) in
      let dur = min (now - pre) t in
      aux (succ i) (sum + dur)
  in
  aux 1 0

let () = Scanf.scanf "%d %d\n" solve |> Printf.printf "%d\n"

Measured memory_bytes: 6144
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 110;
ll n, W;

ll w[N] , v[N];
ll dp[N][100005];

ll go(ll i , ll weight)
{
	if(i > n)
		return 0;
	ll &ans = dp[i][weight];
	if(ans != -1)
		return ans;
	if(weight + w[i] <= W)
		ans = max( go(i+1 , weight) , v[i] + go(i+1 , weight + w[i]) );
	else
		ans = max( ans , go( i+1 , weight ));

	return ans;


}

signed main()
{
	fast;
	memset(dp , -1 , sizeof dp);
////////////////////////////////////////////////////////////////////////////////////////////
	cin >> n >> W;
	rep(i,1,n+1)
		cin >> w[i] >> v[i];

	cout<<go(1 , 0)<<endl;









////////////////////////////////////////////////////////////////////////////////////////////


	
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> vi(n), da(n), vo(n);
    for(int i = 0; i < n; ++i) {
        cin >> vi[i] >> da[i] >> vo[i];
    }

    vector<double> p(m + 1, 0);
    p[0] = 1;
    for(int i = 0; i < m; ++i) {
        vector<double> nxt(m + 1);
        for(int i = 0; i <= m; ++i) {
            nxt[i] += p[i] * 2 / 3.0;
            if(i != m) {
                nxt[i + 1] += p[i] / 3.0;
            }
        }
        p = move(nxt);
    }
    for(int i = 0; i < m; ++i) {
        p[i + 1] += p[i];
    }

    auto calc = [&](vector<int> const& v) {
        vector<vector<double>> dp(m + 1, vector<double>(4));
        for(int i = 0; i < m + 1; ++i) {
            dp[i][0] = dp[i][3] = 1;
        }
        for(int i = 1; i < n; ++i) {
            vector<vector<double>> nxt(m + 1, vector<double>(4));
            for(int j = 0; j <= m; ++j) {
                const int t = v[0] * j;
                const int cnt = (t + v[i] - 1) / v[i];
                const double win = p[min(m, cnt - 1)];
                for(int k = 0; k < 3; ++k) {
                    nxt[j][k] += (cnt == 0 ? 0 : dp[j][k] * win); // win
                    if(k + 1 < 3) {
                        nxt[j][k + 1] += (cnt == 0 ? dp[j][k] : dp[j][k] * (1 - win)); // lose
                    }
                }
                nxt[j][3] += dp[j][3] * (1 - win);
            }
            dp = move(nxt);
        }
        return dp;
    };
    auto dp1 = calc(vi);
    auto dp2 = calc(da);
    auto dp3 = calc(vo);

    double ans = -1e9;
    for(int i = 0; i <= m; ++i) {
        for(int j = 0; j + i <= m; ++j) {
            int k = m - i - j;
            double t = (dp1[i][0] + dp1[i][1] + dp1[i][2]) * 5;
            t += (dp2[j][0] + dp2[j][1] + dp2[j][2]) * 3;
            t += (dp3[k][0] + dp3[k][1] + dp3[k][2]) * 2;
            t -= (dp1[i][3] + dp2[j][3] + dp3[k][3]);
            ans = max(ans, t);
        }
    }

    cout << fixed << setprecision(10) << ans << endl;
}



Measured memory_bytes: 3820
#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>
#include<set>

using namespace std;

struct UnionFind{
    vector<int> par;
    vector<int> rank;

    void init(int n) {
        par = vector<int>(n);
        rank = vector<int>(n);

        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] > rank[y]) {
            par[y] = x;
        } else {
            par[x] = y;
            if (rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};
int n, m;
int main()
{
    cin >> n >> m;
    UnionFind uf;
    uf.init(n);
    for (int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }

    set<int> st;
    for (int i = 0; i < n; ++i) {
        st.insert(uf.find(i));
    }
    cout << st.size() << endl;
}



Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9;
const long long LLINF = 1e18;

int a, b;
int cnt;
int main() {
    cin>>a>>b;
    if(a<=b) cout<<a<<endl;
    else cout<<a-1<<endl;
    return 0;
}

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

int main(){
    int n;
    string str;
    cin>>n>>str;

    int b[sz],g[sz],r[sz];

    memset(b,0,sizeof b);
    memset(g,0,sizeof g);
    memset(r,0,sizeof r);

    int cntb=0,cntg=0,cntr=0;
    ll ans=0;
    for(int i=n-1;i>=0;--i){
        if(str[i]=='R') cntr++;
        else if(str[i]=='G') cntg++;
        else cntb++;

        b[i]=cntb, g[i]=cntg, r[i]=cntr;
    }

    for(int i=0;i<str.size()-2;i++){
        for(int j=i+1;j<str.size();j++){
            int k = j+(j-i);
            if(k<n) if(str[i]!=str[j] && str[j]!=str[k] && str[k]!=str[i]) ans--;

            if(str[i]=='R' && str[j]=='B' || str[i]=='B' && str[j]=='R') ans+=g[j];
            else if(str[i]=='B' && str[j]=='G' || str[i]=='G' && str[j]=='B') ans+=r[j];
            else if(str[i]=='G' && str[j]=='R' || str[i]=='R' && str[j]=='G') ans+=b[j];
        }
    }

    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3644
{-# LANGUAGE FlexibleContexts #-}
import           Control.Monad
import           Data.Array.IArray
import           Data.Array.Unboxed (UArray)
import qualified Data.Array.Unboxed as U

main :: IO ()
main = do
  [n,m,q] <- map read . words <$> getLine :: IO [Int]
  let l2t4 = \[a,b,c,d] -> (a,b,c,d)
  abcds <- map (l2t4 . map read . words) <$> replicateM q getLine :: IO [(Int,Int,Int,Int)]
  let seqAs = map (U.listArray (1,n)) $ genSeqAs n m :: [UArray Int Int]

  print $ maximum $ map (score abcds) seqAs

score :: [(Int,Int,Int,Int)] -> UArray Int Int -> Int
score abcds seqA = foldr (\(a,b,c,d) x -> if seqA!b - seqA!a == c
                                          then x + d
                                          else x) 0 abcds

genSeqAs :: Int -> Int -> [[Int]]
genSeqAs n m = go n 1
  where go 0 _   = [[]]
        go len p = [a:as | a <- [p..m], as <- go (len-1) a]


Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define N 3010
#define M 1010
#define int long long
using namespace std;
int n,m;
int v[N],h[N];
int t[M],s[M];

int Max(int &a,int b){return a = max(a,b);}

int dp[M][N][2];
int DP(){
  memset(dp,-1,sizeof(dp));  
  dp[0][0][0] = 0;

  for(int i=0;i<m;i++){ //monster
    int money = t[i];
    for(int j=0;j<=n;j++){ //item
      if(dp[i][j][0] >= s[i]) Max(dp[i+1][j][0],dp[i][j][0]);
      if(dp[i][j][1] >= s[i]) Max(dp[i+1][j][0],dp[i][j][1]);
      if(j == n)continue;
      
      money -= v[j];
      if(money < 0) continue;

      if(dp[i][j][0]!=-1){
        int power = dp[i][j][0]+h[j];
        Max(dp[i][j+1][1],power);
      }
      if(dp[i][j][1]!=-1){
        int power = dp[i][j][1] + h[j] + abs(h[j] - h[j-1]);
        Max(dp[i][j+1][1],power);
      }
    }
  }

  for(int j=0,sum=0;j<=n;sum+=v[j++]) if(dp[m][j][0]!=-1) return t[m-1]-sum;
  return -1;
}

signed main(){

  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>v[i]>>h[i];
  for(int i=0;i<m;i++)cin>>t[i]>>s[i];

  cout<<DP()<<endl;
  return 0;
}

Measured memory_bytes: 50660
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
    int a, b, k, ans, cnt = 0;
    vector<int> c;
    cin >> a >> b >> k;
    for(int i = 1; i <= 100; i++){
        if(a % i == 0 && b % i == 0){
            cnt++;
            c.push_back(i);
        }
    }
    cout << c[cnt - k] << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    input = input.split("\n");
 var n= parseInt(input[0], 10);
   var tmp = input[1].split(" ");

   var L = [];


    //var amax=1;var amin=1000000000;at=0;
for (var i = 0; i < n ; i++){
     var r= parseInt(tmp[i], 10);
      L[i]=r;}
   //  console.log(L);
   L.sort((a,b) =>(a-b));
  //console.log(L);
  for(i=0;i<n-1;i++){
      if(L[i]==L[i+1]){console.log('NO');
                       break;}
        // else{console.log('Yes');}
  }
  if(i==n-1){console.log('YES');}
  
  

}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 36124
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(2*c>=a+b)
    {
        cout<<x*a+b*y<<nl;
    }
    else
    {
        ll mi=min(x,y);
        x-=mi;
        y-=mi;
        if(x)
        {
            if(2*c<=a)
            {
                mi+=x;
                x=0;
            }
        }
        else
        {
            if(2*c<=b)
            {
                mi+=y;
                y=0;
            }
        }
        cout<<x*a+b*y+mi*(2*c)<<nl;
    }
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    string a, b;
    cin >> a >> b;
    int ab = stoi(a + b);
    int root_ab = sqrt(ab);
    if(ab == pow(root_ab, 2.0)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

sum_tmp = sum(a[:k])
sum_max = sum_tmp
for i in range(k,len(a)):
    sum_tmp += a[i] - a[i-k]
    if sum_tmp > sum_max:
        sum_max = sum_tmp
print((sum_max + k)/2)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<pll>
#define vl vector<ll>
#define f first
#define s second
#define N 50000
#define pb push_back
#define MAP map<ll,ll>
#define MAPs map<<ll,sl>
#define MAPv map<ll,vl>
#define  mset(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define foo(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,a,b) for(ll i=(a);i>=(b);i--)
#define FOR(i,v) for(auto &(i):(v))
#define sl set<ll>
#define sll set<pll>
#define ub upper_bound
#define lb lower_bound
using namespace std;

const ll   INF = 0x7f7f7f7f7f7f7f7f;
const ll NINF = -INF;
const ll MAXN  = 1e+6 + 8;

int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
//<<-----Declare Variable Here------->>//
ll red, blue, green, k;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN() {
    cin >> red >> green >> blue >> k;

    ll cnt = 0;
    while (green <= red) {
        green *= 2;
        cnt++;
    }
    while (blue <= green) {
        blue *= 2;
        cnt++;
    }

    cout << (cnt <= k ? "Yes\n" : "No\n");
}

int main() {
    fastio;
    ll t = 1;
    // cin>>t;
    while (t--) {
        MAIN();
    }

    // #ifndef ONLINE_JUDGE
    // cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    // #endif
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<math.h>
using namespace std;
typedef long long int ll;

int main()
{
	const int MAX_N=100000;
    int D,n,m,d[MAX_N],k;
	while(true){
		scanf("%d",&D);
		if(D==0)return 0;
		scanf("%d%d",&n,&m);
		d[0]=0;
		for(int i=1;i<n;i++)scanf("%d",&d[i]);
		ll ans=0;
		sort(d,d+n);

		for(int i=0;i<m;i++){
			scanf("%d",&k);
			int l=0,r=n-1;
			while(r-l>=1){
				int c=(r+l)/2;
				if(d[c]==k)goto a;
				else if(d[c]>k)r=c;
				else l=c+1;
			}
			if(r==n-1){
				ans+=(ll)min(abs(d[n-1]-k),abs(d[0]-k+D));
			}
			else if(l==0){
				ans+=(ll)min(abs(d[n-1]-k-D),abs(d[0]-k));
			}
			else {
				ans+=(ll)min(abs(d[l]-k),min(abs(d[l-1]-k),abs(d[l+1]-k)));
			}
a:;
		}
		printf("%lld\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1596
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
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; }

    int n;
    ll a[100010][3];
    ll dp[100010][3];

signed main(){
    
    cin >> n;
    rep(i, n){
        rep(j, 3){
            cin >> a[i][j];
        }
    }

    rep(i, n){
        rep(j, 3){
            rep(k, 3){
                if(j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll ans = 0;
    rep(i, 3) chmax(ans, dp[n][i]);
    cout << ans << endl;

}

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

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n;
	cin>>n;
	unordered_map<string,int> t;
	int mx = -1;
	for(int i=0;i<n;i++){
		string str;
		cin>>str;
		t[str]++;
		mx = max(mx,t[str]);
	}
	vector<string> re;
	for(auto &item:t){
		if(item.second==mx){
			re.push_back(item.first);
		}
	}
	sort(re.begin(),re.end());
	for(auto &item:re){
		cout<<item<<endl;
	}
}


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


Measured memory_bytes: 25284
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

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

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,Q,sf=0,vf=0,ans=0;
  string s,t;
  vector<string> v(2);
  //0>first 1>second vf=swap;
  cin>>s;
  //0>first 12>swap
  cin>>Q;
  while(Q--){
    cin>>i;
    if(i==1){
      sf^=1;
      vf^=1;
      continue;
    }
    cin>>j>>t;
    v[(j-1)^vf]+=t[0];
  }
  reverse(all(v[vf]));
  if(sf)reverse(all(s));
  cout<<v[vf]<<s<<v[vf^1]<<endl;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define ll long long
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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


const int mod = 1e9+7;
const int nax = 200009;
int fact[nax];
ll int  powermod(ll int base, ll int exp, ll int mod) {
	ll int result = 1;
	while (exp != 0) {
    if (exp&1) result = (result * base) % mod;
    	base = (base * base) % mod;
   		exp /= 2;
	}
	return result;
}
ll int c(ll int n,ll int r){
    ll int va = 1;
    if(r > n-r){
        r = n - r;
    }
    ll int res = 1;
    for (size_t i = 0; i < r; i++) {
        va = (va*(n-i)%mod);
        res = (res*(r - i)%mod);
    }

    va = ((va % mod)*(powermod(res , mod - 2 , mod) % mod)) % mod;

    return va;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll int n,a,b;cin>>n>>a>>b;
    ll int ans = 0;
    ans = powermod(2,n,mod);
   
    ans = (ans - c(n,a) - c(n,b) - 1)%mod;
    ans = (ans + mod) % mod;
    cout<<ans;

}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

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

	REP(i, m) {
		int shoki, nennsuu, shurui;
		cin >> shoki >> nennsuu >> shurui;
		vi result(shurui, shoki);

		REP(j, shurui) {
			int fukuri, tesuuryou;
			double nennritu;
			cin >> fukuri >> nennritu >> tesuuryou;

			int rishi = 0;
			REP(k, nennsuu) {
				if(fukuri) {
					result[j] += (result[j]*nennritu-tesuuryou);

				} else {
					rishi += result[j]*nennritu;
					result[j] -= tesuuryou;
				}
			}
			result[j] += rishi;
		}

		int max = 0;
		REP(j, result.size()) {
			if(max < result[j]) {
				max = result[j];
			}
		}

		cout << max << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            String str = sc.next();
            if(str.equals("-"))
                break;
            int n = sc.nextInt();
            for(int i = 0 ; i < n ; i++)
            {
                int h = sc.nextInt();
                String a = str.substring(0,h);
                String b = str.substring(h);
                str = b + a;
            }
            System.out.println(str);
        }
    }
}


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

int main(){
	int n;
	cin >> n;
	long long ans = 0;
	int mn = 1000000000;
	bool equall = true;
	for (int i = 1; i <= n; ++ i){
		int x, y;
		cin >> x >> y;
		if (x != y)
			equall = false;
		ans += x;
		if (x > y)
			mn = min(mn, y);
	}
	if (equall)
		cout << 0 << endl;
	else
		cout << ans - mn << endl;
}


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

    if a.count(0) >= 1:
        print("0")
        return

    MAX = 1000000000000000000
    ans = 1
    for x in a:
        if (ans <= MAX):
            ans *= x

    if ans > MAX:
        print("-1")
    else:
        print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 84696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    deque < char > que;
    int u=s.size();
    for(int i=0;i<u;i++)
		que.push_back(s[i]);
    int rev=0;
    int q;
    cin>>q;
    while(q--)
	{
        int t;
        cin>>t;
        if(t==1)
		{
            rev=1-rev;
        }
		else
		{
            int f;
            char c;
            cin>>f>>c;
            f--;
            if(rev^f)
			{
                que.push_back(c);
            }
			else
			{
                que.push_front(c);
            }
        }
    }
    if(rev!=0) 
		reverse(que.begin(), que.end());
	int p=que.size();
    for(int i=0;i<p;i++)
		cout<<que[i];
    return 0;
}

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

int n, k;
string s;
void flip(string& s) {
  for (int i = 0; i < n; ++i) {
    if (i & 1) {
      s[i] = s[i] == 'A' ? 'B' : 'A';
    }
  }
}

int main() {
  cin >> n >> k >> s;
  flip(s);
  int i = 0;
  int r = 0;
  for (int z = 0; z < k; ++z) {
    if (i >= n) {
      if ((k - z) & 1) r = 1;
      break;
    }
    if (s[i] == 'B') {
      ++i;
    } else if (r == 1) {
      r = 0;
      ++i;
    } else {
      r = 1;
    }
  }
  
  string t = s.substr(i) + string(i, n % 2 == 0 ? 'B' : 'A');
  
  if (r) {
    t[0] = 'B';
  }

  flip(t);
  cout << t << endl;
}


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

#define PI 3.14159265359
#define INF 1000000009
#define LINF 1000000000000000009
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};
using namespace std; 

int solve(string s)
{
    int ans = 0;
    int len = s.size();
    int start = 0;

    while(start < len) {
        int cnt = 1;
        char t = s[start++];
        while(start < len) {
            if(t == s[start]) {
                cnt++;
                start++;
            } else {
                break;
            }
        }
        ans += cnt/2;
    }
    return ans;
}

int main(void)
{
    string s; 
    cin >> s;

    ll k; 
    cin >> k;
    
    bool unique = true;
    irep(i, s.size()-1) {
        if(s[i] != s[i+1]) {
            unique = false;   
        }
    }

    if(unique) {
        cout << (k * s.size()) / 2 << endl;
    } else {
        string t(s+s);
        //cout << t << endl;
        ll first = solve(s);
        ll diff = solve(t) - solve(s);
        cout << first + diff * (k-1) << endl;
    }
    return 0;
}
/** tcoder **/


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

const int N = (3e5) + 5;
int n, a[N];
int freq[N];
int ac[N];

ll f(ll x) {
  ll pos = lower_bound(freq, freq + n, x) - freq;
  ll sum = x * (n - pos);
  if (0 <= pos - 1 and pos - 1 < n) {
    sum += ac[pos - 1];
  }
  return sum;
}

bool predicate(ll med, ll y) {
  return !(med * y <= f(med));
}

ll bs(ll lo, ll hi, ll y, ll back = 0) {
  if ( predicate(lo, y)) return lo - back;
  if (!predicate(hi, y)) return hi + 1 - back;
  while (hi - lo > 1) {
    ll med = lo + (hi - lo) / 2;
    if (predicate(med, y)) hi = med;
    else lo = med;
  }
  return hi - back;
}

int main() { // claudio van
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    freq[a[i] - 1]++;
  }
  sort(freq, freq + n);
  partial_sum(freq, freq + n, ac);
  for (int k = 1; k <= n; ++k) {
    printf("%lld\n", bs(0, ac[n - 1], k, 1));
  }
  return 0;
}

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

int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W) );
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  vector<bool> xh(H,false), xw(W,false);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(a.at(i).at(j) == '#') xh.at(i) = true;
    }
  }
  for(int i=0; i<W; i++){
    for(int j=0; j<H; j++){
      if(a.at(j).at(i) == '#') xw.at(i) = true;
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(xh.at(i) && xw.at(j)) cout << a.at(i).at(j);
    }
    if(xh.at(i))cout << endl;
  }  
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3


def min_turns(n, x, ys):
    zs = ys[:]
    if zs[0] > x:
        zs[0] = x
    for i in range(n - 1):
        if zs[i] + zs[i + 1] > x:
            zs[i + 1] = x - zs[i]
    ans = sum(y - z for y, z in zip(ys, zs))
    return ans


def main():
    n, x = (int(z) for z in input().split())
    ys = [int(z) for z in input().split()]
    print(min_turns(n, x, ys))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14592
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
//
const int MX = 3002;
int dp[MX][MX]; // 1 - win, 0 - lose
int32_t main()
{
    // A =  { a_1 , a_ 2, ... a _ n}
    //
    int n;
    cin >> n;
    vector<int>a(n);
    forn(i,n)
    cin >> a[i];
    vector<int>pre(n + 1, 0);
    // правая не вкл
    pre[0]=0;
    for(int i = 1 ;i <= n; i++){
        pre[i]=pre[i-1]+a[i-1];
    }
    // .....a[i]
    // сколько набирает тот кто ходит
    for (int len = 1; len <= n; len++) {
        for(int l = 0; l < n; l++) {
            int r = l + len;
//            A  B
//            pre[r] - pre[l] - dp[l + 1][r]
//            dp[l + 1][r]
            dp[l][r] = max(dp[l][r], pre[r] - pre[l] - dp[l + 1][r]);
            dp[l][r] = max(dp[l][r], pre[r] - pre[l] - dp[l][r - 1]);
        }
    }
    cout << dp[0][n] - (pre[n] - dp[0][n]) << endl;
    return 0;
}

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

int main() {
  int A, B, x;
  int sum = 0;
  cin >> A >> B;
  
  for (int i = A; i<B+1; i++) {
    int a1 = i % 10;
    int a2 = (i % 100)/10;
    int a3 = (i % 1000)/100;
    int a4 = (i % 10000)/1000;
    int a5 = i / 10000;
    if (a1 == a5 && a2 == a4)
      sum++;
  }
  
  cout << sum << endl;
  
}

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


void solve(std::vector<std::string> c){
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

int main(){
    std::vector<std::string> c(3);
    for(int i = 0 ; i < 3 ; i++){
        std::cin >> c[i];
    }
    solve(std::move(c));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

ll fact[3000005];

inline ll pow(ll x,ll y,ll p)
{
    ll ans=1; 
    x=x%p;
    while(y>0)
    {
        if(y&1)
            ans=(ans*x)%p;
        y=y>>1;
        x=(x*x)%p;  
    }
    return ans;
}
inline ll invmod(ll x,ll p)
{
    return pow(x,p-2,p);
}

int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif

    fact[0]=1;
    for(ll i=1;i<3000005;i++)
    {
        fact[i]=(i*fact[i-1])%1000003;
    }

    ll q;cin>>q;
    while(q--)
    {
        ll x,d,n;cin>>x>>d>>n;
        ll a=(x*invmod(d,1000003))%1000003;

        if(x==0)
        {
            cout<<0<<endl;
            continue;
        }

        if(d==0)
        {
            cout<<pow(x,n,1000003)<<endl;
            continue;
        }

        ll l=a,r=(a+n-1)%1000003;
        if(l+n-1>=1000003 || l-1<0) cout<<0<<endl;
        else
        {
            ll x=fact[r];
            x=(x*invmod(fact[l-1],1000003))%1000003;
            x=(x*pow(d,n,1000003))%1000003;
            cout<<x<<endl;
        }
    }

    #ifdef APNA_IO
        end_routine();
    #endif
}

Measured memory_bytes: 24320
#include <iostream>

using namespace std;

struct card {
	char hua;
	int val;
};

void printArr(card a[], int len) {


	for (int i = 0; i < len; i++)
	{
		if (i == 0) cout << a[0].hua << a[0].val;
		else cout << " " << a[i].hua << a[i].val;
	}
	cout << endl;
}


void bubbleSort(card a[], int len) {

	bool flag = false;	//是否完成
	for (int i = 0; i < len; i++) {
		flag = true;
		for (int j = len - 1; j > i; j--) {
			if (a[j].val < a[j - 1].val) {
				swap(a[j], a[j - 1]);
				flag = false;
			}
		}
		if (flag) return;
	}
}


void selectionSort(card a[], int len) {

	for (int i = 0; i < len; i++) {
		int min = i;
		for (int j = i + 1; j < len; j++) {
			if (a[min].val > a[j].val) min = j;
		}
		if (min != i) swap(a[i], a[min]);
	}
}

int main() {

	int n;
	cin >> n;
	
	card* r1 = new card[n];
	card* r2 = new card[n];

	for (int i = 0; i < n; i++) {
		cin >> r1[i].hua >> r1[i].val;
		r2[i] = r1[i];
	}

	bubbleSort(r1, n);
	selectionSort(r2, n);

	bool stable = true;

	for (int i = 0; i < n; i++)	{
		if (r1[i].hua != r2[i].hua) {
			stable = false;
			break;
		}
	}

	printArr(r1, n);
	cout << "Stable\n";
	printArr(r2, n);
	if (stable) cout << "Stable\n";
	else cout << "Not stable\n";


	delete[] r1;
	delete[] r2;
	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll long long
ll n;
ll answer = 0;
int main(){
	scanf("%lld", &n);
	for (ll i = 1; i*i <= n; i++){
		if (n % i == 0){
			if (n/i - i >= 2){
				answer += (n/i - 1);
			}
		}
	}
	printf("%lld\n", answer);
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,w;cin>>n>>w;
    int ww[105],vv[105];
    rep(i,n)cin>>ww[i]>>vv[i];
    long long d[2][100010];
    for(int i=0;i<2;i++)for(int j=0;j<=w;j++)d[i][j]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=w;j++){
            if(j-ww[i]>=0)d[(i+1)&1][j]=max(d[(i+1)&1][j],d[i&1][j-ww[i]]+vv[i]);
            d[(i+1)&1][j]=max(d[(i+1)&1][j],d[i&1][j]);
        }
    }
    cout<<d[n&1][w]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N;
	int a[100100], b[100100], c[100100];
	cin >> N;
	for (int i = 0; i < N; ++i)cin >> a[i] >> b[i] >> c[i];
	int dp[100100][3];
	for (int i = 0; i < 100100; ++i) {
		for (int j = 0; j < 3; ++j) {
			dp[i][j] = 0;
		}
	}
	for (int i = 0; i < 100010; ++i) {
		dp[i + 1][0] = max(dp[i+1][0],max(dp[i][1] + a[i], dp[i][2] + a[i]));
		dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0] + b[i], dp[i][2] + b[i]));
		dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][0] + c[i], dp[i][1] + c[i]));
	}
	int ans = 0;
	for (int i = 0; i < 3; ++i) {
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;
	return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string a, b;
    cin >> a >> b;

    string aa;
    string bb;
    for(ll i = 0; i < stoi(b); i++){
        aa += a;
    }

    for(ll i = 0; i < stoi(a); i++){
        bb += b;
    }

    if(aa < bb){
        cout << aa << endl;
    }else{
        cout << bb << endl;
    }

}

Measured memory_bytes: 256