akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn dp(i: usize, s: &Vec<char>, pre: Vec<char>, cache: &mut Vec<HashMap<Vec<char>, i32>>) -> i32 {
    // println!("{}, {:?}", i, pre);
    if i == s.len() {        
        return 0;
    } else if i == s.len() + 1 {
        return std::i32::MIN;
    }

    if cache[i].contains_key(&pre) {
        return cache[i][&pre]
    }
    let mut max = std::i32::MIN;
    if (pre.len() != 1 || pre[0] != s[i]) {
        // 1文字入れる        
        let pre_new = vec![s[i]];
        let num = dp(i+1, s, pre_new, cache) + 1;
        if num > max {
            max = num;
        }
    }
    
    if (i < s.len() - 1 && (pre.len() != 2 || pre[0] != s[i] || pre[1] != s[i+1])) {
        // 2文字入れる
        let pre_new = vec![s[i], s[i+1]];
        let num = dp(i+2, s, pre_new, cache) + 1;
        if num > max {
            max = num;
        }
    }
    cache[i].insert(pre, max);
    max
}

fn main() {
    let s: String = input();
    let s: Vec<char> = s.chars().collect();
    let mut cache: Vec<HashMap<Vec<char>, i32>> = vec![HashMap::new(); 2 * 100_000];
    println!("{}", dp(0, &s, vec![], &mut cache));
}


Measured memory_bytes: 347900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

ll a, b, k;

int main(){

cin >> a >> b>> k;

if(b-a+1>=2*k){

rep(i, 0, k-1){
cout << a+i << endl;
}
rep1(i, k-1, 0){
cout << b-i<< endl;
}
}

else {
    rep(i, a, b){
    cout << i << endl;
    }

}


return 0;}


Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <algorithm>
    #include <map>
    using namespace std;
     
    int main(void){
      int N;
      cin >> N;
      vector<pair<long long, long long>> vs(N);
      for(int i = 0; i < N; i++){
        cin >> vs.at(i).first >> vs.at(i).second;
      }
      sort(vs.begin(), vs.end());
     
      int ans = 1;
      long long edge = vs.at(0).first + vs.at(0).second;
      for(int i = 1; i < N; i++){
        long long right_edge = vs.at(i).first + vs.at(i).second;
        long long left_edge = vs.at(i).first - vs.at(i).second;
        if(edge > right_edge){
          edge = right_edge;
          continue;
        }else if(edge <= left_edge){
          ans++;
          edge = right_edge;
        }
      }
     
      cout << ans << endl;
    }

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string s;
    cin >> s;
    unordered_map<char, int> m;
    bool ok = true;
    for(auto c: s){
        if(m[c])
            ok = false;
        else
            m[c]++;
    }
    cout << (ok ? "yes" : "no") << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>

using namespace std;

inline void grade(int sum, int l, int h, char c) {
  if (sum >= l && sum < h) {
    printf("%c\n", c);
  }
}

int main() {
  int m, f, r;
  for (;;) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) {
      break;
    }

    const int sum = m + f;
    if (m == -1 || f == -1 || sum < 30) {
      printf("F\n");
      continue;
    }

    if (sum >= 30 && sum < 50) {
      if (r >= 50) {
        printf("C\n");
      } else {
        printf("D\n");
      }
    }
    grade(sum, 50, 65, 'C');
    grade(sum, 65, 80, 'B');
    grade(sum, 80, 201, 'A');
  }

  return 0;
}

Measured memory_bytes: 1148
#include<stdio.h>
main(){
  int A[4],B[4],a=0,b=0,i,j,k;
  while(scanf("%d %d %d %d %d %d %d %d",&A[0],&A[1],&A[2],&A[3],&B[0],&B[1],&B[2],&B[3]) != EOF){
    b=0;
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
	if(i != j){
	  if(A[i] == B[j]){
	    b++;
	  }
	}
      }
    }
    a=0;
    for(k=0;k<4;k++){
      if(A[k] == B[k]){
	a++;
      }
    }
    printf("%d %d\n",a,b);
  }
  return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=300050;
ll n,c[maxn],s[maxn],ans[maxn];
bool calc(ll x,ll y)
{
	if(s[x]>=x*y) return true;
	return false;
}
int main()
{
	read(n);
	F(i,1,n)
	{
		int x;read(x);
		c[x]++;
		s[c[x]]++;
	}
	for(int i=1;i<=n;i++) s[i]+=s[i-1];
	int t=0;
	for(int i=n;i>=1;i--)
	{
		while(t<n&&calc(t+1,i)) t++;
		ans[i]=t;
	}
	for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 7936
s = input()
k = int(input())

from itertools import groupby

n=len(s)
cnt =0

gp = groupby(s)

Keys=[]
values=[]
for key,value in gp:
    Keys.append(key)
    values.append(len(list(value)))

if len(Keys)==1:
    print(values[0]*k//2)
    exit(0)

if k==1:
    for i in values:
        cnt+=i//2
    print(cnt)
    exit(0)

if k==2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        for i in range(len(values)-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (values[0]+values[-1])//2

    print(cnt)
    exit(0)

if k>2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        m=len(values)

        for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (k-1) * ((values[0]+values[-1])//2)

        for j in range(m):
            if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

        print(cnt)
        exit(0)

for i in values:
    if i>1:
        cnt += k*(i//2)


print(cnt)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

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

int factorization(int n){
    int fac_ans = 1.0;
    for(int i=1;i<=n;i++) fac_ans *= i;
    return fac_ans;
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 100000000;


int main() {
    int64_t n,q,ans=0;
    cin >> n;

    vector<int> a(n);
    vector<int> num(100005,0);
    rep(i,n){
        cin >> a[i];
        num[a[i]]++;
        ans += a[i];
    }

    cin >> q;
    vector<int> b(q);
    vector<int> c(q);
    rep(i,q) cin >> b[i] >> c[i];

    rep(i,q){
        ans += (c[i]-b[i])*num[b[i]];
        cout << ans  << endl;
        num[c[i]] += num[b[i]];
        num[b[i]] = 0;
    }

}


Measured memory_bytes: 4836
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.Random;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMakingTriangle solver = new BMakingTriangle();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMakingTriangle {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);

            Util.safeSort(a);

            int answer = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    for (int k = j + 1; k < n; k++) {
                        if (a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k])
                            answer++;
                    }
                }
            }

            out.println(answer);
        }

    }

    static class Util {
        public static void safeSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}



Measured memory_bytes: 26044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	string S; cin >> S;
	int L = S.size();
	stack<char> T;

	for (int i = 0; i < L; i++) {
		if (!T.empty() && T.top() == 'S' && S[i] == 'T') T.pop();
		else T.push(S[i]);
	}

	cout << T.size() << endl;

	return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int s=0,n;
	cin>>n;
	int num[n];
	int b[100005];
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		if(temp>100000)
			s++;
		else
			b[temp]++;
	}
	for(int i=0;i<=100000;i++)
		if(b[i]!=0&&b[i]!=i)
			if(b[i]>i)
				s+=b[i]-i;
			else
				s+=b[i];
	cout<<s;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back

const ll mod = 1000000007;

int main() {
	int N, L;
	int sum = 0;
	cin >> N >> L;
	
	int minabs = 10000;
	int min = 10000;
	for (int i = 1; i <= N; i++) {
		int a = L + i - 1;
		sum += a;
		if (abs(a) < minabs) {
			minabs = abs(a);
			min = a;
		}
	}

	cout << sum - min << endl;
	return 0;
}

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

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

	int l, r;
	int lmax = 0;
	int rmin = 100001;
	for (int i = 0; i < m; ++i) {
		cin >> l >> r;
		if (lmax < l) {
			lmax = l;
		}
		if (r < rmin) {
			rmin = r;
		}
	}

	int result = rmin - lmax + 1;
	if (result < 0) {
		result = 0;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; ll m; cin >> n >> m;
	vector<ll> v;
	ll k = sqrt(m);
	for (int i = 1; i <= k; i++) {
		if (m%i == 0) {
			v.push_back(i);
			v.push_back(m / i);
		}
	}
	ll out = 1;
	rep(i, (int)v.size()) {
		if (v[i] * n <= m) {
			out = max(out, v[i]);
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)
ans = A[0]
i = 1
count = 1

for _ in range(1,N-1):
  ans += A[i]
  count += 1
  if count%2 != 0:
    i += 1

print(ans)

Measured memory_bytes: 31356
use std::io;
use std::io::prelude::*;
use std::io::BufReader;

fn main() {
    let mut count: [i32; 4] = [0, 0, 0, 0];
    let f = BufReader::new(io::stdin());
    for x in f.split(b'\n').skip(1) {
        let i = match &x.unwrap()[..] {
            b"AC" => 0,
            b"WA" => 1,
            b"TLE" => 2,
            _ => 3,
        };
        count[i] += 1;
    }
    for (s, c) in "AC WA TLE RE".split(' ').zip(&count) {
        println!("{} x {}", s, c);
    }
}


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) sum = sum + (long) (n + 1 - i) * i;
        for (int i = 0; i < n - 1; i++) {
            int u = sc.nextInt(); int v = sc.nextInt();
            int min = Math.min(u, v); int max = Math.max(u, v);
            sum = sum - (long) min * (n - max + 1);
        }
        out.println(sum);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 55060
n = int(input())
a_list = []
for i in range(n):
    a_list.append(int(input()))
next = a_list[0]
log = [0]*n
log[0] = 1
count = 1
for i in range(n):
    if next == 2:
        print(count)
        break
    if log[next-1] == 1:
        print(-1)
        break
    else:
        log[next-1] = 1
    next = a_list[next-1]
    count += 1

Measured memory_bytes: 7852
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return deque(lis[:now+1] + [item] + lis[now+1:])

res = K - sum(cut)
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(list(length), list(a))
  length.pop()

print(math.ceil(length.popleft()[0]))

Measured memory_bytes: 59208
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    if (A < B) {
        if (A < C) {
            if (C < B) {
                printf("Yes");
                return 0;
            } 
        }
    }
    else if(B < A) {
        if (B < C) {
            if (C < A) {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  ll a,b,k;cin>>a>>b>>k;
  if(a>=k){
    a-=k;
  }else{
    k-=a;
    a=0;
    if(b>=k){
      b-=k;
    }else{
      b=0;
    }
  }
  cout << a << " "<< b << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019


n = input()
arr = []
for i in range(n):
    xi, yi, hi = map(int, raw_input().split())
    arr.append((xi, yi, hi))

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            if arr[k][2] > 0:
                H = abs(arr[k][0]-cx)+abs(arr[k][1]-cy) + arr[k][2]
                break
        flag = 0
        for k in range(n):
            if arr[k][2] != max(H - abs(arr[k][0]-cx) - abs(arr[k][1]-cy), 0):
                flag = 1
                break
        if flag == 0:
            print cx, cy, H


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

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] < 0) {
      cnt++;
      a[i] *= -1;
    }
  }

  sort(a, a + N);
  if (cnt & 1) {
    cout << accumulate(a + 1, a + N, 0LL) - a[0] << endl;
  } else {
    cout << accumulate(a, a + N, 0LL) << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    string rgb(3, ' ');
    cin >> rgb[0] >> rgb[1] >> rgb[2];
    int i = stoi(rgb);
    if (i % 4 == 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

int main()
{
	int a, b;
	while (cin >> a >> b)
	{
		if (a < b) swap(a, b);
		int A = a; int B = b;
		while (1)
		{
			a -= (a / b)*b;
			if (a == 0) break;
			swap(a, b);
		}
		cout << b << " " << A / b*B << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int mo = 1e9 + 7;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

const int N = 25005;

const int M = 405;

int n, k, m, a[N];
int la[N], ed[N], d[N], d0;
ll f[N][M], g[N][M], s[M], s2[M];
int cnt[N], st, en;

ll ans;

ll fac(int n) {
	ll s = 1;
	fo(i, 1, n) s = s * i % mo;
	return s;
}

int main() {
	scanf("%d %d %d", &n, &k, &m);
	fo(i, 1, m) scanf("%d", &a[i]);

	ans = ksm(k, n - m) * (n - m + 1) % mo;

	fo(i, 1, m) {
		la[i] = ed[a[i]];
		ed[a[i]] = i;
	}
	int l = 1, r = 0;
	fo(i, 1, m) {
		while(l <= r && d[l] <= i - k) l ++;
		while(l <= r && la[d[r]] <= la[i]) r --;
		d[++ r] = i;
		if(la[d[l]] <= i - k) {
			pp("%lld\n", ans);
			return 0;
		}
	}
	fo(i, 1, m) {
		if(cnt[a[i]]) break;
		st = i; cnt[a[i]] ++;
	}

	fo(i, 1, k) cnt[i] = 0;
	fd(i, m, 1) {
		if(cnt[a[i]]) break;
		en = m - i + 1; cnt[a[i]] ++;
	}

	if(st == m) {
		ll ans = fac(k) * ksm(fac(k - m) % mo, mo - 2) % mo * ksm(k, n - m) % mo * (n - m + 1) % mo;
		f[0][0] = 1;
		fo(i, 1, n) {
			s[0] = f[i - 1][0];
			fo(j, 1, k) {
				s[j] = f[i - 1][j] + s[j - 1];
				s2[j] = g[i - 1][j] + s2[j - 1];
			}
			fo(j, 1, k) {
				f[i][j] = s[k - 1] - s[j - 1] + f[i - 1][j - 1] * (k - j + 1);
				f[i][j] %= mo;
				g[i][j] = s2[k - 1] - s2[j - 1] + g[i - 1][j - 1] * (k - j + 1);
				g[i][j] %= mo;
				if(j >= m) g[i][j] = (g[i][j] + f[i][j]) % mo;
			}
		}
		fo(j, 1, k - 1) ans = (ans - g[n][j] + mo) % mo;
		pp("%lld\n", ans * ksm(fac(k) * ksm(fac(k - m), mo - 2) % mo, mo - 2) % mo);
		return 0;
	}

	f[0][st] = 1;
	fo(i, 1, n - m + 1) {
		fo(j, 1, k) s[j] = f[i - 1][j] + s[j - 1];
		fo(j, 1, k) {
			f[i][j] = s[k - 1] - s[j - 1] + f[i - 1][j - 1] * (k - j + 1);
			f[i][j] %= mo;
		}
	}
	g[0][en] = 1;
	fo(i, 1, n - m + 1) {
		fo(j, 1, k) s[j] = g[i - 1][j] + s[j - 1];
		fo(j, 1, k) {
			g[i][j] = s[k - 1] - s[j - 1] + g[i - 1][j - 1] * (k - j + 1);
			g[i][j] %= mo;
		}
	}
	fo(i, 1, n - m + 1) {
		ll sf = 0, sg = 0;
		fo(j, 1, k - 1) sf = (sf + f[i - 1][j]) % mo, sg = (sg + g[n - (i + m) + 1][j]) % mo;
		ans = (ans - sf * sg % mo + mo) % mo;
	}
	pp("%lld\n", ans);
}

Measured memory_bytes: 158464
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  cout << min((b / a), c);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 1001001001;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    ll ans = 0;
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        ans += x-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//ROADTOBLUE
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


#define ull unsigned ll
// #define endl '\n'
#define mp make_pair
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define DO(x) for(int i = 1; i <= x; i++){ solve(i); }
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
#define M_PI 3.14159265358979323846
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }


const long long MAXN = 1e9;
const int SIZE = 2e5 + 5;  //are u sure ?
const int MOD = 1e9 + 7;


void solve(int CASE) {
	int have = 0;
	int sum = 15;
	for(int i = 1; i <= 5; i++) {
		int n; cin >> n;
		have += n;
	}	cout << sum - have << endl;
}


int main(){
	speedhack()
	// int IT; cin >> IT;
	int IT = 1;
	DO(IT);
	return 0;
}

Measured memory_bytes: 3652
# ABC065C - Reconciled? (ARC076C)
def factorial_mod(x: int) -> int:
    MOD = 10 ** 9 + 7  # change the value if needed
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    n, m = min(n, m), max(n, m)
    dif = m - n
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial_mod(n) ** 2 * 2) % MOD  # n == m -> (n!)^2 * 2
        else:  # sandwich (DMD or MDM)
            ans = (factorial_mod(n) ** 2 * m) % MOD  # n + 1 == m -> (n!)^2 * m
        print(ans)


if __name__ == "__main__":
    main()

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

int main(){
  string s;
  cin >> s;
  
  if((s[0] == s[1]) && (s[1] == s[2])){
    cout << "Yes" << endl;
  }else if((s[1] == s[2]) && (s[2] == s[3])){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; ll K; cin>>N>>K;
  vector<int> A(N, 0), seq(N, -1);
  vector<int> pos;
  REP(i,N) {
    int v; cin>>v; A[i] = v - 1;
  }
  int cur = 0;
  int ans = 0;
  seq[cur] = 0;
  pos.push_back(0);
  for(ll step = 1; ; step++) {
      cur = A[cur];
      if(step == K) {
	ans = cur;
	break;
      }
      if(seq[cur] >= 0) {
	//	cout << "OK" " " << seq[cur] << " " << step << endl;
	ll cnt = K - (ll)seq[cur];
	cnt = cnt % (ll)(step - seq[cur]);
	cnt += seq[cur];
	ans = pos[(int)cnt];
	break;
      }
      seq[cur] = step;
      pos.push_back(cur);
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5464
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long r1,r2,c1,c2,f[1010101],g[1010101];
long long pw(long long a,long long b)
{
	long long rt=1;
	while(b)
	{
		if(b&1)
		{
			rt*=a;
			rt%=md;
		}
		b/=2;
		a*=a;
		a%=md;
	}
	return rt;
}
long long js(long long x,long long y)
{
	memset(g,0,sizeof(g));
	memset(f,0,sizeof(f));
	g[0]=x+1;
	f[1]=x+1;
	for(int i=2;i<=y+1;i++)
	{
		f[i]=f[i-1]*(x+i)%md*pw(i,md-2)%md;
	}
	for(int i=1;i<=y;i++)
	{
		g[i]=(g[i-1]+f[i+1])%md;
	}
	return g[y];
}
int main()
{
	cin>>r1>>c1>>r2>>c2;
	cout<<(js(r2,c2)-js(r1-1,c2)-js(r2,c1-1)+js(r1-1,c1-1)+md)%md<<endl;
	return 0;
}

Measured memory_bytes: 16000
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    ll now = 10;
    while(now<=n){
        ans += n/now;
        now*=5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int s[2]={0},i,t,n;
	for(i=0;i<8;s[i/4]+=t,i++)scanf("%d",&t);
	printf("%d\n",s[0]>s[1]?s[0]:s[1]);
	return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int h = sc.nextInt();
    	int w = sc.nextInt();
    	int n = sc.nextInt();
    	int cnt = 1;
    	sc.close();
    	int t = Math.max(h, w);
    	while(n > (t * cnt)){
    		cnt++;
    	}
    	System.out.println(cnt);
    }
}

Measured memory_bytes: 23764
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String a = scanner.nextLine();
        String b = scanner.nextLine();
        String c = scanner.nextLine();

        int count = 0;
        for (int i = 0; i < n; i++) {
            char chA = a.charAt(i);
            char chB = b.charAt(i);
            char chC = c.charAt(i);

            if (chA == chB && chB == chC) {
                // pass
            } else if (chA == chB || chB == chC || chA == chC) {
                count++;
            } else {
                count += 2;
            }
        }
        System.out.println(count);
    }
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int a, b, h;
    cin >> a >> b >> h;

    cout  << (h * (a+b))/2<< endl;
    return 0;
}   
/** atcoder **/


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

// main関数の外で宣言しないとメモリの関係でセグフォする.
ll w[110], v[110];
ll dp[110][155555];

int main(){
    int N;
    ll W;
    cin >> N >> W;
    for(int i=0; i<N; i++) cin >> w[i] >> v[i];

    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j+w[i] <= W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for(int i=0; i<=W; i++) ans = max(ans, dp[N][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 121856
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

void solve()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	bool isAlice[101] = { false };
	bool isBob[101] = { false };
	for (int i = A; i <= B; ++i)
	{
		isAlice[i] = true;
	}
	for (int i = C; i <= D; ++i)
	{
		isBob[i] = true;
	}
	int ans = 0;
	for (int i = 0; i <= 100; ++i)
	{
		if (isAlice[i] == true && isBob[i] == true)
		{
			++ans;
		}
	}
	if (ans > 0)
	{
		--ans;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
using namespace std;

bool comp(vector<ll>v1,vector<ll>v2)
{
    for(ll i=0;i<v1.size();i++)
    {
        if(v1[i]!=v2[i])
        return false;
    }
    return true;
}

ll factorial(ll n)
{
    ll ans=1;
    ll i=2;
    while(i<=n)
    {ans*=i;i++;}
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
      ll n,i;
      cin>>n;
      vector<ll>p(n),q(n);
      for(i=0;i<n;i++)cin>>p[i];
      for(i=0;i<n;i++)cin>>q[i];
      vector<ll>a=p;
      sort(a.begin(),a.end());
      ll cnt=1;
      ll ans1,ans2;
      ll t=factorial(n);
      while(t--)
      {
          if(comp(p,a)) ans1=cnt;
           if(comp(q,a)) ans2=cnt;
          cnt++;
          next_permutation(a.begin(),a.end());
      }
      cout<<abs(ans1-ans2);
      
    }
    
    return 0;
}


Measured memory_bytes: 256
n,c,k = gets.chomp.split(" ").map(&:to_i)
ans = 1
m = 1
s = n.times.map{gets.to_i}.sort
temp = s[0]
s[1..-1].each do |t|
  if temp+k >= t && m != c
    m += 1
  else
    ans += 1
    temp = t
    m = 1
  end
end
puts ans

Measured memory_bytes: 4656
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int nam = sc.nextInt();
      	Set<Integer> set = new HashSet<Integer>();
      		
 		for(int i = 0;i < nam ;i++){
        	set.add(sc.nextInt());
        }
      System.out.print(set.size());
    }
}

Measured memory_bytes: 21844
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
LL A[80];

LL ans = 0;

void solve(){
	LL money = 1000;
	for(int i=0;i<=N-2;i++){
		if(A[i]<A[i+1]){
			money = money/A[i]*A[i+1] + money%A[i];
		}
	}
	ans = money;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];

    solve();

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

Measured memory_bytes: 3192
package main

import (
	"fmt"
)

type Operation struct {
	y1, x1, y2, x2 int
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	ops := make([]Operation, 500 * 500)
	opsInd := 0
	a := make([][]int, h)
	for i := 0; i < h; i++ {
		a[i] = make([]int, w)
		for j := 0; j < w; j++ {
			fmt.Scan(&a[i][j])
			if j > 0 && a[i][j-1] % 2 == 1 {
				a[i][j-1]--
				a[i][j]++
				ops[opsInd] = Operation{i + 1, j, i + 1, j + 1}
				opsInd++
			}
		}
	}

	for i := 1; i < h; i++ {
		if a[i-1][w-1] % 2 == 1 {
			a[i-1][w-1]--
			a[i][w-1]++
			ops[opsInd] = Operation{i, w, i + 1, w}
			opsInd++
		}
	}

	ops = ops[:opsInd]
	fmt.Println(opsInd)
	for _, op := range ops {
		fmt.Println(op.y1, op.x1, op.y2, op.x2)
	}
}

Measured memory_bytes: 19456
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int ans = 0;
	if(c-(a-b) < 0){
		ans = 0;
	}else{
		ans = c-(a-b);
	}
	cout << ans;
	return 0;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n); // freq
    vector<int> c(n+1); // freq of a
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        a[x-1]++;
    }
    for (int x: a) c[x]++;

    int sum = n;
    int last = n;
    cout << last << "\n";
    int wasted = 0;
    for (int i = 2; i <= n; i++) {
        while (last > sum/i) {
            int best = min(last, sum/i);
            for (int j = last; j > best; j--) {
                wasted += c[j];
                sum -= wasted;
            }
            last = best;
        }
        cout << last << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 3200
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

counter = 0
now = 1
visit = [False] * n
visit[0] = True
while True:
    counter += 1
    if a[now - 1] == 2:
        print(counter)
        break
    elif visit[a[now - 1]-1] == True:
        print(-1)
        break
    else:
        visit[a[now - 1]-1] = True
    now = a[now - 1]


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

int main()
{
    long N;
    cin >> N;
    ll a[N];
    rep(i,N){
        cin >> a[i];
    }
    map<ll,long> m;
    rep(i,N){
        if(m.find(a[i])==m.end()){
            m[a[i]]=1;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 14336
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s,s1;
  cin>>s>>s1;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]!=s1[i])
    {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll ;

vector <ll> a[200010] ;
queue <ll> q ;
bool vis[200010] ;
ll dep[200010] ;

int main()
{
    ll n,m ;
    cin >> n >> m ;
    for (int i=0 ; i<m ; i++)
    {
        ll aa,bb ;
        cin >> aa >> bb ;
        a[aa].push_back(bb) ;
        a[bb].push_back(aa) ;
    }
    q.push(1) ;
    vis[1]=1 ;
    dep[1]=0 ;
    while (!q.empty())
    {
        ll x=q.front() ;
        q.pop() ;
        for (int i=0 ; i<a[x].size() ; i++)
        {
            if (vis[a[x][i]]==0)
            {
                if (a[x][i]==n && dep[x]==0)
                {
                    continue ;
                }
                vis[a[x][i]]=1 ;
                q.push(a[x][i]) ;
                dep[a[x][i]]=dep[x]+1 ;
            }
        }
    }
    if (dep[n]==2)
    {
        cout << "POSSIBLE" << endl ;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl ;
    }
    return 0;
}


Measured memory_bytes: 15336
#include<stdio.h>
#include<math.h>
 
int main(void){
    double x1, x2, y1, y2;
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
    printf("%lf", sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,d,x;
	cin>>n>>d>>x;
	for(int i=0;i<10;i++)
	{
	  x=x*n-d;
	  cout<<x<<endl;
	}
    return 0;
}  


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

using namespace std;

int main(){
    int N,K,l[51];
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>l[i];
    }
    sort(l,l+N,greater<int>());
    int ans=0;
    for(int i=0;i<K;i++){
        ans+=l[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
#define PI 3.14159265359
 
typedef struct{
    double x;
    double y;
}Point;
 
void kock(int, Point, Point);
 
main(){
    int n;
    Point p1 = { 0, 0 }, p2 = { 100, 0 };
 
    scanf("%d", &n);
 
    printf("%f %f\n", 0, 0);
    kock(n, p1, p2);
    printf("%f %f\n", (double)100, 0);
 
    return 0;
}
 
void kock(int n, Point p1, Point p2){
    Point s, u, t;
    if (n == 0) return;
 
    s.x = (2 * p1.x + p2.x) / 3;
    s.y = (2 * p1.y + p2.y) / 3;
    t.x = (p1.x + 2 * p2.x) / 3;
    t.y = (p1.y + 2 * p2.y) / 3;
    u.x = (t.x - s.x)*cos(PI / 3) - (t.y - s.y)*sin(PI / 3) + s.x;
    u.y = (t.x - s.x)*sin(PI / 3) + (t.y - s.y)*cos(PI / 3) + s.y;
 
    kock(n - 1, p1, s);
    printf("%f %f\n", s.x, s.y);
    kock(n - 1, s, u);
    printf("%f %f\n", u.x, u.y);
    kock(n - 1, u, t);
    printf("%f %f\n", t.x, t.y);
    kock(n - 1, t, p2);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
char s[N + 1];
int main()
{
	cin >> s + 1; 
	int len = strlen(s + 1);
	reverse(s + 1, s + len + 1);
	s[len + 1] = '0';
	s[len + 2] = '\0';
	ll cnt = 0, cur = 0;
	for (int i = 1; i <= len + 1; i++)
	{
		int val = s[i] -'0' + cur;
		cur = 0;
		if (i == len + 1)
		{
			cnt += val;
			break;
		}
		if (0 <= val && val <= 4)
		cnt += val;
		else if(6 <= val && val <= 9)
		{
			cur = 1;
			cnt += 10 - val;
		}
		else if (val == 10)
		cur = 1;
		else if (val == 5)
		{
			cnt += 5;
			if (s[i + 1] - '0' >= 5)
			cur = 1;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>

int a[1001][2001]={0};
int main() {
    int N, K;
    int x, y;
    char c;
    scanf("%d %d", &N, &K);
    int i,j;
    for(i=0;i<N;i++) {
        scanf("%d %d %c", &x, &y, &c);
        y%=2*K;
        if(c=='W')x+=K;
        if(y>=K){
            x+=K;
            y-=K;
        }
        x%=2*K;
        a[y][x]++;
        a[K][x]--;
        if(x<=K){
            a[y][x+K]--;
            a[K][x+K]++;
            if(y!=0){
                if(x!=K){
                    a[0][x+K]++;
                    a[y][x+K]--;
                    a[0][2*K]--;
                    a[y][2*K]++;
                }
                if(x!=0){
                    a[0][0]++;
                    a[y][0]--;
                    a[0][x]--;
                    a[y][x]++;
                }
            }
        }else{
            a[y][2*K]--;
            a[K][2*K]++;

            a[y][0]++;
            a[K][0]--;
            a[y][x-K]--;
            a[K][x-K]++;
            if(y!=0){
                a[0][x-K]++;
                a[y][x-K]--;
                a[0][x]--;
                a[y][x]++;
            }
        }
    }

    for(i=0;i<K;i++){
        for(j=0;j<=2*K;j++){
            a[i+1][j]+=a[i][j];
        }
    }
    for(i=0;i<=K;i++){
        for(j=0;j<2*K;j++){
            a[i][j+1]+=a[i][j];
        }
    }

    int ans=0;
    for(i=0;i<K;i++){
        for(j=0;j<2*K;j++){
            if(ans<a[i][j])ans=a[i][j];
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 7936
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    for(int i=0;i<m;i++){
        int k;
        cin >> k;
        s[i].resize(k);
        for(int j=0;j<k;j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(m);
    for(int i=0;i<m;i++){
        cin >> p[i];
    }

    int lb = (1 << n) - 1;
    int ans = 0;
    for(int i=0;i<=lb;i++){
        vector<int> sw(n);
        for(int j=0;j<n;j++){
            sw[j] = ((i >> j) & 1);
        }

        bool success = true;
        for(int j=0;j<m;j++){
            int cnt = 0;
            for(int k=0;k<s[j].size();k++){
                if(sw[s[j][k]]){
                    cnt++;
                }
            }
            if(cnt % 2 != p[j]){
                success = false;
            }
        }
        if(success){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pb                  push_back
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=INT_MIN,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n;cin>>n;
    int a[n],b[n];
    fo0(i,n){
        cin>>a[i];
        d=max(a[i],d);
        b[i]=d;
    }
    fo0(i,n){
        ans+=b[i]-a[i];
    }
    cout<<ans;

}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<fixed<<setprecision(3)<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 6924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll k; cin >> k;
    ll cnter = 0;
    while(b<=a){
        b*=2;
        cnter++;
    }
    while(c<=b){
        c*=2;
        cnter++;
    }
    if (cnter<=k) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616