akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std ;

int main(){
	
	int n ;
	int x , y , b , p ;
	int c , d ;
	
	cin >> n ;
	for( int i=0 ; i<n ; i++ ){
		cin >> x >> y >> b >> p ;
		
		c = x*b + y*p ;
		if( b >= 5 && p >= 2 ) d = ( x*b + y*p ) * 80 / 100 ;
		else if( b >= 5 ) d = ( x*b + y*2 ) * 80 / 100 ;
		else if( p >= 2 ) d = ( x*5 + y*p ) * 80 / 100 ;
		else d = ( x*5 + y*2 ) * 80 / 100 ;
		
		if( c < d ) cout << c << endl ;
		else cout << d << endl ;
	}
	
return 0; 
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

/*
int lucas(int num){
  if(num == 0){
    return 2;
  }else if(num == 1){
    return 1;
  }else{
    return lucas(num - 1) + lucas(num - 2);
  }
}
*/

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

  long arr[100] = {0};
  arr[0] = 2;
  arr[1] = 1;
  for(int i = 2; n >= i; i++){
    arr[i] = arr[i-1] + arr[i-2];
  }

  cout << arr[n] << endl;
}


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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repd(i,n) for(ll i = (n); i >= 0; i--)
#define FOR(i,t,n) for(ll i = (t); i < (n); i++)
#define FORD(i,t,n) for(ll i = (n); i >= t; i--)
#define ALL(x) x.begin(),x.end()
#define asort(x) sort(ALL(x))

int main() {
    string S;
    int cnt = 0, res = 0;
    cin >> S;
    rep(i,S.size()) {
        if(S[i] == 'R') {
            cnt++;
            res = max(res,cnt);
        } else {
            cnt = 0;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

#define NOT_FOUND 0

int binarySearch(int);
int n,A[100000];
int main()
{
  int i,q,count=0,T[50000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
    if(binarySearch(T[i])==1) count++;
  }
  printf("%d\n",count);
  return 0;
}
int binarySearch(int key)
{
  int left=0,right=n,mid;
  while(left<right){
    mid = (left+right)/2;
    if(A[mid]==key){
      return 1;
    }
    else if(key<A[mid]){
      right = mid;
    }
    else left = mid+1;
  }
  return NOT_FOUND;
}

Measured memory_bytes: 1180
//
//M-SOLUTIONS 2020
//A
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int x;
    cin >> x;

    int ans = 0;
    if ((400 <= x) && (x < 600)) ans=8;
    else if ((600 <= x) && (x < 800)) ans=7;
    else if ((800 <= x) && (x < 1000)) ans=6;
    else if ((1000 <= x) && (x < 1200)) ans=5;
    else if ((1200 <= x) && (x < 1400)) ans=4;
    else if ((1400 <= x) && (x < 1600)) ans=3;
    else if ((1600 <= x) && (x < 1800)) ans=2;
    else if ((1800 <= x) && (x < 2000)) ans=1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
//#define int long long

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

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

    int n;
    while(cin >> n, n){
        vector<vector<int>> t(n, vector<int>(n+1, 0));
        REP(i, n) REP(j, n+1) cin >> t[i][j];

        vector<int> dp(1 << 16, INF);
        dp[0] = 0;
        for(int mask = 1; mask < (1 << n); mask++){
            REP(i, n) if(mask & (1 << i)){
                int sum = dp[mask ^ (1 << i)];
                int min_num = t[i][0];
                REP(j, n) if(i != j && mask & (1 << j)){
                    min_num = min(min_num, t[i][j+1]);
                }

                dp[mask] = min(dp[mask], sum + min_num);
            }
        }
        
        cout << dp[(1 << n) - 1] << endl;
    }
}



Measured memory_bytes: 3440
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct PriorityQueue(alias _fun, T) {
    import std.functional : binaryFun;
    import std.algorithm : swap;
    alias fun = binaryFun!_fun;

    ///
    this(T[] ts) {
        foreach (t; ts) enqueue(t);
    }

    ///
    PriorityQueue!(_fun, T) enqueue(T e) {
        if (this.tree.length == 0) this.tree.length = 1;
        if (this.tree.length == this.n) this.tree.length *= 2;
        this.tree[this.n] = e;
        auto i = this.n;
        this.n += 1;
        while (i) {
            auto j = (i-1)/2;
            if (fun(this.tree[i], this.tree[j])) {
                swap(this.tree[i], this.tree[j]);
                i = j;
            } else break;
        }
        return this;
    }

    alias insertFront = enqueue;
    alias insert = enqueue;

    ///
    T dequeue() {
        auto ret = this.tree[0];
        this.n -= 1;
        this.tree[0] = this.tree[this.n];
        this.tree = this.tree[0..$-1];
        size_t i;
        for (;;) {
            auto l = i*2+1;
            auto r = i*2+2;
            if (l >= this.n) break;
            size_t j;
            if (r >= this.n) {
                j = l;
            } else {
                j = fun(this.tree[r], this.tree[l]) ? r : l;
            }
            if (fun(this.tree[j], this.tree[i])) {
                swap(this.tree[i], this.tree[j]);
                i = j;
            } else break;
        }
        return ret;
    }

    ///
    @property
    T front() {
        return this.tree[0];
    }

    ///
    @property
    bool empty() {
        return this.n == 0;
    }

    ///
    void popFront() {
        this.dequeue();
    }

    alias removeFront = popFront;

    ///
    @property
    size_t length() {
        return this.n;
    }

private:
    size_t n;
    T[] tree;
}

///
PriorityQueue!(fun, T) priority_queue(alias fun, T)(T[] ts = []) {
    return PriorityQueue!(fun, T)(ts);
}

alias T = Tuple!(long, "t", long, "x", char, "st");
T[10^^5*4] TS;

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];

    foreach (i; 0..N) {
        auto stx = readln.split.to!(long[]);
        auto x = stx[2];
        TS[i] = T(stx[0]-x, x, 'S');
        TS[N+i] = T(stx[1]-x, x, 'T');
    }
    sort!"a.t < b.t"(TS[0..N*2]);

    size_t i;
    auto QQ = priority_queue!("a < b", long)();
    auto PP = priority_queue!("a < b", long)();
    foreach (_; 0..Q) {
        auto D = readln.chomp.to!long;

        while (i < N*2 && TS[i].t <= D) {
            if (TS[i].st == 'S') {
                QQ.enqueue(TS[i].x);
            } else {
                if (QQ.front == TS[i].x) {
                    QQ.dequeue();
                    while (!PP.empty && !QQ.empty && QQ.front == PP.front) {
                        PP.dequeue();
                        QQ.dequeue();
                    }
                } else {
                    PP.enqueue(TS[i].x);
                }
            }
            ++i;
        }

        if (QQ.empty) {
            writeln("-1");
        } else {
            writeln(QQ.front);
        }
    }
}

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

int main(int argc, const char * argv[])
{
    int a, b, c;
    cin >> a >> b >> c;
    
    int result = a + b + c;
    if (result == 17) {
        cout << "YES" << "\n";
    }
    else
    {
        cout << "NO" << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll mod = 1e9 + 7;
ll dp[3005][3005]; 
ll n, m; string s;
ll prefix[3005], r[3005];
int main(){
	fastio;
	ll n, m; cin >> n >> m;
	string s; cin >> s;
	reverse(s.begin(), s.end()); s.pb('0'); reverse(s.begin(), s.end());
	for (ll i = 1; i <= n; i++){
		r[i] = i; prefix[i] = prefix[i - 1] + (s[i] == '1');
	}
	for (ll i = 0; i < m; i++){
		ll u, v; cin >> u >> v; r[u] = max(r[u], v);
	}
	dp[0][0] = 1;
	for (ll i = 1; i <= n; i++){
		r[i] = max(r[i], r[i - 1]);
		if (prefix[r[i]] < r[i] - i + 1) dp[i][0] = dp[i - 1][0];
		for (ll j = 1; j <= i; j++){
			if (prefix[r[i]] - j < r[i] - i + 1) dp[i][j] = dp[i - 1][j];
			if (prefix[r[i]] - j >= 0) dp[i][j] += dp[i - 1][j - 1];
			if (dp[i][j] >= mod) dp[i][j] -= mod;
		}
	}
	cout << dp[n][prefix[n]] << endl;
}

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

string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int n, x, y;
    cin >> n >> x >> y;
    vector <int> ans(n, 0);

    for(int i = 1; i < n; i++) {
        for(int j = i+1; j <= n; j++) {
            // dist b/w i and j
            int dist = min(j - i, abs(x - i) + 1 + abs(y - j));
            ans[dist]++;
        }
    }
    for(int i = 1; i < n; i++) cout << ans[i] << '\n';
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
class Tree():
    def __init__(self):
        self.root = None
    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def print(self):
        print('', ' '.join(map(str, self.root.inwalk())))
        print('', ' '.join(map(str, self.root.prewalk())))

    def find(self, x, k):
        while x != None and k != x.key:
            if k < x.key:
                x = x.left
            else:
                x = x.right
        return x

class Node():
    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None

    def prewalk(self):
        ret = [self.key]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret

    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.key]
        if self.right:
            ret += self.right.inwalk()
        return ret

tree = Tree()
n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == "insert":
        tree.insert(int(com[1]))
    elif com[0] == "find":
        ans = tree.find(tree.root, int(com[1]))
        if ans != None:
            print("yes")
        else:
            print("no")
    else:
        tree.print()



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


#define itn int
#define LL long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(x) (x).begin(), (x) end()
#define sz(x) (int)((x).size())
#define REP(i,a,b) for(int i = a ; i <= b; i ++)

using namespace std;
inline int GetInt(){
	int x;
	scanf("%d" , &x);
	return x;
}
inline string GetString(void){
	char x[100005];
	scanf("%s",x); string s = x;
	return s;
}
void solve(){
	string a,b,c;
	cin >> a >> b >> c;
	if(a.back() == b[ 0 ] && b.back() == c[ 0 ]){
		cout <<"YES";
	}else{
		cout << "NO";
	}
}
int main(){

	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/

	int T = 1;
	while(T--){
		solve();
	}
	  	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int h,w;
	char c[100][100];
	cin>>h>>w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>c[i][j];
		}
	}
	for(int k=0; k<h; k++){
		for(int r=0; r<2; r++){
			for(int l=0; l<w; l++){
				cout<<c[k][l];
			}
			cout<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N = int(input())
    X = [None] * N
    l = list(input())
    Xc = 0
    for i in range(N):
        X[i] = int(l[i])
        Xc += X[i]

    if Xc == 0:
        [print(1) for i in range(N)]
    elif Xc == 1:
        d = X.index(1)
        ans1 = 0
        for j in range(N):
            if X[j]:
                ans1 += pow(2,N-1-j,Xc+1)
                ans1 %= Xc+1

        for j in range(N):
            if d == j:
                print(0)
            else:
                if d == N-1 or j == N-1:
                    print(2)
                else:
                    print(1)
    else:
        ans1 = 0
        ans2 = 0
        for j in range(N):
            if X[j]:
                ans1 += pow(2,N-1-j,Xc+1)
                ans1 %= Xc+1
                ans2 += pow(2,N-1-j,Xc-1)
                ans2 %= Xc-1

        for i in range(N):
            if X[i]:# 1->0
                ans = (ans2 - pow(2,N-1-i,Xc-1)) % (Xc-1)
            else:# 0->1
                ans = (ans1 + pow(2,N-1-i,Xc+1)) % (Xc+1)
            count = 1
            while ans > 0:
                tmp = str(bin(ans)).count('1')
                ans %= tmp
                count += 1
            print(count)

if __name__ == "__main__":
    main()


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b;
    cin >> a >> b;
    // 処理
    // 出力
    cout << ((a > b) ? (a - 1) : a) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <sstream>
#include <string>
#include <vector>

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

  size_t k;
  size_t n;

  std::cin >> k;
  std::cin >> n;

  std::vector<size_t> a;
  a.reserve(n);

  for (size_t i = 0; i < n; i++) {
    size_t tmp;
    std::cin >> tmp;
    a.push_back(tmp);
  }

  std::vector<size_t> d;
  d.reserve(n);

  for (size_t i = 0; i < a.size() - 1; i++) {
    d.push_back(a.at(i + 1) - a.at(i));
  }
  d.push_back(a.at(0) + k - a.back());


  size_t d_max = 0;
  for (size_t i = 0; i < d.size(); i++) {
    d_max = std::max(d_max, d.at(i));
  }

  std::cout << k - d_max << "\n";

  return 0;
}

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

vector<pair<long long int, long long int>> prime_factorize(long long int n){// (prime, power)'s vector
    
    vector<pair<long long int, long long int>> prime_power;
    for (long long int p=2; p*p<=n; p++) {
        if(n % p != 0) continue;// break and proceed to p+1

        int power = 0;
        while(n % p == 0){
            power += 1;
            n /= p;
        }
        prime_power.push_back(make_pair(p, power));
    }

    // n has been divided by all primes (with power) smaller than sqrt(n)
    if(n != 1){
        prime_power.push_back(make_pair(n, 1));
    }

    return prime_power;
}

int main(){
    long long int a, b;
    cin >> a >> b;

    int ap = prime_factorize(a).size();
    vector<int> a_primes(ap);
    for(int i=0; i<ap; i++){
        a_primes[i] = prime_factorize(a)[i].first;
    }

    int bp = prime_factorize(b).size();
    vector<int> b_primes(bp);
    for(int i=0; i<bp; i++){
        b_primes[i] = prime_factorize(b)[i].first;
    }

    vector<int> result;
    set_intersection(a_primes.begin(), a_primes.end(),
                     b_primes.begin(), b_primes.end(),
                     inserter(result, result.end()));
    
    cout << result.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll ca=0;
ll ans=0;
for(ll i=0; i<n; i++){
cin>>a[i];
ca+=a[i]-1;}
cout<<ca<<endl;}


Measured memory_bytes: 3572
#include <stdio.h>

int N,M,P[100100],D[100100];

int find(int x)
{
	if (x != P[x]){
		int r = P[x];
		P[x] = find(P[x]);
		D[x] += D[r];
	}
	return P[x];
}

int main()
{
	scanf ("%d %d",&N,&M);
	for (int i=1;i<=N;i++) P[i] = i;

	for (int i=0;i<M;i++){
		int l,r,d; scanf ("%d %d %d",&l,&r,&d);
		int L = find(l);
		int R = find(r);
		if (L != R){
			P[R] = L;
			D[R] = d + D[l] - D[r];
		}
		else{
			if (D[r] - D[l] != d){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
 
int main(){
  int su1[10],su2[10],n,keta,ai,aj,max,min;
  int isu[1000000];
  int i,j,k,f;
  int temp;
 
  while(1){
    scanf("%d %d",&n,&keta);
    if(n==0 && keta == 0) break;
    isu[0] = n;
    for(i=0;i<keta;i++){
      su1[i] = n%10;
      su2[i] = n%10;
      n /= 10;
    }
     
    for(i=1;i<100000;i++){
 
      for(j=0;j<keta;j++){
    for(k=keta-1;k>0;k--){
      if(su1[k]>su1[k-1]){
          temp=su1[k];
          su1[k]=su1[k-1];
          su1[k-1]=temp;
        }
        if(su2[k]<su2[k-1]){
          temp=su2[k];
          su2[k]=su2[k-1];
          su2[k-1]=temp;
        }
    }
      }
      max=0;
      min=0;
      for(j=0;j<keta;j++){
    max = (max*10)+su1[j];
    min = (min*10)+su2[j];
      }
      isu[i] = max-min;
      f=0;
      for(j=0;j<i;j++){
    if(i != j && isu[j] == isu[i]){
      aj = j;
      ai = i;
      f = 1;
    }
      }
      if(f==1) break;
      n=isu[i];
 
      for(j=0;j<keta;j++){
    su1[j] = n%10;
    su2[j] = n%10;
    n /= 10;
      }
    }
    printf("%d %d %d\n",aj,isu[aj],ai-aj);
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a; i<=b; ++i)

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
typedef vector<vector<int>> vv;
///-------------------------
const ll mod = 1e9+7;
int main()
{
    Phuong_; /// <3333
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum=0;
    for(int i=0; i<n; ++i){
        cin >> a[i];
        a[i]%=mod;
        sum= (sum +a[i]) % mod;
    }
    ll ans=0;
    for(int i=0; i<n; ++i){
        sum = (sum - a[i])% mod;
        if (sum<0) sum+=mod;
        ans += (sum*a[i]) % mod;
        ans%=mod;
    }
    cout << ans;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll n, m, X, Y; cin >> n >> m >> X >> Y;
  ll mx = X;
  ll my = Y;
  vector<ll> x(n);
  REP(i, n) {
    cin >> x[i];
    if(mx < x[i]) mx = x[i];
  }
  vector<ll> y(m);
  REP(i, m) {
    cin >> y[i];
    if(my > y[i]) my = y[i];
  }
  
  // ll ans = 0;
  bool ok = false;
  if(mx<my) ok = true;
  
  // cout << ans << endl;
  cout << (ok?"No War":"War") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,ans=0;
    cin >> n;
    ll v[n],c[n];
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    rep(i,n){
        if(v[i]-c[i]>0) ans+=v[i]-c[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# 入力
A,B=map(int,input().split())
S=input()

# A+1番目が'-'出ない場合は'No'
if S[A]!='-':
  print('No')
  exit()
else:
  for x in S[:A]:
    # 1文字目からA文字目までが数字であることを確認
    if x not in '0123456789':
      print('No')
      exit()
  
  for x in S[A+2:]:
    # A+2文字目から最後までが数字であることを確認
    if x not in '0123456789':
      print('No')
      exit()

# チェックに引っかからなければ形式を満たす文字列である
print('Yes')

Measured memory_bytes: 40708
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s; cin>>s;
    string t; cin>>t;
    vector<string>res;
    int index=0;
    for(int i=0;i<s.size();i++){
        bool flag=true;
        int temp=i;
        for(int j=0;j<t.size();j++){
            if(temp+j>(int)s.size()-1){flag=false;break;}
            if(s[temp+j]=='?')continue;
            else if(s[temp+j]==t[j])continue;
            else flag=false;
        }
        
        if(!flag)continue;
        cmax(index,i);
        string foo;
        for(int j=0;j<s.size();j++){
            if(j==index){
                foo+=t;
                rep(i,(int)t.size()-1)j++;
            }else if(s[j]=='?')foo.push_back('a');
            else
                foo.push_back(s[j]);
        }
        res.push_back(foo);
    }
    sort(all(res));
    if(res.size())cout<<res[0]<<endl;
    else cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;

ll N;
vector<ll> C;

const ll MOD = 1e9 + 7;
ll mod(ll x) {return x % MOD;}

void input() {
    cin >> N ;
    C.resize(N);
    for (auto& c : C)
        cin >> c;
}

ll solve() {
    vector<ll> dp(N, 1);
    vector<ll> prevs(200001, -1);
    dp[0] = 1;
    prevs[C[0]] = 0;
    for (ll i = 1; i < N; i++) {
        auto& prevci = prevs[C[i]];
        if (prevci >= 0 and prevci < i - 1) {
            dp[i] = mod(dp[i - 1] + dp[prevci]);
        } else {
            dp[i] = dp[i - 1];
        }
        cerr << dp[i] << endl;
        prevci = i;
    }
    return dp.back();
}

int main() {
    input();
    cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 5624
M,D = map(int,input().split())
ans = 0
for m in range(1,M+1):
    for d in range(1,D+1):
        d1 = d % 10
        d10 = d //10
        if d1 >= 2 and d10 >= 2 and d1*d10 == m:
            ans += 1
print(ans)

Measured memory_bytes: 2940
N , M , C = gets.split.map{|a| a.to_i}
B = gets.split.map{|a| a.to_i}
arr = Array.new(M)
count = 0

N.times do |i|

    arr = gets.split.map{|a| a.to_i}
    k = 0

    M.times do |j|
        k += arr[j] * B[j]
    end

    if k + C > 0
        count += 1
    end
end

puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

class Combination
{
public:

    vec fact, invfact;
    int MAX_N, mod;

    Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
        fact = vec(MAX_N + 1);
        invfact = vec(MAX_N + 1);
        fact[0] = 1;
        FOR(i, 1, MAX_N + 1){
            fact[i] = (fact[i - 1] * i) % mod;
        }
        invfact[MAX_N] = fastpow(fact[MAX_N], mod - 2, mod);
        IREP(i, MAX_N){
            invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
        }
    }

    int comb(int n, int r){
        if(r > n || r < 0 || n < 0) return 0;
        int a = fact[n];
        a = (a * invfact[r]) % mod;
        a = (a * invfact[n - r]) % mod;
        return a;
    }
};

signed main(){

    int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    mat dp(N + 1, vec(N + 1, 0));
    dp[A - 1][0] = 1;

    int mod = 1000000007;
    Combination Comb(N, mod);

    FOR(n, A, B + 1){
        REP(i, N + 1) dp[n][i] = dp[n - 1][i];
        REP(i, N + 1){
            int m = N - i;
            int c = 1;
            FOR(k, 1, m / n + 1){
                c *= Comb.comb(m - (k - 1) * n, n);
                c %= mod;
                if(C <= k && k <= D){
                    int tmp = (c * Comb.invfact[k]) % mod;
                    dp[n][i + n * k] += dp[n - 1][i] * tmp;
                    dp[n][i + n * k] %= mod;
                }
            }
        }
    }

    cout << dp[B][N];
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 8064
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t = input()
res = 0
te_log = []

def judg(te):
  if te == "r":
    return "p"
  if te == "s":
    return "r"
  if te == "p":
    return "s"

def score(te):
  if te == "r":
    return r
  if te == "s":
    return s
  if te == "p":
    return p
  
for i in range(n):
  if i+1 <= k:
    res += score(judg(t[i]))
    te_log.append(judg(t[i]))
    continue
  comp = t[i]
  no = te_log[i-k]
  me = judg(comp)
  if no == me:
    if i+1+k > n:
      te_log.append(comp)
    elif judg(t[i+k]) == comp:
      te_log.append(judg(judg(comp)))
    else:
      te_log.append(comp)
    continue
  res += score(me)
  te_log.append(me)

print(res)

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

int main() {
	int n;
	cin >> n;
	if (n == 2) {
		cout << -1 << endl;
	} else if (n % 2 == 0) {
		for (int i = 0; i < n / 2; i++) {
			for (int j = 0; j < n - 1; j++) {
				if (j) cout << ' ';
				cout << (i + j + 1) % n + 1;
			}
			cout << endl;
		}
		for (int i = n / 2; i < n; i++) {
			cout << (i + n / 2) % n + 1;
			for (int j = 1; j < n - 1; j++) {
				cout << ' ' << (i + j) % n + 1 + (j < n / 2 ? 0 : 1);
			}
			cout << endl;
		}
	} else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - 1; j++) {
				if (j) cout << ' ';
				cout << (i + j + 1) % n + 1;
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
 int x=0, maxmum=0;
 int n;
 string s;
cin>>n>>s;
 for(int i=0;i<n;i++){
   if(s[i]=='I'){
   x++;
    if (maxmum<x)
    maxmum=x;
}
 else
 x--; 
 
 }

cout<<maxmum;
    return 0;
}


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

const int N=2e5+20;

int n,a[N],f[N];
long long ans;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]),f[a[i]]++;

	for(int i=1;i<N;i++) ans+=1ll*f[i]*(f[i]-1)/2;
	for(int i=0;i<n;i++)
	{
		printf("%lld\n",ans-f[a[i]]+1);
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main()
{
    char s[27];
    cin >> s;
    int flag=1;
    for(int i=1; i<strlen(s); i++){
        for(int j=0; j<i; j++){
            if(s[i]==s[j]){
                flag=0;
                break;
            }
        }
        if(flag==0){
            break;
        }
    }
    if(flag==1){
        cout << "yes";
    }else{
        cout << "no";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

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

VI  WAcnt(N+1, 0);
vector<bool> AC(N+1, false);
rep(i, 0, M){
    int p; string S; cin >> p >> S;
    if (S == "AC") AC[p] = true;
    else if (!AC[p]) ++WAcnt[p];
}
i64 WA = 0;
rep(i, 1, N+1)
    if (AC[i]) WA += WAcnt[i];

cout << accumulate(ALL(AC), 0) << ' ' << WA << "\n";

}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   int a[3];
   rep(i,3)cin>>a[i];
   sort(a,a+3);
   cout << a[0] + a[1];
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

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


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

    ll A[N + 1];
    A[0] = 0;
    ll a;
    ll B[M + 1];
    B[0] = 0;
    ll b;
    REP(i, N){
        cin >> a;
        A[i] = A[i - 1] + a;
    }
    REP(j, M){
        cin >> b;
        B[j] = B[j - 1] + b;
    }

    ll ap = 0;
    ll bp = 0;
    ll ans;
    while(ap < N + 1 && A[ap] <= K){
        ap++;
    }
    if(ap >= N + 1 || A[ap] > K){
        ap--;
    }//cout << "ap: " << ap << endl;
    while(bp < M + 1 && B[bp] <= K - A[ap]){
        bp++;
    }
    if(bp >= M + 1 || A[ap] + B[bp] > K){
        bp--;
    }
    ans = ap + bp;//cout << "a ap: " << ap << ", bp: " << bp << endl;
    for(; ap > 0 && bp < M + 1;){
        ap--;
        while(bp < M + 1 && B[bp] <= K - A[ap]){
            bp++;
        }
        if(bp >= M + 1 || A[ap] + B[bp] > K){
            bp--;
        }
        if(ans < ap + bp){
            ans = ap + bp;//cout << "b ap: " << ap << ", bp: " << bp << endl;
        }
    }

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


Measured memory_bytes: 6760
n = gets.to_i
s = gets.chars

stack = []

n.times do |i|
  if s[i] == '('
    stack.push '('
  else
    if left_index = stack.rindex('(')
      create_stack = [')']
      (stack.length - left_index).times do |i|
        create_stack.push stack.pop
      end
      stack.push create_stack.reverse.join('')
    else
      stack.push ')'
    end
  end
end

stack.count(')').times do |i|
  right_index = stack.index(')')
  create_stack = ['(']
  (right_index+1).times do |j|
    create_stack.push stack.shift
  end
  stack.unshift create_stack.join('')
end

stack.count('(').times do |i|
  left_index = stack.rindex('(')
  create_stack = [')']
  (stack.length - left_index).times do |i|
    create_stack.push stack.pop
  end
  stack.push create_stack.reverse.join('')
end

puts stack.join('')

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

int main() {
	int n, r = 0; cin >> n;
	string S; cin >> S;
	for(int i = 1; i < n - 1; i++)
		if(S[i - 1] == 'A' && S[i] == 'B' && S[i + 1] == 'C')
			r++;
	cout << r;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for(int i = 0; i<=k; i++) {
    for(int j = 0; j<=k; j++) {
      if(i+j<=s && i+j>=s-k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int n;

#ifdef ONLINE_JUDGE
#define DEBUGMODE 0
#else
#define DEBUGMODE 1
#endif

#if DEBUGMODE
string ans;
int query_count = 0;

char query(int m) {
    query_count++;
    if (query_count > 210)
        cerr << "ERROR: QUERY LIMIT EXCEEDED" << endl;
    if (ans.empty()) {
        ans.resize(2*n, 'B');
        for (int i = 0; i < n; i++) ans[i] = 'R';
        mt19937 mt;
        for (int i = ans.size() - 1; i >= 1; i--) {
            uniform_int_distribution<int> dist(0, i-1);
            int j = dist(mt);
            swap(ans[i], ans[j]);
        }
        cerr << "generated answer: " << ans << endl;
    }
    int r = 0, b = 0;
    for (int i = 0; i < n; i++)
        if (ans[m+i-1] == 'R') r++; else b++;

    char ret = r > b ? 'R' : 'B';

    cerr << "?";
    for (int i = 0; i < n; i++) cerr << ' ' << m + i;
    cerr << endl;
    cerr << "returning " << ret << endl;

    return ret;
}

char query(vector<int> &q) {
    query_count++;
    if (query_count > 210)
        cerr << "ERROR: QUERY LIMIT EXCEEDED" << endl;
    if (ans.empty()) {
        ans.resize(2*n, 'B');
        for (int i = 0; i < n; i++) ans[i] = 'R';
    }
    int r = 0, b = 0;
    for (int x : q) if (ans[x-1] == 'R') r++; else b++;

    char ret = r > b ? 'R' : 'B';

    cerr << "?";
    for (int x : q) cerr << ' ' << x;
    cerr << endl;
    cerr << "returning " << ret << endl;

    return ret;
}

#else

char query(int m) {
    cout << "?";
    for (int i = 0; i < n; i++) cout << ' ' << m + i;
    cout << endl;
    string s; cin >> s;
    return s[0];
}

char query(vector<int> &q) {
    cout << "?";
    for (int x : q) cout << ' ' << x;
    cout << endl;
    string s; cin >> s;
    return s[0];
}

#endif


int main() {
    cin >> n;
    char ans[2*n+1];
    int lb = 1, ub = n+1;
    char L = query(1), R = query(n+1);
    while (ub - lb > 1) {
        int m = (lb + ub) / 2;
        char r = query(m);
        if (r == L) lb = m;
        else ub = m;
    }
    vector<int> q_in, q_out;
    for (int i = 1; i <= 2*n; i++)
        if (lb < i && i < lb + n) q_in.push_back(i);
        else if (i < lb || lb + n < i) q_out.push_back(i);
    ans[lb] = L; ans [lb + n] = R;
    cerr << q_in.size() << " " << q_out.size() << " size" << endl;
    q_in.push_back(-1);
    q_out.push_back(-1);
    for (int i = 1; i <= 2*n; i++) {
        if (i < lb || lb + n < i) {
            q_in.back() = i;
            ans[i] = query(q_in);
        } else if (lb < i && i < lb + n) {
            q_out.back() = i;
            ans[i] = query(q_out);
        }
    }
    cout << "! ";
    for (int i = 1; i <= 2*n; i++) cout << ans[i];
    cout << endl;
}


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

typedef long long LL;

const int N=200000;

int n,a[N+9];
LL m;
vector<int>p[N+9];

void into(){
  scanf("%d%lld",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
}

int fir[N+9],last[N+9],nxt[N+9];

void Get_nxt(){
  for (int i=1;i<=n;++i){
	if (!fir[a[i]]) fir[a[i]]=i;
	if (last[a[i]]) nxt[last[a[i]]]=i;
	last[a[i]]=i;
  }
  for (int i=1;i<=N;++i)
	if (fir[a[i]]) nxt[last[a[i]]]=fir[a[i]];
}

int vis[N+9],ans[N+9],ca;

void Get_ans(int p){
  for (int i=p;i<=n;++i)
	if (vis[a[i]]){
	  for (;ca&&vis[a[i]];--ca) vis[ans[ca]]=0;
	}else vis[ans[++ca]=a[i]]=1;
}

void Get_ans(){
  int cnt=0;
  for (int k=1;2333;){
	if (nxt[k]<=k) ++cnt;
	if ((k=nxt[k])==n) {++cnt;break;}
	++k;
  }
  m%=cnt;
  if (!m) return;
  for (int k=1;2333;){
	if (m==1) {Get_ans(k);return;}
	if (nxt[k]<=k) --m;
	k=nxt[k]+1;
  }
}

void work(){
  Get_nxt();
  Get_ans();
}

void outo(){
  for (int i=1;i<=ca;++i)
	printf("%d ",ans[i]);
  puts("");
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int H, N; cin >> H >> N;
    vector<int> A(N + 1), B(N + 1);
    for(int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i];
    }
    int dp[N + 1][H + 1];
    for(int i = 0; i <= N; i++) for(int j = 0; j <= H; j++) dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i = 1; i <= N; i++) dp[i][0] = B[i];
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= H; j++) {
            int value = (j + A[i] - 1) / A[i];
            dp[i][j] = min(dp[i - 1][j], B[i] * value);
            if(j > A[i]) dp[i][j] = min(dp[i - 1][j], dp[i][j - A[i]] + B[i]);
            //cout << dp[i][j] <<" ";
        }
        //cout << endl;
    }
    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 42716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x>=400 && x<=599)
    {
        cout<<8<<endl;
    }
    else if(x>=600 && x<=799)
        cout<<7<<endl;
    else if(x>=800 && x<=999)
        cout<<6<<endl;
    else if(x>=1000 && x<=1199)
        cout<<5<<endl;
    else if(x>=1200 && x<=1399)
        cout<<4<<endl;
    else if(x>=1400 && x<=1599)
        cout<<3<<endl;
    else if(x>=1600 && x<=1799)
        cout<<2<<endl;
    else if (x>=1800 && x<=1999)
        cout<<1<<endl;
    return 0;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
typedef vector<vector<int>> Mat;
const int inf = 1e9;
const int mod = 1e9 + 7;

int N, M, A, B, C, T;

Mat mulMatMat(const Mat& a, const Mat& b) {
    int n = a.size();
    int m = b[0].size();
    assert(a[0].size() == b.size());
    Mat c(n, V(m, 0));
    rep(i, n) {
        rep(j, m) {
            rep(k, a[0].size()) {
                (c[i][j] += a[i][k] * b[k][j]) %= M;
            }
        }
    }
    return c;
}

V mulMatVec(const Mat& a, const V& v) {
    int n = a.size();
    assert(a[0].size() == v.size());
    V c(n, 0);
    rep(i, n) {
        rep(j, a[0].size()) {
            (c[i] += a[i][j] * v[j]) %= M;
        }
    }
    return c;
}

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

    while (cin >> N >> M >> A >> B >> C >> T, N) {
        V s(N + 2);
        rep2(i, 1, N + 1) cin >> s[i];

        VV a(N + 2, V(N + 2));
        rep2(i, 1, N + 1) {
            a[i][i - 1] = A,    a[i][i] = B,    a[i][i + 1] = C;
        }

        for (; T > 0; T >>= 1) {
            if (T & 1) {
                s = mulMatVec(a, s);
            }
            a = mulMatMat(a, a);
        }

        rep2(i, 1, N + 1) {
            cout << (i != 1 ? " " : "") << s[i];
        }
        cout << endl;

    }
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second 
using namespace std;
typedef pair<int,int> PII; 
typedef long long ll;
const int P = 1e9+7;
const int N = 200010;
int a[N],a1,a2,n,m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 0;i<n;i++) scanf("%d",a+i);
	for(int i =0;i<n;i++){
		
		 a1=(a1+1ll*(a[i+1]-a[i])*(i+1)%P*(n-i-1)%P)%P;
	}
	for(int i = 0;i<m;i++) scanf("%d",a+i);
	for(int i= 0;i<m;i++){
	
		 a2=(a2+1ll*(a[i+1]-a[i])*(i+1)%P*(m-i-1)%P)%P;
	}
	//cout<<a1<<' '<<a2<<endl;
	int ans= (1ll*a1*a2%P+P)%P;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n;
  vi u(2);
  cin >> n >> u[0] >> u[1];
  u[0]--;
  u[1]--;
  vector<vi> g(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<vi> d(2, vi(n, -1));
  rep(k, 2) {
    queue<int> q;
    q.push(u[k]);
    d[k][u[k]] = 0;
    while(!q.empty()) {
      int i = q.front();
      q.pop();
      for(auto ni : g[i]) {
        if(d[k][ni] != -1) continue;
        d[k][ni] = d[k][i] + 1;
        q.push(ni);
      }
    }
  }
  int mx = 0;
  rep(i, n) if(d[0][i] < d[1][i]) mx = max(mx, d[1][i]);
  cout << mx - 1 << endl;
}

Measured memory_bytes: 7040
#include <stdio.h>

int main(void){

  int n,i;
  int max, min;
  long int sum = 0;

  scanf("%d",&n);
  int a[n];

  for(i=0; i<n; i++){
    if(i){scanf(" %d",&a[i]);}
    else {scanf("%d",&a[i]);}
  }

  /***** maximum value *****/
  max = a[0];
  for(i=0; i<n; i++){
    if(max <= a[i]){max = a[i];}
  }

  /***** minimum value *****/
  min = a[0];
  for(i=0; i<n; i++){
    if(min >= a[i]){min = a[i];}
  }

  /***** sum *****/
  for(i=0; i<n; i++){
    sum = sum + a[i];
  }

  /***** result *****/

  printf("%d %d %ld\n",min, max, sum);

  return 0;

}

Measured memory_bytes: 640