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

using namespace std;
#define rep(j,n) for(int j=0;j<(n);j++)

using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;
const ll MAX = 1000000000000001;
const int INF = 1001001001;

int main(int, char**)
{
    ll n;
    cin >> n;

    string ans;
    while (n) {
        ll nn = n % 26;
        n /= 26;
        if (nn == 0) { nn = 26; n--; }
        ans.push_back('a' + nn - 1);
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int, input().split()))
f = 0
m = 10**6 + 10
t = [0] * (10**6 + 10)

def bunkai(n):
    global f
    if n % 2 == 0 and t[2] == 0:
        t[2] = 1
    elif n % 2 == 0 and t[2] == 1:
        f = 1
        return
    while n % 2 == 0:
        n //= 2
    l = 3
    while l * l < n:
        if n % l == 0:
            if t[l] == 1:
                f = 1
                return
            while n % l == 0:
                n //= l
        l += 2
    if n != 1:
        if t[n] == 1:
            f = 1
        else:
            t[n] = 1

for i in range(N):
    bunkai(A[i])
    if f == 1:
        break

from math import gcd
g = A[0]
if f == 1:
    for i in range(1, N):
        g = gcd(g, A[i])
        if g == 1:
            break

if f == 0:
    print("pairwise coprime")
elif g == 1 and f == 1:
    print("setwise coprime")
else:
    print("not coprime")

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

typedef long long ll;
typedef long double ld;

ll a;
ld b;

int main()
{
    cin >> a >> b;
    ll B = b * 100 + 1e-9l;
    cout << a * B / 100ll << endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    
    int ans = 0;
    for(int i=1; i<=N; i++){
        double sum = i * 1.0800000;
        int nedan = sum;

        if(nedan == N){
            ans = i;
            break;
        }
    }

    if (ans == 0){
        cout << ":(" << endl;
    }
    else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<numeric>
#include<cmath>
using namespace std;

int calc(int n, const vector<int>a)
{
	int sum = 0;
	for(auto it=a.begin(); it!=a.end(); it++)
		sum += pow(*it - n, 2);

	return sum;
}

int main(void)
{
	int N;
	cin >> N;

	vector<int> a(N);
	for(int i=0; i<N; i++)
		cin >> a[i];

	int sum = accumulate(a.begin(), a.end(), 0);
	double t = ceil(1.0*sum/N);
	double b = floor(1.0*sum/N);

	cout << min(calc(t, a), calc(b, a)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  vector<int>v(N);
  rep(i,N)cin >> v[i];
  sort(all(v));
  rep(i,N){
    K-=v[i];
    if(K<0){
      cout << i << endl;
      return 0;
    }
  }
  if(K!=0) cout << N-1 << endl;
  else cout << N << endl;
  return 0;
}


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

using namespace std;

int main(void)
{
    int N;
    long long stepSum = 0, stepHeight = 1;
    cin >> N;
    vector<long long> A(N, 0);

    for (int i = 0; i < A.size(); i++) {
        cin >> A[i];
    }
    stepHeight = A[0];
    for (int i = 1; i < A.size(); i++) {
        if (stepHeight > A[i]) {
            stepSum += stepHeight - A[i];
        }
        else {
            stepHeight = A[i];
        }
    }

    cout << stepSum << endl;

    return 0;
}





Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    ll h,w;
    cin>>h>>w;
    ll ans=INF;
    if(h%3==0||w%3==0)ans=0;
    else{
        ans=min(h,w);
        ll t=h/2;
        for(ll i=1;i<=w-1;i++){
            ll a=t*(w-i);
            ll b=(h-t)*(w-i);
            ll c=h*i;
            ans=min(ans,max({a,b,c})-min({a,b,c}));
        }
        t=w/2;
        for(ll i=1;i<=h-1;i++){
            ll a=t*(h-i);
            ll b=(w-t)*(h-i);
            ll c=w*i;
            ans=min(ans,max({a,b,c})-min({a,b,c}));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import deque

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def dfs(x, y):
  stack = deque()
  stack.append((x, y))
  num_w = 0
  num_b = 0
  while stack:
    cx, cy = stack.popleft()
    cc = S[cy][cx]
    for i, j in zip(dx, dy):
      nx = i + cx
      ny = j + cy
      if (0 <= nx < w and 0 <= ny < h) and not visited[ny][nx] and S[ny][nx] != cc:
        visited[ny][nx] = True
        stack.append((nx, ny))
        if cc == ".":
          num_w += 1
        else:
          num_b += 1
  else:
    return num_w, num_b

h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]

visited = [[False] * w for _ in range(h)]
  
ans = 0
for i in range(w):
  for j in range(h):
    if not visited[j][i]:
      num_w, num_b = dfs(i, j)
      ans += num_b * num_w
      
print(ans)

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

int main() {
	int n;
	cin >> n;
	if (n < 10);
	else if (n < 100) n = 9;
	else if (n < 1000) n -= 90;
	else if (n < 10000) n = 909;
	else if (n < 100000) n -= 9090;
	else n = 90909;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int a[200005],b[200005];
int main(){
	int n;
	scanf("%d",&n);
	priority_queue<pair<int,int> > q;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	for(int i=0;i<n;i++){
		scanf("%d",b+i);
		q.push(make_pair(b[i],i));
	}
	long long cnt=0,op=0;;
	while(1){
		long long x=q.top().first,v=q.top().second;
		q.pop();
		long long vpre=((v-1)%n+n)%n,vnxt=(v+1)%n;
		long long nt=max(b[vpre],max(a[v],b[vnxt]));
		long long reduce=b[vpre]+b[vnxt];
		long long times=(x-nt+reduce-1)/reduce;
		x-=1ll*reduce*times;
		b[v]=x;
		if(b[v]<a[v]){
			cout<<-1;
			return 0;
		}
		if(b[v]==a[v]){
			cnt++;
		}
		else{
			q.push(make_pair(b[v],v));
		}
		op+=times;
		if(cnt==n) break;
	}
	cout<<op;
}

Measured memory_bytes: 3700
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int m = in.nextInt();

		boolean[] f = new boolean[n];
		f[0] = true;

		int[] cnt = new int[n];
		Arrays.fill(cnt, 1);

		for (int i=0; i<m; i++) {
			int x = in.nextInt() - 1;
			int y = in.nextInt() - 1;
			cnt[x]--; cnt[y]++;
			if (f[x]) {
				f[y] = true;
				if (cnt[x] == 0) f[x] = false;
			}
		}

		int ans = 0;
		for (int i=0; i<n; i++) {
			if (f[i]) ans++;
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

const ll MOD=1e9+7;

int main(){
  fastread;
  ll res=0;

  ll n,m;
  cin >> n >> m;
  char a[n][m];
  ll dp[n][m];
  rep(i,0,n){
    rep(j,0,m)
      cin >> a[i][j];
  }

  dp[0][0]=1;

  rep(i,1,n)
    if(a[i][0]=='#')
      dp[i][0]=0;
    else
      dp[i][0]=dp[i-1][0];

  rep(i,1,m)
    if(a[0][i]=='#')
      dp[0][i]=0;
    else
      dp[0][i]=dp[0][i-1];

  rep(i,1,n){
    rep(j,1,m){
      if(a[i][j]=='#')
        dp[i][j]=0;
      else
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    }
  }

  cout << dp[n-1][m-1] << nl;
  return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>
#include <map>
#include <queue>

#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define vec vector

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

int main() {
  ll n, d;
  cin >> n >> d;
  int ans = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if ((x*x + y*y) <= (d*d)) {
      ans++;
    }
  }
  say(ans);
  return 0;
}


Measured memory_bytes: 3192
using Yorukatsu026.Questions;
using Yorukatsu026.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu026.Questions
{
    /// <summary>
    /// ABC055 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            yield return 800 * n - 200 * (n / 15);
        }
    }
}


namespace Yorukatsu026
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu026.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu026.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
ll dp[100010];
void input(ll n, ll arr[]) {
	rep(i, 0, n)cin >> arr[i];
}
void dfs(V<ll> g[], ll src, bool v[]) {
	v[src] = true;
	for (auto child : g[src]) {
		if (!v[child])dfs(g, child, v);
		dp[src] = max(dp[src], 1 + dp[child]);
	}
}
void dfs(V<ll> g[], ll n, ll m) {
	bool v[n + 1]; init(v, false);
	rep(i, 1, n + 1) {
		if (!v[i])dfs(g, i, v);
	}
	ll ans = -inf;
	rep(i, 1, n + 1)ans = max(ans, dp[i]);
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	ll n, m; S2(n, m);
	V<ll> g[n + 1];
	rep(i, 0, m) {
		ll a, b;
		S2(a, b);
		g[a].pb(b);
	}
	dfs(g, n, m);

}


Measured memory_bytes: 9344
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node* left, * right, * parent;
};

Node* root, * NIL;
void insert(int k)
{
	Node* y = NIL;
	Node* x = root;
	Node* z;
	z = (Node*)malloc(sizeof(struct Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL)
	{
		root = z;
	}
	else
	{
		if (z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y->right = z;
		}
	}
}
void inorder(Node* u)
{
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}
void preorder(Node* u)
{
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}
int main()
{
	int i, n, x;
	string com;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		cin >> com;
		if (com == "insert")

		{
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print")
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
			
		}
	}
	return 0;
}


Measured memory_bytes: 26744
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

inline int S(ll x) { int ret = 0; while (x) ret += x % 10, x /= 10; return ret; }
inline ll pw(int b, int e) { ll ret = 1; while (e--) ret *= b; return ret; }

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	
	ll K, a = 2, b = 0, i = 0; cin >> K;
	while (i < K) {
		ll x = a * pw(10, b) - 1, y = (a + 1) * pw(10, b) - 1;
		if (x * S(y) <= y * S(x)) {
			cout << x << '\n';
			++i, ++a;
		}
		else a = x / pw(10, ++b) + 1;
	}
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#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 ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int N;	cin >> N;
	S s;
	REP(i, N){
	 	int input;	cin >> input;
		s.insert(input);
	}
	SCOUT(s.size()) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()
const int MOD=1e9+7;
const ll MAX = 210000;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll H,W,A,B;cin>>H>>W>>A>>B;
  COMinit();
  vll tmp(H-A,0);
  ll ans=0;
  rep(i,H-A){
    tmp[i] = COM(B+i,i);
    ans += COM((W-1-B)+(H-1-i),W-1-B) * ((tmp[i] - (i == 0 ? 0 : tmp[i-1]) + MOD) % MOD);
    ans %= MOD;
    //cout << "i " << i << "comb+i,i" << COM(B+i,i) << "tmp" << tmp[i] << " W-1-B " << W-1-B << " H-1-i " << H-1-i << " ans " << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5888
N = int(input())
S = input()
codePoint = []

splitedInput = list(S)
wordCount = len(splitedInput)
for i in range(wordCount):
    convertAscii = ord(splitedInput[i]) + N
    if convertAscii > ord("Z"):
        convertAscii = convertAscii - ord("Z") + ord("A") - 1
    conversion = chr(convertAscii)
    codePoint.append(conversion)

ans = "".join(codePoint)
print(ans)

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

int main(void) {
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<long long>> dp(N, vector<long long>(3, 0));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < N; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]}) << endl;
    return 0;
}

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

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edge(n+1, vector<int>());
    rep(i, m){
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    vector<int> col(n+1);
    stack<P> st;
    st.emplace(1, 1);
    bool bipartite = true;
    while(not st.empty()){
        int v = st.top().first;
        int c = st.top().second;
        st.pop();

        if(col[v] != 0){
            if(col[v] != c){
                bipartite = false;
                break;
            }
            continue;
        }
        col[v] = c;

        for(int u : edge[v]){
            st.emplace(u, c * -1);
        }
    }

    int b = 0;
    int w = 0;
    rep(i, n){
        if(col[i+1] == 1){
            b++;
        }else{
            w++;
        }
    }

    if(bipartite){
        cout << b * w - m << endl;
    }else{
        cout << n * (n-1) / 2 - m << endl;
    }

    return 0;
}


Measured memory_bytes: 7808
from collections import deque
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    ans = 0
    d = deque()
    d.append(A[N-1])
    for i in range(N-2,-1,-1):
        ans += d.popleft()
        d.append(A[i])
        d.append(A[i])
    print(ans)
resolve()

Measured memory_bytes: 32520
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.08 19:49:53
**/

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


class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par.resize(n, -1);
    }
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    int n,q;cin >> n >> q;
    UnionFind uf(n);
    while(q--) {
        int t,u,v;cin >> t >> u >> v;
        if (t == 0) {
            uf.unite(u,v);
        }
        else {
            cout << uf.same(u,v) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3844
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

ll N;
vl T, A;

bool ok(ll x){
    ll nt = x/(T[0]+A[0])*T[0];
    ll na = x/(T[0]+A[0])*A[0];
    
    FOR(i, 1, N){
        ll mt = nt/T[i];
        ll ma = na/A[i];
        if(mt == 0 || ma == 0) return false;
        ll m = min(mt, ma);
        nt = m*T[i];
        na = m*A[i];
    }
    
    return true;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    T = vl(N); A = vl(N);
    rep(i, N){ cin >> T[i] >> A[i];};
    reverse(T.begin(), T.end());
    reverse(A.begin(), A.end());
    
    ll z = T[0]+A[0];
    ll l = 1, r = (1e18+z-1)/z;
    while(abs(l-r)>1){
        ll mid = (l+r)/2;
        if(ok(mid*z)) r = mid;
        else l = mid;
    }
    ll ans = 0;
    if(ok(l*z)) ans = l*z;
    else ans = r*z;
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 256
# Your code here!

n = gets.to_i
judges = readlines
c_0 = 0
c_1 = 0
c_2 = 0
c_3 = 0

judges.each do |judge| 
    if judge.start_with?("AC")
        c_0 += 1
    elsif judge.start_with?("WA")
        c_1 += 1
    elsif judge.start_with?("TLE")
        c_2 += 1
    elsif judge.start_with?("RE")
        c_3 += 1
    end
end
puts "AC x #{c_0}"
puts "WA x #{c_1}"
puts "TLE x #{c_2}"
puts "RE x #{c_3}"

Measured memory_bytes: 22560
import java.math.BigInteger;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] map = new int[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextInt();
		}
		
		BigInteger key = BigInteger.ONE;
		for (int i = 0; i < N; i++) {
			key = key.multiply(BigInteger.valueOf(map[i]));
		}
		key = key.subtract(BigInteger.ONE);
		
		BigInteger ans = BigInteger.ZERO;
		for (int j = 0; j < N; j++) {
			ans = ans.add(key.remainder(BigInteger.valueOf(map[j])));
		}
		System.out.println(ans);
	}
	
}

Measured memory_bytes: 44588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+5;
int a[MAXN]={0};
map<int,int>mm;
int vis[MAXN]={0};
int solve(int n,int maxnum){
    if(vis[n])
        return 0;
    for(int i=n;i<=maxnum;i+=n)
        vis[i]=1;
    if(mm[n]>1)
        return 0;
    return 1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mm[a[i]]++;
    }
    sort(a,a+n);
    int ans = 0;
    for(int i=0;i<n;i++)
        ans+=solve(a[i],a[n-1]);
    cout <<ans << endl;
    return 0;
}


Measured memory_bytes: 16688
n, k = [int(i) for i in input().split(' ')]
counts = [0 for i in range(n)]
ans = 0
for i in range(k):
  input()
  for owner in [int(o) for o in input().split(' ')]:
    counts[owner - 1] = 1
for i in range(n):
  if counts[i] == 0:
    ans += 1 
print(ans)

Measured memory_bytes: 9196
#include <stdio.h>

int main()
{
    int k, a, b;
    scanf("%d %d %d", &k, &a, &b);
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k == 0){
      cout<<"OK\n";
      return;;
    }
  }
  cout<<"NG\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


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

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

int main(){
    int a[3],b[3],c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    a[0] = 0;
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(c[i][j] != a[i] + b[j]){
                cout << "No";
                return 0;
            }
        }
    }

    cout << "Yes";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 2019;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 200000 + 5;
const long long int MINN = 2e5 + 5;
const long long int inf = 1e7;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 10050;
const int MAXN = 105;
int binsearch(int lo, int hi){
    while(lo<hi){
        int mid=(lo+hi)/2;
        if((mid))   // check(mid)
            hi=mid;
        else
            lo=mid+1;
    }
    return lo;
}
ll power(ll x,ll y){
    ll res=1;
    while(y>0){
      if(y&1) res=((res*x));

      y/=2;
      x=((x*x));
    }
    return res;
}

int main(){
    FAST
    
    string t;
    cin>>t;
    for(int i=0;i<t.length();i++){
        if(t[i]=='?') t[i]='D';
    }
    cout<<t;
    return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
#define re register
int main()
{
	re int n,N;
	scanf("%d",&n);
	for(N=1;N<=n;N<<=1);N>>=1;
	if(n==N){puts("No");return 0;}
	if(N==2)N=4;
	puts("Yes");
	for(re int i=1;i<N-1;i++)printf("%d %d\n%d %d\n",i,i+1,i+n,i+n+1);
	printf("%d %d\n",N-1,n+1);
	for(re int i=N;i+1<=n;i+=2)
	{
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,i+1,i+1,1,1,i+n,i+n,i+n+1);
	}
	if(!(n&1))
	{
		if((n&-n)==2)
		printf("%d %d\n",n^(n&-n)^1,n),
		printf("%d %d\n",n&-n,2*n);
		else
		printf("%d %d\n",(n^(n&-n))+n,n),
		printf("%d %d\n",n&-n,2*n);
	}
}

Measured memory_bytes: 2560
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

void exec() {
	vector<int> col;
	vector<int> num;
	col.push_back(-1);
	num.push_back(0);
	int n;
	cin >> n;
	if(n==0)exit(0);
	for(int i=0;i<n;i++){
		int v;
		cin >> v;
		if(col.back()==v){
			num.back()++;
		}
		else
		{
			col.push_back(v);
			num.push_back(1);
		}
	}
	col.push_back(-2);
	num.push_back(0);
	int ret=0;
	for(int i=1;i<col.size()-1;i++){
		if(num[i]==1){
			for(int k=1;k<=3;k++){
				int i0=i-1,i1=i+1;
				int m=1;
				if(col[i-1]==k){
					m+=num[i-1];
					i0=i-2;
				}
				if(col[i+1]==k){
					m+=num[i+1];
					i1=i+2;
				}
				if(m>=4){
					while(col[i0]==col[i1]){
						int s=num[i0]+num[i1];
						if(s<4)break;
						m+=s;
						i0--;
						i1++;
					}
					ret=max(ret,m);
				}
			}
		}
		else{
			if(num[i-1]==3)
			{
				int m=4;
				if(col[i-2]==col[i]&&num[i-2]+num[i]-1>=4){
					m+=num[i-2]+num[i]-1;
					int i0=i-3;
					int i1=i+1;
					while(col[i0]==col[i1]){
						int s=num[i0]+num[i1];
						if(s<4)break;
						m+=s;
						i0--;
						i1++;
					}
				}
				ret=max(ret,m);
			}
			if(num[i+1]==3){
				int m=4;
				if(col[i]==col[i+2]&&num[i]-1+num[i+2]>=4){
					m+=num[i]-1+num[i+2];
					int i0=i-1;
					int i1=i+3;
					while(col[i0]==col[i1]){
						int s=num[i0]+num[i1];
						if(s<4)break;
						m+=s;
						i0--;
						i1++;
					}
				}
				ret=max(ret,m);
			}
		}
	}
	cout << n-ret << endl;
}
int main(){
	while(1)exec();
}

Measured memory_bytes: 1304
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  string s;
  int ccount=0,scount=0;
  cin>>s;
  if(s[0]=='A' and s[s.size()-1]!='C' and s[1]>='a' and s[1]<='z'){
    for(int i=1;i<s.size();i++){
      if(s[i]=='C')
        ccount++;
      if(s[i]>='a' and s[i]<='z')
        scount++;
    }
    if(ccount==1 and scount==s.size()-2)
      cout<<"AC"<<endl;
    else
      cout<<"WA"<<endl;
  }
  else 
    cout<<"WA"<<endl;
}

Measured memory_bytes: 256
n = gets.to_i
input = []
c_1 = [".",",","!","?"," "]
c_2 = ["a","b","c"]
c_3 = ["d","e","f"]
c_4 = ["g","h","i"]
c_5 = ["j","k","l"]
c_6 = ["m","n","o"]
c_7 = ["p","q","r","s"]
c_8 = ["t","u","v"]
c_9 = ["w","x","y","z"]
n.times do 
	input.push(gets.to_s.chomp)
end
#a = input[0].chars
input.each do |tmp|
	tmp_s = []
	str = []
	tmp_c = "a"
	tmp.each_char do |c|
		if c != "0"
			tmp_s.push(c)
		#elsif tmp_c = c &&c == "0"
		elsif c == "0" && tmp_c != "0"
			tmp_ss = tmp_s.join("")
			tmp_cnt = tmp_ss.length
			#puts tmp_cnt
			tmp_c = tmp_c.to_i
			if  tmp_c == 7 || tmp_c == 9
				tmp_cnt %= 4
				tmp_cnt -= 1
				#puts tmp_cnt
				#print("tmp_cnt = ",tmp_cnt," tmp_c = ",tmp_c,"\n")
				if tmp_c == 7
					str.push(c_7[tmp_cnt])
				else
					str.push(c_9[tmp_cnt])
				end
			elsif tmp_c == 1
				tmp_cnt %= 5
				tmp_cnt -= 1
				str.push(c_1[tmp_cnt])
			else
				tmp_cnt %= 3
				tmp_cnt -= 1
				if tmp_c == 2
					str.push(c_2[tmp_cnt])
				elsif tmp_c == 3
					str.push(c_3[tmp_cnt])
				elsif tmp_c == 4
					str.push(c_4[tmp_cnt])
				elsif tmp_c == 5
					str.push(c_5[tmp_cnt])
				elsif tmp_c == 6
					str.push(c_6[tmp_cnt])
				elsif tmp_c == 8
					str.push(c_8[tmp_cnt])
				end
			end
			tmp_s = []
		end
		tmp_c = c
		#p tmp_ss
	end
	puts str.join("")
end

Measured memory_bytes: 8924
[a,b,c,d]=[int(input()) for i in range(1,4+1)]
a1 = d // 500
b1 = d// 100
c1 = d// 50
coun = 0
for i in range(0,min([a+1,a1+1])):
    a = 500*i
    if a == d:
        coun = coun +1
        break
    for j in range(0,min([b+1,b1+1-5*i])):
        s = a + 100*j
        if s == d :
            coun = coun +1
            break
        for k in range(0,min([c+1,c1+1-10*i-2*j])):
            v = s + 50*k
            if v == d :
                coun = coun+1
                break
print(coun)

Measured memory_bytes: 9092
#include <iostream>
#include<math.h>
using namespace std;
int main(void){
    int n,y,m,d;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>y>>m>>d;
        int b=0;
        for(int i=y+1;i<=999;i++){
            if((i%3)!=0)
                b=b+195;
            else {
                b=b+200;
            }
        }
       
       int a=0;
       if(y%3==0){
          a=(10-m)*20+(20-d+1);
       }
       else{
           a=(10-m)*20+(20-d+1);
           for(int i=m;i<10;i++){
               if(i%2!=0){
                   a=a-1;
               }
           }
           if(m%2==0)
           a=a-1;
       }
       b=b+a;
        cout<<b<<endl;
    }
    return 0;
}



Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>

using namespace std;

const int MAX = 110;

int main() {
	int N;
	cin >> N;
	int D[MAX];

	for (int i = 0; i < N ; i++) {
		cin >> D[i];
	}
	sort(D, D+N);
	int c = 0;
	for (int i = 0; i < N ; i++) {
		if(N%2==0)c=c+pow(-1,i+1)*D[i];
		else c=c+pow(-1,i)*D[i];
	}
	// int a =pow(-1,1);
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],T[N][N];

void tofree(){
  int i,j;
  for(i=0;i<N;i++)row[i]=col[i]=FREE;
  for(i=0;i<2*N-1;i++)dpos[i]=dneg[i]=FREE;
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(T[i][j]==1){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

int main(){
  int i,j,k,r,c;
  tofree();
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      T[i][j]=0;
    }}
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    T[r][c]=1;
  }
  putQueen(0);
  return 0;
}

  



Measured memory_bytes: 2112
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define M 2505
#define ll long long
#define reg register
struct D{
	int t,d;
};
int p,n,m,mark[M],cnt[M];
bool flag[M];
ll dis[M];
vector<D>edge[M];
vector<int>G[M];
queue<int>Q;
inline int Rd(){
	int num=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	do{
		num=num*10+c-'0';
		c=getchar();
	}while(c>='0'&&c<='9');
	return num;
}
int spfa(int st){
	Q.push(st);mark[st]=1;dis[st]=0;
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		mark[x]=0;
		if(cnt[x]>n)return -1;
		for(reg int i=0;i<edge[x].size();++i){
			int y=edge[x][i].t,d=edge[x][i].d;
			ll k=dis[x]+d-p;
			if(dis[y]<k&&flag[y]){
				dis[y]=k;cnt[y]=cnt[x]+1;
				if(!mark[y])Q.push(y),mark[y]=1;
			}else if(dis[y]==k&&flag[y]&&cnt[x]+1<cnt[y]){
				cnt[y]=cnt[x]+1;
				if(!mark[y])Q.push(y),mark[y]=1;
			}
		}
	}
	if(dis[n]==-1e9)return -1;
	return max(0ll,dis[n]);
}
queue<int>Q1;
void Spfa(){
	Q1.push(n);flag[n]=1;
	while(!Q1.empty()){
		int x=Q1.front();Q1.pop();
		for(reg int i=0;i<G[x].size();++i){
			int y=G[x][i];
			if(!flag[y])Q1.push(y),flag[y]=1;
		}
	}
}
int main(){
	n=Rd();m=Rd();p=Rd();
	for(int i=1;i<=n;++i)dis[i]=-1e9;
	for(reg int i=1,u,v,d;i<=m;++i){
		u=Rd();v=Rd();d=Rd();
		edge[u].push_back((D){v,d});
		G[v].push_back(u);
	}
	Spfa();
	printf("%d",spfa(1));
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,x;
  cin >> n >> x;
  ll ans = 0;
  int p = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(a>x) ans+=a-x, a=x;
    if(p+a>x) ans+=p+a-x, a=x-p;
    p=a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,inc=0;
    cin>>n>>m;
    vector<int >a(n+1);
    for(int k,i=0;i<m;i++){
        cin>>k;
        a[k] = -1;
    }
    a[0] = 1;
    for(int k,i=1;i<n+1;i++){
        k=0;
        if(a[i]==-1)continue;
        if(i-1 >=0 ){
            if(a[i-1]!=-1)
            k=a[i-1];
        }
        if(i-2 >=0)
            if(a[i-2]!=-1)k=(k+a[i-2])%1000000007; 
        a[i] = k; 
    }
    cout<<a[n]<<endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
base = comb(5,3)
m, n = map(int, input().split())
if m > 1 and n > 1:
    ans = comb(n, 2) + comb(m, 2)
elif n > 1:
    ans = comb(n, 2) 
elif m > 1:
    ans = comb(m, 2)
else:
    ans = 0
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int T[SIZE];

int main()
{
	int n,C,K;
	scanf("%d %d %d",&n,&C,&K);
	for(int i=0;i<n;i++) scanf("%d",&T[i]);
	sort(T,T+n);
	int ret=0;
	for(int i=0;i<n;)
	{
		int f=i;
		for(;i<n&&i<f+C&&T[i]-T[f]<=K;i++);
		ret++;
		//printf("%d %d\n",f,i);
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std; 
#define rep(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1<<29;
const int MOD=1073741824;
#define pp pair<ll,ll>
#define ppi pair<int,int>
typedef long long int ll;
bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
////////////////////////////////////////////////////////////////////

int main(){
    int tc=1;
    // cin>>tc;
    while(tc--){
        int x;
        cin>>x;
        int ans;
        if(x<=599)ans=8;
        else if(x<=799)ans=7;
        else if(x<=999)ans=6;
        else if(x<=1199)ans=5;
        else if(x<=1399)ans=4;
        else if(x<=1599)ans=3;
        else if(x<=1799)ans=2;
        else ans=1;
        cout<<ans;
    }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n;
int main()
{
	cin>>n;
	while(n--)
	{
		char t;
		cin>>t;
		if(t=='Y')
		{
			cout<<"Four";
			return 0;
		}
	}
	cout<<"Three";
}

Measured memory_bytes: 256
use strict;
use warnings;
use feature 'say';
use Data::Dumper;

my $N = <>; chomp($N);
my $H = <>; chomp($H);
$H = [split(" ", $H)];
$H = [map {+{number => $_, edited => 0}} @$H];

while (1) {
    my $edited = 0;
    for (0..$N-2) {
        if ($H->[$_]{number} > $H->[$_+1]{number}) {
            unless ($H->[$_]{edited}) {
                $H->[$_]{number}--;
                $H->[$_]{edited} = 1;
                $edited = 1;
            }
            
        }
    }
    last unless $edited;
}

for (0..$N-2) {
    if ($H->[$_]{number} > $H->[$_+1]{number}) {say 'No';exit}
}

say 'Yes';

Measured memory_bytes: 44344
#include <cstdio>
int N;

int digit_sum(int num)
{
	int res = 0;
	while(num)
	{
		res += num % 10;
		num /= 10;
	}
	return res;
}

int main()
{
	scanf("%d", &N);
	puts((N % digit_sum(N)) ? "No" : "Yes");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string.h>
using ULL = unsigned long long;
using namespace std;

int main(){
  char S[12];
  cin>>S;
  int len=strlen(S);
  if(len%2==1){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<len-1;i+=2){
    if(!(S[i]=='h' && S[i+1]=='i')){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

int main(){
    int Q, L;
    /* 00.51sec 
    while(scanf("%d %d", &Q, &L) != EOF && Q > 0){
        deque<int> deq;
        for(int q, x; Q--;){
            scanf("%d %d", &q, &x);
            while(deq.size() > L) deq.pop_front();
            if(q == 0) deq.push_back(x);
            if(q == 1) deq.erase(deq.begin() + x - 1);
            if(q == 2) printf("%d\n", deq[x - 1]);
            if(q == 3) deq.erase(find(deq.begin(), deq.end(), x));
        }
        puts("end");
    }
    */
    while(scanf("%d %d", &Q, &L) != EOF && Q > 0){
        vector<int> vec;
        for(int q, x; Q--;){
            scanf("%d %d", &q, &x);
            while(vec.size() > L) vec.erase(vec.begin());
            if(q == 0) vec.push_back(x);
            if(q == 1) vec.erase(vec.begin() + x - 1);
            if(q == 2) printf("%d\n", vec[x - 1]);
            if(q == 3) vec.erase(find(vec.begin(), vec.end(), x));
        }
        puts("end");
    }
    return 0;
}

Measured memory_bytes: 1704
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

const ll MAX_N = 1000000;
ll segAdd[MAX_N*2-1], segMin[MAX_N*2-1];
ll size = 1;

void init(ll n){
  while(size<n) size*=2;
  REP(i,2*size-1) segAdd[i] = 0, segMin[i] = 0;
}

void add(ll a, ll b, ll x, ll k, ll l, ll r){
  if(r<=a||b<=l) return;
  if(a<=l&&r<=b){
    segAdd[k]+=x;
    return;
  }
  add(a,b,x,k*2+1,l,(l+r)/2);
  add(a,b,x,k*2+2,(l+r)/2,r);

  segMin[k] = min(segMin[k*2+1]+segAdd[k*2+1],segMin[k*2+2]+segAdd[k*2+2]);
}

ll getMin(ll a, ll b, ll k, ll l, ll r){
  if(r<=a||b<=l) return INF;
  if(a<=l&&r<=b) return segMin[k]+segAdd[k];

  ll left = getMin(a,b,k*2+1,l,(l+r)/2);
  ll right = getMin(a,b,k*2+2,(l+r)/2,r);
  return min(left,right)+segAdd[k];
}

int main(){
  ll n,q;
  cin >> n >> q;
  init(n);
  vector<ll> ans;
  REP(_,q){
    int i; cin >> i;
    if(!i){
      ll s,t,x; cin >> s >> t >> x;
      add(s,t+1,x,0,0,size);
    }else{
      ll s,t; cin >> s >> t;
      ans.push_back(getMin(s,t+1,0,0,size));
    }
  }
  for(ll a: ans) cout << a << endl;
  return 0;
}



Measured memory_bytes: 7920
#include <iostream>

using namespace std;

int main(){
    int n;
    while(cin >> n){
	int res = 0;
	for(int i = 0 ; i <= 9 ; i++){
	    for(int j = 0 ; j <= 9 ; j++){
		for(int k = 0 ; k <= 9 ; k++){
		    for(int l = 0 ; l <= 9 ; l++){
			if(i + j + k + l == n){
			    res++;
			}
		    }
		}
	    }
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
/*
AizuOnline A0162
Hamming Numbers
*/
#include <stdio.h>
#include <math.h>

long int count_3_5(long int x)
{      long int i;
       long int cnt;

       cnt = 0;
       for(i=1;i<=x;i*=3)
         cnt += (1+(int)(log(x/i)/log(5)));
       return(cnt);
}
long int hamming(long int x)
{      long int i;
       long int cnt;

       cnt = 0;
       for(i=1;i<=x;i*=2)
         cnt += count_3_5(x/i);
       return(cnt);
  
}

main()
{
             long int x,y;
             
             while(EOF != scanf("%ld ",&x) && x)
               {  scanf("%ld ",&y);
                 printf("%d\n",hamming(y)-hamming(x-1));
               }
return(0);
}

Measured memory_bytes: 0
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-09 19:32:35
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

template<typename T> void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

int main() {
  //ios_base::sync_with_stdio(false);
  //cin.tie(nullptr);

  int n; fastin(n); int64 k; fastin(k);
  vector<int64> a(n);
  for (int i = 0; i < n; ++i) {
    fastin(a[i]);
    --a[i];
  }

  vector<int64> sum(n + 1, 0LL);
  for (int i = 0; i < n; ++i) {
    sum[i + 1] = sum[i] + a[i];
    sum[i + 1] %= k;
  }
 
  map<int64, int> mp;
 
  int64 ans = 0;
 
  for (int i = 0; i < n + 1; ++i) {
    ans += mp[sum[i]];
    ++mp[sum[i]];
    if (i >= k - 1) {
      --mp[sum[i - k + 1]];
    }
  }  

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 15872