akhauriyash/Code-Regression huggingface dataset:
/*
 * Author : Sadi
 * Sun 05/07/2020
 * 16:41:07.47
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    string s;
    cin >> s;
    if(s[0] == s[1] or s[1] == s[2] or s[2] == s[3]) {
        cout << "Bad" << "\n";
    }
    else {
        cout << "Good" << "\n";
    }
    return 0;
}


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

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
ll dp[100002];

int main()
{
	for(int i = 0;i<100002;i++)dp[i]=-1;
	ll n,x,m;
	cin >> n >> x >> m;
	ll sum = 0;
	ll now = x;
	ll cnt = 1;
	map<ll,ll> mp;
	map<ll,ll> mp2;
	for(int i = 0;i<n;i++)
	{
		if(dp[now]!=-1)
		{
			ll roopsum = sum- mp[dp[now]]+mp2[dp[now]];
			ll rooptime = (n-cnt+1)/(cnt-dp[now]);
			sum += roopsum*rooptime;
			n-=cnt;
			n++;
			n %= cnt-dp[now];
			for(int j = 0;j<n;j++)
			{
				sum +=now;
				(now*=now)%=m;
			}
			cout<<sum<<endl;
			return 0;
		}
		sum+=now;
		mp2[cnt] = now;
		mp[cnt] = sum;
		dp[now] = cnt++;
		(now*=now)%=m;
	}
	cout<<sum<<endl;

}



Measured memory_bytes: 10544
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>

using namespace std;

int main() {

	int X,A;

	cin >> X >> A;

	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout <<10 << endl;
	}




	return 0;
}


Measured memory_bytes: 256
n,a=map(int,input().split())
x=list(map(int,input().split()))
p=max(max(x),a)
s=[i-a for i in x]
dp=[[0]*(2*n*p+1) for i in range(n+1)]
dp[0][n*p]=1
for i in range(1,n+1):
    for j in range(2*n*p+1):
        if j-s[i-1]<0 or j-s[i-1]>2*p*n:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=dp[i-1][j]+dp[i-1][j-s[i-1]]
print(dp[n][n*p]-1)

Measured memory_bytes: 5616
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  string s;
  int k;
  cin>>s>>k;
  int ans=1;
  for(int i=0;i<k;i++){
    if(s[i]!='1'){
      ans=s[i]-'0';
      break;
    }
  }cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> v(h + 1, vector<int>(w + 1, 0));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> v[i][j];
		}
	}
	vector<vector<int>> res;
	int valid = 0;
	int coin = 0;
	int lx = 0, ly = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			int x = i, y = j;
			if (x % 2 == 0) y = w + 1 - j;
			if (v[x][y] % 2 == 1) {
				coin = 1 - coin;
				if (coin == 0) res.push_back({lx, ly, x, y});
				if (coin == 0) valid = res.size();
			} else {
				if (coin == 1) res.push_back({lx, ly, x, y});
			}
			lx = x, ly = y;
		}
	}
	cout << valid << endl;
	for (int i = 0; i < valid; i++) {
		cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << " " << res[i][3] << endl;
	}
}


Measured memory_bytes: 11140
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1e9

const int MAX_N = 100000;

int n, width = 1;
int dat[MAX_N*4];

void init(){
    while(width<n) width*=2;
    REP(i,2*width-1) dat[i] = INF;
}

void update(int i, int x){
    i += width-1;
    dat[i] = x;
    while (i>0){
        i = (i-1)/2;
        dat[i] = min(dat[i*2+1],dat[i*2+2]);
    }
}

int query(int a, int b, int k, int l, int r){
    if (r<=a || b<=l) return INF;
    if (a<=l && r<=b) return dat[k];
    int vl = query(a,b,k*2+1,l,(l+r)/2);
    int vr = query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
}

int main() {
    ll nn, x;
    cin >> nn >> x;
    n = 2*nn;
    init();
    VL a(2*n);
    ll ans = 0;
    REP(i,nn){
        cin >> a[i];
        ans += a[i];
        a[nn+i] = a[i];
        update(i, a[i]);
        update(i+nn, a[i]);
    }
    FOR(i,1,nn-1){
        ll res = i*x;
        FOR(j,nn,2*nn-1){
            res += query(j-i,j+1,0,0,width);
        }
        ans = min(ans,res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
vector<llong> PrimeFactorization(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
llong N;
llong ANS = 0;
int main() {
	cin >> N;
	auto NF = PrimeFactorization(N - 1);
	ANS += NF.size() - 1;
	NF = PrimeFactorization(N);
	for (int i = 0; i < NF.size(); i++) {
		if (NF[i] == 1) continue;
		llong tmp = N;
		while (tmp % NF[i] == 0) tmp /= NF[i];
		if (tmp % NF[i] == 1) ANS++;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  vector<int> v(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int maxx = 0, acc = 0;
  for (int i = 1; i < n; i++) {
    if (v[i] <= v[i-1]) acc++;
    else acc = 0;
    maxx = max(maxx, acc);
  }
  cout << maxx;
  return 0;
}

Measured memory_bytes: 640
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let _: i32 = read();
    let s: String = read();
    let mut cnt = 0;
    let mut pre = 0;
    for c in s.bytes() {
        // let c = c as char;
        if c == b'(' {
            cnt += 1;
        } else {
            if cnt == 0 {
                pre += 1;
            } else {
                cnt -= 1;
            }
        }
    }
    // println!("{}{}{}",
    //          String::from_utf8(vec![b'(';pre]).unwrap(),
    //          s,
    //          String::from_utf8(vec![b')';cnt]).unwrap());
    // print!("{}", String::from_utf8(vec![b'(';pre]).unwrap());
    // print!("{}", s);
    // print!("{}", String::from_utf8(vec![b')';cnt]).unwrap());
    // let mut ans = String::new();
    for _ in 0..pre {
        print!("(");
    }
    print!("{}", s);
    for _ in 0..cnt {
        print!(")");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
using namespace std;
int a[100001][2]={0};
int n;
int s0=0,s1=0,s2=0;
int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		cin>>a[i][0];
	    if (a[i][0]%2==0) a[i][1]++;
	    if (a[i][0]%4==0) a[i][1]++;
	    if (a[i][1]==0) s0++;
	    if (a[i][1]==1) s1++;
	    if (a[i][1]==2) s2++;
	}
	int o=1;
	if ((s2==0)&&(s1==0)) o=0;
	if (s2<s0-1) o=0;
	if ((s2==(s0-1))&&((s1%2)!=0)) o=0;
	if (o==0) cout<<"No";
	    else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
A, B = map(int, input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

# 1の時には[]が返される
A_fact_set = set(prime_factorize(A))
A_fact_set.add(1)
B_fact_set = set(prime_factorize(B))
B_fact_set.add(1)

ans_set = A_fact_set & B_fact_set
print(len(ans_set))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll cnt1=0,cnt2=0,cnt3=0;
    rep(i,n){
        if(s[i]=='R') cnt1++;
        if(s[i]=='G') cnt2++;
        if(s[i]=='B') cnt3++;
    }
    ll ans=cnt1*cnt2*cnt3;
    for(int d=1;d<n;d++){
        for(int m=0;m<n;m++){
            if(m-d<0||m+d>=n) continue;
            if(s[m-d]!=s[m+d]&&s[m]!=s[m+d]&&s[m-d]!=s[m]) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int T = sc.nextInt();
		int H = sc.nextInt();
		int L = sc.nextInt();
		
		int[] h = new int[n];
		int[] t = new int[n];
		for(int i=0;i<n;i++){
			t[i] = sc.nextInt();
			h[i] = sc.nextInt();
		}
		
		int sum = 0;
		int ans = -1;
		for(int p=0;;p++){
			if(t[p]==0 && h[p]==0){
				ans = p+1;
				break;
			}
			if(t[p]>0){
				if(T==L){
					ans = p+1;
					break;
				}
				sum += 10;
				if(sum<=90){
					t[p]--;
					T++;
				}
				if(sum>=90) sum = 0;
			}else{
				h[p]--;
				T -= (sum+10)/10;
				t[p] += (sum+10)/10;
				sum = 0;
			}
			if(T<0){
				ans = p+1;
				break;
			}

			if(p==n-1) p = -1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 20404
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int NMAX = 100005;

vector<int> G[NMAX];
int values[NMAX];
int64_t dpOut[NMAX];

void dfs(int node, int prev) {
    if (SZ(G[node]) == 1) {
        dpOut[node] = values[node];
    } else {
        int64_t sum = 0;
        int64_t vmax = 0;
        for (int to: G[node]) {
            if (to != prev) {
                dfs(to, node);
                sum += dpOut[to];
                vmax = max(vmax, dpOut[to]);
            }
        }
        int pr = 2 * (sum - values[node]);
        dpOut[node] = sum - pr;
        if (2 * (vmax - dpOut[node]) > pr || 
                dpOut[node] < 0 || pr < 0) {
            cout << "NO\n";
            exit(0);
        }
    }
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> values[i];
    }
    for (int i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    if (n == 2) {
        cout << (values[1] == values[2] ? "YES\n": "NO\n") << '\n';
        return 0;
    }

    int root = 1;
    while (SZ(G[root]) == 1) {
        ++root;
    }

    dfs(root, -1);
    cout << (dpOut[root] ? "NO\n": "YES\n") << '\n';
}


Measured memory_bytes: 13568
#include<stdio.h>

int main(){
	int i = 0;
	int x = 1;
	while (x<= 10000){
		
		
			scanf("%d", &i);
			if (i == 0){
				break;
			}
			printf("Case %d: %d\n",x, i);
			x = x + 1;
		
		 

	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define mod 1000000007
using namespace std;
int n,x,a[205];
int dp[205][100005];
signed main(){
	cin >> n >> x;
	rep(i,n){
		cin >> a[i];
	}
	sort(a,a+n);
	rep(i,x+1)dp[0][i]=i;
	rep(i,n){
		rep(j,x+1){
			dp[i+1][j]+=dp[i][j%a[i]];
			dp[i+1][j]+=dp[i][j]*i;
			dp[i+1][j]%=mod;
		}
	}
	cout<<dp[n][x]<<endl;
}


Measured memory_bytes: 157952
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n,a;cin>>n>>a;
  int x[n];
  rep(i,n){
    cin>>x[i];
    x[i]-=a;
    }
  ll dp[55][6000];
  rep(i,6000)dp[0][i]=0;
  dp[0][3000]=1;
  rep(i,n)rep(j,6000){
    dp[i+1][j]=dp[i][j];
    if(0<=j-x[i]&&j-x[i]<6000)dp[i+1][j]+=dp[i][j-x[i]];
    }
  cout<<dp[n][3000]-1<<endl;
  return 0;         
  }

Measured memory_bytes: 2688
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

Q,H,S,D = imn()
N = iin()

min1L = min(Q*4, H*2, S)
min2L = min(min1L*2, D)

ans = N//2*min2L
if N % 2 == 1: ans += min1L
print(ans)

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d; cin>>a>>b>>c>>d;
    print(a*b-c*b-d*(a-c));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll n,x;
    cin >> n >>x;
    vector <ll> a(n);
    rep(i, 0,n) {
        cin>> a[i];
        a[i] -=x;
    }
    ll ans = abs(a[0]);
    for (ll i=0;i< n;i++) {
        ans = gcd(ans,abs(a[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
h,w=map(int,input().split())
T=[["#"]*(w+2)]
T.extend([["#"]+[s for s in input()]+["#"] for _ in range(h)])
T.append(["#"]*(w+2))
L=[[0]*w for _ in range(h)]
R=[[0]*w for _ in range(h)]
U=[[0]*w for _ in range(h)]
D=[[0]*w for _ in range(h)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if T[i][j]==".":
      if j==1:
        L[i-1][j-1]=1
      else:
        L[i-1][j-1]=L[i-1][j-2]+1
      if i==1:
        U[i-1][j-1]=1
      else:
        U[i-1][j-1]=U[i-2][j-1]+1
    if T[h+1-i][w+1-j]==".":
      if j==1:
        R[h-i][w-j]=1
      else:
        R[h-i][w-j]=R[h-i][w-j+1]+1
      if i==1:
        D[h-i][w-j]=1
      else:
        D[h-i][w-j]=D[h-i+1][w-j]+1
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j]-3)
print(ans)


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    long long ans = 1LL << 60;
    for (int bit = 0; bit < 1 << N; ++bit) {
        int pre = A[0], num = 1;
        long long sum = 0;
        for (int i = 1; i < N; ++i) {
            if (bit >> i & 1) {
                num++;
                if (A[i] > pre) {
                    pre = A[i];
                } else {
                    sum += pre - A[i] + 1;
                    pre++;
                }
            } else {
                if (A[i] > pre) num++;
                pre = max(pre, A[i]);
            }
        }
        if (num >= K) ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>)
{
    var s = readString().reversed()
    val words = listOf("dream", "dreamer", "erase", "eraser").map{ it.reversed() }

    var flag = true
    while(flag && s.length > 0)
    {
        val containFlag = if (s.take(words[0].length) == words[0])
        {
            0
        }
        else if (s.take(words[1].length) == words[1])
        {
            1
        }
        else if (s.take(words[2].length) == words[2])
        {
            2
        }
        else if (s.take(words[3].length) == words[3])
        {
            3
        }
        else
        {
            -1
        }
        
        if (containFlag != -1)
        {
            s = s.drop(words[containFlag].length)
        }
        else
        {
            flag = false
        }
    }

    println(if (flag) "YES" else "NO")
}

// Read an integer
// Usage: val a = readInt()
fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
fun readString() = readLine()!!


Measured memory_bytes: 121128
#include<iostream>

#include<string>
#include <algorithm> 
using namespace std;

int main()
{
    string s1,s2,s3,s;
    cin >> s1 >> s2 >> s3;

    s = s1.substr(0,1)+s2.substr(0,1)+s3.substr(0,1);
    transform (s.begin (), s.end (), s.begin (), ::toupper);

    cout << s << endl;
}

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

int main(){
  int N,K,total;
  total = 1;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    if(total<K)
      total *= 2;
    else
      total += K;
  }
  cout << total << endl;

}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim_right().to_owned().parse().unwrap();

    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.split_whitespace();
    let mut hs: Vec<u32> = Vec::new();
    for h in s {
        hs.push(h.parse().unwrap());
    }
    let hmax: usize = *hs.iter().max().unwrap() as usize;
    let mut cluster_num = vec![0; hmax + 1];

    for num in 1..(hmax + 1) {
        let mut valey_flg = true;
        for i in 0..n {
            if hs[i] >= num as u32 && valey_flg == true {
                cluster_num[num] += 1;
                valey_flg = false;
            } else if hs[i] < num as u32 {
                valey_flg = true;
            }
        }
    }
    let total: u32 = cluster_num.iter().sum();
    println!("{}", total);
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var answer = 1000 - N % 1000;
        if (answer == 1000)
        {
            answer = 0;
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 27540
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s,t;
  cin>>s>>t;
  int i,cnt=0;
  for(i=0; i<s.size(); ++i) if(s[i]==t[i]) ++cnt;
  if(cnt==s.size()) cout<<"Yes"<<endl; else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
int main(void){
	int N,K,di,i,j,A,sum=0;
	scanf("%d %d",&N,&K);
	int S[N];
	for(i=0;i<N;i++){
		S[i]=0;
	}
	for(i=1;i<=K;i++){
		scanf("%d",&di);
		for(j=0;j<di;j++){
			scanf("%d",&A);
			S[A-1]=S[A-1]+1;
		}
	}
	for(i=0;i<N;i++){
		if(S[i]==0){
			sum=sum+1;
		}
	}
	printf("%d\n",sum);
	return 0;
}

		

Measured memory_bytes: 1724
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
int calcAve(int bottom,int top){
	if((bottom + top) % 2 == 1){
		return (bottom + top - 1)/2;
	}else{
		return (bottom + top)/2;
	}
}
int main () {
	int n;
	cin >> n;
	int S[n];
	for(int i = 0; i < n; i++){
		cin >> S[i];
	}
	int q;
	cin >> q;
	int T[q];
	for (int i = 0; i < q; ++i)
	{
		cin >> T[i];
	}
	int score = 0;
	for (int i = 0; i < q; ++i)
	{

		int bottom = 0;
		int top = n-1;
		while(top >= bottom){
			if(S[calcAve(bottom,top)] == T[i]){
				score++;
				break;
			}
			if(S[calcAve(bottom,top)] > T[i]){
				top = calcAve(bottom,top) - 1;
			}else if(S[calcAve(bottom,top)] < T[i]){
				bottom = calcAve(bottom,top) + 1;				
			}

			//cout << top << " " << bottom << endl;
		}

	}
	cout << score << endl;
}


Measured memory_bytes: 3676
#include<stdio.h>

long long gcd(long long a,long long b){
long long c;
while(a%b){
c=a%b;
a=b;
b=c;
}
return b;
}

int main(){
long long n,g,ans;
scanf("%lld",&n);
g=gcd(n,2);
ans=2*n/g;
printf("%lld",ans);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

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

    vector<ll> c(3);
    for(int i=0; i<N; i++){
        if(s[i]=='R') c[0]++;
        else if(s[i]=='G') c[1]++;
        else c[2]++;
    }

    ll ans = c[0] * c[1] * c[2];

    for(int l=1; 2*l<N; l++){
        for(int i=0; i<N; i++){
            int j = i+l;
            int k = j+l;
            if(k >= N) break;
            if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]) ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3228
s = list(input())
t = list(input())

s.sort()
t.sort(reverse=True)

flg = False
for i in range(len(s)):
    if i >= len(t):
        break
    if ord(s[i]) > ord(t[i]):
        break
    if ord(s[i]) < ord(t[i]):
        flg = True
        break
    if i == len(s)-1 and i < len(t)-1:
        flg = True
        break
        
print('Yes') if flg else print('No')

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

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*****************************************************START******************************************************************/


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T =1 ;
	 //cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		int n,W; 
		cin >> n >> W; 
		vector<ll>dp(W+1);
		while(n--){
			ll w,v; 
			cin >> w >> v; 
			
			for(int weight = W-w; weight>=0; weight--){
				dp[weight + w] = max(dp[weight]+v ,dp[weight+w]);
				//debug(dp[weight]);
			}
		}
		ll ans = 0; 
		for(int i=1; i<=W; i++){
			ans = max(ans,dp[i]);
		}
		cout << ans << endl;
		
	}
	return 0;
}


Measured memory_bytes: 3972
#include <stdio.h>
/*ここから上は消さないで*/

int main(){
	int a;
	int b;
	int sum;
	int count;
	while(scanf("%d %d", &a, &b) != EOF){
		sum = a + b;

		for(count = 0 ; sum != 0 ; count++){
			sum /= 10;
		}
		printf("%d\n", count);
	}
	return 0;	//ここの行、重要
}

Measured memory_bytes: 600
/*
 * 2322.cc: Chinese Classics
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

typedef vector<int> vi;
typedef map<string,int> msi;

/* global variables */

bool res[MAX_N], used[MAX_N];
msi types;
int tn, ts[MAX_N], nums[MAX_N];
vi jmps[MAX_N];

/* subroutines */

void read(int k) {
  if (used[k]) return;
  printf("%d\n", k + 1);
  used[k] = true;
    
  if (k > 0 && res[k - 1]) read(k - 1);
  if (nums[k] > 0) {
    vi &jv = jmps[ts[k]];
    if (jv.size() > nums[k]) read(jv[nums[k]]);
  }
}

void parse(string &s, string &type, int &num, bool &re) {
  type = "";
  num = 0;
  re = false;
  if (s == "-") return;
  
  int n = s.size();
  
  if (s[n - 1] == 'v') {
    n--;
    re = true;
  }

  int pos = 0;
  while (pos < n && s[pos] >= 'a' && s[pos] <= 'z')
    type += s[pos++];
  while (pos < n && s[pos] >= '0' && s[pos] <= '9')
    num = num * 10 + (s[pos++] - '0');
}

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

    memset(res, false, sizeof(res));
    memset(used, false, sizeof(used));
    memset(ts, -1, sizeof(ts));
    memset(nums, 0, sizeof(nums));
    types.clear();
    tn = 0;

    for (int i = 0; i < n; i++) {
      string s, type;
      cin >> s;
      parse(s, type, nums[i], res[i]);

      if (nums[i] > 0) {
	msi::iterator mit = types.find(type);
	if (mit == types.end() || jmps[mit->second][0] >= 0) {
	  ts[i] = types[type] = tn++;
	  jmps[ts[i]].assign(nums[i], -1);
	  jmps[ts[i]][nums[i] - 1] = i;
	}
	else {
	  ts[i] = mit->second;
	  jmps[ts[i]][nums[i] - 1] = i;
	}
      }
    }
    
    for (int pc = 0; pc < n; pc++)
      if (! res[pc] && nums[pc] <= 1) read(pc);
  }

  return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N;
    cin >> N;
    int cnt = 0;
    for (size_t i = 1; i <= N; i++) {
        if (i % 2) cnt++;
    }
    cout << (ld)cnt / (ld)N << endl;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;
    i64 L0=2,L1=1;
    if(N==0){
        cout << L0 << endl;
        return;
    }
    if(N==1){
        cout << L1 << endl;
        return;
    }
    rep(i,0,N-1){
        i64 tmp=L1;
        L1=L0+L1;
        L0=tmp;
    }
    cout << L1 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int w,h,n;
char c[22][22];
int sy[4],sx[4],gy[4],gx[4];
short dist[1<<24];
int dy[]={0,1,0,-1,0};
int dx[]={1,0,-1,0,0};

#define state(ay,ax,by,bx,cy,cx) ((ay)<<20 | (ax)<<16 | (by)<<12 | (bx)<<8 | (cy)<<4 | (cx)<<0)

int main2(){
	fill(sy,sy+4,0);
	fill(sx,sx+4,0);
	fill(gy,gy+4,0);
	fill(gx,gx+4,0);
	rep(i,h)rep(j,w){
		if(islower(c[i][j])){
			sy[c[i][j]-'a'] = i;
			sx[c[i][j]-'a'] = j;
			c[i][j] = ' ';
		}
		if(isupper(c[i][j])){
			gy[c[i][j]-'A'] = i;
			gx[c[i][j]-'A'] = j;
			c[i][j] = ' ';
		}
	}
	memset(dist,-1,sizeof(dist));
	int s = state(sy[0],sx[0],sy[1],sx[1],sy[2],sx[2]);
	dist[s] = 0;
	queue<int> Q;
	Q.push(s);
	while(sz(Q)){
		int s = Q.front();Q.pop();
		int y[4],x[4];
		y[0] = s>>20 & 15;
		x[0] = s>>16 & 15;
		y[1] = s>>12 & 15;
		x[1] = s>> 8 & 15;
		y[2] = s>> 4 & 15;
		x[2] = s>> 0 & 15;
		
		int done=1;
		rep(i,n)if(y[i] != gy[i] || x[i] != gx[i]){
			done=0;break;
		}
		if(done)return cout<<dist[s]<<endl,0;
		int ny[4],nx[4],ns;
		rep(dir0,5){
			ny[0] = y[0] + dy[dir0];
			nx[0] = x[0] + dx[dir0];
			if(c[ny[0]][nx[0]]=='#')continue;
			rep2(dir1,n==1 ? 4 : 0, 5){
				ny[1] = y[1] + dy[dir1];
				nx[1] = x[1] + dx[dir1];
				if(n>=2 && c[ny[1]][nx[1]]=='#')continue;
				rep2(dir2,n<=2 ? 4 : 0, 5){
					ny[2] = y[2] + dy[dir2];
					nx[2] = x[2] + dx[dir2];
					if(n==3 && c[ny[2]][nx[2]]=='#')continue;
					
					rep(i,n)rep2(j,i+1,n){
						if(ny[i]==ny[j] && nx[i]==nx[j])goto fail;
						if(ny[i]==y[j] && nx[i]==x[j]
						&& ny[j]==y[i] && nx[j]==x[i])goto fail;
					}
					ns = state(ny[0],nx[0],ny[1],nx[1],ny[2],nx[2]);
					if(dist[ns]==-1){
						dist[ns] = dist[s]+1;
						Q.push(ns);
					}
					
					fail:;
				}
			}
		}
	}
	return 1;
}

int main(){
	//cin.tie(0);
	//ios_base::sync_with_stdio(0);
	
	while(cin>>w>>h>>n,w){
		gets(c[0]);
		rep(i,h)gets(c[i]);
		main2();
	}
}

Measured memory_bytes: 34904
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<ll> h(n);
	rep(i, n)cin >> h[i];
	sort(all(h));
	ll res = 0;
	rep(i, n - k)
	{
		res += h[i];
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

template <unsigned T>
bool nextBitset(bitset<T> &bs, int digit)
{
    if(bs.none())
        return false;
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

int main()
{
    vector<vector<int> > dp(1<<10, vector<int>(331, 0));
    dp[0][0] = 1;
    for(int i=0; i<(1<<10); ++i){
        bitset<10> bs(i);
        for(int j=0; j<10; ++j){
            if(bs[j])
                continue;
            bitset<10> bs1 = bs;
            bs1[j] = true;
            int a = j * bs1.count();
            for(int k=0; k+a<331; ++k)
                dp[bs1.to_ulong()][k+a] += dp[bs.to_ulong()][k];
        }
    }

    for(;;){
        int n, s;
        if(!(cin >> n >> s))
            return 0;

        if(s > 330){
            cout << 0 << endl;
            continue;
        }

        int ret = 0;
        bitset<10> bs((1<<n)-1);
        do{
            ret += dp[bs.to_ulong()][s];
        }while(nextBitset(bs, 10));
        cout << ret << endl;
    }
}

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

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

    int X[M];
    for(int i=0;i<M;i++){
        cin >> X[i];
    }
    sort(X, X + M);

    int dist[M-1];
    for(int i=0;i<M-1;i++){
        dist[i] = X[i+1] - X[i];
    }

    sort(dist, dist + (M-1));

    int res = 0;
    for(int i=0;i<(M-N);i++){
        res += dist[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
static const int MAX_N = 100;
static const int MAX_W = 10000;

int N, W;
int w[MAX_N], v[MAX_N], m[MAX_N];

int dp[MAX_W + 1];
int deq[MAX_W + 1];
int deqv[MAX_W + 1];

void solve(){
	for(int i = 0; i < N; i++){
		for(int a = 0; a < w[i]; a++){
			int s = 0, t = 0;
			for(int j = 0; j * w[i] + a <= W; j++){
				int val = dp[j * w[i] + a] - j * v[i];
				while(s < t && deqv[t - 1] <= val) t--;
				deq[t] = j;
				deqv[t++] = val;
				dp[j * w[i] + a] = deqv[s] + j * v[i];
				if(deq[s] == j - m[i]){
					s++;
				}
			}
		}
	}
	printf("%d\n", dp[W]);
}

int main(){
	scanf("%d %d", &N, &W);
	for(int i = 0; i < N; i++) scanf("%d %d %d", &v[i], &w[i], &m[i]);
	solve();
	return 0;
}

Measured memory_bytes: 2876
#include<cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
char a[105];
int main() {
	string s;
	cin>>s;
	int flag = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if(s[i]=='C')
			for (int j = i+1; j < s.length(); j++)	
			{
				if (s[j] == 'F')
				{
					flag = 1;
					break;
				}
			}
		if (flag)
			break;
	}
	if (flag)
		printf("Yes\n");
	else
		printf("No\n");
		return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)











class unionfind {
private:
    vector<int> par;
    vector<int> rank;
    vector<int> counter;
public:
    unionfind(int n) : rank(n), counter(n, 1){
        for(int i = 0; i < n; i++){
            par.push_back(i);
        }
    }
    
    int find(int x){
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        
        if (rank[x] < rank[y]) {
            counter[y] += counter[x];
            counter[x] = counter[y];
            par[x] = y;
        }
        else {
            counter[y] += counter[x];
            counter[x] = counter[y];
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
    
    ll count(int x){
        return counter[find(x)];
    }
};


int main(){
    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    vector<vector<ll>> xx(100005);
    REP(i, n){
        cin >> x[i] >> y[i];
        xx[x[i]].push_back(y[i]);
    }
    
    unionfind uni(100005);
    REP(i, 100005){
        if(xx[i].size() >= 2){
            for(ll j = 1; j < xx[i].size(); j++){
                uni.unite(xx[i][0], xx[i][j]);
            }
        }
    }
    
    ll ans = 0;
    REP(i, 100005){
        vector<bool> used(100005);
        REP(j, xx[i].size()){
            ll p = uni.find(xx[i][j]);
            if(used[p]){
                ans--;
                continue;
            }
            used[p] = true;
            ans += uni.count(xx[i][j]) - 1;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n;
    int max_turn = INT_MAX;

    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;

        int counter = 0;
        while(num % 2 == 0) {
            num = num / 2;
            ++counter;
        }

        max_turn = min(max_turn, counter);
    }

    cout << max_turn << endl;
}

Measured memory_bytes: 3192
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int a,b,l,u,t,c;(a=s.nextInt())>0;System.out.println(l+" "+c))for(b=s.nextInt(),c=0,l=a>b?a:b,u=a<b?a:b;u>0;l=u,u=t,++c)t=l%u;}}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <cmath>

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

    std::cout << ((a+b) >= c ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
lis1 = []
lis2 = []
lis3 = []
count = 0
for num in input().split():
    lis1.append(int(num))
for num in input().split():
    lis2.append(int(num))
for num in input().split():
    lis3.append(int(num))
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            count = 0
            if lis1[0] - a1 == lis2[0] - a2 == lis3[0] - a3:
                count += 1
            if lis1[1] - a1 == lis2[1] - a2 == lis3[1] - a3:
                count += 1
            if lis1[2] - a1 == lis2[2] - a2 == lis3[2] - a3:
                count += 1
            if count == 3:
                print("Yes")
                break
        if count == 3:
          	break
    if count == 3:
      break
    if a1 == 100 and count != 3:
      	print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
cin>>A>>B;
if((A*B*1)%2!=0)cout<<"Yes";
else if((A*B*2)%2!=0)cout<<"Yes";
else if((A*B*3)%2!=0)cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

const int mod = 1e9 + 7;

int pw(int a, int b) {
    int res = 1;
    while (b) {
        if (b % 2) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b /= 2;
    }
    return res;
}

int get(int n, int k) {
    int f = 1;
    for (int i = n - k + 1; i <= n; i++) {
        f *= i;
        f %= mod;
    }
    int r = 1;
    for (int i = 1; i <= k; i++) {
        r *= i;
        r %= mod;
    }
    return f * pw(r, mod - 2) % mod;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, a, b;
    cin >> n >> a >> b;
    int ans = (pw(2, n) - 1);
    ans = (ans - get(n, a) + mod) % mod;
    ans = (ans - get(n, b) + mod) % mod;
    cout << ans % mod<< endl;

    return 0;
}


Measured memory_bytes: 256
// 11.07.2017


//# include <stdio.h>

//# include <iostream>
# include <cstdio>
//# include <conio.h>

//using namespace std;



int main ()
{
//
//freopen ("A.TXT", "r", stdin);
//freopen ("A.OUT", "w", stdout);
//

   int a, i, n, p, m=0, k=0;
   long long int sum = 0, t;

   scanf ("%d%d\n", &n, &p);
   for ( i=0; i < n; i++ )
   {
      scanf ("%d", &a);
      if ( a % 2 == 0 )
         k++;
      else
			m++;
   }
//
//printf ("n=%d p=%d m=%d k=%d\n", n, p, m, k);
//
   if ( p == 0 )
   {
      t = 1;
      sum = t;
      for ( i=2; i <= m; i+=2 )
      {
		   t = t*(m-i+1)*(m-i+2)/i/(i-1);
		   sum += t;
//printf ("== sum=%I64d t=%I64d\n", sum, t);
		}
		for ( i=0; i < k; i++ )
		   sum *= 2;
   }
   else
   {
	 	t = m;
	 	if ( m > 0 )
	 	   sum = m;
      for ( i=3; i <= m; i+=2 )
      {
		   t = t*(m-i+1)*(m-i+2)/i/(i-1);
		   sum += t;
//printf ("=  sum=%I64d t=%I64d\n", sum, t);
		}
      for ( i=0; i < k; i++ )
		   sum *= 2;
   }

   printf ("%lld", sum);
//   printf ("%I64d", sum);

   return 0;
}


Measured memory_bytes: 128