akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int keta(int a) {
	return to_string(a).size();
}
signed main() {
	int a;
	cin >> a;
	cout << a * a << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define MAX 1000000

int main(void) {
	int a[4], b[4];
	int hit, blow;
	int i, j;
	int mask[4];

	while (scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) != EOF) {
		scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
		hit = 0;
		blow = 0;
		j = 0;
		for (i = 0; i < 4; i++)
			mask[i] = 0;
		for (i = 0; i < 4; i++) {
			if (a[i] == b[i]) {
				hit++;
				mask[i] = 1;
				continue;
			}
			for (j = 0; j < 4; j++) {
				if (mask[j])
					continue;
				if (a[i] == b[j]) {
					blow++;
					mask[j] = 1;
				}
			}
		}
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

Measured memory_bytes: 0
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
M = 10**9+7

""" def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod """
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac

ans = 0
fac,ifac = make_tables(M,N)
for i in range(K-1,N):
    t = cmb(i,K-1,M,fac,ifac)
    ans += t*A[i]
A.sort(reverse=True)
for i in range(K-1,N):
    t = cmb(i,K-1,M,fac,ifac)
    ans -= t*A[i]
print(ans%M)


Measured memory_bytes: 20040
'use strict';

const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const iS = () => inputs.shift();
const sMpI = (str) => str.split(' ').map(v => parseInt(v, 10));
const sMpIS = () => sMpI(iS());
const pI = v => parseInt(v);

iS();

const resultTypes = ['AC', 'WA', 'TLE', 'RE'];
const results = { AC: 0, WA: 0, TLE: 0, RE: 0 };

for (const input of inputs) {
  ++results[input];
}

for (const resultType of resultTypes) {
  console.log(`${resultType} x ${results[resultType]}`)
}

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

using namespace std;


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

    int ans = 0;
    if (W % 2 == 0 && H % 2 == 0) {
        if (W / 2 == x && H / 2 == y) {
            ans = 1;
        }
    }

    double area = W / 2.0 * H;
    cout << setprecision(12) << area << " " << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	/*
	 * 表計算
	 *
	 * 表計算を行う簡単なプログラムを作成します。
	 *
	 * 表の行数rと列数c、r × c の要素を持つ表を読み込んで、各行と列の合計を挿入した新しい表を出力するプログラムを作成して下さい。
	 *
	 * Input 最初の行にrとcが空白区切りで与えられます。続くr行にそれぞれc個の整数が空白区切りで与えられます。
	 *
	 * Output (r+1) × (c+1)
	 * の新しい表を出力して下さい。各行の隣り合う整数は１つの空白で区切って下さい。各行の最後の列としてその行の合計値を
	 * 、各列の最後の行としてその列の合計値を、最後の行・列に表全体の合計値を挿入して下さい。
	 *
	 * Constraints 1 ? r, c ? 100
	 */
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] array = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				array[i][j] = sc.nextInt();
				array[i][c] += array[i][j];
				array[r][j] += array[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			array[r][c] += array[r][i];
		}

		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
				if (j >= 0 && j < array[i].length -1) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}

		sc.close();
	}
}

Measured memory_bytes: 39536
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;

using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {

	int N;
	cin >> N ;



	if (N<1200) {
		ce("ABC");
	}
	else if (N < 2800) {
		ce("ARC");
	}
	else {
		ce("AGC");
	}

}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]

all_list = [i for i in range(1, M+1)]
res_set = set()

for i in range(len(KA)):
    diff_set = set(all_list) ^ set(KA[i][1:])
    res_set = res_set | diff_set

print(M - len(res_set))


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

int main() {
    int N;
    cin >> N;
    vector<pair<int,int>> V(N);
    rep(i,N) {
        cin >> V[i].first >> V[i].second;
    }
    int count = 0;
    int max = 0;
    rep(j,N) {
        if (V[j].first == V[j].second) {
            count++;
        }
        else {
            count = 0;
        }
        if (count > max) {
            max = count;
        }
    }
    if (max >= 3) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e6 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cout << n * n << endl;
	return 0;
}

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

const int N = 1e5 + 7;

int n, l, a[N];

int main() {
	scanf("%d %d", &n, &l);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	bool flag = false;
	for (int i = 1; i < n; i++) {
		if (a[i] + a[i + 1] >= l) {
			flag = true;
			puts("Possible");
			for (int j = 1; j < i; j++) {
				printf("%d\n", j);
			}
			for (int j = n - 1; j > i; j--) {
				printf("%d\n", j);
			}
			printf("%d\n", i);
			return 0;
		}
	}
	if (flag == false) {
		puts("Impossible");
		return 0;
	}
	return 0;
}

Measured memory_bytes: 1280
/*
  Lower bound: first element that is greater-or-equal.
  int i=lower_bound(a,a+n,x)-a;
  Upper bound: first element that is strictly greater.
  #include<boost/multiprecision/cpp_int.hpp>
  namespace mp=boost::multiprecision;
  mp::cpp_int u=1; for(unsigned i=1;i<=n;i++) u*=i;
*/
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
const int WASTE=(int)2e5;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //#define int long long
    char c;
    int i=3;
    int ctr=0;
    while(i--){
    	cin>>c;
    	if(c=='1')
    		ctr++;
    }
    cout<<ctr;
	return 0;
}

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

int main() {
  int L,R;
  cin >> L >> R;
  int ans = 2019;
  int t1;
  int t2;
  int term;
  for (int i=L; i<min(R,L+2019);i++) {
    for (int j=i+1; j<min(R+1,i+2020);j++) {
      t1 = i%2019;
      t2 = j%2019;
      term = t1*t2%2019;
      ans = min(ans,term);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final String x = scanner.next();
        int s = 0;
        int t = 0;
        for (int i = 0; i < x.length(); i++) {
            final char c = x.charAt(i);
            if (c == 'S') {
                s++;
            } else if (s > 0) {
                t++;
                s--;
            }
        }
        System.out.println(x.length()-2*t);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

int main(){
    int n,mid=1;
    long long left=0,right=0,sum=0;
    cin>>n;
    long long arr[n];
    for (int i=0;i<n;i++) {
        cin >> arr[i];
        sum+=arr[i];
    }
    for (int i=0;i<n;i++) {
        left+=arr[i];
        if (left >= sum/2) {
            mid=i;
            break;
        }
    }
    left=0;
    for (int i=0;i<mid;i++){
        left+=arr[i];
    }
    for (int i=mid+1;i<n;i++){
        right+=arr[i];
    }
    if (left>=right) right+=arr[mid];
    else left+=arr[mid];
    cout<<abs(left-right);
}

Measured memory_bytes: 1792
#include <fstream>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXN = 1000;
const int MAXVAL = 5000;
const int INF = 1000000000;

vector<int> g[1 + MAXN];
int sum[1 + MAXN], limit = 0;
int dp[1 + MAXN], best[1 + MAXVAL], newBest[1 + MAXVAL];

void DFS(int node) {
    if (!g[node].size()) {
        dp[node] = 0;
        return;
    }
    for (auto &son : g[node])
        DFS(son);
    for (int i = 0; i <= MAXVAL; i++)
        best[i] = INF;
    for (auto &son : g[node]) {
        for (int i = 0; i <= MAXVAL; i++)
            newBest[i] = INF;
        if (son == g[node][0]) {
            if (dp[son] <= MAXVAL)
                newBest[dp[son]] = min(newBest[dp[son]], sum[son]);
            newBest[sum[son]] = min(newBest[sum[son]], dp[son]);
        }
        else {
            for (int i = MAXVAL; i >= sum[son]; i--)
                newBest[i] = min(newBest[i], best[i - sum[son]] + dp[son]);
            for (int i = MAXVAL; i >= dp[son]; i--)
                newBest[i] = min(newBest[i], best[i - dp[son]] + sum[son]);
        }
        for (int i = 0; i <= MAXVAL; i++)
            best[i] = newBest[i];
    }
    dp[node] = INF;
    for (int i = 0; i <= sum[node]; i++)
        dp[node] = min(dp[node], best[i]);
    if (dp[node] == INF) {
        printf("IMPOSSIBLE\n");
        exit(0);
    }
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        int x;
        scanf("%d", &x);
        g[x].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &sum[i]);
        limit = max(limit, sum[i]);
    }
    DFS(1);
    printf("POSSIBLE\n");
    return 0;
}


Measured memory_bytes: 384
require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b=gsmi

1.upto 2000 do |i|
  a1=(i*1.08).to_i-i
  b1=(i*1.1).to_i-i
  putsend i if a1==a && b1==b
end
puts -1

Measured memory_bytes: 2044
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define sz(x) int(x.size())
#define ll long long

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  s = s + s;
  vector<vector<int>> next(26);
  for (int i = 0; i < sz(s); i++) {
    next[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < sz(s); i++) {
    next[s[i] - 'a'].push_back(i + sz(s));
  }

  int p = 0;
  ll ans = 0;
  for (int i = 0; i < sz(t); i++) {
    int c = t[i] - 'a';
    if (sz(next[c]) == 0) {
      cout << -1 << endl;
      return 0;
    }
    p = *lower_bound(next[c].begin(), next[c].end(), p) + 1;
    if (p >= sz(s)) {
      p -= sz(s);
      ans += sz(s);
    }
  }
  ans += p;
  cout << ans << endl;
}


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

int main() {
    char a, b;
    std::cin >> a >> b;

    if (a == 'H') {
        if (b == 'H') {
            std::cout << "H\n"; 
        } else {
            std::cout << "D\n";
        }
    } else {
        if (b == 'H') {
            std::cout << "D\n";
        } else {
            std::cout << "H\n"; 
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
const Int INF = 1e17;
struct edge{
  Int w,u,v,to;
  edge(){}
  edge(Int w,Int u,Int v,Int to):w(w),u(u),v(v),to(to){}
  bool operator<(const edge &a)const{
    if(w!=a.w) return w<a.w;
    if(u!=a.u) return u<a.u;
    return v<a.v;
  }
};
struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(Int n):n(n),r(n,1),p(n){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    if(x==p[x]) return x;
    return p[x]=find(p[x]);
  }
  Int same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=p[x];
  }
};
struct LowLink{
  Int n,cnt;
  vector<vector<edge> > G;
  vector<Int> sum,used,pre,low,par;
  
  LowLink(Int n):n(n),cnt(0),G(n),sum(n),used(n),pre(n),low(n),par(n){}

  void add_edge(Int u,Int v,Int w){
    G[u].emplace_back(w,u,v,v);
    G[v].emplace_back(w,u,v,u);
  }

  void dfs(Int v,Int p,Int d=0){
    pre[v]=low[v]=d;
    used[v]=1;
    for(auto e:G[v]){
      Int u=e.to;
      if(!used[u]){
	par[u]=v;
	dfs(u,v,d+1);
	low[v]=min(low[v],low[u]);
	sum[v]+=sum[u]+e.w;
      }else if(u!=p){
	low[v]=min(low[v],pre[u]);
        sum[u]+=e.w;
      }      
    }
  }
};



signed main(){
  Int n;
  cin>>n;
  LowLink G(n);
  for(Int i=0;i<n;i++){
    Int u,v;
    cin>>u>>v;
    u--;v--;
    G.add_edge(u,v,0);
  }
  UnionFind uf(n);
  G.dfs(0,-1);

  using P = pair<Int, Int>;
  set<P> br;
  for(Int i=1;i<n;i++)
    if(G.low[i]==G.pre[i]) br.emplace(i,G.par[i]),br.emplace(G.par[i],i);
  
  for(Int v=0;v<n;v++){
    for(auto e:G.G[v]){
      Int u=e.to;
      if(!br.count(P(u,v))) uf.unite(u,v);
    }
  }
    
  Int q;
  cin>>q;
  for(Int i=0;i<q;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    if(uf.same(a,b)) cout<<2<<endl;
    else cout<<1<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 36284
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int a[10010];
set<int> s;

int main(){
    int n, q, op, ans = 0;
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &op);
        s.insert(op);
    }
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%d", &op);
        ans += s.count(op);
    }
    printf("%d\n", ans);
}



Measured memory_bytes: 7896
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 200005

int N,M;
int A[SIZE],B[SIZE];

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d",&A[i]);
	}
	sort(A,A+N);


	scanf("%d",&M);

	for(int i = 0; i < M; i++){

		scanf("%d",&B[i]);
	}
	sort(B,B+M);

	vector<int> C;

	set_intersection(A,A+N,B,B+M,inserter(C,end(C)));

	for(int i = 0; i < C.size(); i++){

		printf("%d\n",C[i]);
	}

	return 0;
}



Measured memory_bytes: 4952
#include <stdio.h>

int main(){
  int n,i,t;
  int tmax,tmin;
  long long int tsum;
  scanf("%d\n",&n);
  for(i=0,tsum=0,tmax=-1000000,tmin=1000000;i<n;i++){
    scanf("%d",&t);
    tsum += t;
    if(tmax<t)tmax=t;
    if(tmin>t)tmin=t;
  }
  printf("%d %d %lld\n",tmin,tmax,tsum);
  return 0;
}

Measured memory_bytes: 2740
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    int ans = 100;

    REP(i, N)
    {
        int A;
        int cnt = 0;
        cin >> A;
        while (A % 2 == 0)
        {
            A /= 2;
            cnt++;
        }
        ans = min(cnt, ans);
    }

    cout << ans << endl;

    return 0;
}


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

int sosuu(int i){
  if(i==1)return 0;
  else if(i==2)return 1;
  else if(i%2==0)return 0;
  for(int j=3;j*j<=i;j+=2){
    if(i%j==0)return 0;
  }
  return 1;
}

int main(){
  vector<int>::iterator p;
  vector<int> ve;
  int i=0,k,n;
  ve.clear();
  k=0;
  while(k<=50000){
    i++;
    if(sosuu(i)){
      k=i;
      ve.push_back(i);
    }
  }
  //for(int j=0;j<=100;j++)cout<<ve[i]<<endl;////////
  while(cin>>n){
    p=lower_bound(ve.begin(),ve.end(),n);
    if(*p==n)cout<<*(p-1)<<" "<<*(p+1)<<endl;
    else cout<<*(p-1)<<" "<<*p<<endl;
  }
return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc159/abc159_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  ll ans = 0;
  if (N >= 2) {
    ans += N * (N - 1) / 2;
  }
  if (M >= 2) {
    ans += M * (M - 1) / 2;
  }

  cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



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

    int x = n.size();

    if(n[x-1]=='3'){
        cout << "bon" << endl;
    }else if(n[x-1]=='0'||n[x-1]=='1'||n[x-1]=='6'||n[x-1]=='8'){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3600
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

l = list(map(int, input().split()))
l.sort()

dif = 2*l[2] - l[1] - l[0]
if dif%2==0:
    print(dif//2)
else:
    print((dif+3)//2)


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

int main()
{
	int a[3][3];
	for(size_t i = 0; i<3; i++)
	{
		for(size_t ii = 0; ii<3; ii++)
		{
			cin>>a[i][ii];
		}
	}
	int n;
	cin>>n;
	int b[100];
	for(size_t i = 0; i<n; i++)
	{
		cin>>b[i];
	}
	int c[3][3]{0};
	for(size_t i = 0; i<3; i++)
	{
		for(size_t ii = 0; ii<3; ii++)
		{
			for(size_t iii = 0; iii<n; iii++)
			{
				if(a[i][ii]==b[iii])
				{
					c[i][ii]=1;
				}
			}
		}
	}
	int ans = 0;
	if(c[0][0]==1&&c[0][1]==1&&c[0][2]==1)
		ans = 1;
	if(c[1][0]==1&&c[1][1]==1&&c[1][2]==1)
		ans = 1;
	if(c[2][0]==1&&c[2][1]==1&&c[2][2]==1)
		ans = 1;
	if(c[0][0]==1&&c[1][0]==1&&c[2][0]==1)
		ans = 1;
	if(c[0][1]==1&&c[1][1]==1&&c[1][2]==1)
		ans = 1;
	if(c[0][2]==1&&c[1][2]==1&&c[2][2]==1)
		ans = 1;
	if(c[0][0]==1&&c[1][1]==1&&c[2][2]==1)
		ans = 1;
	if(c[0][2]==1&&c[1][1]==1&&c[2][0]==1)
		ans = 1;
	if(ans==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll r, c, toori;
typedef pair<ll, ll> P;

ll a[11][11451];//kachi,kazu,b;
vector<vector<ll>> kekka(50001);
ll maxa = 0,moto=0;
//-------------------関数----------------------//


int main() {
	ll a, b, c; cin >> a >> b; c = a + b;
	if (a % 3 == 0 || b % 3 == 0 || c % 3 == 0) { cout << "Possible" << endl; }
	else { cout << "Impossible" << endl; }
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cstdio>
#include <vector>

int main()
{
    long long n;
    while (scanf("%lld", &n) == 1) {
        std::vector<int> digits;
        n ++;
        while (n) {
            digits.push_back(n % 10);
            n /= 10;
        }
        int result = 9 * ((int)digits.size() - 1);
        int sum = 0;
        for (int i = (int)digits.size() - 1; i >= 0; -- i) {
            if (digits[i]) {
                result = std::max(result, sum + digits[i] - 1 + 9 * i);
            }
            sum += digits[i];
        }
        printf("%d\n", result);
    }
}


Measured memory_bytes: 256
n,m = map(int,input().split())
aclist = [0]*(n+1)
walist = [0]*(n+1)
for i in range(m):
  p,s = input().split()
  if aclist[int(p)] == 0:
    if s == 'AC':
      aclist[int(p)] += 1
    else:
      walist[int(p)] += 1
for i in range(len(walist)):
  if aclist[i] == 0:
    walist[i] = 0
print(sum(aclist),sum(walist)) 


Measured memory_bytes: 45784
from collections import defaultdict
import bisect


S = input()
T = input()

if set(T) - set(S):
    print(-1)
    exit()

dic = defaultdict(list)
leng_dic = defaultdict(int)

for pos, s in enumerate(S):
    dic[s].append(pos)
    leng_dic[s] += 1

length = len(S)
now = -1
count = 0
for t in T:
    if dic[t][-1] < now+1:
        now = -1
        count += 1
    idx = bisect.bisect_left(dic[t], now+1)
    now = dic[t][idx]

ans = count*length + now + 1
print(ans)

Measured memory_bytes: 7924
#include <stdio.h>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long int ll;
constexpr int kN = int(3E3 + 10);

int val[kN][kN];
ll dp[kN][kN][4];

int main() {
	int r, c, k, x, y, v;
	ll ans = 0;
	scanf("%d%d%d", &r, &c, &k);
	for (int i = 1; i <= k; i++) {
		scanf("%d%d%d", &x, &y, &v);
		val[x][y] = v;
	}
	for (int i = 1; i <= r; i++) {
		for (int j = 1; j <= c; j++) {
			dp[i][j][0] = max({dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2], dp[i - 1][j][3], dp[i][j - 1][0]});
			dp[i][j][1] = max({dp[i][j][0] + val[i][j], dp[i][j - 1][0] + val[i][j], dp[i][j - 1][1]});
			dp[i][j][2] = max({dp[i][j - 1][1] + val[i][j], dp[i][j - 1][2]});
			dp[i][j][3] = max({dp[i][j - 1][2] + val[i][j], dp[i][j - 1][3]});
			ans = max({ans, dp[i][j][0], dp[i][j][1], dp[i][j][2], dp[i][j][3]});
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 319148
#include <bits/stdc++.h>
#define pii pair <int, int>

using namespace std;

const int N = 2005, M = 4005;
int n, a[N], edge[N][N], ans[N], root[N], sz[N], b[N], ed[N], fa[N];
bool vis[N];

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


void dfs(int x) {
    vis[x] = 1;
    sz[x] = 1;
    for (int xx = 1; xx <= n; xx++) {
        if (edge[x][xx] && !vis[xx]) {
            dfs(xx);
            sz[x] += sz[xx];
        }
    }
}

void solve(int x, int l, int r)
{
    priority_queue <pii> q;
    vis[x] = 1;
    int now = l;
    for (int xx = 1; xx <= n; xx++) {
        if (edge[x][xx] && !vis[xx]) {
            solve(xx, now + 1, now + sz[xx]);
            q.push(pii(ans[now + 1], now + 1));
            now += sz[xx];
        }
    }
    now = 0;
    while (!q.empty()) {
        pii xx = q.top();
        q.pop();
        b[++now] = xx.first;
        if (xx.second < ed[xx.second]) {
            q.push(pii(ans[xx.second + 1], xx.second + 1));
        }
    }
    ans[l] = a[x];
    ed[l] = r;
    for (int i = l + 1; i <= r; i++) {
        ans[i] = b[i - l];
        ed[i] = r;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (gcd(a[i], a[j]) > 1) {
                edge[i][j] = 1;
                edge[j][i] = 1;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            dfs(i);
            edge[0][i] = 1;
            edge[i][0] = 1;
        }
    }
    memset(vis, 0, sizeof(vis));
    solve(0, 0, n);
    for (int i = 1; i < n; i++) {
        cout << ans[i] << " ";
    }
    cout << ans[n] << endl;
    return 0;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    int dp[1001][1001];
    cin>>n;
    int i, j, k;
    int ans = 0;
    for(i=0; i<n; i++){
        string s, v;
        cin>>s>>v;
        int l = s.length();
        int m = v.length();
        for(j=0; j<1001; j++){
            for(k=0; k<1001; k++){
                dp[j][k] = 0;
            }
        }
        for(j=0; j<l; j++){
            for(k=0; k<m; k++){
                if(s[j] == v[k]){
                    dp[j+1][k+1] = dp[j][k]+1;
                }
                else{
                    dp[j+1][k+1] = max(dp[j][k+1], dp[j+1][k]);
                }
            }
        }
        cout<<dp[l][m]<<endl;

    }
    return 0;
}


Measured memory_bytes: 7124
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// ll mod=1000000007;
 
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,k,temp,temp2,n,m,x,y,sum=0;
    cin >> t;
    for(i=1;i<=t;i++){
        if(i%3!=0&&i%5!=0)
        sum+= i;
    }
    cout << sum;
}

Measured memory_bytes: 3652
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
 
let num=readInts()
let a=num[0]
let b=num[1]

if a>9||b>9{
  print(-1)
}else{
  print(a*b)
}

Measured memory_bytes: 8204
/* 
 * Project: AtCoder Beginners Contest 136 B - Uneven Numbers
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/09/08
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <string>
using namespace std;

int32_t n;

void solve() {

    uint32_t odd = 0;

    for (int i=1;i<=n;i++) {
        if (to_string(i).length()%2==1) {
            odd++;
        }
    }

    printf("%d\n", odd);

}

int main() {

    scanf("%d", &n);

    solve();

}


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

const long long int MOD = 1000000007;

int main() {

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

    long long int ans = 0;
    for ( long long int p = k; p <= n + 1; p++ ) {
        long long int mi = ( p - 1 + 0 ) * p / 2;
        long long int ma = ( n + ( n - p + 1 ) ) * p / 2;
        ans += ma - mi + 1;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3636
#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>;

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> cnt(M);
  for (int x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x) cnt[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if (cnt[x] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#if 1
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

#define int long long

int mod;
int n;

long long inq(int a, int b)
{
    if (!b) return 1;
    int l = inq(a, b / 2);
    if (b % 2) return l * l % mod * a % mod;
    return l * l % mod;
}

int sti2[4000][4000];
int st2[4000 * 4000];
int st2euler[4000];
int stst2[4000];
int res[4000];
int cnk[4000][4000];
int rev[4000];
int fact[4000];

signed main()
{
    //freopen("input_02.txt", "r", stdin);
    //freopen("output_02.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    cin >> n >> mod;
    //n = 3, mod = 1e9 + 7;
    st2[0] = 1, st2euler[0] = 1, rev[1] = 1, fact[0] = 1;
    for (int i = 2; i < 4000; i++) rev[i] = (mod - rev[mod % i] * (mod / i)) % mod;
    for (int i = 1; i < 4000 * 4000; i++) st2[i] = st2[i - 1] * 2 % mod;
    for (int i = 1; i < 4000; i++) st2euler[i] = st2euler[i - 1] * 2 % (mod - 1), fact[i] = fact[i - 1] * i % mod;
    for (int i = 0; i < 4000; i++) stst2[i] = inq(2, st2euler[i]);
    for (int i = 0; i < 4000; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (j == 0) sti2[i][j] = (i == 0);
            else sti2[i][j] = (sti2[i - 1][j - 1] + j * sti2[i - 1][j]) % mod;
            if (j) cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % mod;
            else cnk[i][j] = 1;
        }
    }
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            res[i] = (res[i] + (sti2[i][j + 1] * (j + 1) % mod + sti2[i][j]) * st2[j * (n - i)] % mod * stst2[n - i]) % mod;
            //cout << i << " " << j << " " << (sti2[i][j + 1] * (j + 1) + sti2[i][j]) * st2[j * (n - i)] % mod * stst2[n - i] % mod << endl;
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++)
    {
        //cout << res[i] << endl;
        if (i % 2 == 0)
            ans = (ans + cnk[n][i] * res[i]) % mod;
        else
            ans = (ans + mod * mod - cnk[n][i] * res[i]) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 373760
#include <iostream>
#include <vector>

using namespace std;

bool is_product_day(int m, int d){
	int d1 = d % 10;
	int d2 = d / 10;
	return d1 >= 2 && d2 >= 2 && m == d1 * d2;
}

int main()
{
	int m, d;
	cin >> m >> d;
	int counter = 0;
	for (int i = 1; i <= m; ++i){
		for (int j = 1; j <= d; ++j){
			if (is_product_day(i, j)) ++counter;
		}
	}
	cout << counter;
}

Measured memory_bytes: 256
program sample
    implicit none
    character(100)::s
    integer(8) :: i,j,n,a,b,c,d,ma,k,l
    integer(8),allocatable :: x(:),y(:),z1(:),z2(:),m(:)
  
    read(*,*) n,k
    allocate(x(n),y(n),z1(n),z2(n),m(n))
    read(*,*)x
    read(*,*)y
    if(k==1)then
        write(*,*)maxval(y)
        stop
    end if

    do i=1,n
        m(:)=-10**9
        
        a=i
        a=x(a)
        m(1)=y(a)
        do j=2,k
            a=x(a)
            m(j)=m(j-1)+y(a)
            if(j==k)then
                z1(i)=maxval(m)
                exit
            elseif(a==i)then
                if(m(j)>0)then
                    b=(k/j-1)*m(j)+maxval(m)
                    d=mod(k,j)
                    ma=-10**9
                    do l=1,d
                        if(m(l)>ma)then
                            ma=m(l)
                        end if
                    end do
                    c=(k/j)*m(j)+ma
                    z1(i)=max(b,c)
                else
                    z1(i)=maxval(m)
                endif
                exit
            end if
        end do
    end do
    write(*,*)maxval(z1)

    stop
end program sample
  



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;

int main()
{
	int n, m;
	cin >> n >> m;
	if (n <= 0 && m >= 0) OUT("Zero");
	if (n > 0) OUT("Positive");
	int ile = m - n + 1;
	if (ile % 2 == 0) OUT("Positive");
	cout << "Negative";
}


Measured memory_bytes: 256
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define sharingan cerr << "\n-------------------------------------------\n\n";
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define slow ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define set_bits(x) __builtin_popcount(x)
#define __gcd(a, b) __algo_gcd(a, b)
#define PI 3.14159265358979323846
#define mod 1000000007

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

#define int long long

int32_t main(){
    int n;
    cin >> n;
    int sum = 0;
    int ar[n];
    for( int i = 0; i < n; i++ ){
        cin >> ar[i];
    }
    int pre = ar[0];
    for( int i = 1; i < n; i++ ){
        if( ar[i] < pre )sum += abs(ar[i]-pre);
        pre = max(pre, ar[i]);
    }
    cout << sum;
}

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,y;
  cin >> a >> b >>c >> x >> y;
  if(a+b >= 2*c){
    int ans;
    if(x>y){
      ans = y * 2 * c + (x-y) * a;
      ans = min(ans, 2*x*c);   
    }else{
      ans = x * 2 * c + (y-x) * b;
      ans = min(ans, 2*y*c);   
    }
    cout << ans << endl;
  }else{
    cout << a*x + b*y << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<int> p(n),q(n);
    rep(i,n) cin>>p[i];
    rep(i,n) cin>>q[i];
    int a = 0; int b = 0;
    vector<int> x(n);
    for (int i = 1; i <= n; ++i) x[i-1] = i;
    int tmp = 0;
    do {
        tmp++;
        if (p==x) a = tmp;
        if (q==x) b = tmp;
    } while (next_permutation(x.begin(), x.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MOD = 1e9 + 7;

int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; }
int sub(int x, int y) { x -= y; if (x < 0) x += MOD; return x; }
int mul(int x, int y) { return 1ll * x * y % MOD; }

int pw(int a, int k) {
  int res = 1;
  while (k) {
    if (k % 2 == 1)
      res = mul(res, a);
    a = mul(a, a);
    k /= 2;
  }
  return res;
}

const int MAXN = 100 + 10;
int N;
int h[MAXN];
VI nums;

int dp[MAXN][MAXN];
int f(int x, int y) {
  if (dp[x][y] >= 0)
    return dp[x][y];
  assert(x >= 1 && y >= 0 && y <= h[x]);
  if (x == 1) {
    dp[x][y] = pw(2, nums[h[x]] - nums[y]);
    if (y > 0)
      dp[x][y] = mul(2, dp[x][y]);
    debug("dp[%d][%d(%d)] = %d\n", x, y, nums[y], dp[x][y]);
    return dp[x][y];
  }
  int t1 =  mul(f(x - 1, min(y, h[x - 1])), pw(2, max(0, min(nums[h[x]] - nums[y], nums[h[x]] - nums[h[x - 1]]))));
  int t2 =  mul(f(x - 1, min(h[x], h[x - 1])), pw(2, max(0, min(nums[h[x]] - nums[y], nums[h[x]] - nums[h[x - 1]]))));
  dp[x][y] = add(t1, t2);
  debug("dp[%d][%d(%d)] = %d\n", x, y, nums[y], dp[x][y]);
  return dp[x][y];
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> N;
  nums.PB(0);
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
    nums.PB(h[i]);
  }
  sort(ALL(nums));
  nums.resize(unique(ALL(nums)) - begin(nums));
  for (int i = 1; i <= N; i++)
    h[i] = lower_bound(ALL(nums), h[i]) - begin(nums);
  cout << f(N, 0) << endl;
  return 0;
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;

const int N = 1e5+1;
int n, k, F[N], h[N];

int main()
{
	FASTIO;
	cin >> n >> k;
	for (int i=1; i<=n; i++) cin>>h[i];
	h[0] = -1e8;
	for (int i=2; i<=n; i++) {
		int V = INT_MAX;
		for (int j=1; j<=k and i>j; j++) 
			V = min(V, F[i-j]+abs(h[i]-h[i-j]));
		F[i] = V;
	}
	cout << F[n];
	return 0;
}


Measured memory_bytes: 1024
A = str(input())
B = str(input())

A = list(A)
B = list(B)

AL = len(A)
BL = len(B)

b = []
for i in range(BL):
  b.append(A[i] + B[i])
if AL -BL == 1:
    # b.append(A[-1])
  b.append(A[-1])
print(",".join(b).replace(",", ""))

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      x += a[i];
    } else {
      y += a[i];
    }
  }
  cout << x - y << '\n';

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
	public static void main (String[] args) {
		Reader in = new Reader ();
		int n = in.nextInt();
		int [] d = new int [n + 5];
		int [] cnt = new int [n + 5];
		
		int diametre = 0;
		for(int i = 1; i <= n; i++) {
			d[i] = in.nextInt();
			cnt[d[i]] += 1;
			diametre = Math.max(diametre, d[i]);
		}
		boolean ans = true;
		if(diametre >= n) ans = false;
		if(diametre % 2 == 1) {
			int mid = (diametre >> 1) + 1;
			for(int i = mid; i <= diametre; i++) {
				if(cnt[i] > 1) {
					cnt[i] -= 2;
				} else {
					ans = false;
					break;
				}
			}
			for(int i = 0; i <= n; i++) {
				if(cnt[i] > 0) {
					if(i <= mid) ans = false;
				}
			}
		} else {
			int mid = diametre >> 1;
			for(int i = mid; i <= diametre; i++) {
				if(i == mid) {
					if(cnt[i] > 0) {
						cnt[i] -= 1;
					} else {
						ans = false;
						break;
					}
				} else {
					if(cnt[i] > 1) {
						cnt[i] -= 2;
					} else {
						ans = false;
						break;
					}
				}
			}
			for(int i = 0; i <= n; i++) {
				if(cnt[i] > 0) {
					if(i <= mid) ans = false;
				}
			} 
		}
		if(ans) System.out.println("Possible");
		else System.out.println("Impossible");
	}
	static class Reader {
		private BufferedReader a;
		private StringTokenizer b;
		Reader() {
			a = new BufferedReader (new InputStreamReader (System.in));
		} 
		public String next () {
			while(b == null || !b.hasMoreTokens()) {
				try {
					 b = new StringTokenizer (a.readLine());
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
			 return b.nextToken();
		}
		public int nextInt () {
		     return Integer.parseInt(next());
		}
		public long nextLong () {
			return Long.parseLong(next());
		}
		public double nextDouble () {
			return Double.parseDouble(next());
		}
		public String nextLine () {
		 	try {
		 		return a.readLine();
		 	} catch (IOException e) {
		 		e.printStackTrace ();
		 	}
		 	return "##";
		}
	}
}


Measured memory_bytes: 22484
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> pos[200001];
  bool ng = true;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a == 1) ng = false;
    pos[a].push_back(i);
  }
  if (ng) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0, before = -1;
  for (int i = 1; i <= n; ++i) {
    auto it = upper_bound(pos[i].begin(), pos[i].end(), before);
    if (it == pos[i].end()) break;
    ans++;
    before = *it;
  }
  cout << n - ans << endl;
  return 0;
}

Measured memory_bytes: 11136
<?php
  $n = trim(fgets(STDIN));
  $list = [];
  for($i=1; $i<=$n; $i++){
    $count = 0;
    if($i%2 == 1){
      for($j=1; $j<=$i; $j++){
        if($i%$j == 0){
          $count++;
        }
      }
      if($count==8){
        $list[] = $i;
      }
    }
  }

  echo count($list)."\n";

Measured memory_bytes: 4604
#include "bits/stdc++.h"
using namespace std;
int main(void)
{
	int N; cin >> N;
	vector<string>arr(101, "  ");
	bool bo = true;
	for (int i = 0; i < N; i++)
	{
		string s;
		cin >> s;
		if (i != 0)
		{
			if (s[0] != (arr[i - 1].back()))
			{
				bo = false;	
			}
		}
		for (int j = 0; j < 101; j++)
		{
			if (s == arr[j])
			{
				bo = false;
			}
		}
		arr[i] = s;
	}
	if (bo)
	{
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
}


Measured memory_bytes: 256