akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  string S;
  cin >> S;

  if(S=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
  }else if(S.size()==26){
    char y;
    for(int i=S.size()-1;i>0;i--){
      if(S.at(i) > S.at(i-1)){
        y=S.at(i-1);
        S=S.substr(0,i-1);
        break;
      }
    }
    int A[26]={0};
    REP(i,S.size()){
      A[S.at(i)-'a']++;
    }

    FOR(i,y-'a'+1,26){
      if(A[i]==0){
        char x = i+'a';
        cout << S+x << endl;
        break;
      }
    }
  }else{
    int A[26]={0};
    REP(i,S.size()){
      A[S.at(i)-'a']++;
    }

    REP(i,26){
      if(A[i]==0){
        char x = i+'a';
        cout << S+x << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10001;
vector < int > edge[maxn];
int c[maxn], ans, degree[maxn], cval[maxn];
int n;
int togo[maxn];
void solve(){
	int j = 0;
	for(int i = 1;i <= n;++i)
		if(degree[i] == 1)togo[j++] = i;
	for(int i = 0;i < j;++i){
		cval[togo[i]] = c[i];
		ans += c[i] * degree[togo[i]];
		for(auto &e : edge[togo[i]]){
			if(--degree[e] == 1)togo[j++] = e;
		}
	}
}
int main(){
	cin >> n;
	for(int i = 1, a, b;i < n;++i){
		cin >> a >> b;
		++degree[a];
		++degree[b];
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	for(int i = 0;i < n;++i)cin >> c[i];
	sort(c, c + n);
	solve();
	cout << ans << '\n';
	for(int i = 1;i <= n;++i)cout << cval[i] << ' ';
}


Measured memory_bytes: 1024
fn factor(mut x: usize) -> Vec<usize> {
    let mut div = 2;
    let mut results = vec![];
    while x > 0 {
        while x % div == 0 {
            results.push(div);
            x /= div;
        }
        div += 1;
        if div * div > x {
            break;
        }
    }
    if x != 1 {
        results.push(x);
    }
    results
}

fn ok(x: usize, k: usize, a: &[usize]) -> bool {
    let mut b = vec![];
    for &v in a.iter() {
        b.push(v % x);
    }
    b.sort();
    let n = b.len();
    let mut left = vec![0; n + 1];
    for i in 0..n {
        left[i + 1] = left[i] + b[i];
    }
    let mut right = vec![0; n + 1];
    for i in (0..n).rev() {
        right[i] = x - b[i] + right[i + 1];
    }

    // println!("{} {:?} {:?} {:?}", x, left, right, b);
    for i in 0..n + 1 {
        if std::cmp::max(left[i], right[i]) <= k {
            return true;
        }
    }

    false
}

fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut a: Vec<usize> = sc.vec(n);
    a.sort();
    let result = a.iter().fold(0, |sum, a| sum + a);
    let factors = factor(result);

    // println!("{:?}", factors);
    let mut result = 1;
    for bit in 0..(1usize << factors.len()) {
        let mut value = 1;
        for i in 0..factors.len() {
            if (bit >> i) & 1 != 0 {
                value *= factors[i];
            }
        }
        if ok(value, k, &a) {
            result = std::cmp::max(result, value);
        }
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main()
{
	long long int i=1, j, count=0, n;
	cin >> n;
	j=(n-i)/i;
	while(i<j)
	{
		//cout << i << " " << j << endl;
		if((n-i)%j==0)
			count+=j;
		i+=1;
		j=(n-i)/i;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#-------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------

from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[j - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] =  j
    return pi

def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else '0' * (length - len(y)) + y



def solve(n, x, t):
    a = x
    ans = t
    for i in range(1, 10000):
        if (a >= n):
            return ans
        else:
            a += x
            ans += t
    return 0


n, x, t = map(int, input().split())
print(solve(n, x, t))


Measured memory_bytes: 63108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int r, g;
    cin >> r >> g;
    cout << 2 * g - r << endl;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    int res = 0;
    vector<int> a(m), b(m), c(m);
    vector<vector<int> > g(n, vector<int>(n, Inf));
    rep (i, n) g[i][i] = 0;
    rep (i, m) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i], --b[i];
        g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
    }
    rep (k, n) rep (i, n) rep (j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    rep (i, m) {
        if (g[a[i]][b[i]] < c[i]) res++;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int d,s,t,x;
    scanf("%d%d%d",&d,&s,&t);
    x=t*s;
    if(x>=d)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


Measured memory_bytes: 1604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using point = complex<double>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    int m1;
    cin >> m1;
    vector<point> p1(m1);
    double x, y;
    rep(i, m1) {
      cin >> x >> y;
      p1[i] = point(x, y);
    }
    for (int i = m1-1; i >= 0; i--)
      p1[i] -= p1[0];
    rep(i, n) {
      int m2;
      cin >> m2;
      vector<point> p2(m2);
      rep(j, m2) {
        cin >> x >> y;
        p2[j] = point(x, y);
      }
      if (m1 != m2)
        continue;
      bool same = false;
      rep(i, 2) {
        for (int j = m2-1; j >= 0; j--)
          p2[j] -= p2[0];
        rep(j, 4) {
          bool flag = true;
          rep(k, m2) {
            if (p2[k] != p1[k]) {
              flag = false;
              break;
            }
          }
          if (flag)
            same = true;
          rep(k, m2)
            p2[k] *= point(0, 1);
        }
        reverse(p2.begin(), p2.end());
      }
      if (same)
        cout << i+1 << '\n';
    }
    cout << "+++++" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[105],n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int sum=1;
	int maxv=a[1];
	for(int i=2;i<=n;i++){
		if(a[i]>=maxv){
			sum++;
			maxv=a[i];
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc145/tasks/abc145_d

X, Y = list(map(int, input().split()))
MOD = int(1e9 + 7)

def combination(n, r, mod=MOD):
    def modinv(a, mod=MOD):
        return pow(a, mod-2, mod)
    # nCr with MOD
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# 1回の移動で3増えるので，X+Yは3の倍数 (0, 0) start
if (X + Y) % 3 != 0:
    ans = 0
    print(0)
else:
    # X+Yは3の倍数
    # (+1, +2)をn回，(+2, +1)をm回実行
    # n + 2m = X
    # 2n + m = Y
    # 3 m = 2 X - Y
    # m = (2 X - Y) // 3
    # n = X - 2 * m
    
    m = (2 * X - Y) // 3
    n = X - 2 * m

    if m < 0 or n < 0:
        print(0)
    else:
        print(combination(m + n, m, MOD))


Measured memory_bytes: 72704
// コード長666Byte, 実行時間30ms, メモリ896KB
// 余分な配列を使わないように、場合分けではみ出た部分を参照しないようにしたもの。
#include <stdio.h>

int main()
{
  int i, j, k, n, d;
  scanf("%d %d", &n, &k);
  
  int h[n];
  int cost[n-1];
  for (i=0; i<n; i++)  scanf("%d", &h[i]);
  
  cost[n-2] = h[n-2] - h[n-1];
  if (cost[n-2] < 0)  cost[n-2] = -cost[n-2];
  for (i=n-3; i>=0; i--) {
    d = h[i]-h[i+1];
    if (d<0)  d = -d;
    cost[i] = d + cost[i+1];
    
    for (j=2; j<=k && i+j<n; j++) {
      d = h[i] - h[i+j];
      if (d < 0) d = -d;
      if (i+j >= n-1) {
	if (cost[i] > d)
	  cost[i] = d;
      } else {
	if (cost[i] > d + cost[i+j])
	  cost[i] = d + cost[i+j];
      }
    }
  }
  printf("%d\n", cost[0]);

  return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int N,K;
ll dp[50][50][101];
ll VS[50];

void init() {
  REP(i,50)REP(j,50)REP(k,101) dp[i][j][k] = -1;
  REP(i,N) cin>>VS[i];
}

ll dfs(int l, int r, int k, priority_queue<ll> owns, ll total) {
  if (dp[l][r][k]!=-1) return dp[l][r][k];

  if (k==0) {
    dp[l][r][k] = total;
    return total;
  }

  ll res = total;

  if (l<r) {
    priority_queue<ll> owns1(owns);
    priority_queue<ll> owns2(owns);
    owns1.push(-VS[l]);
    owns2.push(-VS[r]);
    res = max(res, dfs(l+1,r,k-1,owns1,total+VS[l]));
    res = max(res, dfs(l,r-1,k-1,owns2,total+VS[r]));
  } else if (l==r && l==0) {
    priority_queue<ll> owns1(owns);
    owns1.push(-VS[l]);
    res = max(res, dfs(l+1,r,k-1,owns1,total+VS[l]));
  } else if (l==r && l==N-1) {
    priority_queue<ll> owns1(owns);
    owns1.push(-VS[r]);
    res = max(res, dfs(l,r-1,k-1,owns1,total+VS[r]));
  }

  // ownsはマイナスで保存してある
  if (!owns.empty()) {
    ll o = owns.top();owns.pop();
    res = max(res, dfs(l,r,k-1,owns,total+o));
  }


  dp[l][r][k] = res;
  return res;
}

int main() {
  cin>>N>>K;
  init();

  // DFSxDP
  // 行動の選択肢は右・左からとるか石を返すか何もしないか
  // それらのmaxを取ってDFS
  // dp[l][r][k]：l~rの範囲でk回行動できる時の最大価値
  priority_queue<ll> owns;
  OUT(dfs(0,N-1,K,owns,0));

  return 0;
}

Measured memory_bytes: 2304
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();
		long a = 0;
		long b = 0;
		long ans = Long.MAX_VALUE;
		for(int i = 1; i <= Math.sqrt(n); i++) {
			if(n%i == 0) {
				a = i;
				b = n/i;
				ans = Math.min(ans, b+a-2);
				}
			}
		System.out.println(ans);

		}
	}

Measured memory_bytes: 23764
L, R = map(int, input().split())
a = 0
b = 2019
if R - L >= 2018:
    b = 0
else:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            a = i * j % 2019
            if a <= b:
                b = a

print(b)


Measured memory_bytes: 2940
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int N = Integer.parseInt(s[0]);
    long W = Long.parseLong(s[1]);
    long[] weight = new long[N];
    int[] value = new int[N];
    
    long max_w = 0;
    int max_v = 0;
    for(int i = 0; i < N; i++){
      String[] t = sc.nextLine().split(" ");
      weight[i] = Long.parseLong(t[0]);
      value[i] = Integer.parseInt(t[1]);
      max_w = Math.max(max_w, weight[i]);
      max_v = Math.max(max_v, value[i]);
    }
    
    int M = max_v * N;
    long MM = max_w * N;
    long[][] result = new long[N+1][M+1];
    for(long[] arr : result){
      Arrays.fill(arr, MM);
    }
    result[0][0] = 0;
    for(int i = 0; i <= N; i++){
      for(int j = 0; j <= M; j++){
        if(i == 0){
        }else if(j - value[i-1] >= 0){
          result[i][j] = Math.min(result[i-1][j], weight[i-1]+result[i-1][j - value[i-1]]);
        }else{
          result[i][j] = result[i-1][j];
        }
      }
    }
    for(int i = M; i >= 0; i--){
      if(result[N][i] <= W){
        System.out.println(i);
        break;
      }
    }
  }
}

Measured memory_bytes: 129748
#include <stdio.h>
int main(void){
	int arr[5], final=10,index,soma=0;
	for(int i=0;i<5;i++){
		scanf("%d", &arr[i]);
		if(arr[i]%10<final && arr[i]%10!=0){
			final = arr[i]%10;
			index=i;
		}
	}
	final = arr[index];
	arr[index]=0;
	for(int j=0;j<5;j++){
		if(arr[j]%10!=0)soma+=arr[j]+10-(arr[j]%10);
		else soma+=arr[j];
	}
	soma+=final;
	printf("%d\n",soma);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  string s; cin >> s;
  if(s[0] == s[2]) cout << "Yes\n";
  else cout << "No\n";
  return;
}

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


Measured memory_bytes: 256
n = int(input())
robot = []
for i in range(n):
    x, l = map(int,input().split())
    robot.append([x + l, x - l]) #left, right
robot.sort()
preright = robot[0][1]
ans = 0
for i in range(n):
    left = robot[i][1]
    #print(preright, left)
    if preright <= left:
        ans += 1
        preright = robot[i][0]
print(ans)


Measured memory_bytes: 20148
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
const ll N = 104; 
ll a[N],dp[N][100005];

int32_t main(){
    IOS;
    ll i,j,k,n,m,p,q;
    cin >> n >> k;
    fori2(n) cin >> a[i];
    for(j = 0 ;j <= a[1] ; j++) dp[1][j] = 1;
    for(i = 1 ; i <= k ; i++ ) {
        dp[1][i] += dp[1][i-1];    
        dp[1][i] %= md;
    }
    for(i = 2 ; i <= n ; i++){
        dp[i][0] = 1;
        for(j = 1 ; j <= k ; j++){
            ll l = j - min(a[i],j);
            ll r = j;
            ll sum  = dp[i-1][r];
            if(l>0) sum -= dp[i-1][l-1];
            dp[i][j] += sum;
            dp[i][j] %= md;    
            dp[i][j] += dp[i][j-1];
            dp[i][j] %= md;
        }
    }    
    cout << (dp[n][k] - dp[n][k-1]+md)%md <<"\n";
} 

Measured memory_bytes: 79360
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int N, K;
  cin >> N >> K;
  int cnt = 0;
  rep(i, N){
    if(i==0){
      cnt = K;
    }
    else{
      cnt *= K-1;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  int n = in;

  auto a = in.Array(n);
  sort(all(a));
  reverse(all(a));

  ll x = 0;
  ll y = 0;
  rep(i, n - 1)if (a[i] == a[i + 1]) {
    if (x == 0) {
      x = a[i];
    }
    else {
      y = a[i];
      break;
    }
    i++;
  }
  cout << (x*y) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 100005
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
int n;
vector <P> adj[maxn];
int c[maxn];
void dfs(int u,int cc,int f){
  c[u] = cc;
  for(int i = 0;i < (int)adj[u].size();i++){
    int v = adj[u][i].first, w = adj[u][i].second;
    if(v == f) continue;
    dfs(v,cc ^ (w & 1),u);
  }
}
int main(){
  n = getint();
  for(int i = 1;i < n;i++){
    int u = getint(), v = getint(), w = getint();
    adj[u].push_back(mp(v,w));
    adj[v].push_back(mp(u,w));
  }
  dfs(1,0,-1);
  for(int i = 1;i <= n;i++){
    printf("%d\n",c[i]);
  }
  return 0;
}


Measured memory_bytes: 9984
# -*- coding: utf-8 -*-
S = input()
revS = S[::-1]
addStrings = ['dream', 'dreamer', 'erase', 'eraser']

T = ""
counter = 0
while True:
    existFlg = False
    for i in range(4):
        if revS[counter:counter + len(addStrings[i])] == addStrings[i][::-1]:
            existFlg = True
            T = T + addStrings[i][::-1]
            counter += len(addStrings[i])
            
    if not existFlg:
        break

if revS == T:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

using namespace std;

int main(){
    long long n, c, ans = 0;
    cin >> n >> c;
    vector<long long> p1(n + 2), p2(n + 2),x(n + 2), v(n + 2);
    for(int i = 1; i < n + 1; i++){
        cin >> x[i] >> v[i];
    }
    x[n + 1] = c; v[n + 1] = 0;
    for(int i = 1; i < n + 1; i++){
        p1[i] = p1[i - 1] + v[i] - (x[i] - x[i - 1]);
    }
    for(int i = 1; i < n + 1; i++){
        p1[i] = max(p1[i - 1], p1[i]);
    }
    for(int i = n; i >= 0; i--){
        p2[i] = p2[i + 1] + v[i] - (x[i + 1] - x[i]);
    }
    for(int i = n - 1; i >= 0; i--){
        p2[i] = max(p2[i], p2[i + 1]);
    }
    for(int i = 1; i < n + 1; i++){
        long long tmp = p1[i], tmp2 = p2[i + 1] - x[i];
        if(i < n && tmp2 > 0) tmp += tmp2;
        ans = max(ans, tmp);
    }
    for(int i = 1; i < n + 1; i++){
        long long tmp = p2[i], tmp2 = p1[i - 1] - (c - x[i]);
        if(i > 1 && tmp2 > 0) tmp += tmp2;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int a[105];

int main(){
int m,n,sum=0,k=0;
cin>>m>>n;
for(int i=0;i<m;i++){
    cin>>a[i];
    sum+=a[i];
}
for(int i=0;i<m;i++){
    if(a[i]>=1.0/4/n*sum)
        k++;
}
if(k>=n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A0168
kannon sama
*/
#include <stdio.h>
#include <math.h>

int dansu;

long long kannon(int dan)
{
  //printf("dan=%d\n",dan);
  if(dan == 1)
    return(1);
  if(dan == 2)
    return(2);
  if(dan == 3)
    return(4);
  return(kannon(dan-1)+kannon(dan-2)+kannon(dan-3));
}

main()
{
  while(EOF != scanf("%d",&dansu) && dansu)
    {
      printf("%d\n",(int)(ceil((double)kannon(dansu)/3650)));
    }

return(0);
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll a, b;
	cin >> a >> b;

	ll k = b / a, cnt = 1, ans = 0;
	while(cnt <= k){
		ans++;
		cnt *= 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int a,b,c,x;
scanf("%d %d %d",&a,&b,&c);
 if(a>b){
   x = b;
   b = a;
   a = x;
 }
 if(a>c){
   x = c;
   c = a;
   a = x;
 }
 if(b>c){
   x = c;
   c = b;
   b = x;
 }
   printf("%d %d %d\n", a, b, c); 
 return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
import sys
from itertools import product


def solve(N, M, X, C, A):
    L = list(product([True, False], repeat=N))
    mn = 100000000000
    for l in L:
        cst = 0
        rikai = [0 for _ in range(M)]
        for i in range(N):
            if l[i]:
                cst += C[i]
                for j in range(M):
                    rikai[j] += A[i][j]
        tf = True
        for j in range(M):
            if rikai[j] < X:
                tf = False
                break
        if tf:
            mn = min(mn, cst)
    if mn == 100000000000:
        print(-1)
    else:
        print(mn)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    C = [0 for _ in range(N)]
    A = [[0 for _ in range(M)] for _ in range(N)]
    for i in range(N):
        C[i] = int(next(tokens))
        for j in range(M):
            A[i][j] = int(next(tokens))
    solve(N, M, X, C, A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 74932
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y] 

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
      
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

n,m,k=map(int,input().split())
uf=UnionFind(n+1)
cnt=[0]*(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a,b)
  cnt[a]+=1
  cnt[b]+=1
for _ in range(k):
  c,d=map(int,input().split())
  if uf.is_same(c,d):
    cnt[c]+=1
    cnt[d]+=1
for i in range(1,n+1):
  print(uf.get_size(i)-cnt[i]-1,end=' ')

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair

using namespace std;

using uint=unsigned int;
using ll=long long;

uint xor128(){
	static uint d[]={1145141919,1919810893,810893364,364114514};
	uint t=d[0]^(d[0]<<11);
	REP(i,3)
		d[i]=d[i+1];
	return d[3]=d[3]^(d[3]>>19)^(t^(t>>8));
}

struct Node{
	Node *l,*r;
	uint pri;
	int s,v,mn;
} buf[200000];

using NP=Node*;

NP newNode(int v){
	static int c=0;
	buf[c]=Node{NULL,NULL,xor128(),1,v,v};
	return &buf[c++];
}

const int inf=1145141919;

inline int Mini(NP x){
	return x?x->mn:inf;
}

inline int Size(NP x){
	return x?x->s:0;
}

inline NP Update(NP x){
	x->s=Size(x->l)+Size(x->r)+1;
	x->mn=min({x->v,Mini(x->l),Mini(x->r)});
	return x;
}

inline NP LinkL(NP x,NP l){
	x->l=l;
	return Update(x);
}

inline NP LinkR(NP x,NP r){
	x->r=r;
	return Update(x);
}

inline NP CutL(NP x){
	x->l=NULL;
	return Update(x);
}

inline NP CutR(NP x){
	x->r=NULL;
	return Update(x);
}

inline NP Merge(NP a,NP b){
	if(!a)
		return b;
	else if(!b)
		return a;
	else if(a->pri>b->pri)
		return LinkR(a,Merge(a->r,b));
	else
		return LinkL(b,Merge(a,b->l));
}

using Res=Node;

inline Res Split(NP x,int k){
	if(k<=0)
		return Res{NULL,x};
	else if(x->s<=k)
		return Res{x,NULL};
	else if(k<=Size(x->l)){
		Res s=Split(x->l,k);
		return Res{s.l,Merge(s.r,CutL(x))};
	}else{
		Res s=Split(x->r,k-Size(x->l)-1);
		return Res{Merge(CutR(x),s.l),s.r};
	}
}

inline void Set(NP x,int k,int v){
	int ls=Size(x->l);
	if(k<ls)
		Set(x->l,k,v);
	else if(k==ls)
		x->v=v;
	else
		Set(x->r,k-ls-1,v);
	Update(x);
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

NP t[200000];

int main(){
	int n=read(),q=read();
	REP(i,n)
		t[i]=newNode(read());
	while(n>1){
		int k=n/2;
		REP(i,k)
			t[i]=Merge(t[i*2],t[i*2+1]);
		if(k*2<n)
			t[k]=t[k*2];
		n=(n+1)/2;
	}
	NP root=t[0];
	REP(_,q){
		int x=read(),y=read(),z=read();
		if(x==0){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y-1);
			Res s3=Split(s2.r,1);
			root=Merge(Merge(s1.l,s3.l),Merge(s2.l,s3.r));
		}else if(x==1){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y);
			printf("%d\n",Mini(s2.l));
			root=Merge(s1.l,Merge(s2.l,s2.r));
		}else if(x==2){
			Set(root,y,z);
		}
	}
}

Measured memory_bytes: 11044
m,d = map(int, input().split())

count = 0
for i in range(1, m+1):
  for j in range(1, d+1):
    d_1 = j % 10
    if d_1 >= 2:
      d_10 = int(j/10)
      if d_10 >= 2:
        if i == d_1 * d_10 :
          count += 1
print(count)


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

int main(void) {
    int n, y;
    cin >> n >> y;

    int bill_10000 = -1, bill_5000 = -1, bill_1000 = -1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n-i; j++) {
            int k = n - i - j;
            if ((i+j+k == n) && (10000*i + 5000*j + 1000*k == y)) {
                bill_10000 = i;
                bill_5000 = j;
                bill_1000 = k;
                break;
            }
        }
    }

    cout << bill_10000 << ' ' << bill_5000 << ' ' << bill_1000 << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, M, l, r, cnt int
	fmt.Scan(&N, &M)
	lmax := 0
	rmin := math.MaxInt64
	for i := 0; i < M; i++ {
		fmt.Scan(&l, &r)
		lmax = max(lmax, l)
		rmin = min(rmin, r)
	}
	cnt = rmin - lmax
	if cnt >= 0 {
		cnt++
	} else {
		cnt = 0
	}
	fmt.Println(cnt)
}

func min(a, b int) int {
	if b < a {
		return b
	}
	return a
}

func max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


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

int arr[100005];
int INF=(1<<31);
int dp[100005];
bool vis[100005];
int n,k;
int rec(int pos)
{
    if(pos<0)return 100005;
    if(pos==0)return 0;
    if(pos==1)return abs(arr[1]-arr[0]);
    if(vis[pos])return dp[pos];
    vis[pos]=true;
    int rta=0;
    rta=rec(pos-1)+abs(arr[pos]-arr[pos-1]);
    for(int i=2;i<=k;i++){
      rta=min(rta,rec(pos-i)+abs(arr[pos]-arr[pos-i]));
    }
    dp[pos]=rta;
    return dp[pos];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=0; i<n; i++)cin>>arr[i];
    memset(vis,false,sizeof(vis));
    cout<<rec(n-1)<<"\n";

    return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	int m=sqrt(n);
	for(int i=m;i>=0;i-- )
	{
		if(i*i<=n)
		{
			cout<<(i*i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

            // リーダーが一番左の場合
            int ans = 0;
            for (int i = 1; i < n; i++) {
                if (s.charAt(i) == 'E') {
                    ans++;
                }
            }
            int prev = ans;
//            System.out.println("prev: " + prev);

            // リーダーが左から2番目〜一番右の場合
            // リーダーが自分の左隣だったときの値(prev)より値を算出する
            for (int i = 1; i < n; i++) {
                if (s.charAt(i - 1) == 'W') {
                    prev++;
                }
                if (s.charAt(i) == 'E') {
                    prev--;
                }
                // update ans
                if (prev < ans) {
                    ans = prev;
                }
//                System.out.println("prev: " + prev);
            }

//            System.out.println("---");
            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 30536
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vs grid(h);
    rep(i, h) cin >> grid[i];
    rep(i, h) rep(j, w) {
        if (grid[i][j] == '#') {
            bool flag = false;
            rep(k, 4) {
                int ni = i + dy[k], nj = j + dx[k];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (grid[ni][nj] == '#') {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(a));i>=((int)(b));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int n; cin >> n;
	vector<lli> a(n), s(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	
	s[0] = a[0];
	rep(i, n-1) s[i+1] = s[i] + a[i+1];

	int ans = 1;
	ireg(i, n-1, 1){
		if(a[i] <= s[i-1]*2) ans++;
		else break;
	}

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

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  int sum=0,t;
  rep(i,n+10){
    if(sum>=n) break;
    sum+=i; t=i;
  }
  rrep(i,t+1){
    if(n&&n>=i){
      cout<<i<<endl;
      n-=i;
    }
  }
  return 0;
}


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

int main() {
  int n,mn=1e9+1,mx=0;
  cin>>n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin>>a;
    mn=min(mn,a);
    mx=max(mx,a);
  }
  cout<<mx-mn<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
int k;
vector<int> mp(10);
bool valid(int n) {
	while (n) {
		int tmp = n % 10;
		for (int i = 0; i < k; ++i)
			if (mp[i] == tmp)
				return false;
		n /= 10;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n >> k;

	for (int i = 0, x; i < k; ++i)
		cin >> mp[i];
	for (int i = n;; ++i)
		if (valid(i))
			return cout << i, 0;

}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a);

        a = (a * a); 
        b >>= 1;
    }
    return res;
}

#define N 200010
#define MOD 1000000007

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


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;

    int f[n + 1] = {};

    for (int i = 1; i < 100; ++i)
    {
        for (int j = 1; j < 100; ++j)
        {
            for (int k = 1; k < 100; ++k)
            {
                int val = i * i + j * j + k * k + i * j + j * k + k * i;
                if ( val <= n )
                {

                    // cout << i << " " << j << " " << k << " " << val << "\n";
                    f[val]++;
                }
            }
        }
    }

    for (int i = 0; i < n; ++i)
    {
        cout << f[i + 1] << "\n";
    }
    cout << endl;
    return 0;
}


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

int main() {
  ll N; cin >> N;
  vector<char>A(N);
  rep(i,N){
    cin >> A[i];
  }
  ll R1 = 0, R2 = 0;
  rep(i,N){
    if(A[i] == 'R'){
      R1++;
    }
  }
  rep(i,R1){
    if(A[i] == 'W'){
      R2++;
    }
  }
  cout << R2;
}
  

Measured memory_bytes: 3564
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;

void main() {
  auto N = readln.chomp.to!ulong;
  ulong sum = 0;

  for(ulong i=0; i<N; i++) {
    sum += i;
  }

  writeln(sum);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<int> > v(n+1);
    rep(i,m) {
        int c, d;
        scanf("%d %d", &c, &d);
        v[c].push_back(d);
        v[d].push_back(c);
    }
    bool ans=false;
    for (auto x: v[n]) {
        for(auto y:v[x]) if(y==1) ans=true;
    }
    if(!ans) printf("IMPOSSIBLE\n");
    else printf("POSSIBLE\n");
}


Measured memory_bytes: 12016
import sys
readline = sys.stdin.buffer.readline

s = readline().rstrip().decode('utf-8')

n = len(s)

tf = True if s[0]==s[-1] else False

if n%2==0:
    if tf:
        print("First")
    else:
        print("Second")
else:
    if not tf:
        print("First")
    else:
        print("Second")

Measured memory_bytes: 39280
using namespace std;
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr
 
#define DEBUG_ // 提出時はコメントアウト
#ifdef DEBUG_
#define DEB
#else
// DEB と打つとデバッグ時以外はコメントアウトになる
#define DEB /##/
#endif
 
// 変数ダンプ用マクロ。デバッグ時以外は消滅する
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DEB DUMPOUT<<"  "; \
DUMPOUT<<#__VA_ARGS__; \
DUMPOUT<<":=> "; \
dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
 
// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
 
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/
#define debug(x)                 cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define debug2(x, y)             cerr << __LINE__ << #x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define debug3(x, y, z)          cerr << __LINE__ << #x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug4(a, b, c, d)       cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define debug5(a, b, c, d, e)    cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define debug6(a, b, c, d, e, f) cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define db_2d(d,n,m) rep(i,n){rep(j,m){ cerr << (d)[i][j] << (((j)==(m-1))?"\n":" "); }}
#define db_1d(d,n) rep(i,n){cout << d[i] << (((i)==(n-1))?"\n":" ") << __LINE__}
#define INF 999999999
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n,a,b;
  cin>>n>>a>>b;

  int c = abs(b-a);

  if (!(c&1)) cout << "Alice" << endl;
  else  cout << "Borys" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N=2e5+10;
typedef long long LL;
int a[N];
int n;
LL sum;
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		if(a[i]<a[i-1])
		{
			sum+=LL(a[i-1]-a[i]);
			a[i]=a[i-1];
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 4408
{-# LANGUAGE ViewPatterns #-}

import qualified Data.Sequence as S
import Data.Sequence (Seq, (|>), ViewL((:<)))

type Process = (String, Int)
readProc :: IO Process
readProc = do
  [name, stime] <- fmap words getLine
  return (name, read stime)

process :: Int -> Seq Process -> Int -> IO ()
process rtt ps' e = case S.viewl ps' of
  S.EmptyL -> return ()
  ((n, t) :< ps) ->
    if (t > rtt) then
      process rtt (ps |> (n,t-rtt)) (e + rtt)
    else do
      putStrLn $ n ++ " " ++ show (e+t)
      process rtt ps (e+t)

main :: IO ()
main = do
  [n, rtt] <- fmap (map read . words) getLine
  procs <- S.replicateM n readProc
  process rtt procs 0

Measured memory_bytes: 23240
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	int H, W;
	int h, w;
	char c_tmp;
	int count;
	int ans = 0;
	queue<vector<int>> q_block;
	vector<int> block(2, 0);
	vector<int> tmp_block(2);
	vector<int> h_next = {1, 0, -1, 0};
	vector<int> w_next = {0, 1, 0, -1};
	cin >> H >> W;

	vector<vector<int>> meiz(H, vector<int>(W, 0));

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			cin >> c_tmp;
			if (c_tmp == '#')
				meiz[i][j] = -1;
			else
				ans++;
		}
	}

	meiz[0][0] = 1;
	q_block.push(block);

	for (; !q_block.empty();)
	{
		h = q_block.front()[0];
		w = q_block.front()[1];
		q_block.pop();
		count = meiz[h][w];
		if (h == H - 1 && w == W - 1)
		{
			cout << ans - count << endl;
			return;
		}
		for (int i = 0; i < 4; i++)
		{
			int check_h = h + h_next[i];
			int check_w = w + w_next[i];
			if (meiz[min(max(check_h, 0), H - 1)][min(max(check_w, 0), W - 1)] == 0)
			{
				meiz[check_h][check_w] = count + 1;
				block[0] = check_h;
				block[1] = check_w;
				q_block.push(block);
			}
		}
	}
	cout << "-1" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256