akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
#define Rep(i, n, a) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, n, 0)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;

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

    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1)
    {
        cout << "No" << endl;
        return 0;
    }
    vector<int> ans(2 * n - 1);
    if (x == 2)
    {
        ans[n - 2] = 3;
        ans[n - 1] = 2;
        ans[n] = 1;
        ans[n + 1] = 4;
        int num = 5;
        rep(i, 2 * n - 1)
        {
            if (i >= n - 2 && i <= n + 1)
                continue;
            ans[i] = num++;
        }
    }
    else
    {
        ans[n - 1] = x;
        ans[n - 2] = x + 1;
        ans[n - 3] = x - 2;
        ans[n] = x - 1;
        int num = 1;
        rep(i, 2 * n - 1)
        {
            if (i >= n - 3 && i <= n)
                continue;
            if (num == x - 2)
                num += 4;
            ans[i] = num++;
        }
    }
    cout << "Yes" << endl;
    rep(i, 2 * n - 1) cout << ans[i] << endl;
}

Measured memory_bytes: 2304
from collections import deque
import copy

h,w = map(int, input().split())
s = [["#"]*(w+2)]+[["#"]+list(input())+["#"] for i in range(h)]+[["#"]*(w+2)]
q = deque([(i, j) for i in range(1,h+1) for j in range(1,w+1) if s[i][j] == "#"])
white = 0
while True:
  q2 = deque()
  while q:
    a,b = q.popleft()
    if s[a-1][b] == ".":
      s[a-1][b] = "#"
      q2.append((a-1,b))
    if s[a+1][b] == ".":
      s[a+1][b] = "#"
      q2.append((a+1,b))
    if s[a][b-1] == ".":
      s[a][b-1] = "#"
      q2.append((a,b-1))
    if s[a][b+1] == ".":
      s[a][b+1] = "#"
      q2.append((a,b+1))   
  if q2:
    q = copy.copy(q2)
    white += 1
  else:
    print(white)
    break

Measured memory_bytes: 135248
#include <stdio.h>

int main(void) {
  int t[4], n[4];
  for (int i = 0; i < 4; i++) {
    scanf("%d%d", &t[i], &n[i]);
  }

  for (int i = 0; i < 4; i++) {
    switch (t[i]) {
      case 1 : printf("%d\n", (n[i] * 6000));
      break;
      case 2 : printf("%d\n", (n[i] * 4000));
      break;
      case 3 : printf("%d\n", (n[i] * 3000));
      break;
      case 4 : printf("%d\n", (n[i] * 2000));
    }
  }
  return 0;
}



Measured memory_bytes: 2088
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
q=[]
for i in range(n):
    if t[i]=='r':
        q.append('p')
    elif t[i]=='s':
        q.append('r')
    else:
        q.append('s')
ans=0
for i in range(n):
    if i<k:
        if t[i]=='r':
            ans+=p
        elif t[i]=='s':
            ans+=r
        else:
            ans+=s
        continue
    else:
        if q[i-k]==q[i]:
            q[i]=''
        else:
            if t[i]=='r':
                ans+=p
            elif t[i]=='s':
                ans+=r
            else:
                ans+=s
print(ans)

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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

const LL MOD = 1000000007;

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

    vector<LL> inv(1e6, 0);
    inv[1] = 1;
    for(int i = 2; i < 1e6; ++i) {
        inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD;
    }
    vector<LL> fac(1e6,1), invfac(1e6,1);
    for(int i = 2; i < 1e6; ++i) {
        fac[i] = (fac[i - 1] * i) % MOD;
        invfac[i] = (invfac[i - 1] * inv[i]) % MOD;
    }
    
    int N, M;
    cin >> N >> M;
    LL ans = 0;
    for(int k = 0; k <= N; ++k) {
        LL s = 1;
        if(k & 1) {
            s = MOD - 1;
        }
        ans = (ans + ((((((fac[M - k] * invfac[N - k]) % MOD) * invfac[k]) % MOD) * s) % MOD)) % MOD;
    }
    cout << (((((((ans * fac[N]) % MOD) * fac[M] % MOD) * invfac[M - N]) % MOD) * invfac[M - N]) % MOD) << "\n";
    
    
    return 0;
}


Measured memory_bytes: 26632
import java.util.Scanner;

//ICPC Score Totalizer Software
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int s = 0;
			int max = 0;
			int min = 1000;
			for(int i=0;i<n;i++){
				int a = sc.nextInt();
				s += a;
				max = Math.max(max, a);
				min = Math.min(min, a);
			}
			System.out.println((s-max-min)/(n-2));
		}
	}
}

Measured memory_bytes: 0
n, c, k = map(int, input().split())
p = [0 for i in range(n + 1)]
t0 = [int(input()) for i in range(n)]
t0.sort()
t = []
for i in range(n):
    temp = t0[i]
    t.append([temp, 1, i])
    t.append([temp + k, 2, i])
t.sort()
count = 0
for i in t:
    num = i[2]
    if i[1] == 1:
        p[num] += 1
    else:
        num2 = (p[num] - 1) // c + 1
        count += num2
        temp = num + 1
        num3 = c * num2 - p[num]
        while num3 > 0:
            if p[temp] == 0:
                break
            else:
                num4 = min(num3, p[temp])
                num3 -= num4
                p[temp] -= num4
                temp += 1
        p[num] = 0
print(count)

Measured memory_bytes: 40904
#include<iostream>
#include<math.h>

using namespace std;

int main(){

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    for(int i=0;i<(x2-x1);i++)cout << 'R';
    for(int i=0;i<(y2-y1);i++)cout << 'U';
    for(int i=0;i<(x2-x1);i++)cout << 'L';
    for(int i=0;i<(y2-y1);i++)cout << 'D';

    cout << 'D';
    for(int i=0;i<(x2-x1+1);i++)cout << 'R';
    for(int i=0;i<(y2-y1+1);i++)cout << 'U';
    cout << "LU";
    for(int i=0;i<(x2-x1+1);i++)cout << 'L';
    for(int i=0;i<(y2-y1+1);i++)cout << 'D';
    cout << "R\n";


    cout << endl;
}


Measured memory_bytes: 256
n=gets.to_i
s=[]
a=[]
n.times do |i|
  s[i],a[i]=gets.split.map &:chomp
end
ans=a.zip(s,[*1..n]).sort_by!{|i|[i[1], -i[0].to_i]}
ans.each do |i|
  puts i[2]
end


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

ll v[3000][3000], dp[3000][3000][4];

int main(void){
    int r, c, t;
    cin >> r >> c >> t;
    fill(v[0], v[r], 0);
    rep(i, t){
        int a, b;
        cin >> a >> b;
        cin >> v[a - 1][b - 1];
    }
    fill(dp[0][0], dp[r][0], 0);
    if(v[0][0] > 0) dp[0][0][2] += v[0][0];
    rep(i, r){
        rep(j, c){
            ll val = v[i][j];
            rep(k, 4){
                if(i > 0){
                    dp[i][j][3] = max(dp[i][j][3], dp[i - 1][j][k]);
                    dp[i][j][2] = max(dp[i][j][2], dp[i - 1][j][k] + val);
                }
                if(j > 0){
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                    if(k > 0){
                        dp[i][j][k - 1] = max(dp[i][j][k - 1], dp[i][j - 1][k] + val);
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(k, 4)
        ans = max(ans, dp[r - 1][c - 1][k]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 354956
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  ll n, k; cin>>n>>k;
  dump(n,k);

  vi a(n,0);
  rep(i,n) cin >> a[i];

  int log2k = log2(k)+2;

  vvi A(log2k,vi(n,0));
  rep(j, log2k){
    if(j==0) { rep(i, n) A[0][i] = a[i]; }
    else {
      rep(i, n) A[j][i] = A[j-1][A[j-1][i]-1];
    }
  }

  int here = 1;
  for(int i=0;i<log2k;++i){
    if( (k>>(log2k-i-1)) & 1 ) here = A[log2k-i-1][here-1];
  }
  cout << here << endl;
  return 0;
}


Measured memory_bytes: 52712
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	sett = set()
	for _ in range(int(inp())):
		sett.add(inp())
	print(len(sett))



if __name__ == "__main__":
	solve()

Measured memory_bytes: 31632
#include <iostream>
#include <set>
#include <vector>
#include <map>
using namespace std;

int main() {
  int64_t n, k, start = 0;
  cin >> n >> k;
  int a[2 * n], next[n];
  for (int i = 0; cin >> a[i]; ++i) {
    a[i + n] = a[i];
  }
  map<int, int> index;
  for (int i = 2 * n - 1; i >= n; --i) {
    index[a[i]] = i;
  }
  for (int i = n - 1; i >= 0; --i) {
    auto it = index.find(a[i]);
    next[i] = it->second - i + 1;
    it->second = i;
  }
  do {
    if (start + next[start % n] < n * k) {
      start += next[start % n];
    } else {
      break;
    }
  } while (start % n != 0);
  set<int> set;
  vector<int> result;
  for (auto i = start == 0 ? 0 : n * k / start * start; i < n * k; ) {
    if (i + next[i % n] < n * k) {
      i += next[i % n];
    } else {
      auto it = set.find(a[i % n]);
      if (it == end(set)) {
        set.emplace(a[i % n]);
        result.emplace_back(a[i % n]);
      } else {
        while (result.back() != *it) {
          set.erase(result.back());
          result.pop_back();
        }
        result.pop_back();
        set.erase(it);
      }
      ++i;
    }
  }
  for (auto i : result) {
    cout << i << ' ';
  }
  return 0;
}

Measured memory_bytes: 24596
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int R =	sc.nextInt();
	if(R<1200) {
            System.out.println("ABC");
        }else if(R<2800) {
            System.out.println("ARC");
        }else {
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 21844
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void sublime(){ 
	#ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
      }
	
int main()
{   
   //sublime();
	  ll n,i;
	   ll a,b;
	   cin>>a>>b;
	   if(a>=13)
	   cout<<b;
	   else
	   if(a>=6 && a<=12)
	   cout<<b/2;
	   else
	   cout<<0; 
	   
	return 0;
}

Measured memory_bytes: 3608
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        List<Integer> arr = new ArrayList<>();

        for (int i = 0; i < N; ++i) {
            arr.add(fs.nextInt());
        }
        Collections.sort(arr);

        int ans = 0;
        for (int i = 0; i <= N-3; ++i) {
            for (int j = i+1; j <= N-2; ++j) {
                if (arr.get(i).equals(arr.get(j))) continue;
                for (int k = j+1; k <= N-1; ++k) {
                    if (arr.get(j).equals(arr.get(k))) continue;
                    if (arr.get(k) < arr.get(i) + arr.get(j)) ++ans;
                }
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 33676
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn exe(s: String) -> bool {
    s.chars().nth(2).unwrap() == s.chars().nth(3).unwrap()
        && s.chars().nth(4).unwrap() == s.chars().nth(5).unwrap()
}

fn main() {
    input! {
        s: String,
    }
    let ans = exe(s);
    println!("{}", if ans { "Yes" } else { "No" });
}

#[test]
fn test() {
    assert_eq!(exe("sippuu".to_string()), true);
    assert_eq!(exe("iphone".to_string()), false);
    assert_eq!(exe("coffee".to_string()), true);
}


Measured memory_bytes: 4352
def main():
    x,y = map(int,input().split())
    p = list(map(int,input().split()))

    number = sum(p[0:y])
    bigNumber = number

    for i in range(x-y):

        number = number - p[i] + p[i+y]

        if number > bigNumber:
            bigNumber = number

    print((bigNumber + y) / 2)

main()


Measured memory_bytes: 71792
#include<bits/stdc++.h>
using namespace std;
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
inline int read(){
	   int a=0,fh=1;char c=getchar();
	   while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	   while('0'<=c&&c<='9'){
		   a=a*10+c-48;
		   c=getchar();
	   }
	   return a*fh;
}
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b)swap(a,b);
	if(b>c)swap(c,b);
	if(a>b)swap(a,b);
	puts(((a==b)^(b==c))?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    ll N, M;
    cin >> N >> M;

    ll ans;
    if (N == 1 && M == 1)
    {
        ans = 1;
    }
    else if (N >= 2 && M >= 2)
    {
        ans = (N - 2) * (M - 2);
    }
    else if (N >= 2)
    {
        ans = N - 2;
    }
    else if (M >= 2)
    {
        ans = M - 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3532
import math

def resolve():
    _,K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    start = 0
    end = 10**9

    while end - start > 1:
        cnt = 0
        mid = (start + end) // 2
        for a in A:
            cnt += math.ceil(a/mid) - 1
        if cnt <= K:
            end = mid
        else:
            start = mid

    print(end)
    
resolve()

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

int main(){
  string s;
  cin >> s;
  int karians = 0;
  int ans = 0;
  rep(i,s.size()+1){
    if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
      karians++;
    }else{
      ans = max(ans,karians);
      karians = 0;
    }
  }
  cout << ans << endl;
}




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

char matrix[1000+1][1000+1];
long long int ans[1001][1001]={0};
long long dp(int i,int j){
    if(i<=0||j<=0){
        return(0);
    }
    else if(i==1&&j==1){
        return(1);
    }
    else if(ans[i][j]!=-1){
        return(ans[i][j]);
    }
    else{
        if(matrix[i][j-1]!='#'&&matrix[i-1][j]!='#'){
            ans[i][j]=(dp(i-1,j)+dp(i,j-1))%1000000007;
            return(ans[i][j]);
        }
        else if(matrix[i][j-1]!='#'){
            ans[i][j]=dp(i,j-1);
            return(ans[i][j]);
        }
        else if(matrix[i-1][j]!='#'){
            ans[i][j]=dp(i-1,j);
            return(ans[i][j]);
        }
        else{
            ans[i][j]=0;
            return(0);
        }
    }
}

int main() {
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=m;j++){
	        cin >> matrix[i][j];
	    }
	}
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=m;j++){
	        ans[i][j]=-1;
	    }
	}
	cout << dp(n,m) << endl;
	return 0;
}

Measured memory_bytes: 9088
from fractions import gcd
a, b, c, d = map(int, input().split())

def lcm(x,y):
	return (x*y)//gcd(x,y)
e = lcm(c,d)

f = (b//c + b//d) - b//e
g = ((a-1)//c + (a-1)//d) - (a-1)//e
print (b-a+1-(f-g))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
string lcs(string a,string b,int n,int m)
{
    for(int i=0;i<=n;++i)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=m;++i)
    {
        dp[0][i]=0;
    }
    
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]= max(dp[i][j-1],dp[i-1][j]);
            }
        }
        
    }
   
    int i = n, j = m;
    string result = "";
    while(i>0 && j>0)
    {
        if(a[i-1]==b[j-1])
        {
            result.push_back(a[i-1]);
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
                i--;
        }
        else
        {
                j--;
        }
        
        
    }
    return result;
}
int main()
{
    string a,b;
    cin>>a;
    cin>>b;
    string  p= lcs(a,b,a.length(),b.length());
    reverse(p.begin(),p.end());
    cout<<p<<endl;
    
    
    return 0;
}

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

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    int sum = a + b + c;

    if(sum >= 22)
        cout << "bust" << endl;
    else
       cout << "win" << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
int x,y,z;
int n1=0,m1=0;

while(scanf("%d %d %d",&x,&y,&z)!=EOF){
n1=10000*x+100*y+z;
if(n1>=19890108){printf("heisei ");x=x-1988;}
else if(n1>=19261225){printf("showa ");x=x-1925;}
else if(n1>=19120730){printf("taisho ");x=x-1911;}
else if(n1>=18680908){printf("meiji ");x=x-1867;}
else if(n1<18680908)printf("pre-meiji\n");

if(n1>=18680908)printf("%d %d %d\n",x,y,z);
n1=0;
}
return 0;
}

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

int main() {
  int N,H,W;
  cin>>N>>H>>W;
  if(N==1){
    int a;
    cin>>a;
    cout<<abs(W-a)<<endl;
  }
  else{
    for(int i=0;i<N-2;i++){
      int a;
      cin>>a;
    }
    int b,c;
    cin>>b>>c;
    cout<<max(abs(W-c),abs(b-c))<<endl;
  }
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> vec(h);
  for (int i = 0; i < h; i ++) {
    cin >> vec.at(i);
  }

  vector<bool> col(h, false);
  vector<bool> row(w, false);
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      if (vec.at(i).at(j) == '#') {
        col.at(i) = true;
        row.at(j) = true;
      }
    }
  }

  for (int i = 0; i < h; i ++) {
    if (col.at(i)) {
      for (int j = 0; j < w; j ++) {
        if (row.at(j)) {
          cout << vec.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, m;
    cin >> n >> m;
    vector<queue<int>> a(n, queue<int>());
    rep(i, n){
        rep(j, m){
            int x;
            cin >> x;
            a[i].push(x);
        }
    }

    int ans = INF;
    set<int> exclude;
    rep(i, m){
        rep(j, n){
            while(exclude.find(a[j].front()) != exclude.end()){
                a[j].pop();
            }
        }

        vector<int> cnt(m + 1);
        rep(j, n){
            cnt[a[j].front()]++;
        }
        int maxId = 0;
        rep(j, m + 1){
            if(cnt[maxId] < cnt[j]){
                maxId = j;
            }
        }
        ans = min(ans, cnt[maxId]);
        exclude.insert(maxId);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
S = input()
s = [i for i in S]
ans = ["k","e","y","e","n","c","e"]
f = 0
for i in range(7):
    if s[:i]+s[-(7-i):] == ans:
        f = 1
        break
if f == 0:
    print("NO")
else:
    print("YES")


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

using namespace std;

#define int long long
#define double long double 
const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const int MOD = 1e9 + 7;
const int INF = 1e18 + 7;


typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef unordered_map<int,int> mii;
typedef unordered_map<char,int> mci;
typedef unordered_map<string,int> msi;

#define pb push_back
#define f first
#define s second 
 

void solve() {
    int n,b,e,sum; cin>>n;
    vi A(n);
    for(int i=0;i<n;i++) {
        cin>>A[i];
    }
    vvi dp(n,vi(n));
    for(int i=0;i<n;i++) {
        dp[i][i] = 0;
    }
    for(int i=2;i<=n;i++) {
        for(int j=0;j<=n-i;j++) {
            b = j,e = j+i-1;
            dp[b][e] = INF;
            sum = 0;
            for(int k=b;k<=e;k++) {
                sum += A[k];
            }
            for(int k=b;k<=e-1;k++) {
                dp[b][e] = min(dp[b][e],dp[b][k] + dp[k+1][e]+sum);
            }
        }
    }
    // for(int i=0;i<n;i++) {
    //     for(int j=0;j<n;j++) {
    //         cout<<dp[i][j]<<' ';
    //     }
    //     cout<<endl;
    // }
    cout<<dp[0][n-1]<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);
    //#ifdef LOCAL
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif

    int tc; tc=1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int n;cin>>n;
  int ans=0;
  REP(i,n){
    ll a;cin>>a;
    int cnt=0;
    while(a%2==0){
      cnt++;
      a/=2;
    }
    ans+=cnt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int x;
  cin >> x;
  ll ans = 0;
  ans = x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout << ans << endl;
}

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

int n;
long long a[100010];
long long mod = 1e9+7;
long long fact[100010];
long long s[100010];
long long ans;

long long inv(long long x){
	long long res = 1;
	for(int i=0; ((mod-2)>>i)>0; ++i){
		if((((mod-2)>>i) & 1) == 1){
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
	}
	return res;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n; ++i)
		cin >> a[i];
	fact[0] = 1;
	for(int i=1; i<=n; ++i)
		fact[i] = fact[i-1] * i % mod;
	for(int i=1; i<=n; ++i)
		s[i] = inv(i);
	for(int i=2; i<=n; ++i){
		s[i] += s[i-1];
		s[i] %= mod;
	}
	for(int i=1; i<=n; ++i){
		ans += a[i] * (s[i] + s[n-i+1] - 1) % mod;
		ans %= mod;
	}
	ans *= fact[n];
	ans %= mod;
	cout << ans << "\n";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

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

  int a[100005],b[100005];
  int max_a=0;
  for (int i=0; i<n; i++) {
    cin>>a[i]>>b[i];
    max_a=max(max_a,a[i]);
  }
  int cnt=0;
  sort(b,b+n);
  reverse(b,b+n);
  for (int i=0; i<n; i++) {
    if (b[i]<max_a) {
      cnt+=(h+max_a-1)/max_a;
      cout<<cnt<<endl;
      return 0;
    }
    h-=b[i];
    cnt++;
    if (h<=0) {
       cout<<cnt<<endl;
       return 0;
    }
  }
  cnt+=(h+max_a-1)/max_a;
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ppll pair<pll,ll>
#define vi vector <ll>
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define f(i,x,n) for(ll i=x;i<n;i++)
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;} 
const ll N = 1e6 + 5, M = 1e18 + 7; 

int main(){
    FAST;
    ll n, k, t, m = 0, x = 0, i, ans = 0, j, y = 0, z = 4, c = 0;
    cin >> n;
    f(i, 1, n + 1){
        if(i%3 != 0 && i%5 != 0) ans += i;
    }
    cout << ans;
}   

Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var q = long.Parse(Console.ReadLine());
        long[] b = new long[q];
        long[] c = new long[q];
        for (long i = 0; i < q; i++)
        {
            long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray();
            b[i] = tmp[0];
            c[i] = tmp[1];
        }

        var dic = new Dictionary<long, long>();
        var ans = a.Sum();
        for (long i = 0; i < n; i++)
        {
            if (!dic.ContainsKey(a[i]))
            {
                dic.Add(a[i], 1);
            }
            else
            {
                dic[a[i]]++;
            }
        }

        for (long i = 0; i < q; i++)
        {
            if (dic.ContainsKey(b[i]))
            {
                if (dic.ContainsKey(c[i]))
                {
                    ans -= dic[b[i]] * b[i];
                    dic[c[i]] += dic[b[i]];

                    ans += dic[b[i]] * c[i];
                    dic[b[i]] = 0;
                }
                else
                {
                    ans -= dic[b[i]] * b[i];
                    dic.Add(c[i], dic[b[i]]);

                    ans += dic[b[i]] * c[i];
                    dic[b[i]] = 0;
                }
            }

            Console.WriteLine(ans);
        }

    }
}

Measured memory_bytes: 50596
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;

const ll mod = 1000000007;
int main(){
  ll n;
  cin >> n;
  vector<ll> zero(61, 0);
  vector<ll> one(61, 0);
  rep(i, n){
    ll a;
    cin >> a;
    rep(j, 61){
      if (a % 2 == 0) zero[j]++;
      else one[j]++;
      a /= 2;
    }
  }
  
  ll ans = 0;
  ll two = 1;
  rep(i, 61){
    ll add = (zero[i] * one[i]) % mod * two;
    ans = (ans + add) % mod;
    two = (two * 2) % mod;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    char s[10];
    scanf("%s", s);
    int left = (s[0] - '0') * 10 + s[1] - '0';
    int right = (s[2] - '0') * 10 + s[3] - '0';
    if ((left > 12 || left == 0) && right <= 12 && right >= 1) {
        printf("YYMM\n");
    } else if ((right > 12 || right == 0) && left <= 12 && left >= 1) {
        printf("MMYY\n");
    } else if (right >= 1 && right <= 12 && left <= 12 && left >= 1) {
        printf("AMBIGUOUS\n");
    } else {
        printf("NA\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
void print(bitset<32> b) {
    for (int i = 0; i < 32; i++) {
        if (b.test(i)) {
            cout << " " << i;
        }
    }
}
 
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    bitset<32> b1, b2;
    vector<int> vec;
 
    int n; cin >> n;
    int k; cin >> k;
    int max = 1 << k;
    for (int i = 0; i < k; i++) {
        int x; cin >> x;
        vec.push_back(x);
    }
    for (int i = 0; i < max; i++) {
        b1 = i;
        b2.reset();
        for (int j = 0; j < vec.size(); j++) {
            if (b1.test(j) == 1) {
                b2.set(vec[j]);
            }
        }
        cout << b2.to_ulong() << ":";
        print(b2);
        cout << endl;
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, count = 0; string S; cin >> N >> S;
  for(int i = 0; i < N - 2; i++) {
    count += ((S.substr(i, 3) == "ABC") ? 1 : 0);
  }
  cout << count << endl;
}

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

typedef long long LL;  
using namespace std;

#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'

const int M = (int)1e9+7;
const int N = 1005; 

struct pt {int xx; int yy;int rr;}; 

double arr[N][N];
double sp[N];
bool vis[N];

double dis2(pt &a,pt &b)
	{
	double xxx = (a.xx-b.xx);
	double yyy = (a.yy-b.yy);	

	return 	sqrt(xxx*xxx+yyy*yyy);
	}


double dis(pt &a,pt &b)
	{
	double dc = dis2(a,b);
	double rrr = a.rr+b.rr;

	if(dc<= rrr)
		return 0;
	else
		 return (dc-rrr);
	}


int main()
{
//ios_base::sync_with_stdio(0); 
cout.precision(15);
cout.setf(ios::fixed);

int i,j,n;
int a,b,c,d;

cin >> a >> b >> c >> d;

cin >> n;

vector <pt> v(n+2);

v[0].xx = a; v[0].yy = b; v[1].xx = c; v[1].yy = d;

for(i=2;i<n+2;i++)
	{
	cin >> v[i].xx >> v[i].yy >> v[i].rr; 	
	}

n = n+2;

for(i=0;i<n;i++)
	for(j=0;j<n;j++)
		{
		arr[i][j] = dis(v[i],v[j]);	
		// cout << i << ' ' << j << ' '<< arr[i][j] << endl;
		}

set <pair<double,int> > st;
st.insert(MP(0,0));
pair <double,int> ss;
set < pair <double,int> >  :: iterator it;

while(!st.empty()) 
{
it = st.begin();
st.erase(it);
ss = *it;

if(vis[ss.second]) continue;

vis[ss.second] = true;
sp[ss.second] = ss.first;

// cout<<ss.first << ' '<<ss.second<<endl;

for(i=0;i<n;i++)
	{
	if(!vis[i])
		st.insert(MP(ss.first+arr[ss.second][i],i));	
	}
}

cout<<sp[1]<<endl;
}


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

int main(){
    int a,b,k;
    cin>>k>>a>>b;
    bool ans=false;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            ans=true;
            break;
        }
    }
    if(ans){
        cout<<"OK"<<endl;
    }else{
        cout<<"NG"<<endl;
    }
}

Measured memory_bytes: 3636
c=[]
for i in range(3):
    c_i=list(map(int,input().split()))
    c.append(c_i)
h01=c[0][1]-c[0][0]
h12=c[0][2]-c[0][1]
v01=c[1][0]-c[0][0]
v12=c[2][0]-c[1][0]
buf=1
for i in range(1,3):
    if c[i][1]-c[i][0]!=h01 or c[i][2]-c[i][1]!=h12 or c[1][i]-c[0][i]!=v01 or c[2][i]-c[1][i]!=v12:
        buf=0
        break
if buf==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;


void solve()
{
	string s;
	cin>>s;
	int ans=0;
	for(auto i:s)ans+=i-'0';
	ans%=9;
	if(ans)cout<<"No";
	else cout<<"Yes";
	
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
	solve();
    return 0;
}


Measured memory_bytes: 3776
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])
    count = 0
    for i in range(1, N+1):
        if len(str(i)) % 2 == 1:
            count += 1
    return count




def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	string N;
	cin >> N;

	cout << "ABC" + N << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int M = 3e5;
const int mod = 1e9 + 7;
using pii = pair<int, int>;
int h, w, n, fac[M], dp[N];
pii points[N];

int mul(int x, int y) {
	return (x * 1LL * y) % mod;
}

int exp(int x, int y) {
	long long ans = 1;
	while (y) {
		if (y & 1) {
			ans = mul(ans, x);
		}
		x = mul(x, x);
		y >>= 1;
	}

	return ans;
}

int sub(int x, int y) {
	if (x - y < 0) {
		return x - y + mod;
	}
	return x - y;
}

int inv(int x) {
	return exp(x, mod - 2);
}

int paths(int x, int y) {
	if (x < 0 || y < 0) {
		return 0;
	}
	return mul(fac[x + y], inv(mul(fac[x], fac[y])));
}

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

	fac[0] = 1;
	for (int i = 1; i < M; i ++) {
		fac[i] = mul(fac[i - 1], i);
	}

	cin >> h >> w >> n;

	for (int i = 0; i < n; i++) {
		cin >> points[i].first >> points[i].second;
		points[i].first--;
		points[i].second--;
	}

	sort(points, points + n);

	points[n] = {h - 1, w - 1};
	n++;

	for (int i = 0; i < n; i++) {
		pii p = points[i];
		dp[i] = paths(p.first, p.second);

		for (int j = 0; j < i; j++) {
			dp[i] = sub(dp[i], mul(dp[j], paths(p.first - points[j].first, p.second - points[j].second)));

		}
	}

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


Measured memory_bytes: 1408
s=input()
n=len(s)
a=2**(n-1)
t = [bin(i)[2:] for i in range(a)]
for i in range(a):
    t[i]='0'*(n-1-len(t[i]))+t[i]
    t[i]=t[i][::-1]
ans=0
#print(s)
#print(t)
for i in range(a):
    k=0
    for j  in range(n-1):
        if t[i][j]=="1":
            ans+=int(s[k:j+1])
            #print(s[k:j+1])
            k=j+1
            #print(ans,i,j)
    #print("ah",s[k:n])
    ans+=int(s[k:n])
print(ans)

Measured memory_bytes: 39280
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int len,n;
int x[MAXN];


int a[MAXN];
int b[MAXN];

ll asum[MAXN+1],axsum[MAXN+1];
ll bsum[MAXN+1],bxsum[MAXN+1];


ll calc(int *z,ll *zsum,ll *zxsum,int cnt,int lim) {
	ll ret=0;
	// 2*(cnt-1-j)<=lim -> j>=cnt-1-lim/2
	int upto=max(0,cnt-1-lim/2);
	ret+=zsum[upto]*lim;
	ret-=zsum[upto]*2*(cnt-1)-zxsum[upto]*2;
	ret+=zsum[cnt]*2*(cnt-1)-zxsum[cnt]*2;
	return ret;
}

ll solve1dir() { // last is on the right
	//printf("a:"); REP(i,n) printf(" %d",a[i]); puts("");
	//printf("b:"); REP(i,n) printf(" %d",b[i]); puts("");
	asum[0]=0; REP(i,n) asum[i+1]=asum[i]+a[i];
	bsum[0]=0; REP(i,n) bsum[i+1]=bsum[i]+b[i];
	axsum[0]=0; REP(i,n) axsum[i+1]=axsum[i]+(ll)i*a[i];
	bxsum[0]=0; REP(i,n) bxsum[i+1]=bxsum[i]+(ll)i*b[i];

	ll ret=LLONG_MIN;
	REP(i,n) {
		int na=i+1,nb=n-na;
		// last on a side gets 1, one before 3, one before 6, etc. up to 2*min(na,nb)-1
		// last on b side gets 2, one before 4, one before 6, etc. up to 2*min(na,nb)
		ll cur=0; int alim=na>nb?2*nb+1:2*na+1,blim=2*min(na,nb);
		cur+=asum[na];
		cur+=calc(a,asum,axsum,na,alim-1);
		cur+=2*bsum[nb];
		if(nb>0) cur+=calc(b,bsum,bxsum,nb,blim-2);
		//REP(j,na) cur+=(ll)a[na-1-j]*min(2*j+1,alim);
		//REP(j,nb) cur+=(ll)b[nb-1-j]*min(2*j+2,blim);
		ret=max(ret,cur);
		//printf("na=%d nb=%d -> %lld (alim=%d,blim=%d)\n",na,nb,cur,alim,blim);
	}

	return ret;
}

ll solve() {
	REP(i,n) a[i]=x[i]; for(int i=n-1;i>=1;--i) a[i]-=a[i-1];
	REP(i,n) b[i]=len-x[n-i-1]; for(int i=n-1;i>=1;--i) b[i]-=b[i-1];
	ll opt1=solve1dir();
	REP(i,n) swap(a[i],b[i]);
	ll opt2=solve1dir();
	return max(opt1,opt2);
}

void run() {
	scanf("%d%d",&len,&n);
	REP(i,n) scanf("%d",&x[i]);
	printf("%lld\n",solve());
}

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


Measured memory_bytes: 8832
a = int(input())
b = int(input())
c = int(input())
x = int(input())

comb = []
count = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
                comb.append([i, j, k])
for i in range(len(comb)):
    if (x == 500*comb[i][0] + 100*comb[i][1] + 50*comb[i][2]) and \
        (a >= comb[i][0]) and (b >= comb[i][1]) and (c >= comb[i][2]):
        count += 1

print(count)


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



int n, k;
vector<double> a;

bool c(double m){
  int cnt = 0;
  for(int i=0; i<n; i++){
    cnt = cnt + (int)(a[i]/m);
    if(m*(int)(a[i]/m) == a[i]){
      cnt--;
    }
  }
  return cnt > k;
}

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

  if(k == 0){
    int ans = 0;
    for(int i=0; i<n; i++)
      ans = max(ans, (int)a[i]);
    cout << ans << endl;
    return 0;
  }

  double s = 0, t = 1000000002;
  for(int i=0; i<1000; i++){
    double mid = (s + t) / 2.0;

    if(c(mid))  s = mid;
    else  t = mid;
  }

  int ans = (int)(s);
  if(s-(double)(int)s)ans++;

  cout << ans << endl;

  return 0;
}


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

int main(){

  int N; cin >> N;

  int count = 0;
  for(int i=0; i<=N; i++){
    if(i<10)
      count++;
    if(i>=100 && i<1000)
      count++;
    if(i>=10000 && i <100000)
      count++;
  }
  cout << count-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
char str[100005];
int num[5];
int main()
{
    scanf("%s", str);
    int len = strlen(str);
    memset(num, 0, sizeof(num));
    FOR(i,0,len-1)
    {
        if(str[i] == 'a')num[0]++;
        if(str[i] == 'b')num[1]++;
        if(str[i] == 'c')num[2]++;
    }
    int mins = min(num[0], min(num[1], num[2]));
    num[0] -= mins;
    num[1] -= mins;
    num[2] -= mins;
    bool ok = true;
    FOR(i,0,2)
    if(num[i] >= 2)ok = false;
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 384
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n;
	cin>>n;
	vector<int>a(n);

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

	int Max=0,sum=0;

	for(i=0;i<n;i++)
	{
		if(a[i]>Max)
		{
			Max=a[i];
		}
		sum+=(Max-a[i]);
	}

	cout<<sum<<endl;

}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    if(s[s.size()-1] != 's'){
        cout << s << 's' << endl;
    }else{
        cout << s << "es" << endl;
    }
    
    
    
    
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using Graph = struct graph {
    vector<vector<int>> to;
    vector<vector<int>> cost;
    graph(int n) : to(n), cost(n) {}
};

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define debug(x) cerr << "[DEBUG] " << #x << ": " << x << '\n';

// vector<int> color(1e5, -1);
vector<int> color;
bool dfs(const Graph &G) {
    queue<int> q;

    color[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();

        // 該当する頂点の間のコストを取り出す
        rep(i, G.to[v].size()) {
            int u = G.to[v][i];
            int w = G.cost[v][i];

            // 訪問済みであればスキップ
            if (color[u] != -1) continue; 
            
            // 距離の偶奇を判定してその頂点をqueueに入れる
            color[u] = (color[v] + w) % 2;
            q.push(u);
        }
    }

    return true;
}

int main() {
    // 頂点数と辺数
    int N; cin >> N;

    // グラフ入力受取
    Graph G(N);
    rep(i, N - 1) {
        int a, b, w;
        cin >> a >> b >> w;
        a--, b--;

        // toに隣接している頂点入力
        G.to[a].push_back(b);
        G.to[b].push_back(a);

        // costを入力
        G.cost[a].push_back(w);
        G.cost[b].push_back(w);
    }

    // 探索
    color.assign(N, -1);
    dfs(G);

    // 解答の出力
    rep(i, N) cout << color[i] << "\n";
}

Measured memory_bytes: 14540