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

using namespace std;

long long A[100005];

long long B[100005];

int main(){
	int N;
	scanf("%d", &N);
	
	long long sum = 0;
	for(int i = 0; i < N; i ++){
		scanf("%lld", &A[i]);
		sum += A[i];
	}
	
	B[0] = sum;
	
	for(int i = 1; i < N; i += 2){
		B[0] -= A[i]*2; 
	}
	
	for(int i = 1; i < N; i ++){
		B[i] = A[i-1]*2-B[i-1];
	}
	
	for(int i = 0; i < N; i ++){
		printf("%lld", B[i]);
		if(i != N-1){
			printf(" ");
		}
	}
	
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

int V,E,R;
int dist[210][210];//dist2[i][i]=0, and if there aren't any edges between i and j, then dist2[i][j]=INF;
void warshall_floyd(){
    rep(k,V){
        rep(i,V){
            rep(j,V){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
}

signed main(){
    cin>>V>>E>>R;
    vector<int> r(R);
    rep(i,R){
        cin>>r.at(i);
        r.at(i)--;
    }
    sort(all(r));
    rep(i,210){
        rep(j,210){
            if(i==j)dist[i][j]=0;
            else dist[i][j]=INF;
        }
    }
    rep(i,E){
        int a,b,c; cin>>a>>b>>c;
        dist[a-1][b-1]=c;
        dist[b-1][a-1]=c;
    }
    warshall_floyd();
    int ans=INF;
    do{
        int tmp=0;
        rep(i,R-1){
            tmp+=dist[r.at(i+1)][r.at(i)];
        }
        chmin(ans,tmp);
    }while(next_permutation(all(r)));
    cout<<ans<<endl;
}

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

int main() {
   int N;
   cin >> N;
   vector<int> light(N);
   for(int i = 0; i < N; i++){
     cin >>light.at(i);
   }
   int NEXT = 1;
   int count = 0;
   int check = 0;
   for(int i = 0; i < N ; i++){
      count++;
      if(light.at(NEXT - 1) == 2){
         check = 1;
         break;
      }else{
         NEXT = light.at(NEXT - 1);
      }
   }
   if(check == 0){
     cout << -1 << endl;
   }else{
     cout << count << endl;
   }
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
  long a,b,c;
  long originA,originB,originC;
  cin >> a >> b >> c;
  originA = a;
  originB = b;
  originC = c;
  long tmp = 0;
  long tmp2 = 0;
  long ans = 0;
  if((a==b && b==c)&&a%2==0)cout << -1 << endl;
  else{
    while((a%2==0&&b%2==0)&&c%2==0){
      tmp = a;
      tmp2 = b;
      a = b/2 + c/2;
      b = tmp/2 + c/2;
      c = tmp/2 + tmp2/2;
      ans ++ ;
    }
    cout << ans;
  }
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int q;
    cin >> s >> q;
    vector<char> ff, ss;
    int rev = 0;
    while (q--) {
        int typ;
        cin >> typ;
        if (typ == 1) {
            rev ^= 1;
        } else {
            int f;
            char c;
            cin >> f >> c;
            --f;
            if (rev) {
                f ^= 1;
            }
            if (f == 0) {
                ff.emplace_back(c);
            } else {
                ss.emplace_back(c);
            }
        }
    }
    if (rev) {
        swap(ff, ss);
        reverse(s.begin(), s.end());
    }
    reverse(ff.begin(), ff.end());
    for (auto &ch : ff) {
        cout << ch;
    }
    cout << s;
    for (auto &ch : ss) {
        cout << ch;
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 976
N = int(input())
A = list(map(int,input().split(" ")))
A = sorted(A,reverse=True)
a_sum = 0
b_sum = 0
for i in range(len(A)):
    if i%2==0:
        a_sum+= A[i]
    else:
        b_sum += A[i]

print(a_sum-b_sum)

Measured memory_bytes: 3060
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)


int n, x;

vector<int> a;

int main() {
	cin >> n >> x;
	REP(i, n) {
		int aa;
		cin >> aa;
		a.emplace_back(aa);
	}
	sort(ALL(a));
	LL sum = 0;
	REP(i, n) {
		sum += a[i];
		if (sum > x) {
			cout << i << endl;
			return 0;
		}
	}
	cout << (sum == x ? n : n - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll k, s,count=0;
	cin >> k >> s;
	for (ll i = 0; i <= k; i++) {
		for (ll j = 0; j <= k; j++) {
			ll z = s - i - j;
			if (z >= 0 && z <= k) {
				count++;
			}
		}
	}
	cout << count << endl;

}


Measured memory_bytes: 256
import itertools

def main():
    n = int(input())
    tar_list = []
    cnt = 0
    
    for a in range(3,len(str(n))+1):
        target = list(itertools.product([3, 5, 7], repeat=a))
        #print(target)
        for tar in target:
            tar_list = list(tar)
            if tar.count(3) > 0 and tar.count(5) > 0 and  tar.count(7):
                #print(tar_list)
                ans = 0
                i = a-1
                for ii in tar_list:
                    ans += ii*(10**i)
                    #print(ans)
                    i -= 1
                if ans <= n:
                    cnt +=1
        
    print(cnt)
                    
            
            
            
        
               
if __name__ == "__main__":
    main()

Measured memory_bytes: 12340
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int32_t main()
{
	fast;
	int a, b;
	cin>>a>>b;
	cout<<max(a+b, max(a-b, a*b));
	return 0;
}

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

int main() {
  int a,b;
  int c,d,e,f,x,y;
  cin >> a >> b;
  x = a-1;
  y = 0;
  
  
  for (int i=0;i < b - a +1;i++){
    x = x + 1;
    c = x % 10;
    d = x % 100 / 10;
    e = x % 10000 / 1000;
    f = x % 100000 / 10000;
    if (c == f && d == e){
      y = y + 1;
    }
    
  }  
  cout << y << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
    int i,k,ii,n,ms,ss,iii,okiba[200];
    scanf("%d",&n);
    ms = 2 * n;
    int card[ms + 1];/*card[0]は使用しないことに注意*/
    for (i = 1;i <= ms;i++){
        card[i] = i;
    }
    scanf("%d",&ii);
    for (i = 1;i <= ii;i++){
        scanf("%d",&ss);
        if (ss){
            for (iii = 1;iii <= ss;iii++){
                okiba[iii] = card[iii];
            }
            for (iii = 1;iii <= ms - ss;iii++){
                card[iii] = card[iii + ss];
            }
            for (iii = 1;iii <= ss;iii++){
                card[iii + ms - ss] = okiba[iii];
            }
        }
        else{
            for (iii = 1;iii <= ms;iii++){
                okiba[iii] = card[iii];
            }
            for (iii = 1;iii <= n;iii++){
                card[2 * iii - 1] = okiba[iii];
                card[2 * iii] = okiba[iii + n];
            }
        }
    }
    for (i = 1;i <= ms;i++){
        printf("%d\n",card[i]);
    }
    return 0;
}

Measured memory_bytes: 604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ALDS1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            const int MAX = 200000;
            var n = int.Parse(Console.ReadLine());
            var R = new int[MAX];
            for (int i = 0; i < n; i++)
            {
                R[i] = int.Parse(Console.ReadLine());
            }
            var maxR = -int.MaxValue;
            var minR = R[0];
            for (int i = 1; i < n; i++)
            {
                maxR = Math.Max(maxR, R[i] - minR);
                minR = Math.Min(minR, R[i]);

            }
            Console.WriteLine(maxR);
        }
    }
}



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

int main()
{
    char S[17]={};
    char OK[] = "CODEFESTIVAL2016";
    int cnt = 0;
    scanf("%s", S);

    for (int i=0; i<16; i++)
    {
        if (S[i] != OK[i])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int f(std::string s) {
    int l = 0;
    int r = s.size() - 1;
    while (l < r) {
        if (s[l] != 'A') {
            l++;
        }
        if (s[r] != 'Z') {
            r--;
        }
        if (s[l] == 'A' && s[r] == 'Z') {
            break;
        }
    }
    return r - l + 1;
}

int main() {

    std::string s;
    std::cin >> s;

    int res = f(s);
    std::cout << res << std::endl;

    return 0;
}


Measured memory_bytes: 832
//Link : https://atcoder.jp/contests/agc018/tasks/agc018_c

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500005

int A[N],B[N],C[N];
pair<int,int> in[N];

ll getSolve(int x,int y,int z) {
  int n = x + y + z;

  ll ret = 0;
  for(int i=0;i<n;++i) {
    ret += B[i];
    in[i] = make_pair(C[i]-B[i],i);
  }
  sort(in,in+n,greater<pair<int,int> >());
  set<pair<int,int> > maxSet;
  priority_queue<pair<int,int> > q,firstQ;

  for(int i=0;i<z;++i) {
    int id = in[i].second;
    ret += in[i].first;
    firstQ.push(make_pair(A[id]-C[id],id));
  }

  for(int i=z;i<n;++i) {
    int id = in[i].second;
    q.push(make_pair(A[id]-B[id],id));
  }

  while(maxSet.size()<x) {
    maxSet.insert(q.top());
    ret += q.top().first;
    q.pop();
  }
  ll out = 0;
  for(int i=0;;++i) {
    out = max(out,ret);
    if(i==x) {
      break;
    }
    int ind = z + i;
    ret += in[ind].first;
    int id = in[ind].second;
    firstQ.push(make_pair(A[id]-C[id],id));
    pair<int,int> gg = make_pair(A[id]-B[id],id);
    if(maxSet.count(gg)) {
      ret -= gg.first;
      maxSet.erase(gg);
    }

    pair<int,int> tmp = firstQ.top();
    firstQ.pop();
    ret += tmp.first;
    pair<int,int> g = make_pair(A[tmp.second]-B[tmp.second],tmp.second);
    if(maxSet.count(g)) {
      maxSet.erase(g);
      ret -= g.first;
    }
    int rem = x-i-1;
    while(maxSet.size()>rem) {
      set<pair<int,int> >::iterator it = maxSet.begin();
      ret -= (*it).first;
      maxSet.erase(it);
    }
    assert(maxSet.size()==rem);
  }

  return out;
}
void solve() {
  int x,y,z;scanf("%d %d %d", &x,&y,&z);
  int n = x + y + z;
  for(int i=0;i<n;++i) {
    scanf("%d %d %d ", &A[i],&B[i],&C[i]);
  }
  ll ret = getSolve(x,y,z);
  swap(x,z);
  for(int i=0;i<n;++i) {
    swap(A[i],C[i]);
  }
  ret = max(ret, getSolve(x,y,z));
  printf("%lld\n", ret);
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


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

int main()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a = max(a, c);
    b = min(b, d);
    cout << ( (b - a) < 0 ? 0 : (b - a) ) << endl;
    return 0;
}


Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    a, b, c, d = [int(i) for i in list(input())]
    lists = [b, c, d]

    for i in range(2 ** 3):
        s = a
        ops = list('{:03b}'.format(i))
        for op, j in zip(ops, lists):
            if op == '0':
                s += j
            else:
                s -= j
        if s == 7:
            sen = str(a)
            for j, k in zip(lists, ops):
                if k == '0':
                    op1 = '+'
                else:
                    op1 = '-'
                sen = sen + op1 + str(j)
            print(sen + '=7')
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())
nums = list(map(int, input().split()))

if n == 1:
    print('Yes')
    exit()

nums[0] = max(0, nums[0]-1)
for i in range(1, n):
    if nums[i-1] < nums[i]:
        nums[i] -= 1
    if nums[i] < nums[i-1]:
        print('No')
        exit()

print('Yes')

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

using namespace std;

const int N=1e5+5;

int n,a[N<<1];

bool can(int u){
	for(int i=0;i<n-1;i++){
		if(a[n+i]<=u&&a[n+i+1]<=u){
			return true;
		}
		if(a[n-i]<=u&&a[n-i-1]<=u){
			return true;
		}
		if(a[n+i]>u&&a[n+i+1]>u){
			return false;
		}
		if(a[n-i]>u&&a[n-i-1]>u){
			return false;
		}
	}
	return a[1]<=u;
}

int bs(int l,int r){
	if(l==r){
		return l;
	}
	int mid=(l+r)>>1;
	if(can(mid)){
		return bs(l,mid);
	}
	else{
		return bs(mid+1,r);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<(n<<1);i++){
		scanf("%d",&a[i]);
	}
	printf("%d\n",bs(1,(n<<1)-1));
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int N,H,W,i,count;
  int gold[1000][2];
  scanf("%d %d %d",&N,&H,&W);
  for(i=0;i<N;i++){
    scanf("%d %d",&gold[i][0],&gold[i][1]);
  }
  for(i=0;i<N;i++){
    if(gold[i][0]>=H&&gold[i][1]>=W)count++;
  }
  printf("%d",count);
  return 0;
}

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

// @@ !! LIM(f:updMaxMin)
// --> f:updMaxMin
// ---- inserted function updMaxMin from util.cc
template<typename T>
bool updMax(T& tmax, const T& x) {
  if (x > tmax) { tmax = x; return true;  }
  else          {           return false; }
}
template<typename T>
bool updMin(T& tmin, const T& x) {
  if (x < tmin) { tmin = x; return true;  }
  else          {           return false; }
}
// ---- end updMaxMin
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll R, C, K; cin >> R >> C >> K;
  // using sta = pair<ll, ll>;
  // map<sta, ll> mp;
  vector val(R, vector(C, 0LL));
  for (ll i = 0; i < K; i++) {
    ll r, c, v; cin >> r >> c >> v; r--; c--;
    val[r][c] = v;
  }
  vector tbl(R+1, vector(C+1, vector(4, 0LL)));
  for (ll r = 0; r <= R; r++) {
    for (ll c = 0; c <= C; c++) {
      for (ll p = 0; p <= 3; p++) {
	ll cur = tbl[r][c][p];
	ll v = (r < R && c < C) ? val[r][c] : 0;
	if (r+1 <= R) updMax(tbl[r+1][c][0], cur);
	if (c+1 <= C) updMax(tbl[r][c+1][p], cur);
	if (v > 0 && p < 3) {
	  if (r+1 <= R) updMax(tbl[r+1][c][0], cur + v);
	  if (c+1 <= C) updMax(tbl[r][c+1][p+1], cur + v);
	}
      }
    }
  }
  cout << tbl[R][C][0] << endl;

  return 0;
}



Measured memory_bytes: 706516
#include <stdio.h>
#include <math.h>
int main (int argc, char * argv[])
{
    double x1,x2,y1,y2;
    double dis=0;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    dis = sqrt(pow(x2 - x1,2)+(pow(y2 - y1,2)));
    printf("%f\n",dis);
    return 0;
}



Measured memory_bytes: 2112
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        StringBuilder P = new StringBuilder();
        StringBuilder Q = new StringBuilder();
        StringBuilder base = new StringBuilder();
        int a = 0;
        int b = 0;
        PrintWriter out = new PrintWriter(System.out);

        for (int i = 0; i < N; i++) {
            P.append(sc.next());
        }

        for (int i = 0; i < N; i++) {
            Q.append(sc.next());
        }

        if (P.toString().equals(Q.toString())) {
            out.println("0");
            sc.close();
            out.flush();
            return;
        }

        for (Integer i = 1; i <= N; i++) {
            base.append(i.toString());
        }

        String Base = base.toString();
        boolean endPFlg = false;
        boolean endQFlg = false;
        while (!endPFlg || !endQFlg) {

            if (!endPFlg && !(Base.equals(P.toString()))) {
                a++;
            } else {
                endPFlg = true;
            }

            if (!endQFlg && !(Base.equals(Q.toString()))) {
                b++;
            } else {
                endQFlg = true;
            }

            Base = nextPermutation(Base);
        }

        out.println(Math.abs(a - b));
        sc.close();
        out.flush();
    }

    static String nextPermutation(String s) {

        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++)
            list.add(s.charAt(i));

        int pivotPos = -1;
        char pivot = 0;
        for (int i = list.size() - 2; i >= 0; i--) {
            if (list.get(i) < list.get(i + 1)) {
                pivotPos = i;
                pivot = list.get(i);
                break;
            }
        }

        if (pivotPos == -1 && pivot == 0)
            return "Final";

        int L = pivotPos + 1, R = list.size() - 1;
        int minPos = -1;
        char min = Character.MAX_VALUE;
        for (int i = R; i >= L; i--) {
            if (pivot < list.get(i)) {
                if (list.get(i) < min) {
                    min = list.get(i);
                    minPos = i;
                }
            }
        }

        Collections.swap(list, pivotPos, minPos);
        Collections.sort(list.subList(L, R + 1));

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++)
            sb.append(list.get(i));

        return sb.toString();

    }

}

Measured memory_bytes: 58972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    size_t a = 1;
    size_t b = n;
    for (size_t i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            a = i;
            b = n / i;
        }

    }
    cout << a + b - 2 << endl;
    return 0;
}


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

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

int gcd(int* a, int n){
  if(n == 1) return a[0];
  if(n == 2) return gcd(a[0], a[1]);

  int g = gcd(a[0], a[1]);
  for(int i=2; i<n; i++){
    g = gcd(g, a[i]);
  }
  return g;
}


int main(){
  int n, k; cin >> n >> k;
  int a[n];

  int m = 0;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    m = max(a[i], m);
  }

  int g = gcd(a, n);

  if(k % g || k > m){
    cout << "IMPOSSIBLE" << endl;
  }
  else{
    cout << "POSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define REP(i,n) for(i=0;i<(int)(n);++i)
#define SIZE 3010//文字列の長さの最大値
int i,j;//for文の添字

int max(int a,int b){//a,bのうち大きい方を返す
    if(a>b)return a;
    else return b;
}
//変数の初期化
char s1[SIZE],s2[SIZE];
int ls1=0,ls2=0;
int dp[SIZE][SIZE];
char res[SIZE];
int lcslen;
int ms1,ms2;
int cnt = 0;
int main(){
    
    //入力処理
    fgets(s1,SIZE,stdin);
    fgets(s2,SIZE,stdin);

    ls1 = strlen(s1);
    ls2 = strlen(s2);
    REP(i,ls1){//動的計画法
        REP(j,ls2){
            if(i==0||j==0){
                dp[i][j]=0;
            }else{
                if(s1[i-1]==s2[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
    }
    lcslen = dp[ls1-1][ls2-1];
    ms1=ls1-1;
    ms2=ls2-1;
    cnt = lcslen-1;
    while(dp[ms1][ms2]!=0){
        if(s1[ms1-1]==s2[ms2-1]){
            res[cnt--] = s1[ms1-1];
            ms1--;
            ms2--;
        }else if(dp[ms1-1][ms2]>=dp[ms1][ms2-1]){
            ms1--;
        }else{
            ms2--;
        }
    }
    //出力処理
    printf("%s\n",res);
    return 0;
}


Measured memory_bytes: 35456
program main
    implicit none
    integer :: n, d(50), i,j,s = 0

    read(*,*)n
    read(*,*)(d(i),i = 1, n)
    
    do i = 1, n-1
      do j = i+1, n
        s = s + d(i)*d(j)
      end do
    end do
    write(*,*)s
end program main

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

using namespace std;
int main()
{
    char ch, cho;
    cin >> cho;
    printf("%c",toupper(cho));
    while(ch!='\n')
    {
        scanf("%c",&ch);
        if(cho==' ') printf("%c",toupper(ch));
        cho = ch;
    }
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    char c;
    cin >> c;
    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';

    cout << m[c] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int v = max(a,max(b,c));
    int res = a+b+c-v;
    for(int i=1;i<=k;i++){
        v *= 2;
    }
    cout<<res+v<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
ll Pow(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2) return (a * Pow(a, n - 1)) % mod;
    else {
        ll k = Pow(a, n / 2);
        return (k * k) % mod;
    }
}
ll gyakusuu[100001];
ll nCk(ll n, ll k) {
    if (n < k) return 0;
    ll ret = 1;
    for (ll i = 1; i <= k; i++) {
        ret = ret * (n - k + i) % mod;
        ret = ret * gyakusuu[i] % mod;
    }
    return ret;
}
int main() {
    int n;
    int k;
    cin >> n >> k;
    for (int i = 1; i <= 100000; i++) {
        gyakusuu[i] = Pow(i, mod - 2);
    }
    vector<ll> vec;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(), vec.end());
    ll ret = 0;
    ll plus = 1;
    ll minus = nCk(n - 1, k - 1);
    for (int i = 0; i < n ; i++) {
        if (i < k - 1) plus = 0;
        if (i > n - k) minus = 0; 
        if (i == k - 1) plus = 1;
        ret = (ret + ( (plus - minus + mod) % mod * ((vec[i] + mod) % mod) ) ) % mod;
        if (i >= k - 1) plus = ((plus * (i + 1) % mod)  * gyakusuu[i - k + 2]) % mod;
        if (i <= n - k) minus = ((minus * (n - i - k) % mod) * gyakusuu[n - 1 - i]) % mod;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 5036
module Main where
    import Data.List

    main = do
        ns <- words <$> getLine 
        let x = (read (ns !! 0) ::Int)
        let a = (read (ns !! 1) ::Int)
        let b = (read (ns !! 2) ::Int)
        if (abs (a-x)) < (abs (b-x)) 
            then
                putStrLn "A"
            else
                putStrLn "B"


Measured memory_bytes: 508
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<fixed<<setprecision(6)<<a*b/2.0<<" ";
	if(c==a/2.0&&d==b/2.0) cout<<"1"<<endl;
	else cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
using D = double;
using Point = complex<D>;
const D eps = 1e-40;
inline int sgn(const D &a) { return (a < -eps) ? -1 : (a > eps) ? 1 : 0; }
inline D cross(const Point &a, const Point &b) {
    return a.real() * b.imag() - a.imag() * b.real();
}
inline D dot(const Point &a, const Point &b) {
    return a.real() * b.real() + a.imag() * b.imag();
}
istream &operator>>(istream &is, Point &p) {
    D a, b;
    is >> a >> b;
    p = Point(a, b);
    return is;
}
inline int ccw(const Point &a, const Point &b, const Point &c) {
    D d = cross(b - a, c - a);
    if (sgn(d) > 0) {
        return +1; //counter-clockwise
    } else if (sgn(d) < 0) {
        return -1; //clockwise
    } else {
        if (sgn(dot(b - a, c - a)) < 0) {
            return -2; //c,a,b
        } else if (sgn(dot(a - b, c - b)) < 0) {
            return +2; //a,b,c
        }
    }
    return 0; //a,c,b
}
inline Point projection(const Point &p, const Point &a, const Point &b) { //a to b
    return p + (dot(a - p, b - p) / norm(a - p)) * (a - p);
}
inline Point reflection(const Point &p, const Point &a, const Point &b) {
    return b + (projection(p, a, b) - b) * static_cast<D>(2.0);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    Point p0, p1;
    cin >> p0 >> p1;
    int q;
    cin >> q;
    while (q--) {
        Point p2;
        cin >> p2;
        int c = ccw(p0, p1, p2);
        if (c == 1) {
            cout << "COUNTER_CLOCKWISE\n";
        } else if (c == -1) {
            cout << "CLOCKWISE\n";
        } else if (c == -2) {
            cout << "ONLINE_BACK\n";
        } else if (c == 2) {
            cout << "ONLINE_FRONT\n";
        } else {
            cout << "ON_SEGMENT\n";
        }
    }
}



Measured memory_bytes: 3320
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vP u0,r0,d0,l0,u1,r1,d1,l1,u2,r2,d2,l2;
    rep(i,N){
        ll x,y;
        char c;
        cin >> x >> y >> c;
        if(c=='U'){
            u0.pb({x,y});//up&down
            u1.pb({y-x,x});//up&left
            u2.pb({x+y,x});//up&right
        }
        if(c=='D'){
            d0.pb({x,y});//up&down
            d1.pb({y-x,x});//down&right
            d2.pb({x+y,x});//down&left
        }
        if(c=='L'){
            l0.pb({y,x});//left&right
            l1.pb({y-x,x});//up&left
            l2.pb({x+y,x});//down&left
        }
        if(c=='R'){
            r0.pb({y,x});//left&right
            r1.pb({y-x,x});//down&right
            r2.pb({x+y,x});//up&right
        }
    }
    P p={INF/10,INF/10};
    sort(u0.begin(),u0.end());
    sort(u1.begin(),u1.end());
    sort(u2.begin(),u2.end());
    sort(d0.begin(),d0.end());
    sort(d1.begin(),d1.end());
    sort(d2.begin(),d2.end());
    sort(l0.begin(),l0.end());
    sort(l1.begin(),l1.end());
    sort(l2.begin(),l2.end());
    sort(r0.begin(),r0.end());
    sort(r1.begin(),r1.end());
    sort(r2.begin(),r2.end());
    ll ans=INF;
    ll U=u0.size(),D=d0.size(),L=l0.size(),R=r0.size();
    //lのほうが座標はでかい
    //right使うののlower_bound,down使うののlower_bound,up使うののlower_boundの順に
    P res;
    l0.pb(p);l1.pb(p);l2.pb(p);d0.pb(p);u2.pb(p);d1.pb(p);
    rep(i,R){
        res=*lower_bound(l0.begin(),l0.end(),r0[i]);
        if(r0[i].first==res.first){
            ans=min(ans,5*(res.second-r0[i].second));
        }
        res=*lower_bound(d1.begin(),d1.end(),r1[i]);
        if(r1[i].first==res.first){
            ans=min(ans,10*(res.second-r1[i].second));
        }
        res=*lower_bound(u2.begin(),u2.end(),r2[i]);
        if(r2[i].first==res.first){
            ans=min(ans,10*(res.second-r2[i].second));
        }
    }
    rep(i,D){
        res=*lower_bound(l2.begin(),l2.end(),d2[i]);
        if(res.first==d2[i].first){
            ans=min(ans,10*(res.second-d2[i].second));
        }
    }
    rep(i,U){
        res=*lower_bound(d0.begin(),d0.end(),u0[i]);
        if(res.first==u0[i].first){
            ans=min(ans,5*(res.second-u0[i].second));
        }
        res=*lower_bound(l1.begin(),l1.end(),u1[i]);
        if(res.first==u1[i].first){
            ans=min(ans,10*(res.second-u1[i].second));
        }
    }
    if(ans==INF){
        cout << "SAFE" << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15416
#include <bits/stdc++.h>
using namespace std;
int answer = 1e9;
int c[40];
vector<int> g[40];
int n,m;

void dfs(int x,long long bit,int cost){
	long long nextBit = bit;
	int diff = 0;
	// self
	if( !(bit >> x&1) ){
		diff += c[x];
		nextBit |= (1ll<<x);
	}
	// other
	for( auto i : g[x] ){
		if( !(bit >> i & 1) ){
			nextBit |= (1ll<<i);
			diff += c[i];
		}
	}
	int nextCost = cost + diff;
	if( nextCost >= answer ){
		return;
	}
	if( x == n - 1 ){
		answer = nextCost;
		return;
	}
	for( auto i : g[x] ){
		if( (bit >> i & 1) == 0 ) dfs(i,nextBit,nextCost);
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++){
		cin >> c[i];
	}
	for(int i = 0 ; i < m ; i++){
		int a,b;
		cin >> a >> b;
		--a,--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,0,0);
	cout << answer << endl;


}

Measured memory_bytes: 3152
#include <stdio.h>
int main() {
  int A, B, ans1, ans2, ans3;
  scanf("%d%d", &A, &B);
  ans1 = A + B;
  ans2 = A * B;
  ans3 = A - B;
  if(ans1 >= ans2 && ans1 >= ans3){
    printf("%d\n", ans1);
  }
  else if(ans2 >= ans1 && ans2 >= ans3) {
    printf("%d\n", ans2);
  }
  else if(ans3 >= ans1 && ans3 >= ans2) {
    printf("%d\n", ans3);
  }
  return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=2*1e5+7;
const int mod=1e9+7;

int n,k,l;
int f[K],g[K],vis[K];
vector<int >mp[K],cp[K];
map<PII,int>ans;

int fd(int x,int *p)
{
    return x==p[x]?x:fd(p[x],p);
}
void dfs1(int x,int ss)
{
    for(int i=0;i<mp[x].size();i++)
    if(!vis[mp[x][i]])
        f[mp[x][i]]=ss,vis[mp[x][i]]=1,dfs1(mp[x][i],ss);
}
void dfs2(int x,int ss)
{
    for(int i=0;i<cp[x].size();i++)
    if(!vis[cp[x][i]])
        g[cp[x][i]]=ss,vis[cp[x][i]]=1,dfs2(cp[x][i],ss);
}
int main(void)
{

    cin>>n>>k>>l;
    for(int i=1;i<=n;i++)
        f[i]=g[i]=i;
    for(int i=1,x,y;i<=k;i++)
        scanf("%d%d",&x,&y),mp[x].PB(y),mp[y].PB(x);
    for(int i=1,x,y;i<=l;i++)
        scanf("%d%d",&x,&y),cp[x].PB(y),cp[y].PB(x);

    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++)
    if(!vis[i])
            vis[i]=1,dfs1(i,i);
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++)
    if(!vis[i])
            vis[i]=1,dfs2(i,i);
    for(int i=1;i<=n;i++)
        ans[MP(fd(i,f),fd(i,g))]++;
    for(int i=1;i<=n;i++)
        printf("%d%c",ans[MP(fd(i,f),fd(i,g))],i==n?'\n':' ');
    return 0;
}


Measured memory_bytes: 28672
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int H, N; cin >> H >> N;
  pii AB[N];
  rep(i,N) cin >> AB[i].first >> AB[i].second;
  vector<int> dp(H+1,1000000000); // dp[h]: hダメージ与えるときの魔力の最小値
  dp[0] = 0;
  rep(i,N){
    rep(j,H+1){
      dp[min(j+AB[i].first,H)] = min(dp[min(j+AB[i].first,H)], dp[j] + AB[i].second);
    }
  }
  cout << dp[H] << endl;
  




  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3664
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
 
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}

void solve()
{
    ll n,k;cin>>n>>k;
    ll arr[n+3];memset(arr,0,sizeof arr);
    for(ll i=1;i<=k;i++)
    {
        ll g;cin>>g;
        while(g--)
        {
            ll k;cin>>k;
            arr[k]=1;
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
        if(!arr[i])ans++;cout<<ans<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

 solve();
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	string s; cin >> s;
	int ans = s.size();
	for (int i = 0; i < 2; i++) {
		int cnt = 0;
		for (int j = 0; j < s.size(); j++) {
			if ((j % 2 == 0) ^ (s[j] == i + '0')) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	
	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;

ll Dp[100010][3];

int main()
{

    SPEED;

    int n,a[100010][3];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    Dp[0][0] = a[0][0];
    Dp[0][1] = a[0][1];
    Dp[0][2] = a[0][2];

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j == k)
                    continue;
                Dp[i][j] = max(Dp[i][j],a[i][j]+Dp[i-1][k]);
            }
        }
    }
    cout << max(Dp[n-1][0],max(Dp[n-1][1],Dp[n-1][2])) << endl;
    R 0;
}


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

#define M 1000000
#define NIL (-1)
#define L 12

char H[M][L]; /* Hash Table */

int getChar(char ch)
{
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[])
{
  long key, i, h;
  
  key = getKey(str);
  for (i = 0;; i++)
  {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) 
      return 1;
    else if (strlen(H[h]) == 0) 
      return 0;
  }
  return 0;
}

int insert(char str[])
{
  long key, i, h;

  key = getKey(str);
  for (i = 0; ; i++)
  {
    h = (h1(key)+i*h2(key)) % M;
    if( strcmp(H[h],str) == 0 ) 
      return 1;
    else if ( strlen(H[h]) == 0 )
    {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main()
{
  int i, n, h;
  char str[L], com[9];

  for (i = 0; i < M; i++) 
    H[i][0] = '\0';
  scanf("%d", &n);
  for(i = 0; i < n; i++)
  {
    scanf("%s %s", com, str);

    if(com[0] == 'i')
      insert(str);
    else
    {
      if(find(str) )
      {
        printf("yes\n");
      } 
      else
        printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 13512
#include <cstdio>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>

using namespace std;

int main() {
    int A=0,B=0,C=0,vec[3],max=0;
    cin>> A>>B>>C;
    vec[0]=A;
    vec[1]=B;
    vec[2]=C;

    sort(vec,vec+ 3);

    printf("%d", 10*vec[2]+vec[1]+vec[0]);
    return 0;

}


Measured memory_bytes: 256
import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
 
#N, K = list(map(int, input().split()))
 
N = int(input())
 
x = []
for i in range(5):
	x.append(int(input()))
 
bottle = min(x)
times = math.ceil(N/bottle)
print(times + 4)

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

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

const int MAX { 310 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll st[MAX][MAX][MAX];

ll dp(int i, int k, int last, int N, const vector<int>& xs)
{
    if (i > N)
        return 0;

    if (st[i][k][last] != -1)
        return st[i][k][last];

    auto res = oo;

    if (xs[i] <= xs[last])
        res = min(res, dp(i + 1, k, i, N, xs)); 
    else
        res = min(res, dp(i + 1, k, i, N, xs) + (xs[i] - xs[last]));

    if (k > 0 and xs[i] != xs[last])
        res = min(res, dp(i + 1, k - 1, last, N, xs));

    st[i][k][last] = res;
    return res;
}

ll solve(int N, int K, vector<int>& xs)
{
    memset(st, -1, sizeof st);

    return dp(1, K, 0, N, xs);
}

int main()
{
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<int> xs(N + 2);

    for (int i = 1; i <= N; ++i)
        cin >> xs[i];

    xs[0] = xs[N + 1] = 0;

    auto ans = solve(N, K, xs);

    cout << ans << '\n';

    return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int h,w;
vector<string>board;

ll solve(){
    vector<vector<ll>>dp(h, vector<ll>(w,inf));
    queue<pii>que;
    que.push(pii(0,0));
    dp[0][0]=1;
    while(!que.empty()){
        pii now = que.front();
        que.pop();
        rep(k, 0, 4){
            int nx = now.first + dx[k];
            int ny = now.second + dy[k];
            if(nx>=h||ny>=w||nx<0||ny<0)continue;
            if(board[nx][ny]=='#')continue;
            if(dp[nx][ny]==inf){
               dp[nx][ny] = dp[now.first][now.second]+1;
               que.push(pii(nx, ny));
            }
        }
    }
    return dp[h-1][w-1];
}
int main() {
    cin >> h >> w;
    board.resize(h);
    int cnt1 = 0;
    rep(i, 0, h){
        cin >> board[i];
        rep(j, 0, w){
            if(board[i][j]=='#')cnt1++;
        }
    }
    if(solve()==inf)cout << -1 << endl;
    else cout << h*w-solve()-cnt1 << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  long long ans = 0;
  if(c >= a + b + 1){
    ans += a + b + 1 + b;
  }else{
    ans += b + c;
  }
  cout << ans << endl;
}

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


int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i=0; i<M; i++){
   cin >> B.at(i);
  }
  int cnt = 0;
  for (int i=0; i<N; i++){
    int sum = 0;
    for(int j=0; j<M; j++){
      int A;
      cin >> A;
      sum += B.at(j)*A;
    }
    if (sum + C > 0) cnt++;
  }
  cout << cnt << endl;
}


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


bool is_sharp(vector<string> &s, int h, int w, int H, int W) {
  return 0 <= h && h < H && 0 <= w && w < W && s.at(h).at(w) == '#';
}

int count_sharp(vector<string>& s, int h, int w, int H, int W) {

  vector<vector<int> > coordinates = {
    {h - 1, w - 1},
    {h - 1, w    },
    {h - 1, w + 1},
    {h    , w + 1},
    {h + 1, w + 1},
    {h + 1, w    },
    {h + 1, w - 1},
    {h    , w - 1}
  };

  int count = 0;
  for (int i = 0; i < coordinates.size(); i++) {
    int h_i = coordinates.at(i).at(0);
    int w_i = coordinates.at(i).at(1);
    if (is_sharp(s, h_i, w_i, H, W)) {
      count++;
    }
  }

  return count;
}

void answer1() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (auto& s_i: s) {
    cin >> s_i;
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (! is_sharp(s, h, w, H, W)) {
        int count = count_sharp(s, h, w, H, W);
        //char c_count = (char)('0' + count);
        //s.at(h).at(w) = c_count;
        cout << count;
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
}

int main() {
  answer1();
}


Measured memory_bytes: 256
from collections import deque

N, L = map(int, input().split())
*A, = map(int, input().split())

ans = []

que = deque()
for i, a in enumerate(A):
    while que and a <= que[-1][1]:
        que.pop()
    que.append((i, a))

    ans.append(que[0][1])

    if que and que[0][0] <= i+1-L:
        que.popleft()

print(*ans[L-1:])



Measured memory_bytes: 126248
#include "bits/stdc++.h"
using namespace std;

int s,sze=0;
set<int> nums;
int collatz(int n, int ret){
	if(sze==nums.size())
		return ret;
	if(n%2==0){
		sze=nums.size();
		nums.insert(n/2);
		return collatz(n/2,ret+1);
	}
	else{
		sze=nums.size();
		nums.insert(3*n+1);
		return collatz(3*n+1,ret+1);
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;
	nums.insert(s);
	cout<<collatz(s,1);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

using namespace std;

int W,H,x,y,r;

int main(){
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(abs(W-x)>= r && abs(H-y)>= r && x>0 && x<W && y>0 && y<H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}


Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
#define MAX 101
#define MAXB (int)1e+5+1

int main() {
    int N, B[MAX];

    cin >> N;
    for (int i=0; i<N-1; i++) cin >> B[i];
    B[N-1] = MAXB;

    int ans = 0;
    for (int i=0; i<=N-1; i++) {
        int minb;
        if (i==0) minb = B[0];
        else minb = min(B[i-1],B[i]);
        ans += minb;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, k;
//ld ;
//string s;

int main() {
    cin >> n >> k;
    ll ans = 0;
    n = n%k;
    ans = (n > k-n) ? k-n : n;
    cout << ans << endl;
    return 0;
}


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

int main(){
    ll N,M; cin>>N>>M;
    vector<ll> H(N,0);
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    vector<bool> h(N,true);
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        if(H[a-1]<=H[b-1])h[a-1]=false;
        if(H[a-1]>=H[b-1])h[b-1]=false;
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(h[i]==true)ans++;
    }
    cout<<ans;
    return 0;
}


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

int n, res[(int)1e5], mx;
vector<pair<int, int> > adj[(int)1e5 + 1];
bool vis[(int)1e5 + 1];

void color(int vtx, int pre){//pre前面已用颜色 
	vis[vtx] = true;
	int col = 1;
	for(int i=0;i<adj[vtx].size(); i++)
		if(!vis[adj[vtx][i].first]){
			if(col == pre) col++;
			res[adj[vtx][i].second] = col, mx = max(mx, col);
			color(adj[vtx][i].first, col);// col先赋值 再++     
          col++;
		}
}

int main(){
    cin >> n;
    for(int i = 1; i < n; i++){
    	int a, b;
    	cin >> a >> b;
    	adj[a].push_back({b, i});
    	adj[b].push_back({a, i});
    }
    color(1, 0);
    cout << mx << "\n";
    for(int i = 1; i <= n - 1; i++) cout << res[i] << "\n";
    return 0;
}


Measured memory_bytes: 8448